phpMyAdmin在尝试将ID(使用SET IDENTITY_INSERT)插入表时给出错误#1064

时间:2017-03-19 16:53:14

标签: mysql sql

所以我遇到了mySQL数据库的问题我被给了,我应该把它放在phpMyAdmin上。以下是导致问题的表格。

/*==============================================================*/
/* Table: ContributionState                                     */
/*==============================================================*/
create table ContributionState
(
   ContributionStateID  int not null auto_increment,
   Title                national varchar(100) not null,
   DisplayOrder         int not null,
   primary key (ContributionStateID)
);

SET IDENTITY_INSERT ContributionState ON
INSERT INTO ContributionState(ContributionStateID,Title,DisplayOrder) 
VALUES (1,N'Vote up',1),
(2,N'Vote Down',2),
(3,N'Vulgar',3),
(4,N'Spam',4),
(5,N'Accepted',5),
(6,N'Rejected',6),
(7,N'Live',7)
SET IDENTITY_INSERT ContributionState OFF

/*==============================================================*/
/* Table: Contribution_States                                   */
/*==============================================================*/
create table Contribution_States
(
   Contribution_StatesID int not null auto_increment,
   ContributionStateID  int not null,
   ContributionID       int not null,
   UserID               int not null,
   CreatedDate          datetime not null default 'getdate()',
   primary key (Contribution_StatesID)
);

/*==============================================================*/
/* Index: INDEX_1                                               */
/*==============================================================*/
create unique index INDEX_1 on Contribution_States
(
   ContributionStateID,
   ContributionID,
   UserID
);

我面临的问题是phpMyAdmin在'ContributionState ON Insert ...'附近返回错误#1064(意味着语法有错误)。我不知道该怎样修复它才能正常运行,因为我是mySQL的初学者,并且会感激一些帮助。

提前致谢。

1 个答案:

答案 0 :(得分:0)

这是三个单独的查询。你需要用分号将它们分开。

SET IDENTITY_INSERT ContributionState ON;
INSERT INTO ContributionState(ContributionStateID,Title,DisplayOrder) 
VALUES (1,N'Vote up',1),
(2,N'Vote Down',2),
(3,N'Vulgar',3),
(4,N'Spam',4),
(5,N'Accepted',5),
(6,N'Rejected',6),
(7,N'Live',7);
SET IDENTITY_INSERT ContributionState OFF;