16
I would like to know the behavior/differences between a Indice Unique and Unique Constraints to the Sql Server ?
Many may think that it makes no difference in the database, but it does! And not only for the DBA/Administrator, but also for the developers because it can influence how a code is written.
As a reference of what may be so different and what I’m interested in knowing follows below an example of how it is in a bank Informix , but in SQL Server how it works?
Indice UNIQUE
- Can be created/deleted ONLINE, with users using the table
This can weigh heavily on the maintenance of 24x7 systems. * Validation oneness is done line by line. A simple example, would be like execute aUPDATE tp01 SET cod = cod + 1;
in a table that the field Cod is sequential and with Intel unico, this update would error in the first line as it would already duplicate * Like all other databases, no can be used as a reference for Foreign Keys...Unique Constraint
(or even Primary key Constraint)
- Cannot be deleted/created with users accessing the table, even read-only. In other words you need exclusive access in the table to perform a maintenance. This is bad in systems 24x7. * Validation is done at the end of the statement In the case of
UPDATE tp01 SET cod = cod + 1;
, would work smoothly because it will validate the uniqueness only when finalizing the update of all lines involved. * It is possible to postpone the validation of the Constraint only at the end of the transaction. That is, at the time of thecommit
. This is possible when using the commandset constraints [all|<constraint>] deffered;
before the updates.
So in the update example above, it will only validate uniqueness when the commit is sent to the bank. Note: This resource applies to all types of constraints (PK, FK, UK)
Source: Difference in Use Index Unique and Unique Constraint in Informix?
Remember, the description above is how IBM Informix works. I would like to know how it is in other banks and understand what additional limitations or resources we can provide for developers.
Talles, thank you for the reply, but I won’t point it out yet because one of my main doubts has not been clarified, what this difference can change for the developer, in his code/transactional control , or does not change anything? Thanks anyway, I pointed out your reply as useful.
– ceinmart