简体   繁体   中英

Error 1064 when running CREATE TABLE script

I am trying to run a SQL script to add tables to my database and keep getting error 1064. Here is the code:

CREATE TABLE 'Bookings' (
'Booking_id' INTEGER(10) NOT NULL AUTO_INCREMENT,
'Arrival_Date' date(8) CURRENT_TIMESTAMP NOT NULL,
'Departure_Date' date(8) CURRENT_TIMESTAMP NOT NULL,
'Registrants_ID' INTEGER(10) DEFAULT NOT NULL,
'Accomodation_ID' INTEGER(10) DEFAULT NOT NULL,
PRIMARY KEY ('Booking_ID'),
KEY 'Accomodation_ID' ('Accomodation_ID'),
KEY 'Registrants_ID' ('Registrants_ID'),
CONSTRAINT 'bookings_ibfk_1' FOREIGN KEY ('Accomodation_ID') REFERENCES 'Accommodation' ('Accomodation_ID')
CONSTRAINT 'bookings_ibfk_2' FOREIGN KEY ('Registrants_ID') REFERENCES 'Registrants' ('Registrants_ID')
);

尝试删除列名称中的'。

You should use datetime for Arrival_Date etc,

current_timestamp give : 2015-02-18 15:34:24

current_date: 2015-02-18

You need to provide a default value if you specify DEFAULT .

Eg

'Registrants_ID' INTEGER(10) DEFAULT 1 NOT NULL,
'Accomodation_ID' INTEGER(10) DEFAULT 1 NOT NULL,

Also you should be using backticks ( ` ) instead of single quotes ( ' ) around field/table/index names.

Also you cannot make a date field default to CURRENT_TIMESTAMP . And if you want a timestamp field to default to CURRENT_TIMESTAMP , you need the DEFAULT keyword. eg: DEFAULT CURRENT_TIMESTAMP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM