Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Is there any way to create a primary key when creating a new table with the Select Into statement ?? The table needs to have an autoincrement primary key. The table is dropped each time and then re-created with new data in a stored procedureThanksPete
royv
Constraint Violating Yak Guru
455 Posts
Posted - 2002-04-15 : 17:08:45
Not while doing the SELECT INTO, but if you alter the table and add a column with autoincrement, it should populate everything for you:SELECT*INT0 tblWhateverFROM tblWhatever2ALTER TABLE tblWhateverADD ID INT IDENTITY(1,1)*************************Just trying to get things done
kaus
Posting Yak Master
179 Posts
Posted - 2002-04-15 : 17:22:00
ThanksPete
Page47
Master Smack Fu Yak Hacker
2878 Posts
Posted - 2002-04-16 : 08:58:09
I hate to be the know-it-all-noobie here, but ...
use pubsgoselect identity(int,1,1) as OrderID, au_lnameinto #au_lname_descfrom authorsorder by au_lname descgoselect OrderID, au_lnamefrom #au_lname_descgo
... there is no need to add the column later, you can do it all in one shot.<O>