Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody,

I have an employee table with three columns, they are emp_id, emp_name and emp_add.

How to set emp_id auto generated by 1? using query.

Thank you.
Posted
Updated 27-Oct-10 3:37am
v4
Comments
Dalek Dave 27-Oct-10 9:10am    
Edited for Grammar and Syntax.

go to design view and select data type as int now u will get properties there u need to put isidentityspecification make it yes and set seed value and increment value

Or by query use it

CSS
ALTER TABLE table-Name
{
    ADD COLUMN column-definition |
    ADD CONSTRAINT clause |
    DROP { PRIMARY KEY | FOREIGN KEY constraint-name | UNIQUE
     constraint-name | CHECK constraint-name | CONSTRAINT constraint-name }
    ALTER column-alteration |
    LOCKSIZE { ROW | TABLE }
}
column-definition:
Simple-column-Name DataType
[ Column-Level-Constraint ]*
[ [ WITH ] DEFAULT {ConstantExpression | NULL } ]
column-alteration:
column-Name SET DATA TYPE VARCHAR(integer) |
column-name SET INCREMENT BY integer-constant
 
Share this answer
 
v2
One of the ways:
1. Go to 'Design Table'
2. Select the column of 'emp_id'
3. See at the properties of the column below.
4. There is an option of making it if 'Identity' column - mark it yes
5. You can also define the increment to any number. By default it is 1.
 
Share this answer
 

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