Create Table In SQL

CREATE TABLE:- CREATE table statement is used to create a table in the database.

SYNTAX:-

 CREATE TABLE table_name(
        column1 datatype,
        column2 datatype,
        column3 datatype,
        ...
);

CREATE TABLE is the keyword that tells the database what you want to do. Then the table name tells that by which name you want to create the table.
The column parameter specifies the names of the column of the table.
The Datatype parameter specifies the type of data the column can hold.

EXAMPLE:- The following example creates a table called student that contains six columns:
"studentID","Name","Email","Age","city","fees":

CREATE TABLE student1(
   student1ID nvarchar(255),
   Name nvarchar(255),
   Email nvarchar(255),
   Age nvarchar(255),
   city nvarchar(255),
   fees nvarchar(255)
);

The empty "student1" table will now look like this:

 student1IDNameEmail Age  city fees
      



SQL PRIMARY KEY WITH CREATE TABLE STATEMENT:-

The following query creates a PRIMARY KEY when the "Emp" table is created.

  CREATE TABLE Emp(
         EmpID nvarchar(255) NOT NULL PRIMARY KEY  IDENTITY(1,1),
         Name varchar(255),
         Email nvarchar(255),
         Age nvarchar(255) ,
         city nvarchar(255),
);
You can use the keyword identity as the data type to the column along with PRIMARY KEY constraint when creating the table. Here starting '1' means starting value and second '1' means the incrementing value.






Comments

Popular posts from this blog

ASP.NET Overview

SQL AND ,OR, NOT Operators

SQL Joins