gpt4 book ai didi

mysql - 关键字 'CONSTRAINT' 附近的语法不正确

转载 作者:行者123 更新时间:2023-11-29 05:10:20 25 4
gpt4 key购买 nike

我收到此错误消息...

Msg 156, Level 15, State 1, Line 20
Incorrect syntax near the keyword 'CONSTRAINT'.

我已经完成了研究,但我仍然坚持要完成这个脚本。

这是我输入的内容。

DROP TABLE SEMESTER; 
DROP TABLE CLASS;
DROP TABLE STUDENT;

CREATE TABLE STUDENT (
stuid int not null,
stulname CHAR(40) not null,
stufname CHAR(40) not null,
stugender CHAR(1) not null,
stubirthdate DATE not null);

CREATE TABLE CLASS (
title CHAR(40) not null PRIMARY KEY,
instructor CHAR(40) not null );

CREATE TABLE SEMESTER (
year int not null );


CONSTRAINT pk_student PRIMARY KEY (stuid, stulname, stufname, stugender, stubirthdate),
CONSTRAINT pk_class PRIMARY KEY (title, instructor),
CONSTRAINT pk_semester PRIMARY KEY (semid, year));

最佳答案

我认为那些CONSTRAINT 语句需要 CREATE TABLE 语句中。例如,STUDENT 表应该如下所示:

CREATE TABLE STUDENT (
stuid int not null,
stulname CHAR(40) not null,
stufname CHAR(40) not null,
stugender CHAR(1) not null,
stubirthdate DATE not null,
CONSTRAINT pk_student PRIMARY KEY (stuid, stulname, stufname, stugender, stubirthdate),
);

否则,RDBMS 怎么知道每个约束实际上属于哪个表?

关于mysql - 关键字 'CONSTRAINT' 附近的语法不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40478978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com