SQL create table
The create table statement is used to create a table in the SQL database. and it involves naming the table also.
Defining tables and columns within the create table statement.
Syntax:
CREATE TABLE table_name(
column 1 datatype,
column 2 datatype,
column 3 datatype, N column datatype,
Primary key(column)
);
When we are using the keyword CREATE TABLE to the database to tell want to create a new table. The table must be the unique and non-repeated name and just we define to the database. and then brackets inside define the list of columns. In this case, you can list the column in the table.
Let take an example we are creating an employee table with Id as the primary key and NOT NULL are the constraint showing to creating records in the table.
CREATE TABLE Employee(
Id int not null,
Name varchar(20) not null,
Age int not null,
Dept varchar(25) not null,
Salary varchar(20) not null,
);
Then click execute or F5 key and then You can verify if you are created the table successfully. By looking at the message displayed menu by the SQL Server.
select * from Employee;
Id | Name | Age | Dept | salary |
---|