Aldur Aldur - 2 months ago 22
MySQL Question

SqlServer create table with MySql like auto_increment primary key

I want to make a table in SqlServer that will add, on insert, a auto incremented primary key. This should be an autoincremented id similar to MySql auto_increment functionality. (Below)

create table foo
(
user_id int not null auto_increment,
name varchar(50)
)


Is there a way of doing this with out creating an insert trigger?

Answer

Like this

create table foo  
(  
user_id int not null identity,  
name varchar(50)  
)