Jump to content

[SOLVED] Primary Key vs Unique


soycharliente

Recommended Posts

I am wondering what the difference between a primary key and the unique attribute is. I looked online and talked with friends and I am still confused. I am beginning to build some basic databases and from what I can gather, you want to set some kind of row id to be the primary key and that on generating the table rows, each row will be given a unique number. But it's all very confusing because they keep using both terms to describe the other term. If anyone can understand what I am trying to convey, some help in understanding the difference, how to use them, and when to use each would be greatly appreciated.

Thanks in advance.
Link to comment
Share on other sites

Essentualy a unique is what it says.  For exampe say you have a table with 30 rows.  You could have a coloum called id.  This colour could have a unique (diffrent) number for each row.  This can be very helpfull for identifiying rows, espesialy for example if two are the same.  so basicly the unique attribute meens not the same as anything else in that row.

You might find it usefull that you can set your database to automaticaly add the next number in a sequence whenever a row is generated.  This meens you will always have a unique value. 

Basicly for most uses they are the same except that for a primary key there can be no blank entries, where as with a unique there could be one blank entrie.

Hope this clarifys things a little!
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.