Make two fields Unique?
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Make two fields Unique?

  1. #1
    Join Date
    Jul 2003
    Location
    Saint Louis MO, USA
    Posts
    8

    Make two fields Unique?

    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.

    Code:
    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);

  2. #2
    Join Date
    Jul 2001
    Posts
    334
    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) );

  3. #3
    Join Date
    Jul 2003
    Location
    Saint Louis MO, USA
    Posts
    8
    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. . .

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width