A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Difference between primary key and index



 
 
Thread Tools Display Modes
  #1  
Old January 29th, 2005, 11:55 PM
Amir
external usenet poster
 
Posts: n/a
Default Difference between primary key and index

What is the difference between primary key and index in Access?
If I define an Index field which is Unique and Not allowed Null, is it a the
same as a PK?
  #2  
Old January 30th, 2005, 12:38 AM
Rick Brandt
external usenet poster
 
Posts: n/a
Default


"Amir" wrote in message
...
What is the difference between primary key and index in Access?
If I define an Index field which is Unique and Not allowed Null, is it a the
same as a PK?


It's pretty darn close. A table can have multiple unique indexes, but only one
PK. For all practical purposes the PK is a unique constraint that doesn't allow
nulls. There are some database engines that will impose the not null constraint
and the unique constraint of the PK without also building an index against it,
but most engines automatically index the PK.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


  #3  
Old January 30th, 2005, 01:44 AM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Sat, 29 Jan 2005 15:55:04 -0800, "Amir"
wrote:

What is the difference between primary key and index in Access?


A Primary Key is a logical construct. An Index is an area on your hard
disk which Access manages, which can (among other things) be used to
implement the logical construct of a Primary Key.

If I define an Index field which is Unique and Not allowed Null, is it a the
same as a PK?


Not necessarily, though the differences are subtle; it will prevent
duplicate records and can be used to create enforced one-to-many or
one-to-one relationships, just like a PK.

John W. Vinson[MVP]
  #4  
Old January 30th, 2005, 04:05 AM
Chris2
external usenet poster
 
Posts: n/a
Default


"Amir" wrote in message
...
What is the difference between primary key and index in Access?
If I define an Index field which is Unique and Not allowed Null, is

it a the
same as a PK?


And my two cents:

A Primary Key is the column or combination of columns (Access refers
to them as "fields") that *uniquely* defines a row in a table. No
true table is without a Primary Key, although most relational database
software products allow it.

An Index is a file-feature that is used for various things, like
making lookups more rapid, for enforcing uniqueness in a column, etc.

Access uses indexes to enforce Primary Keys and Foreign Keys (for
"Referential Integrity").

And, a litte mo

A Foreign Key is a column or combination of columns in one table, that
are also found in another table, where Access uses an index to make
sure that no value(s) in the Foreign Key column(s) exists that does
not also exist in those same columns in the "other" table. This
process is called "enforcing Referential Integrity", and is used, for
example, to make sure that a database doesn't have customer phone
numbers hanging around in the PhoneNumbers table with CustomerID
values that don't exist in the Customers table.


Sincerely,

Chris O.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:11 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.