| From: | "Daniel Serodio" <dserodio(at)gmail(dot)com> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: IS it a good practice to use SERIAL as Primary Key? |
| Date: | 2006-11-28 13:34:39 |
| Message-ID: | 1164720879.223957.276640@l39g2000cwd.googlegroups.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
"Joshua D. Drake" wrote:
<snip/>
>
> That's it, in a nut shell. There is no argument there. That is why you
> don't use artificial keys. That said... pretty much every table I create
> will have an artificial key... because it makes managing data easy. An
> example (to reuse the simple example):
>
> users
> =====
> id serial unique,
> first_name text,
> last_name text,
> primary key (first_name,last_name)
Why not
users
=====
id serial primary key,
first_name text,
last_name text,
unique (first_name, last_name)
? This way, you can use the "id" as foreign key (more efficient),
allows you to "UPDATE first_name" if needed, and if you find out you
need to add another Joshua Drake to the DB, all you need is to drop the
unique constraint?
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Jakub Ouhrabka | 2006-11-28 13:40:10 | Re: vacuum: out of memory error |
| Previous Message | Olexandr Melnyk | 2006-11-28 13:33:54 | Re: FK pointing to a VIEW |