oracle 第2/16行出错:ORA-00907:缺少右括号

niwlg2el  于 2023-04-20  发布在  Oracle
关注(0)|答案(1)|浏览(153)
CREATE TABLE Actor (
  actor_id INT AUTO_INCREMENT PRIMARY KEY,
  actor_name VARCHAR(255) NOT NULL,
  actor_gender ENUM('M', 'F', 'Other') NOT NULL,
  actor_birthdate DATE NOT NULL
);

CREATE TABLE Director (
  director_id INT AUTO_INCREMENT PRIMARY KEY,
  director_name VARCHAR(255) NOT NULL,
  director_birthdate DATE NOT NULL
);

CREATE TABLE Movie (
  movie_id INT AUTO_INCREMENT PRIMARY KEY,
  movie_title VARCHAR(255) NOT NULL,
  movie_release_date DATE NOT NULL,
  movie_runtime INT NOT NULL,
  movie_rating DECIMAL(3,1) NOT NULL,
  genre_id INT NOT NULL,
  FOREIGN KEY (genre_id) REFERENCES Genre(genre_id)
);

CREATE TABLE Genre (
  genre_id INT AUTO_INCREMENT PRIMARY KEY,
  genre_name VARCHAR(255) NOT NULL
);

CREATE TABLE MovieCast (
  movie_id INT NOT NULL,
  actor_id INT NOT NULL,
  PRIMARY KEY (movie_id, actor_id),
  FOREIGN KEY (movie_id) REFERENCES Movie(movie_id),
  FOREIGN KEY (actor_id) REFERENCES Actor(actor_id)
);

CREATE TABLE DirectorOf (
  movie_id INT NOT NULL,
  director_id INT NOT NULL,
  PRIMARY KEY (movie_id, director_id),
  FOREIGN KEY (movie_id) REFERENCES Movie(movie_id),
  FOREIGN KEY (director_id) REFERENCES Director(director_id)
);

我不知道错误在哪里

5f0d552i

5f0d552i1#

在Oracle中,AUTO_INCREMENTENUM都不是有效语法。您需要:

CREATE TABLE Actor (
  actor_id        INT
                  GENERATED ALWAYS AS IDENTITY
                  PRIMARY KEY,
  actor_name      VARCHAR(255) NOT NULL,
  actor_gender    VARCHAR2(5)
                  CHECK ( actor_gender IN ('M', 'F', 'Other'))
                  NOT NULL,
  actor_birthdate DATE NOT NULL
);

CREATE TABLE Director (
  director_id        INT
                     GENERATED ALWAYS AS IDENTITY
                     PRIMARY KEY,
  director_name      VARCHAR(255) NOT NULL,
  director_birthdate DATE NOT NULL
);

CREATE TABLE Genre (
  genre_id   INT
             GENERATED ALWAYS AS IDENTITY
             PRIMARY KEY,
  genre_name VARCHAR(255) NOT NULL
);

CREATE TABLE Movie (
  movie_id           INT
                     GENERATED ALWAYS AS IDENTITY
                     PRIMARY KEY,
  movie_title        VARCHAR(255) NOT NULL,
  movie_release_date DATE NOT NULL,
  movie_runtime      INT NOT NULL,
  movie_rating       DECIMAL(3,1) NOT NULL,
  genre_id           REFERENCES Genre(genre_id)
                     NOT NULL
);

CREATE TABLE MovieCast (
  movie_id REFERENCES Movie(movie_id),
  actor_id REFERENCES Actor(actor_id),
  PRIMARY KEY (movie_id, actor_id)
);

CREATE TABLE DirectorOf (
  movie_id    REFERENCES Movie(movie_id),
  director_id REFERENCES Director(director_id),
  PRIMARY KEY (movie_id, director_id)
);
  • 注意:当你声明一个外键约束时,你不需要声明数据类型,它将从被引用的表/列继承。

fiddle

相关问题