Identity Column in the SQL Table:
How it works in SQL table?
How Many Identity column can be created on the SQL table?
How to insert user defined value in the Identity column?
What will be the next value for the Identity column after the user defined value insertion in the table?
Solution:
Create table #temp --Create the temp table with identity column( A int identity(1,1), --identity column--B int Identity(10,10), -- we can not create two identity column on a able
C varchar(10)
)
--insert values into tableinsert into #temp(c) values ('a') insert into #temp(c) values ('b')insert into #temp(c) values ('c')
Select * from #temp
--set identity insert on ont the table so that we can insert a user defined value in the identity columnSET IDENTITY_INSERT #temp on insert into #temp(A,C) values (5,'d')
--set identity insert off on the table so that it will automatically insert the values in the identity column. the next value of the identity column will be the max value available in the identity column increment value.
SET IDENTITY_INSERT #temp offinsert
into #temp(c) values ('e')
Select * from #temp
--@IDENTITY can be used to find out the last inserted value into an identity column on a table.
Select @@IDENTITY
Comments
Post a Comment