In previous articles I explained Create Identity Column or Auto increment column in SQL Server, Reset identity column in SQL Server, SQL Query to get particular part of string, SQL Query to replace part of string, SQL Query to read xml file, SQL Query to get month wise, year wise data and many articles relating to SQL Server, jQuery, JavaScript. Now I will explain how to insert values into an identity column in SQL Server.
CREATE TABLE UserDtls
(
UserId int PRIMARY KEY IDENTITY,
UserName varchar(120),
Qualification varchar(50)
)
|
INSERT INTO UserDtls(UserId,UserName,Qualification) VALUES(1,'Suresh','B.Tech')
|
Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column in
table 'UserDtls' when IDENTITY_INSERT is set to OFF.
|
SET IDENTITY_INSERT UserDtls ON
INSERT INTO UserDtls(UserId,UserName,Qualification) VALUES(1,'Suresh','B.Tech')
INSERT INTO UserDtls(UserId,UserName,Qualification) VALUES(2,'Rohini','MSC')
SET IDENTITY_INSERT UserDtls OFF
|
---------------------------------------
(1 row(s) affected)
(1 row(s) affected)
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
Subscribe by RSS
Subscribe by Email
1 comments :
nice sir