Insert into a table with only one identity column

Insert into a table with only one identity column

Post by Donna Chan » Tue, 12 Mar 2002 09:15:28



Is it possible to write an INSERT statement to add a row to a table with
just a single column which is an identity column ?

Thanks,
Donna.

 
 
 

Insert into a table with only one identity column

Post by lindawi » Tue, 12 Mar 2002 09:34:36


Donna,

create table i (c1 int identity)

insert i default values
insert i default values
insert i default values

select * from i
drop table i

c1
-----------
          1
          2
          3

Linda


Quote:> Is it possible to write an INSERT statement to add a row to a
table with
> just a single column which is an identity column ?

> Thanks,
> Donna.


 
 
 

Insert into a table with only one identity column

Post by [MS] Hai-Wei » Wed, 13 Mar 2002 12:54:24


Hi ,

You could use "set identity_insert ... on" to allow explicit values to be
inserted into the identity column of a table. For example:

SET IDENTITY_INSERT tablename ON
GO
INSERT INTO tablename(id) values(1)

This posting is provided 'AS IS' with no warranties, and confers no rights.

Regards,
Haiwei Xu