Home > database >  Mysql can at the database level guarantee special uniqueness?
Mysql can at the database level guarantee special uniqueness?

Time:10-06

Mysql table has two fields a, b, when a=1, b=1, the record is the only, current practice is a program to ensure uniqueness, save or update, you must first query sentence,
We know that it is best at the database level to ensure uniqueness, but the special cases to ensure that can trigger or something?

CodePudding user response:

The trigger can be checked,

CodePudding user response:

With the only index not line

CodePudding user response:

You can use a trigger to realize,

Also can have a try with a unique index, but when there is a unique problems, is two columns, but this any column in the two columns, can is empty, also can only, so as to limit the 2 not null

CodePudding user response:

The trigger can be solved, but applications will still be some trouble, because need to deal with update failed
Are you feeling this need is quite strange, don't know whether the application is a special design of time want to slanting

CodePudding user response:

Mysql table has two fields a, b, when a=1, b=1, the record is the only
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- what is a=1, b=1, the record is the only? Is don't need to make sure that the only other values?

CodePudding user response:

reference 5 floor ZJCXC reply:
mysql table has two fields a, b, when a=1, b=1, the record is the only
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- what is a=1, b=1, the record is the only? Is don't need to make sure that the only other values?

He should say is A combination of the only, is A, B two fields combination and uniqueness
  • Related