Sql Error创建表

时间:2014-09-27 01:51:24

标签: mysql sql ddl

我创建了表格电影和位置,但我似乎遇到了一个奇怪的错误,我想知道是否有人能够抓住我在这里做错了什么。

CREATE TABLE ShowTimes
(
   showId int NOT NULL, 
   movieid int NOT NULL,        
   cinemaID int NOT NULL,
   showDate date,
   showTime time,

   PRIMARY KEY (showId),
   FOREIGN KEY ShowTimes (movieid) REFERENCES Movies (movieId),
   FOREIGN KEY (cinemaID) REFERENCES Location (cinemaId)
)

错误:

  

错误代码:1005。无法创建表格' galaxy.showtimes' (错误:150)0.078秒

CREATE TABLE ShowTimes
(
   showId int NOT NULL, 
   movieid int NOT NULL, 
   cinemaID int NOT NULL,
   showDate date,
   showTime time,
   PRIMARY KEY (showId),
   FOREIGN KEY (movieid) REFERENCES Movies (movieId),
   FOREIGN KEY (cinemaID) REFERENCES Location (cinemaId)
);

INSERT INTO ShowTimes VALUES (1, 1, 1, '2013-09-20', '17:00:00'),
                             (2, 1, 1, '2013-09-20', '19:00:00'),
                             (3, 3, 4, '2013-09-20', '17:00:00'),
                             (4, 2, 3, '2013-09-20', '15:15:00');

1 个答案:

答案 0 :(得分:1)

简单的错误:看看你的第一个外键。您正在引用ShowTimes表。尝试删除它。