TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Identity column in SQL-SERVER
Rakesh Kalluri
Apr 01
2015
Code
978
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
--Create Student
if object_id(
'Student'
)
is
null
create
table
Student(id tinyint identity(1,1) ,
Name
varchar
(20),Marks
int
)
--If we observe above Create table statement the Id column is identity column and its data type is tinyint.
We know that tinyint accepts 0
to
255 numbers range.
--insert data into Student table.
Declare
@start
int
=1
while (@start<=256)
begin
insert
into
Student(
Name
,Marks)
values
(
'Rakesh'
,500)
set
@start=@start+1
end
--In the above while loop we are trying to insert same record in 256 time. The identity column automatically supplied value. The 1-255 records gets inserted successfully.256 record get an error because of tinyint accepts 0-255 records only.
(1 row(s) affected)
(1 row(s) affected)
Identity column
SQL Language
SQL Server