i)Which of the following is not a valid SQL command?
a. UPDATE
b. SHOW
c. SELECT
d. INSERT
e. All of the above
f. None of the above
ii)Which of the following commands list columns of a table in MS SQL?
a. DESCRIBE
b. DESC
c. EXEC SP_TABLE
d. EXEC SP_COLUMNS
e. All of the above.
f. None of the above.
The Correct Answer and Explanation is :
i) Which of the following is not a valid SQL command?
Answer: b. SHOW
Explanation:
In SQL, there are several types of commands used to interact with databases, such as SELECT, INSERT, UPDATE, etc. However, SHOW is not a standard SQL command for querying data or modifying a database. The SHOW command is typically used in some databases like MySQL to display information about database objects (e.g., tables, columns, indexes). For example:
SHOW TABLES;displays the list of tables in the current database in MySQL.SHOW COLUMNS FROM table_name;displays column information for a specific table.
But in standard SQL (which is implemented in systems like PostgreSQL, MS SQL Server, etc.), commands like SELECT, UPDATE, and INSERT are the ones used, while SHOW is not included as a standard command.
ii) Which of the following commands list columns of a table in MS SQL?
Answer: d. EXEC SP_COLUMNS
Explanation:
In MS SQL Server, to list the columns of a table, the correct command to use is EXEC SP_COLUMNS. This is a system stored procedure that returns metadata about the columns of a specified table, including column names, data types, and other properties.
Let’s break down the options:
- a. DESCRIBE: This is not a valid command in MS SQL Server. In MySQL,
DESCRIBE table_name;is used to list columns, but not in MS SQL. - b. DESC: Like
DESCRIBE, this is not a valid command in MS SQL Server. It is also commonly used in MySQL to get a similar result. - c. EXEC SP_TABLE: This is incorrect. While
SP_TABLEis a stored procedure in SQL Server, it is used for listing tables, not columns. - d. EXEC SP_COLUMNS: This is the correct command in MS SQL Server. It lists all columns in a table, including their types, sizes, and whether they are nullable.
- e. All of the above: Incorrect, as only
EXEC SP_COLUMNSis valid in MS SQL Server for this task. - f. None of the above: Incorrect, as
EXEC SP_COLUMNSis valid.
Thus, EXEC SP_COLUMNS is the right way to retrieve column details in MS SQL Server.