SQL CREATE TABLE Statement|Create sql table with identity

The CREATE TABLE statement is used to create a table in a database.

Syntax:
CREATE TABLE table_name
(
column_1 data_type(size),
column_2 data_type(size),
column_3 data_type(size),
);
Example:
CREATE TABLE State
(
StateName varchar(100),
CountryCode varchar(100),
CityCode varchar(255),
isCanceled bit default 0  not null
);
 
Select Table.
select * from state
SQL CREATE TABLE with Identity Statement.
Auto increment allows a unique number to be generated when a new record is inserted into a table.
By default starting value for AUTO_INCREMENT is 1.

Example:
CREATE TABLE StateNew
(
Id int identity(1,1),
StateName varchar(100),
CountryCode varchar(100),
CityCode varchar(255),
isCanceled bit default 0  not null
);
Insert Records.
insert into statenew (statename,countrycode,
citycode,iscanceled)values('TamilNadu','1','3',0)

Select Table.
select * from statenew

Result:

Post a Comment

0 Comments