How to Create a Table in SQL ?
Answer : The CREATE TABLE statement is used to create a new table in a database.
Syntax
The basic syntax of CREATE TABLE statement is as follows :
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype
);
CREATE TABLE : This is the keyword telling the database system what you want to do.
table_name : name of the table
column[1,2,3] : name of the column.
data_type : Type of data we want to store in the particular column.
Example :
CREATE TABLE Employees (
Employee_ID INT,
Employee_Name VARCHAR(100),
Salary DECIMAL(10,2)
);
Each column stores a specific type of value:
- Employee_ID → INT
Stores whole numbers (integers).
Example:101,102,103 - Employee_Name → VARCHAR(100)
Stores text/string values with a maximum length of 100 characters.
Example:'Anjali','Priya','Amit' - Salary → DECIMAL(10,2)
Stores numbers with decimal values. Here,10is the maximum total number of digits and2is the number of digits after the decimal point.
Example:50000.50,45000.75
Employees Table
| Employee_ID | Employee_Name | Salary |
|---|---|---|
| INT | VARCHAR(100) | DECIMAL(10,2) |