Click to See Complete Forum and Search --> : Make two fields Unique?


DinoVaught
07-14-2003, 09:01 AM
How can I make the LAST_NAME and FIRST_NAME fields unique? So there can’t be two people with the same first and last names.


CREATE TABLE ROT_MachineUsers
(MU_ID Int PRIMARY KEY,
COMP_ID Varchar(10) UNIQUE NOT NULL,
LAST_NAME Varchar(40) NOT NULL,
FIRST_NAME Varchar(40) NOT NULL);

aph
07-14-2003, 09:14 AM
Is it real data storage technique? Two people in the world can not be the same as first name and last name.

Anyway if you still wants the solution, please follow the following line.


CREATE TABLE ROT_MachineUsers
(MU_ID Int PRIMARY KEY,
COMP_ID Varchar(10) UNIQUE NOT NULL,
LAST_NAME Varchar(40) NOT NULL,
FIRST_NAME Varchar(40) NOT NULL
constraint ln_key unique(last_name);
constraint fn_key unique(first_name) );

DinoVaught
07-14-2003, 10:10 AM
Thanks for the reply. . . It worked!

Actually there’s a third, ID field, thats part of the constraint. I left it out for reasons of simplicity. . . It actually looks like this. . .


CONSTRAINT NAME_KEY UNIQUE (LAST_NAME, FIRST_NAME, COMP_ID));