Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 358
Aldur Avatar asked Sep 17 '08 16:09

Aldur


1 Answers

Like this

create table foo  
(  
user_id int not null identity,  
name varchar(50)  
)
like image 163
SQLMenace Avatar answered Oct 07 '22 17:10

SQLMenace