Friday, February 24, 2012

How to delete a counter in a field ?

I want to delete a counter using an SQL query (alter, drop...)
What could be the SQL queryI want to delete a counter using an SQL query (alter, drop...)

What could be the SQL query

Are your trying to reset an identity column or to drop it?
Plz specify that clearly...

To reset an identity column use

DBCC CHECKIDENT ('table_name',RESEED,0)|||I want to delete the counter (identity) but keep the column.|||Unfortunately, you can't reset the IDENTITY property in Microsoft SQL because of the way that it is implemented. The only safe way to do this is:ALTER TABLE myTable
ADD COLUMN new_column INT NOT NULL -- set type and NULL-ability to taste
GO
UPDATE myTable
SET new_column = old_column
GO
ALTER TABLE myTable
DROP COLUMN old_column
GO
EXECUTE sp_rename 'mytable.new_colum', 'mytable.old_column'
GO-PatP

No comments:

Post a Comment