Re: Exclude Identity Columns to copy rows?
From: Jacco Schalkwijk (NOSPAMjaccos_at_eurostop.co.uk)
Date: 05/06/04
- Next message: Bojidar Alexandrov: "Re: Query Attempt"
- Previous message: Uri Dimant: "Re: SQL Query"
- In reply to: Jim M: "Exclude Identity Columns to copy rows?"
- Next in thread: Jim M: "Re: Exclude Identity Columns to copy rows?"
- Reply: Jim M: "Re: Exclude Identity Columns to copy rows?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 6 May 2004 09:05:25 +0100
As Sohail says you have to include all the other columns, there is no such
thing in T-SQL as except <column name>. Explicitly specifying all the column
names in your insert statement is considered good coding practice though, it
can protect you from problems when the table changes. You can easily
generate the column list if you use Query Analyzer for SQL Server 2000. Just
open up the object browser with F8, find the table you want to insert into,
right click and choose Script Object to New Window As -> Insert. the only
thing you have to do then is remove the identity column from the list.
-- Jacco Schalkwijk SQL Server MVP "Jim M" <anonymouse@discussions.microsoft.com> wrote in message news:OIrpXWyMEHA.1484@tk2msftngp13.phx.gbl... > I want to use the following to copy a row in the same table that has 49 > columns.... > > INSERT INTO table (column1,column2...) SELECT column1,column2... FROM table > WHERE (something); > > Is there a way I could exclude just the identity column like.... > > INSERT INTO table SELECT [All field except ID] FROM table WHERE (something); > > Thanks in advance. > > Jim > >
- Next message: Bojidar Alexandrov: "Re: Query Attempt"
- Previous message: Uri Dimant: "Re: SQL Query"
- In reply to: Jim M: "Exclude Identity Columns to copy rows?"
- Next in thread: Jim M: "Re: Exclude Identity Columns to copy rows?"
- Reply: Jim M: "Re: Exclude Identity Columns to copy rows?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|