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)

SQL Create Table – Interview Questions

Q 1: What is CREATE TABLE used for?
Ans: It creates a new table inside a database.
Q 2: What is the basic syntax?
Ans: CREATE TABLE table_name (column datatype);
Q 3: Can constraints be added during table creation?
Ans: Yes, constraints like PRIMARY KEY and NOT NULL can be defined.
Q 4: What are columns in a table?
Ans: Columns represent fields that store specific types of data.
Q 5: Can a table be created without columns?
Ans: No, at least one column is required.

SQL Create Table – Objective Questions (MCQs)

Q1. Which SQL command is used to create a new table?






Q2. What is the correct syntax to create a table named students?






Q3. Which keyword is used to define columns in a CREATE TABLE statement?






Q4. CREATE TABLE belongs to which SQL category?






Q5. Which constraint ensures that a column cannot have NULL values?






Related SQL Create Table Topics