Friday, February 24, 2012

Identity column

Hi all,
Does anyone know if you can put an identity column into a table that
has been created by SELECT...INTO query, either at the same time as
your creating it or after?
Thanks alot!
RobIDENTITY() function.
"robken" <robin.kennedy@.hotmail.co.uk> wrote in message
news:1155311004.583704.305210@.h48g2000cwc.googlegroups.com...
> Hi all,
> Does anyone know if you can put an identity column into a table that
> has been created by SELECT...INTO query, either at the same time as
> your creating it or after?
> Thanks alot!
> Rob
>|||Sure - take a look at the IDENTITY function in BOL:
USE pubs
go
SELECT emp_id AS emp_num,
fname AS first,
minit AS middle,
lname AS last,
IDENTITY(smallint, 100, 1) AS job_num,
job_lvl AS job_level,
pub_id,
hire_date
INTO employees
FROM employee
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com|||And you might as well want to have a look at the OUTPUT clause, which is
new in SQL Server 2005.
"Mike C#" <xyz@.xyz.com> wrote in news:OWo1Y5VvGHA.356@.TK2MSFTNGP04.phx.gbl:
[vbcol=seagreen]
> IDENTITY() function.
> "robken" <robin.kennedy@.hotmail.co.uk> wrote in message
> news:1155311004.583704.305210@.h48g2000cwc.googlegroups.com...
Ole Kristian Bangs
MCT, MCDBA, MCDST, MCSE:Security, MCSE:Messaging, MCTS, MCITP|||Hi,
Looks like your question is to have the identity property available while
you do a SELECT * INTO or you need to use ALTER Table to
enable identity correct?
If your source table has an IDENTTY then automatically identity column by
itself. Incase if you need to add a new column to
your exiting table you can use below code;-
alter table newtable add colnew int identity(1,1)
Thanks
hari
SQL Server MVP
"robken" <robin.kennedy@.hotmail.co.uk> wrote in message
news:1155311004.583704.305210@.h48g2000cwc.googlegroups.com...
> Hi all,
> Does anyone know if you can put an identity column into a table that
> has been created by SELECT...INTO query, either at the same time as
> your creating it or after?
> Thanks alot!
> Rob
>

No comments:

Post a Comment