anser316 Posted April 25, 2008 Share Posted April 25, 2008 The order table does not insert onto my database: I get this error: Error SQL query: CREATE TABLE Order1( orderId Int( 5 ) NOT NULL AUTO_INCREMENT , customerId Int( 4 ) NOT NULL , date date NOT NULL , CONSTRAINT Order_OrderId_pk PRIMARY KEY ( OrderId ) , CONSTRAINT Order_customerId_fk foriegn KEY ( customerId ) Reference Customer( customerId ) ) MySQL said: #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 'foriegn key(customerId) Reference Customer(customerId))' at line 6 This is my inserts, the customer table works: create table Order1( orderId Int(5) not null AUTO_INCREMENT, customerId Int(4) not null, date date not null, constraint Order_OrderId_pk primary key (OrderId), constraint Order_customerId_fk foriegn key(customerId) Reference Customer(customerId)); create table Customer( customerId Int(4) not null AUTO_INCREMENT, firstName varchar(30) not null, surName varchar(30) not null, telephone varchar(15) not null, mobile varchar(15) not null, dOb Date not null, email varchar(30) not null, password varchar(6) not null, address varchar(50) not null, town varchar(10) not null, county varchar(10) not null, postcode varchar(10) not null, constraint Customer_customerId_pk primary key (customerId), constraint Customer_email_uk UNIQUE (email)); Link to comment https://forums.phpfreaks.com/topic/102930-mysql-table/ Share on other sites More sharing options...
micah1701 Posted April 25, 2008 Share Posted April 25, 2008 you can't name a column "date" in your table because it is a reserved word. change it to something else and see if that helps EDIT: nevermind. its not a reserved word, i just checked. sorry. Link to comment https://forums.phpfreaks.com/topic/102930-mysql-table/#findComment-527331 Share on other sites More sharing options...
phpSensei Posted April 25, 2008 Share Posted April 25, 2008 you can't name a column "date" in your table because it is a reserved word. change it to something else and see if that helps EDIT: nevermind. its not a reserved word, i just checked. sorry. No I think it is reserved, thats why you add ticks ` ` Link to comment https://forums.phpfreaks.com/topic/102930-mysql-table/#findComment-527351 Share on other sites More sharing options...
phpSensei Posted April 25, 2008 Share Posted April 25, 2008 Try CREATE TABLE Order1( orderId Int( 5 ) NOT NULL AUTO_INCREMENT , customerId Int( 4 ) NOT NULL , `date` DATE NOT NULL , CONSTRAINT Order_OrderId_pk PRIMARY KEY ( OrderId ) , CONSTRAINT Order_customerId_fk FOREIGN KEY ( customerId ) references CUSTOMER(customerId)) Link to comment https://forums.phpfreaks.com/topic/102930-mysql-table/#findComment-527352 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.