Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query to change the column type

Status
Not open for further replies.

TMRO

Technical User
Jan 10, 2003
140
CA
hi all,

i need to write a query to change a column type from int to int identity (1,1)

How do I do that?

Thx
 
Alter table doesn't help here, you can't use ALTER TABLE to make a field identity.
If you want to see what EM does when you change this better script whole action and look in generated script, it creates a temporary table, add identity field, add all constraints, all keys and indexes, triggers etc. Insert all records from old table and then rename temp table to old one.

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
WOW, didn't know you couldn't do that.. good to know..
Thanks George.. I will check the resulting script from this
 
Ahem... thanks Boris.

It was good advice, but not mine. [sad]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Or you could just add a new column as type identity, turn Identity Insert On and update the table so the New column values = the Old column values, and then drop the old column if you don't need to keep the values in the old column.

If you want to be complicated about it. @=)



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top