Re: Exclude Identity Columns to copy rows?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Jacco Schalkwijk (NOSPAMjaccos_at_eurostop.co.uk)
Date: 05/06/04


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
>
>


Relevant Pages

  • Re: Code for ADO.NET: The Complete Reference
    ... It involves SQL Server 2000 and ... connect to a Database in SQL will not run and get the error. ... Jim ... website BUT when I go to the Osborne website and enter this ...
    (microsoft.public.dotnet.framework.adonet)
  • HELP: Dropped table column causes sp_addmergearticle to fail with replication
    ... I'm setting up merge replication on sql server 2000 sp3. ... there is no identity column in this table ... The article 'tkDPLRS' could not be added to the publication 'TEST1'. ...
    (microsoft.public.sqlserver.replication)
  • Re: How to insert auto increment?
    ... And there are no other column involved except IDENTITY column. ... single row will do the same thing). ... INSERT INTO tbl DEFAULT VALUES; ... State what version of SQL Server you are using and specify the content ...
    (microsoft.public.sqlserver.mseq)
  • Re: @@Identity
    ... How Does SQL Server Manage Identity Values? ... When you add a row to a table with an Identity column you don't include a ... A scope is a module -- a stored procedure, trigger, function, or ... > If you are inserting a row with your ADO.Net code that will increment the ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: cluster index and identity
    ... Hot spotting data gives the cache manager something to grab hold of. ... Clustering on a narrow unique key also has benefits, ... I do not use the identity column as my Primary Key. ... I support the Professional Association for SQL Server ...
    (microsoft.public.sqlserver.server)