我在使用SQL Server Express的身份功能时遇到问题

时间:2022-06-05 22:26:24

I'm working with SQL Server Express, I created this table

我正在使用SQL Server Express,我创建了这个表

CREATE TABLE inventory
(
    id INT NOT NULL IDENTITY(1,1),
    description nvarchar(50),
    quantity int,
    price money
)

when I insert this statement:

当我插入此声明时:

INSERT INTO inventory VALUES('water', 20, 1.50)

I get this error:

我收到此错误:

The number of columns in the query and the table must match. [ Number of columns in query = 3, Number of columns in table = 4 ]

查询和表中的列数必须匹配。 [query = 3中的列数,表中的列数= 4]

and when I put this statement:

当我发表这个声明时:

INSERT INTO inventory VALUES(1, 'water', 20, 1.50)

I get this error:

我收到此错误:

The column cannot be modified. [ Column name = id ]

该列无法修改。 [列名= id]

I thought identity would auto increment the value, so can't I do either, and how can I fix it? Thanks in advance

我以为身份会自动增加值,所以我也不能这样做,我该如何解决?提前致谢

1 个解决方案

#1


5  

You must explicitly specify columns in your insert

您必须在插入中明确指定列

insert Inventory(Description, Quantity, Price) values ( ...)

#1


5  

You must explicitly specify columns in your insert

您必须在插入中明确指定列

insert Inventory(Description, Quantity, Price) values ( ...)