TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-27-2010, 06:16 PM   #1 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 14
Thanks: 4
fairytale89 is on a distinguished road
Default composite key syntax. How can I fix this?

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 :
Code:
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;
fairytale89 is offline  
Reply With Quote
Old 03-27-2010, 07:46 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

You can't have more than one primary key, thus what makes a primary key primary.
delayedinsanity is offline  
Reply With Quote
Old 03-27-2010, 08:30 PM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

A primary key is what the database uses to identify the row. While you do not have to have one, it makes looking up a particular row a lot faster becuase the database expects you to find it via the primary key. However, it is a unique ID and there can only be one per row.
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
fairytale89 (03-29-2010)
Old 03-27-2010, 11:55 PM   #4 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 14
Thanks: 4
fairytale89 is on a distinguished road
Default

isn't that primary key that referring to another primary key in another table is called as 'composite key'?
i'm not not really agree when you said that i'm actually wanted to declare is a unique ID. 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..
Attached Thumbnails
composite-key-syntax-how-can-i-fix-relationship-room.jpg  
fairytale89 is offline  
Reply With Quote
Old 03-31-2010, 04:19 PM   #5 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by fairytale89 View Post
isn't that primary key that referring to another primary key in another table is called as 'composite key'?
i'm not not really agree when you said that i'm actually wanted to declare is a unique ID. 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..
A primary key can never refer to another table, it is used exclusively to identify each row. What you are looking for is a foreign key, use google to lean about those.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wiki syntax parser FSX Advanced PHP Programming 1 10-24-2008 05:06 PM
Syntax error here why?.. codefreek Absolute Beginners 5 08-12-2008 06:39 PM
Data validation syntax -- looks Greek to me Dave Absolute Beginners 4 04-22-2008 03:51 PM
MySQL syntax for table join on delete delayedinsanity General 5 04-03-2008 05:39 PM
Added Geshi Syntax Highlighting Wildhoney News and Announcements 11 11-20-2007 02:51 AM


All times are GMT. The time now is 07:35 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design