Skip to content

Commit ec50b98

Browse files
authored
Changed unique index advice to unique constraint
In the advice given here, if you need to enforce uniqueness for a column that has a sequence value, the first choice should be a unique constraint, not a unique index i.e. it should be an attribute of the table design, not an index external to the table.
1 parent ae017e9 commit ec50b98

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

docs/relational-databases/sequence-numbers/sequence-numbers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ monikerRange: "=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||
4242
## Limitations
4343
Unlike identity columns, whose values cannot be changed, sequence values are not automatically protected after insertion into the table. To prevent sequence values from being changed, use an update trigger on the table to roll back changes.
4444

45-
Uniqueness is not automatically enforced for sequence values. The ability to reuse sequence values is by design. If sequence values in a table are required to be unique, create a unique index on the column. If sequence values in a table are required to be unique throughout a group of tables, create triggers to prevent duplicates caused by update statements or sequence number cycling.
45+
Uniqueness is not automatically enforced for sequence values. The ability to reuse sequence values is by design. If sequence values in a table are required to be unique, create a unique constraint on the column. If sequence values in a table are required to be unique throughout a group of tables, create triggers to prevent duplicates caused by update statements or sequence number cycling.
4646

4747
The sequence object generates numbers according to its definition, but the sequence object does not control how the numbers are used. Sequence numbers inserted into a table can have gaps when a transaction is rolled back, when a sequence object is shared by multiple tables, or when sequence numbers are allocated without using them in tables. When created with the CACHE option, an unexpected shutdown, such as a power failure, can lose the sequence numbers in the cache.
4848

0 commit comments

Comments
 (0)