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!

question: REMOVING identity property in a TABLE? 1

Status
Not open for further replies.

alfredjp

Technical User
Jul 3, 2002
58
JP
could anyone show me a script on how to remove the IDENTITY property of a table just using ALTER TABLE and ALTER COLUMN?

ps: i do know how to put define a column to be an IDENTITY column, but i would like to do the reverse

thanks!
 
You can just turn it off, if that helps.

SET IDENTITY_INSERT mytable OFF
 
yeah... i have thought about that too...

unfortunately, if i wanted to do an insert on it, i need to put the ENTIRE column names after the
Code:
INSERT INTO
phrase instead of just using
Code:
INSERT INTO aTable SELECT * FROM anotherTable
 
There is no easy way to do it (I asked this same question in a previous post). Here is some info from that post that helped me:


I also found out that if you SELECT INTO and specify the identity column twice that it will remove the identity property from both. As in:

SELECT MyIdentity AS NewCol, * FROM MyTable INTO...

So using this you could simply run the SELECT INTO a table, drop the extra column and rename the table back.

Andy
 
Using '*' is not a particularly good programming practice for several reasons. SQL Server has to do the look up of columns itself, which consumes time and if, somewhere along the line, the table gets a column added, the code breaks.
 
to psprague (Programmer)

thanks for the advice

i guess id do just that - stop relying on
Code:
*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top