It is used to create a new table in a database.
Syntax:
1 2 3 4 5 6 |
CREATE TABLE table_name ( col1 datatype, col2 datatype, col3 datatype, .... ); |
Understanding SQL datatypes:
Below is a table that lists common SQL data types and their descriptions:
Data Type | Description |
---|---|
CHAR(n) | Fixed-length string with a maximum length of n characters. |
VARCHAR(n) | Variable-length string with a maximum length of n characters. |
TEXT | Large variable-length string. |
INT | Integer value. |
BIGINT | Large integer value. |
SMALLINT | Small integer value. |
TINYINT | Tiny integer value. |
FLOAT | Floating-point number. |
DOUBLE | Double-precision floating-point number. |
DECIMAL | Exact decimal value. |
NUMERIC | Exact numeric value. |
DATE | Date value in the format YYYY-MM-DD . |
TIME | Time value in the format HH:MM:SS . |
DATETIME | Date and time value in the format YYYY-MM-DD HH:MM:SS . |
TIMESTAMP | Timestamp value. |
Note: The exact list of data types may vary depending on the database management system you are using. The data types listed above are commonly supported by most SQL implementations.
example of table :
1 2 3 4 5 6 |
CREATE TABLE cars ( id INT PRIMARY KEY, model VARCHAR(255) NOT NULL, color VARCHAR(255) NOT NULL, manufacturer_id INT NOT NULL ); |
above query will create car table with model, color and manufacturer as column
INT, VARCHAR are the datatype of those column representing integer and character respectively .