pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: M.D.G. Lange <mlange@dltmedia.nl>
To: orange_crush_068@hotmail.com
Cc: pgsql-sql@postgresql.org
Subject: Re: Unique primary index?
Date: Tue, 28 Jun 2005 09:50:35 +0200
Message-ID: <42C1014B.5050306@dltmedia.nl> (raw)
In-Reply-To: <1119530632.181638.4330@g49g2000cwa.googlegroups.com>
References: <1119530632.181638.4330@g49g2000cwa.googlegroups.com>

I would say that you should learn a bit about relational databases 
before you start working with them ;-)

All unique fields (or combinations of fields that -combined- are unique) 
can serve as a primary key.
In relational databases we call them 'candidate key'.

if you have more than one candidate key in a table, there's nothing 
wrong. You just simply choose.
Best choices are:
- select the set of the least amount of columns. (preferably only one)
- if you still have more than one candidate key, choose a column with an 
integer (as integers are looked up the fastest, and you want your 
indexes to be fast)
- if you still have more than one candidate key, pick one

That one you define as your primary key. By defenition a primary key is 
unique. But not all unique fields are primary key.

The primary index is the index that should be chosen most, because it is 
your fastest or best index. From my experience it is always the index of 
your primary key, since the reasons for selecting the primary index are 
normally about speed.

How you can create your indexes best, and how many you create and how 
you create them are beyond the scope of this mail. I suggest you read 
the documentation about the indexes.
Also get a book about basics of relational databases, it is really 
useful! Also getting yourself informed about normalisation (usually up 
to the 3rd form suffices) can help you on your way.

- Michiel

orange_crush_068@hotmail.com wrote:

>What are the major differences between Unique, primary index & just
>plain index?
>
>When creating tables I nominate one of these, but not sure what the
>difference is?
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 8: explain analyze is your friend
>
>
>
>  
>



view thread (5+ messages)  latest in thread

Message-ID: <42C1014B.5050306@dltmedia.nl>
Permalink:  ../42C1014B.5050306@dltmedia.nl/
Also on:    postgresql.org/message-id/42C1014B.5050306@dltmedia.nl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mlange@dltmedia.nl, orange_crush_068@hotmail.com
  Subject: Re: Unique primary index?
  In-Reply-To: <42C1014B.5050306@dltmedia.nl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox