How to distinguish rows from each other in a database table?
I have some records that I need to store in a database table and I want to distinguish one record from other records on the basis of name
field.
But as the datatype of name field is varchar
, it will effect the performance because comparing varchar
data with each other is time consuming process in comparision to a numeric field.
So I want each record to have a unique numeric field (say id
). But if I make the id
as primary key, th开发者_开发技巧en the more than one record can contain same name
.
What's the solution to the above problem?
You can still create a UNIQUE
constraint on the name
field:
ALTER TABLE your_table ADD UNIQUE (name);
The UNIQUE
constraint, like the PRIMARY KEY
constraint, will guarantee that your column will contain only unique values.
Note that you can have many UNIQUE
constraints per table, but only one PRIMARY KEY
constraint.
Name can be made unique index.
精彩评论