i wanted to create a table name booking that have 3 composite key where 2 of the composite key is referring to each another table named customer and room. however when i wanted to create the table, it give me error. can someone tell me how can i fix this. Here's the command : CREATE TABLE booking( bookingID INT NOT NULL AUTO_INCREMENT , checkin DATETIME, checkout DATETIME, nights INT, totalprice INT, b_ic_no VARCHAR(30), b_room_no INT, PRIMARY KEY ( bookingID) , PRIMARY KEY ( b_ic_no ) REFERENCES customer( ic_no ) , PRIMARY KEY ( b_room_no ) REFERENCES room( room_no ), ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE = INNODB; Code (markup):
A table in mysql can only have one primary key. I think you want to declare b_ic_no and b_room_no as foreign keys.
isn't that primary key that referring to another primary key in another table is called as 'composite key'? i'm not not really aggree when you said that i'm actually wanted to declare is a foreign key. or, am i wrong in understanding this 'composite key' term? if so, someone please explain to me... i'm sorry, i'm not expert in database i just started to learn it and stil learn about it. however, here's the relationship below and i really thinks what i'm trying to achieve is not foreign key but composite key..
Yes, you are wrong in your notion of composite key. A composite key exists when two or more fields within a table are used to create a unique key for that table, a foreign key is a field within one table that is a primary key in another table. So in your Booking table, 'ic_no' is a foreign key to the customer table and 'room_no' is a foreign key to the rooms table.