Re: Normalization, Natural Keys, Surrogate Keys
Date: Fri, 17 May 2002 21:11:15 -0600
Message-ID: <3ce5c46b$1_15_at_news.teranews.com>
"Daniel Morgan" <dmorgan_at_exesolutions.com> wrote in message
news:3CE583F3.7F5D20D5_at_exesolutions.com...
> Paul Tiseo wrote:
>
> The reason some people go ballistic is as follows:
>
> CREATE TABLE employees (
> surrogate_key NUMBER,
> ssn VARCHAR2(11));
>
> ALTER TABLE employees
> ADD CONSTRAINT pk_employees PRIMARY KEY (surrogate_key);
>
> CREATE SEQUENCE seq_surrogate_key START WITH 1;
You forgot:
CREATE UNIQUE INDEX ssn ON employee (ssn);
(btw, you should use singular rather than plural for table names. <g>)
> INSERT INTO employees
> VALUES
> (seq_surrogate_key.NEXTVAL '555-55-5555');
>
> INSERT INTO employees
> VALUES
> (seq_surrogate_key.NEXTVAL '555-55-5555');
>
> COMMIT;
>
> It happens all the time.
Clearly.
-- Pablo Sanchez, High-Performance Database Engineering mailto:pablo_at_hpdbe.com http://www.hpdbe.com Available for short-term and long-term contractsReceived on Sat May 18 2002 - 05:11:15 CEST