3 回答
TA贡献2080条经验 获得超4个赞
Postgres 10或更高版本
serial
IDENTITY
CREATE TABLE staff ( staff_id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY , staff text NOT NULL);
CREATE TABLE
.
IDENTITY
ALTER TABLE staff ADD COLUMN staff_id int GENERATED BY DEFAULT AS IDENTITY;
ALTER TABLE staff ADD COLUMN staff_id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY;
ERROR: column "staff_id" contains null values
Postgres 9.6或以上
serial
CREATE TABLE staff ( staff_id serial PRIMARY KEY, , staff text NOT NULL);
DEFAULT
nextval()
TA贡献1789条经验 获得超8个赞
但是,在SQLServer中,您没有指定使用的是哪个RDBMS,您可以使用以下语法:
CREATE TABLE [dbo].[Staff]
(
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] VARCHAR(40) NOT NULL,
CONSTRAINT [ID] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
TA贡献1802条经验 获得超10个赞
Identity(1,1)
CREATE TABLE Staff( ID INT IDENTITY(1,1) NOT NULL, Name VARCHAR(40) NOT NULL, PRIMARY KEY (ID));
添加回答
举报