错误代码1064引发,可能是语法错误

时间:2014-03-26 06:54:24

标签: mysql sql

create table approval
(
    app_id smallint not null,
    visitor_id smallint(5),
    approve varchar(5),

    primary key (app_id) auto increment
    foreign key (visitor_id) references trans_req_visitor(visitor_id)
    constraint approval check (approval in ('TRUE', 'FALSE'))
);

我找不到导致错误的地方,我在哪里弄错了?

3 个答案:

答案 0 :(得分:1)

之后缺少逗号
primary key (app_id) auto increment

将您的查询更改为

create table approval(
app_id smallint not null,
visitor_id smallint(5),
approve varchar(5),
primary key (app_id) auto_increment,
FOREIGN KEY (visitor_id) REFERENCES trans_req_visitor(visitor_id),
constraint approval check (approval in ('TRUE', 'FALSE'))
);

答案 1 :(得分:1)

auto incrementREFERENCES trans_req_visitor(visitor_id)

附近缺少逗号

试试这个

create table approval(
app_id smallint not null AUTO_INCREMENT,
visitor_id smallint(5),
approve varchar(5),
primary key (app_id),
FOREIGN KEY (visitor_id) REFERENCES trans_req_visitor(visitor_id),
constraint approval check (approval in ('TRUE', 'FALSE'))
);

答案 2 :(得分:1)

你需要这样做:

create table approval(
app_id smallint not null auto_increment,
visitor_id smallint(5),
approve varchar(5),
primary key (app_id),
FOREIGN KEY (visitor_id) REFERENCES trans_req_visitor(visitor_id),
constraint approval check (approval in ('TRUE', 'FALSE'))
);

(错过逗号,错误输入和错位auto_increment

MySQL不支持

注意 check。出于兼容性原因,此语法仅允许