Reputation: 254
I have a table called Event and has 2 columns - eventID (Primary key, auto incremental, used for relationships, int data type) and an eventName(nvarchar(50) data type). How do I prevent duplication of data/value in my eventName column? I would like to return a message to the user that an event has already occurred through my asp.net page
Upvotes: 0
Views: 33
Reputation: 166396
You can use a UNIQUE
constraint on eventName
You can use UNIQUE constraints to make sure that no duplicate values are entered in specific columns that do not participate in a primary key. Although both a UNIQUE constraint and a PRIMARY KEY constraint enforce uniqueness, use a UNIQUE constraint instead of a PRIMARY KEY constraint when you want to enforce the uniqueness of a column, or combination of columns, that is not the primary key.
Multiple UNIQUE constraints can be defined on a table, whereas only one PRIMARY KEY constraint can be defined on a table.
Also have a look at Creating and Modifying UNIQUE Constraints and SQL UNIQUE Constraint
Upvotes: 2