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.
| Author |
Topic |
|
lily_wibisana
Starting Member
29 Posts |
Posted - 2008-06-13 : 14:40:04
|
I have imported products table from ms-access to sql server 2005.So I have already 88 products.I need to change the Primary key, to auto increment by 1.I tried this statement,ALTER TABLE Products ALTER COLUMN ProductsRecordID IDENTITY (89, 1)But why I got an errorMsg 156, Level 15, State 1, Line 1Incorrect syntax near the keyword 'IDENTITY'.Much appreciate your help  |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-06-13 : 14:44:02
|
| You can't use ALTER TABLE to add the identity option to an existing column. You must do the long way:1. Create a new table with the required table layout2. Move your data, indexes, constraints, etc... to the new table3. Drop the old table4. Rename the new table to the old table nameSQL Server Management Studio can do it for you. It will also generate the code for you if you'd like to see the steps or save them.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
lily_wibisana
Starting Member
29 Posts |
Posted - 2008-06-13 : 15:18:27
|
quote: Originally posted by tkizer You can't use ALTER TABLE to add the identity option to an existing column. You must do the long way:1. Create a new table with the required table layout2. Move your data, indexes, constraints, etc... to the new table3. Drop the old table4. Rename the new table to the old table nameSQL Server Management Studio can do it for you. It will also generate the code for you if you'd like to see the steps or save them.Tara KizerHow do I move the data to the new table?Microsoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
|
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-14 : 02:18:41
|
| http://www.mssqltips.com/tip.asp?tip=1397 |
 |
|
|
|
|
|
|
|