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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 please tell me how to auto increment

Author  Topic 

born2acheive
Yak Posting Veteran

65 Posts

Posted - 2006-11-06 : 23:13:38
hi, i have columns(name,id,salary) in my emp table,see to that there is no primary key in my table, but i want to do auto increment, in my table id has to be auto incremented,so please give me coding to do that,pleaseeeeeeee

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-11-06 : 23:22:45
Alter your table's id column to have identity property like this:

Alter table xyz
Drop column id

Alter table xyz
Add id int identity(1,1)



or do it from enterprise manager

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2006-11-07 : 04:03:12
If you drop the column id and there is data in the table you loose everything. TAKE NOTE

Alternatively you can use EM to add an auto increment ID column in the properties panel without loosing your data
Go to Top of Page

rizwan
Starting Member

9 Posts

Posted - 2006-11-07 : 06:54:56
- Go to Enterprise manager
- Right click on your table and click "Design Table"
- if you want to make your "id" field as auto increment ... then click on id field in design window ( it should be int or any numeric kind of field ) ... now u will see "Identity" in propertied panel below ... change it to yes ... save the table.

Thats all u need to do for making the column auto incremented.

best wishes


--
Riz
www.PDFonFLY.com - generate free pdf online
Go to Top of Page
   

- Advertisement -