Author |
Topic |
rohitmathur11
Yak Posting Veteran
77 Posts |
Posted - 2009-12-16 : 03:12:58
|
I am using sql server 2008 .. i want to import data from one database into another database .. i deleted data from second database ..and trying to import from first database ..in both database PK of all tables is set to identity column ... now during insert ...it is saying error in inserting read only column 'rec_num' .... how i can resolve this error ...? |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-12-16 : 05:44:57
|
Either SET IDENTITY_INSERT <TableName> ONOr give a fieldlist and exclude the identity field. |
 |
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-16 : 05:47:06
|
Don't forget to OFF After InsertSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
savior faire
Posting Yak Master
194 Posts |
Posted - 2009-12-31 : 15:07:22
|
I ran into this issue the other night, while going through a study guide. I searched the SQL Books Online and there is a command where you can reset the Identity settings, on the table. Meaning if the identity is specified as Identity(1,1), I forget the exact syntax, and data has already been added to the table, but you want to re-load, you can reset the values so that you start from the initial values.Sorry but I forget the command.Talk sense to a fool and he calls you foolish. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
savior faire
Posting Yak Master
194 Posts |
Posted - 2010-01-01 : 11:05:28
|
Tara, I forget the command. I needed to remove all entries in the table with the key as Identity. Then reload from an extracted source, and needed to retain the original key values.______________________________________________Talk sense to a fool and he calls you foolish. |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-01-01 : 11:50:40
|
http://www.sqlteam.com/article/understanding-identity-columnsEDIT: And please see what RickD has posted. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
|
rohitmathur11
Yak Posting Veteran
77 Posts |
Posted - 2010-01-18 : 09:08:36
|
In my production database PK is used as a identity column for all tables .. Now i need to import data from prod dtabase to another database.. i am using import wizard in sql server management studio..to import indintity column for each table we need to go to edit > sheck enable identity ... there are 200 tables ..Can we set identity ON or OFF in one sql statement for all tables ..or ..any other way ..any idea .. |
 |
|
Kristen
Test
22859 Posts |
Posted - 2010-01-18 : 09:34:05
|
"Can we set identity ON or OFF in one sql statement for all tables .."Not in the same database connection, no.You can doSET IDENTITY_INSERT TableA ONINSERT INTO TableA SELECT Col1, Col2, ... FROM OtherDatabase.dbo.ThatTableASET IDENTITY_INSERT TableA OFFSET IDENTITY_INSERT TableB ONINSERT INTO TableB SELECT Col1, Col2, ... FROM OtherDatabase.dbo.ThatTableBSET IDENTITY_INSERT TableB OFF... would that do? |
 |
|
|