我正在表创建中寻找有关这些CONSTRAINT语句的帮助。看起来很简单,但由于某种原因我很想念它。当我尝试更改以在语句的不同区域内添加打开或关闭括号时,似乎没有任何更改。
错误代码:1064。在第15行的“ REFERENCES(DISTRIBUTOR.DISTRIBUTOR_ID),CONSTRAINT VIDEO_DVD_FK2 FOREIGN KEY R”附近,查看与您的MySQL服务器版本相对应的手册以使用正确的语法。
错误代码:1064。在第11行的“ CONSTRAINT DISTRIBUTOR_PK主键(DISTRIBUTOR_ID),CONSTRAINT DISTRIBUTOR_”附近,查看与您的MySQL服务器版本相对应的手册以使用正确的语法。
错误代码:1064。检查与您的MySQL服务器版本相对应的手册,以在第25行的'REFERENCES(DISTRIBUTOR.DISTRIBUTOR_ID))'附近使用正确的语法
错误代码:1064。检查与MySQL服务器版本相对应的手册,以在第11行的'REFERENCES(VIDEO_DVD.VIDEO_DVD_ID))'附近使用正确的语法
CREATE TABLE VIDEO_DVD(
VIDEO_DVD_ID VARCHAR(100),
DISTRIBUTOR_ID varchar(100),
MOVIE_ID varchar(100),
CUSTOMER_ID varchar(100),
FINE_AMT numeric(14,0) CHECK (FINE_AMT > 0),
DAMAGE_CHARGES numeric(14,0) CHECK (DAMAGE_CHARGES > 0),
TYPE CHAR(1) check(TYPE IN ('V','D')),
LEASE_DATE DATE,
RETURN_DATE DATE NOT NULL,
CONSTRAINT VIDEO_DVD_PK PRIMARY KEY (VIDEO_DVD_ID),
CONSTRAINT VIDEO_DVD_FK1 FOREIGN KEY REFERENCES (DISTRIBUTOR.DISTRIBUTOR_ID),
CONSTRAINT VIDEO_DVD_FK2 FOREIGN KEY REFERENCES (MOVIE.MOVIE_ID),
CONSTRAINT VIDEO_DVD_FK3 FOREIGN KEY REFERENCES (CUSTOMER.CUST_ID));
CREATE TABLE DISTRIBUTOR(
DISTRIBUTOR_ID VARCHAR(100) ,
MOVIE_ID VARCHAR(100),
VIDEO_DVD_ID VARCHAR(100),
NAME VARCHAR(1000) UNIQUE NOT NULL
CONSTRAINT DISTRIBUTOR_PK PRIMARY KEY (DISTRIBUTOR_ID),
CONSTRAINT DISTRIBUTOR_FK1 FOREIGN KEY REFERENCES (MOVIE.MOVIE_ID),
CONSTRAINT DISTRIBUTOR_FK2 FOREIGN KEY REFERENCES (VIDEO_DVD.VIDEO_DVD_ID));
CREATE TABLE MOVIE(
MOVIE_ID VARCHAR(100),
DIRECTOR VARCHAR(100) NOT NULL,
NAME VARCHAR(100) UNIQUE NOT NULL,
TYPE CHAR(1) CHECK (TYPE IN ('C','H','S')),
DISTRIBUTOR_ID VARCHAR(100),
ACTOR_NAME VARCHAR(100),
LENGTH NUMERIC(14,0) CHECK (LENGTH > 0),
AWARDS VARCHAR(1000),
RATINGS NUMERIC(2,0) CHECK (RATINGS IN (1,2,3,4,5,6,7,8,9,10)),
RELEASE_YEAR NUMERIC(4,0),
CONSTRAINT MOVIE_PK PRIMARY KEY (MOVIE_ID),
CONSTRAINT MOVIE_FK FOREIGN KEY REFERENCES (DISTRIBUTOR.DISTRIBUTOR_ID));
CREATE TABLE CUSTOMER(
CUST_ID VARCHAR(100),
VIDEO_DVD_ID VARCHAR(100),
STREET VARCHAR(1000),
ZIPCODE NUMERIC(6,0),
ACC_NO VARCHAR(20) UNIQUE NOT NULL,
CONSTRAINT CUSTOMER_PK PRIMARY KEY (CUST_ID),
CONSTRAINT CUSTOMER_FK FOREIGN KEY REFERENCES (VIDEO_DVD.VIDEO_DVD_ID));
我正在使用MySQL 5.7 ...
我可以通过删除语句末尾的逗号来清除一些错误,因此我希望这仍然有效。我仍然有这些错误。
14:41:47创建表VIDEO_DVD(VIDEO_DVD_ID VARCHAR(100),DISTRIBUTOR_ID varchar(100),MOVIE_ID varchar(100),CUSTOMER_ID varchar(100),FINE_AMT数字(14,0)CHECK(FINE_AMT> 0),DAMAGE_CHAR 14,0)检查(DAMAGE_CHARGES> 0),TYPE CHAR(1)检查(TYPE IN('V','D')),LEASE_DATE DATE,RETURN_DATE DATE NOT NULL,CONSTRAINT VIDEO_DVD_PK主键(VIDEO_DVD_ID),CONSTRAINT VIDEO_DVD_F密钥(DISTRIBUTOR_ID)参考DISTRIBUTOR.DISTRIBUTOR_ID)CONSTRAINT VIDEO_DVD_FK2外国密钥参考(MOVIE.MOVIE_ID)CONSTRAINT VIDEO_DVD_FK3外国密钥参考(CUSTOMER.CUST_ID)SQL错误;错误代码10:SQL。在第17行0.016秒处,检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在“ CONSTRAINT VIDEO_DVD_FK2 FOREIGN KEY REFERENCES(MOVIE.MOVIE_ID)CONSTRAINT VID”附近使用
14:41:47 CREATE TABLE DISTRIBUTOR(DISTRIBUTOR_ID VARCHAR(100),MOVIE_ID VARCHAR(100),VIDEO_DVD_ID VARCHAR(100),NAME VARCHAR(1000)唯一非NULL约束DISTRIBUTOR_PK主键(DISTRIBUTOR_ID)(CONSTRAINT DISTRIV) .MOVIE_ID),CONSTRAINT DISTRIBUTOR_FK2外键引用(VIDEO_DVD.VIDEO_DVD_ID))错误代码:1064。您的SQL语法有错误;在第11行0.000秒处,查看与您的MySQL服务器版本相对应的手册,以获取在'CONSTRAINT DISTRIBUTOR_PK PRIMARY KEY(DISTRIBUTOR_ID),CONSTRAINT DISTRIBUTOR_'附近使用的正确语法
14:41:47 CREATE TABLE MOVIE(MOVIE_ID VARCHAR(100),DIRECTOR VARCHAR(100)NOT NULL,NAME VARCHAR(100)UNIQUE NOT NULL,CHAR(1)CHECK(TYPE IN('C','H', 'S')),DISTRIBUTOR_ID VARCHAR(100),ACTOR_NAME VARCHAR(100),LENGTH NUMERIC(14,0)检查(LENGTH> 0),AWARDS VARCHAR(1000),RATINGS NUMERIC(2,0)CHECK(RATINGS IN( 1,2,3,4,5,6,7,8,9,10)),RELEASE_YEAR NUMERIC(4,0),CONSTRAINT MOVIE_PK主键(MOVIE_ID),CONSTRAINT MOVIE_FK外键(MOVIE_ID)参考DISTRIBUTOR_DISTRIBUTORID错误代码:1215。无法添加外键约束1.109秒
我的最后3个错误仍然无法解决。任何帮助将不胜感激!谢谢!
CONSTRAINT VIDEO_DVD_FK2 FOREIGN KEY (MOVIE_ID) REFERENCES (MOVIE.MOVIE_ID),
错误代码:1064。请在第17行的“ CONSTRAINT VIDEO_DVD_FK2 FOREIGN KEY(MOVIE_ID)REFERENCES(MOVIE.MOVIE_ID),CO”附近查看与您的MySQL服务器版本相对应的手册,以使用正确的语法。
CONSTRAINT DISTRIBUTOR_PK PRIMARY KEY (DISTRIBUTOR_ID),
错误代码:1064。在第11行的“ CONSTRAINT DISTRIBUTOR_PK主键(DISTRIBUTOR_ID),CONSTRAINT DISTRIBUTOR_”附近,查看与您的MySQL服务器版本相对应的手册以使用正确的语法。
CREATE TABLE MOVIE( MOVIE_ID VARCHAR(100), DIRECTOR VARCHAR(100) NOT NULL, NAME VARCHAR(100) UNIQUE NOT NULL, TYPE CHAR(1) CHECK (TYPE IN ('C','H','S')), DISTRIBUTOR_ID VARCHAR(100), ACTOR_NAME VARCHAR(100), LENGTH NUMERIC(14,0) CHECK (LENGTH > 0), AWARDS VARCHAR(1000), RATINGS NUMERIC(2,0) CHECK (RATINGS IN (1,2,3,4,5,6,7,8,9,10)), RELEASE_YEAR NUMERIC(4,0), CONSTRAINT MOVIE_PK PRIMARY KEY (MOVIE_ID), CONSTRAINT MOVIE_FK FOREIGN KEY (DISTRIBUTOR_ID) REFERENCES DISTRIBUTOR.DISTRIBUTOR_ID)
错误代码:1215。无法添加外键约束0.453秒
最佳答案
您尚未编写外键的列名。您需要编写例如:
CONSTRAINT VIDEO_DVD_FK1 FOREIGN KEY (DISTRIBUTOR_ID) REFERENCES (DISTRIBUTOR.DISTRIBUTOR_ID),
关于mysql - 表创建中的CONSTRAINT语句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47500896/