Link to home
Start Free TrialLog in
Avatar of silver00x00
silver00x00

asked on

SQL join vs Primary key?

I an very new to Databases
Currently studying Access, SQL and using Coldfusion

I was reading in SQL you can use FROM and WHERE to JOIN two tables in a query. Where does the Primary key come in? Or is it even needed based on what you are using? Does the primary key need to be assigned on the tables in order to use that function?

I am confused, please help.
Avatar of Kevin Hill
Kevin Hill
Flag of United States of America image

Each tabele SHOULD have a PK, for the purpose of enforcing uniqueness among the rows.

You can JOIN two tables in a query without using the PK, as long as the datatypes are the same (and the fields being joined make sense...)

Many very large systems have no relationships (not the same thing as JOINs) defined at all, and handle all that in the application...

Clear as mud?
Avatar of silver00x00
silver00x00

ASKER

Very....

So in a very large system that you speak of... What does it use to create a "relation" ?
A relationship is a defined link between tables....many of them don't.  They just use a lot of error handling to ensure they aren't adding child rows without a parent.  Not my preference, but it does work.
Kevin3NF, you are right in all that you said, but you are kind of mixing PK and FK in here and I'm not sure it's clear.
PK = Primary Key, which is one or more columns that can uniquely define a row in a certain table.
FK = Foreign Key, which is a constraint that means any value in a certain column in my table has to exist in another table in order for me to be able to insert it.

Now, basically you don't HAVE to have any Keys(called Constraints)  at all. but they do make your job easier, they enforce the data integrity for you and save you all the trouble.

As to your question directly, the Primary key has no real affect on the query you make(your join) other than the fact it makes it more efficient(run faster). It will not limit you in any way and many systems that were created before the PK and FK were invented(not that many years ago...) still live without them, it just adds them alot of code lines making sure that no bad values are entered into the Database.
ASKER CERTIFIED SOLUTION
Avatar of cpunate9
cpunate9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial