Dear Sir
I am new to MySQL. I've created a table with three keys inside like this:

CREATE TABLE reservation
(
    reservation_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    hotel_id INT UNSIGNED NOT NULL,
    customer_id INT UNSIGNED NOT NULL,
    PRIMARY KEY(reservation_id, hotel_id, customer_id),
    ............................

and I tried to insert the data by using the following sql statements:

INSERT INTO reservation (reservation_id, hotel_id, 
customer_id,business_trip, checkin_month,
checkin_day, checkin_year, checkin_time, checkout_month, checkout_day, 
checkout_year,
total_num_guest, room_type, hotel_recommendation, customer_request, 
customer_comments) VALUES
(NULL, NULL, NULL, 'yes_business', 'January', '01', '2002', '11:00', 
'January', '07', '2002', '3',
'Triple', 'no_recommendations', 'Morning call', 'No')

The book says that I should put NULL in order to let AUTO_INCREMENT generate the id 
for me.
However, it kept telling me that hotel_id can't be null (I guess it was because the 
hotel_id has been
generated in the "hotel" table by using AUTO_INCREMENT as well). How am I supposed to 
connect different primary keys into one table (I mean how can I transfer the hotel_id 
in Hotel table to 
the Reservation table)? And after that how can I insert those primary keys inside one 
table?

Thank you very much for your time.

Sincerely,
Cheri Peng

Reply via email to