User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 391,662 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,838 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 457 | Replies: 2 | Solved
Reply
Join Date: Apr 2006
Posts: 62
Reputation: Fenerbahce is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Fenerbahce Fenerbahce is offline Offline
Junior Poster in Training

foreign keys

  #1  
Mar 30th, 2008
Hi,

I can create all tables but order table. What is wrong, is it foreign key?

  1. CREATE TABLE customer(
  2. customerId INT(10) NOT NULL AUTO_INCREMENT,
  3. customerName VARCHAR(10),
  4. customerSurname VARCHAR(10),
  5. customerAddress VARCHAR(10),
  6. PRIMARY KEY (customerId));
  7.  
  8. CREATE TABLE ORDER(
  9. orderId INT(10) NOT NULL AUTO_INCREMENT,
  10. customerId INT(10),
  11. PRIMARY KEY (orderId),
  12. FOREIGN KEY (customerId) REFERENCES customer(customerId));
  13.  
  14. CREATE TABLE orderDetail(
  15. orderDate DATE,
  16. orderId INT(10),
  17. productId INT(10),
  18. FOREIGN KEY (orderId) REFERENCES ORDER(orderId),
  19. FOREIGN KEY (productId) REFERENCES product(productId));
  20.  
  21. CREATE TABLE product(
  22. productId INT(10) NOT NULL AUTO_INCREMENT,
  23. productName VARCHAR(10),
  24. PRIMARY KEY (productId));
  25.  
  26. CREATE TABLE stock(
  27. stock INT(10),
  28. productId INT(10),
  29. FOREIGN KEY (productId) REFERENCES product(productId));

Thanks
Last edited by peter_budo : Apr 1st, 2008 at 7:06 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2008
Posts: 25
Reputation: blater is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
blater's Avatar
blater blater is offline Offline
Light Poster

Re: foreign keys

  #2  
Mar 30th, 2008
"order" is a reserved word so you need to quote it if you're going to use it for a table name. See here for details.
Reply With Quote  
Join Date: Apr 2006
Posts: 62
Reputation: Fenerbahce is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Fenerbahce Fenerbahce is offline Offline
Junior Poster in Training

Re: foreign keys

  #3  
Mar 31st, 2008
thanks, it works with "orders".
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 1:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC