On Dec 7, 10:18 am, Jim Morris <[email protected]> wrote:
>
> Maybe I am being dense here (not uncommon ;) but what is the
> difference between...
>
> add_primary_key [:user_id, :store, :object, :fn]
>
> and
>
> index [:user_id,  :store, :object, :fn], :unique => true
>
> Both seem to create a multi key unique index, what is the extra
> constraint that is added with primary_key?

in terms of the implementation, almost none - rather it's an assertion
you're making about the semantics of the data... (though a primary key
will also include a not null constraint on all the columns, whereas a
plain unique index will allow null columns)

there's no practical difference between calling something the primary
key and putting a unique not null constraint on it, rather you're
describing the data...for example, given

CREATE TABLE employees (
  employee_id integer primary key default nextval('employee_id_seq'),
  tfn integer not null unique,
  name varchar
);

the tfn (Tax File Number, it's a .au thing) must be present and
unique, but it's not how the company actually refers to employees in
their internal data... there's no difference between requirements on
data in the employee_id and tfn columns, but the schema tells you that
you should prefer to refer to employees by their employee_id rather
than their tfn...

some databases will help you out by magically adding an autoincrement
default to integer columns that are defined as primary key, but that's
another story entirely...

cheers

Russell

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to