SQL Create Table

The table is a collection of rows and columns. when you create a table then column must be defined with the datatype.

Syntax:-


CREATE TABLE tableName(
field1 datatype, 
field2 datatype, 
field3 datatype, 
field4 datatype)

Example:-

Now we are creating an employees table


CREATE TABLE employees(
id INT NOT NULL, 
first_name varchar(255) NOT NULL, 
last_name varchar(255), 
email varchar(50) NOT NULL,
address varchar(255) NOT NULL,
PRIMARY KEY (id)  
) 

Now, after created successfully then check the result through


DESC employees

+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| id         | int(11)      | NO   | PRI | NULL    |       |
| first_name | varchar(255) | NO   |     | NULL    |       |
| last_name  | varchar(255) | YES  |     | NULL    |       |
| email      | varchar(50)  | NO   |     | NULL    |       |
| address    | varchar(255) | NO   |     | NULL    |       |
+------------+--------------+------+-----+---------+-------+
5 rows in set (0.06 sec)