Page 1 of 1
How can define a combination of rows as unique?
Posted: Tue Feb 13, 2007 12:57 am
by Betty_S
Hi
How can define a combination of rows as unique?
I'm using mysql and need to prevent duplicate row inserting. I don't want to define one column as unique but a combination of 3 columns.
How can I do that?
thanks
Posted: Tue Feb 13, 2007 2:21 am
by CoderGoblin
Primary keys are always defined as unique. I know in most databases you can define other columns as unique.
Code: Select all
alter table [table name] add unique ([column name]);
should work.
This is taken from
www.pantz.org - Handy MySQL Commands
Posted: Tue Feb 13, 2007 4:20 am
by Mordred
CoderGoblin wrote:Primary keys are always defined as unique. I know in most databases you can define other columns as unique.
Code: Select all
alter table [table name] add unique ([column name]);
should work.
This is taken from
www.pantz.org - Handy MySQL Commands
For multiple columns, it's
Code: Select all
alter table `table` add unique (`column1`, `column2`);
With phpMyAdmin it's called "Create an index on ... columns"
Posted: Tue Feb 13, 2007 10:20 am
by Kieran Huggins
That's a fine resource CoderGoblin -- thanks!
Posted: Tue Feb 13, 2007 6:30 pm
by RobertGonzalez
CoderGoblin - can you post that link in
the Useful Resources thread?