feynmanium
feynmanium

Reputation: 159

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)
);

Upvotes: 1

Views: 106

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 562348

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.

Upvotes: 2

Related Questions