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
How can define a combination of rows as unique?
Moderator: General Moderators
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Primary keys are always defined as unique. I know in most databases you can define other columns as unique.
should work.
This is taken from www.pantz.org - Handy MySQL Commands
Code: Select all
alter table [table name] add unique ([column name]);This is taken from www.pantz.org - Handy MySQL Commands
For multiple columns, it'sCoderGoblin wrote:Primary keys are always defined as unique. I know in most databases you can define other columns as unique.
should work.Code: Select all
alter table [table name] add unique ([column name]);
This is taken from www.pantz.org - Handy MySQL Commands
Code: Select all
alter table `table` add unique (`column1`, `column2`);- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
CoderGoblin - can you post that link in the Useful Resources thread?