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.
Author |
Topic |
jingjing28
Starting Member
9 Posts |
Posted - 2008-09-22 : 17:59:10
|
I am working on a table A which has the primary key B(int). I need to insert a new record into table A but having issue getting the next incremental value of the primary key. I tried to set the identity on, but it tells me that the table does not have identity, but I guess this is not an option.did anyone have similar issue before?Thanks. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 00:35:43
|
The best thing is to add a new identity column to table and set it as primary key.It will ensure sql automatically puts next incremental value for each insertion. |
|
|
jingjing28
Starting Member
9 Posts |
Posted - 2008-09-23 : 10:22:13
|
there is a vendor table, so I don't want to change the table. any other idea?Thanks. |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-09-23 : 10:36:34
|
Try to enable identity to ON on table properties for Primary key . |
|
|
jingjing28
Starting Member
9 Posts |
Posted - 2008-09-23 : 10:53:30
|
I tried this command but failed-SET IDENTITY_INSERT orheader ONhow to enable identity on primary key level?Thanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 11:35:46
|
quote: Originally posted by jingjing28 I tried this command but failed-SET IDENTITY_INSERT orheader ONhow to enable identity on primary key level?Thanks.
did you add a new identity column? You can enable identity insert only if you've an identity column in your table. |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-09-23 : 16:49:57
|
Right click table - Modify- Enable Identity |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-09-23 : 19:07:01
|
quote: Originally posted by jingjing28 there is a vendor table, so I don't want to change the table. any other idea?Thanks.
How about an example of what you are trying to do? What specifically is the problem -- you cannot insert values to the table because you need to generate a new PK, or after an INSERT you cannot tell what the PK of the newly inserted row is?- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
|
|
|