3

I know that using the following codes will make each column have unique values, but what if I want a full name to be unique?

CREATE TABLE people (first_name varchar2(32) unique,
                     last_name varchar2(32) unique);

this will make each attribute unique on its own, but I need to make them both together unique, like If I have a name "James Smith", I don't want this name to be repeated again, but its ok if there was a "James Sunderland" guy.

4

1 回答 1

4

Define the UNIQUE constraint on the combination of the two columns:

CREATE TABLE people 
  ( first_name varchar2(32) , 
    last_name varchar2(32) ,
    UNIQUE ( first_name, last_name )
  ) ;
于 2012-06-14T20:47:19.150 回答