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
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
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 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply