Re: uniq key and primary key, how they are diffrent?

From: Lew Pitcher (Lew.Pitcher_at_td.com)
Date: 03/25/04


Date: Thu, 25 Mar 2004 12:52:32 -0500


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

somez72 wrote:

| Hello.
| could someone tell me ; In mysql, uniq key and primary key, how they
| are diffrent?

Primary keys are unique keys.

Unique keys can either be primary keys or foreign keys.

Primary keys are keys to the table you are addressing.
Foreign keys are keys to other tables that the the current table can reference.

Think of a contact list app, which implements two tables: a table of persons
(name, phone#, etc.), and a table of businesses (name, address, etc.). Each row
in the person table can (should) have a unique key (it's primary key) that can
be used to distinguish one row from all others. Each row in the business table
should likewise have a unique key, again to distinguish one row from all others.

If a person works at a company, the row in the person table for that person
would also contain the key for the company s/he works for. This key is unique
(it's the unique primary key of the company table entry for the company that the
person works for), but it is not the primary key in the person table. Instead,
it's a "foreign key" in the person table, referencing the company table.

So, unique keys are keys. Primary keys are unique keys. Foreign keys are unique
keys.

- --
Lew Pitcher
IT Consultant, Enterprise Application Architecture,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFAYxxeagVFX4UWr64RAtxoAKCYUYzI2anWTzM7TfmY2DbBC2I77wCguMbS
jHcmD0qTjTLA8DGqTPrw/4E=
=vDxy
-----END PGP SIGNATURE-----



Relevant Pages

  • Re: Get Primary key from Access db
    ... Brendan, article you posted shows how to get index information, i can do it ... But i need keys information - especially foreign keys. ... VARCHAR) and Table2(id integer PRIMARY KEY, idTable1 integer, data ...
    (microsoft.public.access.modulesdaovba)
  • Re: FOREIGN KEY CONSTRAINTS
    ... veracity of your database application. ... keys vs. surrogate keys are available for your reading pleasure. ... surrogate key and a unique index that doesn't allow NULLs on the natural key, ... The EMPID primary key in the employees table remains ...
    (microsoft.public.access.tablesdbdesign)
  • Re: After creating a Form, how do you you put four tables that have a.
    ... Something that you have added is causing 1 of the Foreign Keys to be written ... were not successful because they would create duplicate values in the ... primary key or relationship. ...
    (microsoft.public.access.forms)
  • RE: Multiple Records
    ... Oh no...I didn't set the Primary key and the 2 foreign keys for the ... I do have a hard time with ...
    (microsoft.public.access.gettingstarted)
  • Re: How can you create a field that is concatenated?
    ... keys in relational theory, ... PRIMARY KEY in the SQL language, ... Autonumber in the Jet product. ...
    (microsoft.public.access.tablesdbdesign)