Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Quick Q

Author  Topic 

norty911
Starting Member

41 Posts

Posted - 2007-07-24 : 04:45:29
hey guys, how could you get the primary key field of a record you have just inserted into a table?

Many thanks

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-24 : 05:07:28
what is the datatype of the primary key?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-24 : 05:09:49
if you are using identity column you can use @@identity or scope_identity()


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

norty911
Starting Member

41 Posts

Posted - 2007-07-24 : 05:38:41
Thank you @@identity was exactly what I was looking for. Tell me are there any differences between @@identity and scope_identity()?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-24 : 05:41:04
Yes. Read the BOL for the detail answer


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-24 : 05:41:29
books OnLine = sql server help explains the difference quite nicly.


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-24 : 05:41:50


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -