How can I copy row(s) from table1 to table2 without conflict with
IDENTITY columns using SQL query.
If you want to let SQL Server assign new identity values during the insert,
simply specify a column list and omit the identity column. For example:
INSERT INTO dbo.table2(MyColumn)
SELECT MyColumn
FROM dbo.table1
If you want to include the identity column values from the source table,
specify IDENTITY_INSERT and include the identity column in the column list:
SET IDENTITY_INSERT dbo.table2 ON
INSERT INTO dbo.table2(MyIdentityColumn, MyColumn)
SELECT MyIdentityColumn, MyColumn
FROM dbo.table1
--
Hope this helps.
Dan Guzman
SQL Server MVP
"GTi" <tu****@gmail.comwrote in message
news:11**********************@c28g2000cwb.googlegr oups.com...
>I have two identical tables with one IDENTITY column and several other
columns.
I have tested the COPY * INTO table2 FROM table1 WHERE xx
but it requers that table2 does not exist.
TABLE2 is a history database of TABLE1
How can I copy row(s) from table1 to table2 without conflict with
IDENTITY columns using SQL query.
Or must I do this from a program (C# .NET)