简体   繁体   中英

SQL (MySql) foreign key and composite key syntax error

I am new to SQL and I am trying to figure out what am I doing wrong here. The error that I am getting is:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Cast( movieId int, actorId int, salary decimal(7,2) default '77777.77', fore' at line 1

create table Cast(
movieId int,
actorId int,
salary decimal(7,2) default '77777.77',
primary key(movieId,actorId)
foreign key(actorId) references Actor(actorId),
foreign key(movieId) references Movie(movieId)
);

When you use Cast(... with no space between Cast and the ( , MySQL thinks you are trying to use the CAST() builtin function . That makes no sense following CREATE TABLE , so MySQL is confused.

See https://dev.mysql.com/doc/refman/5.7/en/function-resolution.html

If you put a space before the paren, that fixes that problem.

create table Cast (
                 ^

You also have another minor mistake, you forgot a comma after your PRIMARY KEY.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM