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
 Insert into a table with identity

Author  Topic 

vasu4us
Posting Yak Master

102 Posts

Posted - 2006-08-31 : 17:20:56
I have 2 tables with same structure.only difference is, TableA has key colum which is declared as identity starting from 1.

I want to insert data from TableB into TableA where TableB.Key is all null with TableA.Key starting from 9000001

when i try to do that iam getting an error
"An explicit value for the identity column in table 'lEADlOAN' can only be specified when a column list is used and IDENTITY_INSERT is ON.
"
even when I turned IDENTITY_INSERT ON for TableA

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-31 : 17:31:17
Post the code that you have tried.

Tara Kizer
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-01 : 03:43:41
I am not sure I am clear about what you want?

What is the purpose of updating TableA's key column with key from TableB when TableB's key is all NULL?

BTW, if you are getting error even after identity_insert is on, then you might not be specifying column list like,

insert into TableA(col1, col2) select col1, col2 from TableB


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

vasu4us
Posting Yak Master

102 Posts

Posted - 2006-09-01 : 14:37:47
hay thanks one prob was i was not specifing the col list in the select
and that identity column in tableA was also primary key
i droped the constraints and populated the TableB keycol with different set of ids
and it worked


sorry i may not be clear....but i solved the problem
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-09-01 : 14:50:06
quote:
Originally posted by vasu4us
...i droped the constraints...

Constraints can be very annoying.





CODO ERGO SUM
Go to Top of Page
   

- Advertisement -