nachdem ich endlich die Referenz über Fremdschlüssel hin bekommen habe und meine eigentliche DB anlegen möchte, erhalte ich obige für mich nicht zu erschliessende Fehlermeldung.
Zuerst lege ich folgende 3 Tabellen an:
- Code: Select all
CREATE TABLE area (
area_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
area VARCHAR(20) NULL,
PRIMARY KEY(area_id)
) engine=innoDB;
CREATE TABLE location (
location_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
location VARCHAR(20) NULL,
PRIMARY KEY(location_id)
) engine=innoDB;
CREATE TABLE organisation (
organisation_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
organisation VARCHAR(20) NULL,
PRIMARY KEY(organisation_id)
) engine=innoDB;
Anschliessend möchte ich eine Tabelle mit den Fremdschlüsseln aus den ersten 3 Tabellen erstellen.
- Code: Select all
CREATE TABLE pc (
pc_id INTEGER NOT NULL AUTO_INCREMENT,
area_id INTEGER UNSIGNED NOT NULL,
organisation_id INTEGER UNSIGNED NOT NULL,
location_id INTEGER UNSIGNED NOT NULL,
name VARCHAR(20) NOT NULL,
mac_adress VARCHAR(12) NOT NULL,
static_ip VARCHAR(15) NULL,
date_purchase DATE NOT NULL,
billnr_purchase VARCHAR(12) NOT NULL,
PRIMARY KEY(pc_id),
INDEX i_area_id( area_id ) ,
INDEX i_ogranisation_id( organisation_id ) ,
INDEX i_location_id( location_id ) ,
FOREIGN KEY(location_id)
REFERENCES location,
FOREIGN KEY(organisation_id)
REFERENCES organisation,
FOREIGN KEY(area_id)
REFERENCES area
) engine=innoDB;
an dieser Stelle erhalte ich dann obige Fehlermeldung.
Verwende ich folgende Syntax
- Code: Select all
...
FOREIGN KEY(location_id)
REFERENCES location(location_id),
FOREIGN KEY(organisation_id)
REFERENCES organisation(organisation_id),
FOREIGN KEY(area_id)
REFERENCES area(area_id)
) engine=innoDB;
erhalte ich folgende Fehlermeldung
- Code: Select all
#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 'area(area_id)
) ENGINE = innoDB' at line 18
Ich verstehe auch nicht, warum der Syntax-Fehler erst im Foreign Key für area auftritt und nicht schon früher.
Ich bin ziemlich ratlos
Wo ist mein Fehler?
Vielen Dank
Ngar