Reputation: 11
CREATE TABLE dreams (
dream_id INT PRIMARY KEY,
name VARCHAR (20),
type VARCHAR (10));
DESCRIBE dreams;
(SHOWS AN ERROR )
Upvotes: 0
Views: 1685
Reputation: 11602
How to DESCRIBE a TABLE in SQL
The more SQL standard confirm SQL query which uses information_schema
database and this views.
And less does the same as the non standard desc
MySQL's clause, which was mentioned by Pawan Tiwari answer.
Query
SELECT
information_schema.COLUMNS.COLUMN_NAME AS 'Field'
, information_schema.COLUMNS.COLUMN_TYPE AS 'Type'
, information_schema.COLUMNS.IS_NULLABLE AS 'Null'
, information_schema.COLUMNS.COLUMN_KEY AS 'Key'
, information_schema.COLUMNS.COLUMN_DEFAULT AS 'Default'
, information_schema.COLUMNS.EXTRA AS 'Extra'
FROM
information_schema.TABLES
INNER JOIN
information_schema.COLUMNS ON information_schema.TABLES.TABLE_NAME = information_schema.COLUMNS.TABLE_NAME
WHERE
information_schema.TABLES.TABLE_NAME = 'dreams'
Result
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| dream_id | int(11) | NO | PRI | | |
| name | varchar(20) | YES | | | |
| type | varchar(10) | YES | | | |
See demo
Upvotes: 0
Reputation: 537
mysql> desc constitution;
+-------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+----------------+
| id | int(2) | NO | PRI | NULL | auto_increment |
| constitution_name | varchar(300) | NO | | NULL | |
+-------------------+--------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
Please see the above example.
Upvotes: 1