I am having a problem with creating SQL table with composite and primary keys in it. This is what I have for now:
CREATE TABLE Racunar (
IPAdresa char(15) PRIMARY KEY,
CPU char(20),
HD char(20)
);
CREATE TABLE Program (
Naziv char(15),
Verzija char(20),
Datum char(11),
PRIMARY KEY(Naziv, Verzija)
);
CREATE TABLE Operater (
SifO int PRIMARY KEY,
Ime char(20),
BrTel char(20)
);
CREATE TABLE JeInstaliran (
IPAdresa char(15) FOREIGN KEY REFERENCES Racunar(IPAdresa),
SifO int FOREIGN KEY REFERENCES Operater(SifO),
FOREIGN KEY(Naziv, Verzija) REFERENCES Program(Naziv, Verzija),
DatumInstalacije char(11)
);
The problem is somewhere in the last table. I am using SQL Fiddle and it returned the next error message after trying to build schema:
Schema Creation Failed: 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 ‘FOREIGN KEY REFERENCES Racunar(IPAdresa),
SifO int FOREIGN KEY REFERENCES Oper’ at line 2:
I don’t know why this doesn’t work, so I would appreciate any help. Thanks in advance.
The syntax is incorrect. Instead of defining the
FOREIGN KEYalong with the column, define it after the column definition using the syntaxFOREIGN KEY (colname) REFERENCES tablename (foreign_colname)