UNIQUE - way to have unique rows in table?

constraints, sql, sql-server, sql-server-2008

Solution

Remove the unique index on the individual column and make it on both columns together, like this:

CREATE UNIQUE INDEX ixFullName ON yourTable (LastName, Name);

Problem

I have problem with unique rows in db table, now it is posible to do that: ``` id | Name | LastName | City ------------------------------------- 1 | John | Moore | London 2 | John | Moore | London ``` when i use UNIQUE attribute in all columns i have errors inserting second Moore even it is different Name :/ how use UNIQUE (or maybe INDEX?) to do something like that in my table in db: ``` id | Name | LastName | City ------------------------------------- 1 | John | Moore | London 2 | Jake | Moore | London 3 | John | Keen | London 4 | John | Moore | London //but good error when inserting the same row ``` Sorry if question is easy, but i am beginner at sql, and have problems with find some good example with using a UNIQUE like a want:/ or maybe I must just before inserting a new row selecting a table from db and check if it exist?

Original source