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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 insert values in an auto-identity column
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

bharatg
Starting Member

6 Posts

Posted - 04/04/2005 :  10:54:22  Show Profile
I'm a bit new to SQL Server, but here is the problem I am trying to get around:

1. I have lets say an Employee table where the emp_id is an identity column that is auto assigned by the db.
2. I wish to insert values into the tables, but sometimes I may wish to use the value of the emp_id that i supply while inserting (and sometimes not).

Is there any way in MS SQL to do this? For e.g. is it setup like a constraint that I can temporarily drop. I do not want to alter the table, so that option is ruled out.

Any other ways to do this (I know bcp is one of them that allows me to do this, but looking for ways in the db itself using SQL if possible)

Thanks,
Bharat

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 04/04/2005 :  11:06:07  Show Profile
You can use SET IDENTITY_INSERT = ON in order to do what you want.

SET IDENTITY_INSERT dbo.Employee ON
<Your Insert Commands>
SET IDENTITY_INSERT dbo.Employee OFF

Dustin Michaels
Go to Top of Page

mr_mist
Grunnio

United Kingdom
1870 Posts

Posted - 04/04/2005 :  11:06:21  Show Profile  Visit mr_mist's Homepage
Look up SET IDENTITY INSERT in books on-line.

-------
Moo. :)
Go to Top of Page

bharatg
Starting Member

6 Posts

Posted - 04/04/2005 :  11:11:09  Show Profile
Thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.13 seconds. Powered By: Snitz Forums 2000