为什么我无法将值插入 table?
Why am I not able to insert values into a table?
我有一个名为 Music 的数据库和一个名为 Genre 的 table。我写了下面的代码:
USE Music
INSERT INTO Genre (GenreID, Genre)
VALUES
(1,'Rock'),
(2,'Jazz'),
(3,'Country'),
(4,'Pop'),
(5,'Blues'),
(6,'Hip-Hop'),
(7,'Rap'),
(8,'Punk');
我收到以下错误:
Msg 544, Level 16, State 1, Line 3
Cannot insert explicit value for identity column in table 'Genre' when IDENTITY_INSERT is set to OFF.
知道这是为什么吗?
您可以将此添加到您的代码中
SET IDENTITY_INSERT Genre ON
我有一个名为 Music 的数据库和一个名为 Genre 的 table。我写了下面的代码:
USE Music
INSERT INTO Genre (GenreID, Genre)
VALUES
(1,'Rock'),
(2,'Jazz'),
(3,'Country'),
(4,'Pop'),
(5,'Blues'),
(6,'Hip-Hop'),
(7,'Rap'),
(8,'Punk');
我收到以下错误:
Msg 544, Level 16, State 1, Line 3
Cannot insert explicit value for identity column in table 'Genre' when IDENTITY_INSERT is set to OFF.
知道这是为什么吗?
您可以将此添加到您的代码中
SET IDENTITY_INSERT Genre ON