且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在SQL Server中像MySQL中那样使用空值插入标识列

更新时间:2023-02-07 13:41:06

这应该可以解决问题:

CREATE TABLE employee (
id INTEGER IDENTITY(1,1) PRIMARY KEY,
name VARCHAR(45) NOT NULL,
phone VARCHAR(45),
salary FLOAT DEFAULT 0 NOT NULL
);

当您插入此表时,从插入/选择列表中省略"id",SQL Server将为您处理.

When you insert into this table, omit 'id' from the insert/select list, SQL Server will handle it for you.

例如:

INSERT INTO employee (name,phone,salary) 
VALUES ('Harry','9985099850',60000);