SQL statement to view the table columns and settings
Q) Let’s consider the database table City from the world MySQL database. What are the correct SQL statements to view the table columns and settings?
a) DESC City;
b) VIEW City;
c) DESCRIBE City;
d) SHOW City;
Choose the correct options.
Answer Explanation
The options b and d are NOT correct. The statements are not valid SQL statements.
They result in the following error.
mysql> VIEW City;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘VIEW City’ at line 1
Hence, options b and d are incorrect options.
Correct Answer
The options a and c are correct.
DESCRIBE statement is used to show the list of table column names and other settings. We can also use the short-form DESC for the command.
Syntax:
DESCRIBE <table_name>;
or
DESC <table_name>;
To view the City table columns and settings, we can use the following statements.
mysql> DESC City;
mysql> DESCRIBE City;
+————-+———-+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+————-+———-+——+—–+———+—————-+
| ID | int | NO | PRI | NULL | auto_increment |
| Name | char(35) | NO | | | |
| CountryCode | char(3) | NO | MUL | | |
| District | char(20) | NO | | | |
| Population | int | NO | | 0 | |
+————-+———-+——+—–+———+—————-+
5 rows in set (0.00 sec)
Hence, a and c are correct options.
—
MySQL Tutorials
MySQL Tutorials on this website:
https://www.testingdocs.com/mysql-tutorials-for-beginners/
For more information on MySQL Database: