How to insert an auto_increment key into SQL Server table

后端 未结 4 1070
孤独总比滥情好
孤独总比滥情好 2020-12-15 10:54

I want to insert rows into a table that has a unique, non auto-incremented primary key.

Is there a native SQL function to evaluate the last key and increment it or d

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 11:29

    create table if not exists Emp ( eid int(10) not null primary key auto_increment, name varchar(45) not null, age int(5) default 20, salary int(5) ) insert into emp values(102,'Ranjan',21,450000);

    Then try below sql query . It will automaticaly increment the eid to next number .

    insert into emp (name,salary) values( 'Lisma',118500);

    select * from emp;

提交回复
热议问题