Jump to content

Is there a connection between SQL multi table query and PK and FK?


dani33l_87

Recommended Posts

I have this questions

 

Is there a connection between SQL multi table query and

PK and FK?

 

and this answer

 

SELECT country.Name, countrylanguage.Language FROM

country, countrylanguage WHERE

country.Code = countrylanguage.CountryCode

 

But I need to explain it and I don t understand very good databse.

 

Someone know an answer/explanation easy to remember?

Link to comment
Share on other sites

I have some questions like what is Primary Key, Foreign key. What are the disadvantages and advantages to use these.

I know all this questions instead of this:

 

 

Is there a connection between SQL multi table query and Primary Key and Foreign Key?

 

I have an idea what is the relation but I will need a clear answer for someone that really understand this.

Link to comment
Share on other sites

A primary key is just a special unique index, at its core.

 

A foreign key is way to ensure that cross-referenced values between tables stay consistent (i.e. when the parent gets updated, the child tables do as well).

 

It is often true that the index required in the referencing table is often the PK, but there's no requirement for it to be.

 

Every InnoDB table requires a PK -- and it's a good idea to pick one yourself, or InnoDB will make a poor choice for you. MyISAM can omit the PK, but it's rarely a good idea for most tables.

 

In terms of multi-table queries, once again, indexes are required for these to perform well -- so a PK can often be used.

Link to comment
Share on other sites

1)primary key comes into picture mostly in INSERT and UPDATE queries rather than select primary key basically means that if a column in database has a primary key attribute then no duplicate values can be inserted in that column

2)Foreign key means if a column in a table suppose column id of table marks has a foreign key on column id of student then column id of marks can only contain values that are in id column of student

 

 

 

hope this helps!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.