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
 Does INSERT command returns?

Author  Topic 

mdanaci
Starting Member

2 Posts

Posted - 2009-09-16 : 15:32:56
Hi there;
I have a primary key named pk, name and surname fields.
I need to insert to my table names and surnames.
INSERT INTO People (name,surname) VALUES ('john','black');
I'm not giving pks database gives is auto. But my problem is i need to know the pk that my database gave. Because i have lots of dublicate records.
Is there any way to retrieve pk while inserting to table.
I hope you can understand me :(

mdanaci
Starting Member

2 Posts

Posted - 2009-09-16 : 16:20:49
OK i solved the problem. I'm retrieving it with "SELECT @@IDENTITY" command.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-16 : 22:29:35
note the different in
@@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT

refer to http://msdn.microsoft.com/en-us/library/ms187342.aspx


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

Go to Top of Page

april198474
Starting Member

11 Posts

Posted - 2009-09-21 : 23:27:10
quote:
Originally posted by mdanaci

Hi there;
I have a primary key named pk, name and surname fields.
I need to insert to my table names and surnames.
INSERT INTO People (name,surname) VALUES ('john','black');
I'm not giving pks database gives is auto. But my problem is i need to know the pk that my database gave. Because i have lots of dublicate records.
Is there any way to retrieve pk while inserting to table.
I hope you can understand me :(


that sounds good!
Go to Top of Page

april198474
Starting Member

11 Posts

Posted - 2009-09-22 : 00:47:22
good!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-22 : 03:45:50
quote:
Originally posted by april198474

good!!
--------------------------------
april

Free chat software for you


What is good?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

JCirocco
Constraint Violating Yak Guru

392 Posts

Posted - 2009-09-23 : 08:29:02
madhivanan, did you note all 5 posts (as of now) have the advertising tag line and their response makes no sense?


John

"The smoke monster is just the Others doing barbecue"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-23 : 09:01:36
quote:
Originally posted by JCirocco

madhivanan, did you note all 5 posts (as of now) have the advertising tag line and their response makes no sense?


John

"The smoke monster is just the Others doing barbecue"


Yes. I see now

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -