sql >> Base de Datos >  >> RDS >> Oracle

SQL:creación de tablas con claves primarias y claves foráneas que hacen referencia (

Para una clave externa en línea, no puede usar la foreign key palabra clave. También tienes un , colgando al final:

CREATE TABLE BOOK 
(
  ISBN INTEGER PRIMARY KEY,
  year integer CHECK (year BETWEEN 1900 AND 2016),
  title varchar (60) REFERENCES FORFATTER (BOK),
  publisher utgiver varchar (90) --<<< remove the comma here
);

Alternativamente:

CREATE TABLE BOOK 
(
  ISBN INTEGER PRIMARY KEY,
  year integer CHECK (year BETWEEN 1900 AND 2016),
  title varchar (60),
  publisher utgiver varchar (90), --<< for this syntax you need the comma
  foreign key (title) REFERENCES FORFATTER (BOK) 
);