07. september 2004 - 13:55Der er
26 kommentarer og 1 løsning
Hjælp til foreign key
Hej Hvorfor kan jeg ikke oprette min Wholesale tabel?
CREATE TABLE ATTENDEE ( Attendee_id INT UNSIGNED AUTO_INCREMENT NOT NULL, Phone TINYINT UNSIGNED, Street VARCHAR(30), Street_no TINYINT UNSIGNED, Apt_no VARCHAR(10), City VARCHAR(30), Zip TINYINT UNSIGNED, Country VARCHAR(30), PRIMARY KEY (Attendee_id)) TYPE = Innodb;
CREATE TABLE WHOLESALE ( CVR TINYINT UNSIGNED NOT NULL, Attendee_id INT NOT NULL, Wholesale_name VARCHAR(30), Description VARCHAR PRIMARY KEY (CVR) FOREIGN KEY (Attendee_id) REFERENCES ATTENDEE(Attendee_id)) TYPE = Innodb;
Jeg bruger den seneste mysql, og har lavet en simpel test med en parent og child hvor det virker... Har rodet med det hele dagen :(
Ups min tabeler ser således ud: CREATE TABLE WHOLESALE ( CVR TINYINT UNSIGNED NOT NULL, Attendee_id INT NOT NULL, Wholesale_name VARCHAR(30), Description VARCHAR, PRIMARY KEY (CVR), FOREIGN KEY (Attendee_id) REFERENCES ATTENDEE(Attendee_id)) TYPE = Innodb;
Øh, det havde jeg ikke lige set.... Men den er rettet nu! Men problemmet er stadigvæk der :( Min tabeller: CREATE TABLE ATTENDEE ( Attendee_id INT UNSIGNED AUTO_INCREMENT NOT NULL, Phone TINYINT UNSIGNED, Street VARCHAR(30), Street_no TINYINT UNSIGNED, Apt_no VARCHAR(10), City VARCHAR(30), Zip TINYINT UNSIGNED, Country VARCHAR(30), PRIMARY KEY (Attendee_id)) TYPE = Innodb;
CREATE TABLE WHOLESALE ( CVR TINYINT UNSIGNED NOT NULL, Attendee_id INT UNSIGNED NOT NULL, Wholesale_name VARCHAR(30), Description VARCHAR, PRIMARY KEY (CVR), FOREIGN KEY (Attendee_id) REFERENCES ATTENDEE(Attendee_id)) TYPE = Innodb;
Har lavet dette her eksempel: CREATE TABLE parent ( par_id INT NOT NULL, PRIMARY KEY (par_id) ) TYPE = INNODB; CREATE TABLE child ( par_id INT NOT NULL, child_id INT NOT NULL, PRIMARY KEY (par_id, child_id), FOREIGN KEY (par_id) REFERENCES parent (par_id) ) TYPE = INNODB;
Ja, men så siger jeg tak for hjælpen, og du har selvfølgelig tjent dine points :) Men forstår ikke helt det der index.... Har fået oprettet følgende tabeller: CREATE TABLE ATTENDEE ( Attendee_id INT UNSIGNED AUTO_INCREMENT NOT NULL, Phone TINYINT UNSIGNED, Street VARCHAR(30), Street_no TINYINT UNSIGNED, Apt_no VARCHAR(10), City VARCHAR(30), Zip TINYINT UNSIGNED, Country VARCHAR(30), PRIMARY KEY (Attendee_id)) TYPE = Innodb;
CREATE TABLE WHOLESALE ( CVR TINYINT UNSIGNED NOT NULL, Attendee_id INT UNSIGNED NOT NULL, Wholesale_name VARCHAR(30), Description VARCHAR(200), INDEX Attendee_id_ix (Attendee_id), PRIMARY KEY (CVR), FOREIGN KEY (Attendee_id) REFERENCES ATTENDEE(Attendee_id)) TYPE = Innodb;
CREATE TABLE CUSTOMER ( Customer_id INT UNSIGNED AUTO_INCREMENT NOT NULL, Contact_person VARCHAR(30), Attendee_id INT UNSIGNED NOT NULL, INDEX Attendee_id_ix (Attendee_id), PRIMARY KEY (Customer_id), FOREIGN KEY (Attendee_id) REFERENCES ATTENDEE(Attendee_id)) TYPE = Innodb;
CREATE TABLE EMPLOYEE_TYPE ( Type_id TINYINT UNSIGNED NOT NULL, Type VARCHAR(30), PRIMARY KEY (Type_id)) TYPE = Innodb;
Når jeg nu laver min næste tabel som hedder EMPLOYEE får jeg fejl igen :(
CREATE TABLE EMPLOYEE ( SSN TINYINT UNSIGNED NOT NULL, First_name VARCHAR(30), Middel_name VARCHAR(30), Last_name VARCHAR(30), Sex CHAR, Field_of_work VARCHAR(30), Start_date DATE, Time_rate DOUBLE UNSIGNED, Email VARCHAR(30), Type_id TINYINT UNSIGNED NOT NULL, Attendee_id INT UNSIGNED NOT NULL, INDEX Type_id_ix (Type_id), NDEX Attendee_id_ix (Attendee_id), PRIMARY KEY (SSN), FOREIGN KEY (Type_id) REFERENCES EMPLOYEE_TYPE(Type_id), FOREIGN KEY (Attendee_id) REFERENCES ATTENDEE(Attendee_id)) TYPE = Innodb;
Damm det var min copy paste der mangelede et I foran NDEX.... Nå, men så siger jeg tak for hjælpen :)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.