Negoti Leboti
Negoti Leboti

Reputation: 41

First Name and Last Name must be Unique Together in SQL

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.

Upvotes: 3

Views: 3971

Answers (1)

ypercubeᵀᴹ
ypercubeᵀᴹ

Reputation: 115630

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

Upvotes: 4

Related Questions