SQL IDENTITY

--Create Students table.
Create table Students (id int Identity primary key,student varchar(40))
go
--Inserting values into products table.
Insert into students(student) values ('lizuwu')
Insert into students(student) values ('wuhaiyan')
Insert into students(student) values ('wudi')
go

--Create a gap in the identity values.\
delete students where student='wudi'
GO

select * from students
GO

--Attempt to insert an explicit ID value of 3;
--shoud return a warning.
insert into students(id,student) values(3,'xiaowudi')
GO

--set Identity_Insert to On.
set identity_insert students on
go

--attempt to insert an explicit id values of 3
insert into sutdents(student) values('xiaowudi');set @ID=@@identity;
go

select * from students
go

--drop students table
Drop table students
go

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章