DESCRIBE command in SQL
The DESCRIBE (or DESC) command in SQL is used to display the structure of a table. It provides information about the columns in a table, including:
- Column Name: The name of each column.
- Data Type: The type of data stored in each column (e.g., VARCHAR, INT).
- Nullability: Whether the column allows NULL values or not (YES or NO).
- Key: Indicates if the column is part of a primary key or any other key (like PRI for primary key).
- Default: The default value for the column if no value is specified during insertion.
- Extra: Additional information like AUTO_INCREMENT.
SQL Syntax
DESCRIBE table_name;
Example: Create an Employees table.
SQL
CREATE TABLE Employees (
EmployeeID INT,
FirstName VARCHAR(20),
LastName VARCHAR(20),
Age int
); Describe the table by using the DESCRIBE command.
SQL
DESCRIBE Employees
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| EmployeeID | int | YES | NULL | ||
| FirstName | varchar(20) | YES | NULL | ||
| LastName | varchar(20) | YES | NULL | ||
| Age | int | YES | NULL |