create table sql server auto increment primary key
/* mysql server */CREATETABLE persons (
id intNOTNULLAUTO_INCREMENT,
colour varchar(191)NOTNULL,
created datetime,
modifed datetime);/* sql server IDENTITY*/CREATETABLE persons (
id intIDENTITY(1,1)PRIMARYKEY,
colour varchar(191)NOTNULL,
created datetime,
modifed datetime);INSERTINTO persons (colour, created, modified)VALUES('red','2022-08-05','2022-08-05'),VALUES('green','2022-08-05','2022-08-05'),VALUES('blue','2022-08-05','2022-08-05');
create table sql server auto increment primary key
/* mysql server */CREATETABLE persons (
id intNOTNULLAUTO_INCREMENT,
colour varchar(191)NOTNULL,
created datetime,
modifed datetime);/* sql server IDENTITY*/CREATETABLE persons (
id intIDENTITY(1,1)PRIMARYKEY,
colour varchar(191)NOTNULL,
created datetime,
modifed datetime);INSERTINTO persons (colour, created, modified)VALUES('red','2022-08-05','2022-08-05'),VALUES('green','2022-08-05','2022-08-05'),VALUES('blue','2022-08-05','2022-08-05');
-- using IDENTITY(x, y) to auto increment the value-- x -> start value, y -> steps to increaseCREATETABLE Colleges (
college_id INTIDENTITY(1,1),
college_code VARCHAR(20)NOTNULL,
college_name VARCHAR(50),CONSTRAINT CollegePK PRIMARYKEY(college_id));-- inserting record without college_idINSERTINTO Colleges(college_code, college_name)VALUES("ARD13","Star Public School");
-- using IDENTITY(x, y) to auto increment the value-- x -> start value, y -> steps to increaseCREATETABLE Colleges (
college_id INTIDENTITY(1,1),
college_code VARCHAR(20)NOTNULL,
college_name VARCHAR(50),CONSTRAINT CollegePK PRIMARYKEY(college_id));-- inserting record without college_idINSERTINTO Colleges(college_code, college_name)VALUES("ARD13","Star Public School");
/*
--Syntax for MySQL
MySQL uses the AUTO_INCREMENT keyword to perform an auto-increment feature.
By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record.
*/CREATETABLE Persons (
Personid intNOTNULLAUTO_INCREMENT,
LastName varchar(255)NOTNULL,
FirstName varchar(255),
Age int,PRIMARYKEY(Personid));/* Syntax for SQL Server: */CREATETABLE Persons (
Personid intIDENTITY(1,1)PRIMARYKEY,
LastName varchar(255)NOTNULL,
FirstName varchar(255),
Age int);/* Syntax for Oracle: */CREATE SEQUENCE seq_person
MINVALUE 1STARTWITH1
INCREMENT BY1
CACHE 10;
/*
--Syntax for MySQL
MySQL uses the AUTO_INCREMENT keyword to perform an auto-increment feature.
By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record.
*/CREATETABLE Persons (
Personid intNOTNULLAUTO_INCREMENT,
LastName varchar(255)NOTNULL,
FirstName varchar(255),
Age int,PRIMARYKEY(Personid));/* Syntax for SQL Server: */CREATETABLE Persons (
Personid intIDENTITY(1,1)PRIMARYKEY,
LastName varchar(255)NOTNULL,
FirstName varchar(255),
Age int);/* Syntax for Oracle: */CREATE SEQUENCE seq_person
MINVALUE 1STARTWITH1
INCREMENT BY1
CACHE 10;