SELECT * FROM ID having two column as where id is primary key and fname is the varhcar id | fname INSERT INTO ID VALUES ( IDENTITY (1,1) , 'ASA') when i insert the record into table getting error how can i insert the record into the table as identity
lalitkumar
Member
22 Points
71 Posts
identity in sql server
Nov 17, 2012 09:21 AM|LINK
dhol.gaurav
Contributor
4140 Points
751 Posts
Re: identity in sql server
Nov 17, 2012 09:25 AM|LINK
Hey,
Check below link it may help you into your problem
http://beyondrelational.com/modules/2/blogs/28/posts/10337/sql-server-how-do-i-insert-an-explicit-value-into-an-identity-column-how-do-i-update-the-value-of-an.aspx
let me know if any query
Gaurav Dhol
Skype ID : dhol.gaurav
If My Post contains helped you, Please Mark as Answer
urenjoy
Star
13465 Points
2022 Posts
Re: identity in sql server
Nov 17, 2012 09:30 AM|LINK
You can set Identity column while creating table then no need to insert in the column, it is auto-incremented.
INSERT INTO ID (fname) VALUES ( 'ASA')
lalitkumar
Member
22 Points
71 Posts
Re: identity in sql server
Nov 17, 2012 09:34 AM|LINK
how can i do it using the sp as i hade not made the identity column for the id
ramiramilu
All-Star
97859 Points
14494 Posts
Re: identity in sql server
Nov 17, 2012 03:15 PM|LINK
get the last value from ID column like this -
Select TOP 1 ID From Table Order by Desc and then store it in a variable, then increment it by 1 then use that variable ot insert into the new row....
thanks,
JumpStart
Shailendra S...
Member
551 Points
145 Posts
Re: identity in sql server
Nov 17, 2012 03:25 PM|LINK
is sp you need not to insert in id column.
after insertion just get the identiry after insertion by SELECT @@IDENTITY
www.techaray.com
Anil Srivast...
Member
442 Points
292 Posts
Re: identity in sql server
Nov 17, 2012 03:45 PM|LINK
Hi
run the following
1 by right clicking the database
2 new query
create table id(id int identity(1,1) primary key , fname varchar(50))
insert into id values('Lalit')
insert into id values('Anil')
select * from id
op
Member
48 Points
9 Posts
Re: identity in sql server
Nov 19, 2012 05:12 AM|LINK
create table tblName(id int identity(1,1) primary key , fname varchar(50))
insert into tblName values('Lalit')
select * from tblName