July 28, 2020 at 7:58 pm
Two tables A and B have the same structure and the same number of columns.
First column in both tables is IDENTITY ID.
The script below cause an error because ID.
INSERT INTO B
SELECT * FROM A
How to use "Except" to not select column "ID" from table A?
July 28, 2020 at 8:04 pm
There is no Except. You need to name your columns.
INSERT B (Col1, Col2)
SELECT Col1, Col2
FROM A
July 28, 2020 at 8:13 pm
To add to Phil's correct answer, if there are a lot of columns, open the Object Explorer window, locate the table you need the column names for, find the "columns" folder, click-hold-and-drag it onto the SSMS editor. That will pull all of the column names over and then you can just delete the column name(s) you don't need.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 29, 2020 at 8:11 am
I'd also ask what is the purpose for copying the same data to another table but with a new ID?
Far away is close at hand in the images of elsewhere.
Anon.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy