SQL Server Auto Increment Column value in the table

We have learnt about the UNIQUE and Primary Key values for the columns in our previous blogs.

http://oracleappshelp.com/2020/04/22/sql-server-unique-not-null-constraint-in-table/ http://oracleappshelp.com/2020/04/23/sql-server-primary-key-foreign-key-constraints-in-the-table/

The Primary Key which is a UNIQUE field value needs to be inserted everytime when a record is inserted into the SQL Server table. To initiate the value to be generated automatically , we make the use of AUTO INCREMENT feature provided by SQL Server.

SQL Server Auto Increment Default value . The Automatic generation number will start with the value of 1 with the increment of 1 every time whenever a record is inserted.

CREATE TABLE oracleappshelpUsers
(
    UserId				 INT 				NOT NULL IDENTITY PRIMARY KEY,
    GivenName 			VARCHAR(128) 		NOT NULL,
    MiddelName 			VARCHAR(10)					,
    FamilyName 			VARCHAR(128) 		NOT NULL,
	Age 				INT 				CHECK (Age>=18),
	Status 				VARCHAR(20)			NOT NULL	DEFAULT 'NEW'	
)

SQL Server Auto Increment can be provided with the custom value for start of specified Sequence value and Increment value . The Automatic generation number will start with the value of 1000 with the increment of 1 every time whenever a record is inserted.

CREATE TABLE oracleappshelpUsers
(
    UserId				 INT 				NOT NULL IDENTITY(1000,1) PRIMARY KEY,
    GivenName 			VARCHAR(128) 		NOT NULL,
    MiddelName 			VARCHAR(10)					,
    FamilyName 			VARCHAR(128) 		NOT NULL,
	Age 				INT 				CHECK (Age>=18),
	Status 				VARCHAR(20)			NOT NULL	DEFAULT 'NEW'
)

Bookmark and Share