soycharliente Posted December 5, 2006 Share Posted December 5, 2006 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. Quote Link to comment Share on other sites More sharing options...
artacus Posted December 5, 2006 Share Posted December 5, 2006 The differences are that you can only define 1 primary key and it can not contain nulls. Neither is true for unique. Quote Link to comment Share on other sites More sharing options...
the_oliver Posted December 6, 2006 Share Posted December 6, 2006 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! Quote Link to comment Share on other sites More sharing options...
fenway Posted December 6, 2006 Share Posted December 6, 2006 The PK is just a special case of UNIQUE. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.