-1

If i have a table with fields(Columns) like this:

Username    Password    Name

I want to create a table such that Username && Name is not same for any Tuple(row).

For example, this should not be allowed

Username    Password    Name
John_1      poor        John B
John_1      xxx         John B
Abhishek
  • 1
  • 2
  • 1
    http://en.wikipedia.org/wiki/Compound_key – Rohan Büchner Feb 05 '15 at 13:38
  • Read this answer by marc_s http://stackoverflow.com/a/4737412/1105314 – Rohan Büchner Feb 05 '15 at 13:40
  • 1
    Add unique (Username, Name) constraint to your table! – jarlh Feb 05 '15 at 14:02
  • So, you wouldn't care if there's `('Mary','123','Mary A')` and `('Mary','123','Mary B')`? The main problem with your example is that `Username` isn't unique. Duplicate names is something any system will need to address, usually by presenting the user with enough information to differentiate the two. In any sufficiently large organization, you're all but guaranteed to have users with the same first, middle and last names. And what if one user needs to have two accounts (for testing, for example)? Yes, a compound key answers your question, but I don't think it's going to fix your problem. – Bacon Bits Feb 05 '15 at 14:08

1 Answers1

0

You can make your composite primary key as (Username, Name).

Ankit Bajpai
  • 13,128
  • 4
  • 25
  • 40