Link to home
Start Free TrialLog in
Avatar of mrosier
mrosierFlag for United States of America

asked on

insert into SQL 2005 table

Hello! I am executing the following insert query:

insert into table1 select * from table2

If I get no errors and it completes successfully, can I assume all the imported records came in unchanged from table1? I tried to import table2 into table1 but I go the Identity error since I have a rownumber field in table1. I don't care which table it is though as long as both tables are combined. Can I expect that my records combined without issue in table2?
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

>can I assume all the imported records came in unchanged from table1?
yes

>I tried to import table2 into table1 but I go the Identity error since I have a rownumber field in table1
Then you're going to have to list all columns, except for the identity, that you're ok with new identity values.
Unfortunately there is no SELECT * (except the id column) syntax.

Using the * in an insert is not a best practice, as it is dependant on the schema of the two tables to be EXACTLY the same, and forces an insert on all columns.

>I don't care which table it is though as long as both tables are combined.
Ok.  Based on why you're asking another option is to create a view that UNIONs the two tables.
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrosier

ASKER

this worked perfectly, thank you!!