foreign key

can we create two foreign for three table.

Page 1 of 1

1 Replies - 548 Views - Last Post: 28 July 2010 - 07:10 AM

#1 rakesh0  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 11
  • Joined: 23-July 10

foreign key

Posted 28 July 2010 - 05:00 AM

hi,
i made four table named- country ,customer, product, artwork both having column named as follows:

customer- customer_id(pk) , customer_name , customer_po , customer_part_no , customer_adress.
product- product_id(pk) , product_name , manufacture_date,expiry_date.
country- country_no, country_name,language.
artwork- artwork_no(pk), artwork_name,artwork_code.



here (pk) stands for primary key,i wore it only make you understand,
Can Anybody tell how can i relate these four table using foreign key constraint and where and how many will be used,i tried a lot but unable to get solution, i have just started to work in mysql so m new if anybody provide me help,,,,,

Is This A Good Question/Topic? 0
  • +

Replies To: foreign key

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9044
  • View blog
  • Posts: 33,559
  • Joined: 27-December 08

Re: foreign key

Posted 28 July 2010 - 07:10 AM

To create an FK on a column, you need to use the constraint FOREIGN KEY (col) REFERENCES table(other_col). You can use it in your CREATE or ALTER table statements. Take a look at the W3Schools page for more information.

As a rule of thumb, IDs don't always make good FKs, as they don't have any data. Think about what elements of table_a you want in table_b. For example, if you have an order table, you would want cust_name from the customer table as an FK so you can associate a customer to an order.

Are you just playing around with SQL or do you have an assignment? In layman's terms, what do you see yourself modeling with this database? Can you provide more background information?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1