In MySQL, is it possible to have a UNIQUE constraint on a row?
Appears that MySQL's UNIQUE c开发者_开发百科onstraint is on a columns by column basis, I'm looking for a way to make sure the row are UNIQUE on a row by row basis; guessing the answer is to create a hash from by concatenating the columns per row I want to be UNIQUE then but a UNIQUE on the column storing the hash for that row. Also, the rows themselves unless I create a control will always be UNIQUE, since the ID for the row is a SURROGATE_KEY; meaning it's an integer sequential growing by +1 of the ID of the last row's integer.
You can create a multiple-column UNIQUE
index.
The main ways to ensure a row is completely unique is to use the UNIQUE
constraint on every column or create an analagous UNIQUE
index on every column. If you can allow two columns to accept the same input but you need to uniquely distinguish them, there's no reason why you would need anything more than a primary key (basically an ID column). The other thing you could do is switch to a column-store database such as InfiniDB, which has a MySQL front-end, or MonetDB, both of which are open source alternatives.
精彩评论