Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turning off allowing multiple non-unique rows

Status
Not open for further replies.

jackz15

Programmer
Jun 28, 2006
103
US
I feel lazy and I am busy so i don't want to fix my perl code to only alllow insertion of unique rows. I know mysql is set to allow multiple rows of the same thing but I would like to turn that feature off. Is that possible?
 
ALTER TABLE `tablename` ADD UNIQUE (`fieldname`)

Now remember, this will fail if there is data in the table that is not unique. You may have to copy to a new table, truncate the table, add the unique, and copy the data back.
Mark
 
You don't even need to do all that just run:

Code:
ALTER IGNORE TABLE tablename ADD UNIQUE INDEX (fieldname);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top