Click here to Skip to main content
15,896,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all,


i have a table named Tax , which has columns (TaxId, TaxPercentage).
TaxId is primarykey. Now i want to set TaxId to be identity.
How to do this.

I cannot use designer to do this as sql-server2008-R2 is not allowing me to use designer for already existing table. I searched alot for this on google but was unable to find the right query.
Posted

SQL
IF OBJECT_ID ('Tax', 'U') IS NOT NULL
   DROP TABLE Tax;
GO
CREATE TABLE Tax
(
 TaxId int IDENTITY(1,1),

);
 
Share this answer
 
v2
Comments
Karthik Harve 18-Apr-12 8:02am    
[Edit] pre tags added.
hey,

to alter existing table try following

SQL
Alter Table Tax
Add TaxId_new Int Identity(1, 1)
Go

Alter Table Tax Drop Column TaxID
Go

Exec sp_rename 'Tax.TaxId_new', 'TaxID', 'Column'


Hope it will help u
Best Luck
Happy Coding :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900