Unique_index_id Value in sys.key_constraints & is_unique Column in sys.indexes

In summary: Not sure what you mean; certainly I was just looking at the specs of your own question.Index metadata is not redundant or not normalized.
  • #1
Pepper Mint
91
139
I find in SQL Server, sys.indexes contains an is_unique column and sys.key_constraints contains unique_index_id. Could you help confirm me that the unique_index_id value in the latter is also the index_id value of the former when its is_unique becomes true or 1 ?

Thank you.
 
Technology news on Phys.org
  • #2
Seems so, according to MSDN:https://technet.microsoft.com/en-us/library/ms174321(v=sql.110).aspx
ID of the corresponding unique index in the parent object that was created to enforce this constraint.

This gives me sensible results:

Code:
select      Object_Name(I.object_id) ObjectName, I.name IName, C.name ConstraintName
    ,       I.type_desc IndexType, C.type_desc ConstraintType
from        sys.indexes I
left join   sys.key_constraints C
    on      I.object_id = C.parent_object_id
    and     i.index_id = C.unique_index_id
where       I.is_unique = 1
    and     not c.object_id is null

(Slightly odd SQL as I was running it in bits (not always all of it at once) to see effects.)
 
  • Like
Likes Pepper Mint
  • #3
sdkfz said:
Thanks! I just feel something redundant in SQL Server.
This gives me sensible results:

Code:
select      Object_Name(I.object_id) ObjectName, I.name IName, C.name ConstraintName
    ,       I.type_desc IndexType, C.type_desc ConstraintType
from        sys.indexes I
left join   sys.key_constraints C
    on      I.object_id = C.parent_object_id
    and     i.index_id = C.unique_index_id
where       I.is_unique = 1
    and     not c.object_id is null
(Slightly odd SQL as I was running it in bits (not always all of it at once) to see effects.)

uhmm..., despite of the bits you are doing, I think this query is generally correct but not enough to cover all cases of various DB designs.
 
  • #4
Pepper Mint said:
Thanks! I just feel something redundant in SQL Server.uhmm..., despite of the bits you are doing, I think this query is generally correct but not enough to cover all cases of various DB designs.

Not sure what you mean; certainly I was just looking at the specs of your own question.
 
  • Like
Likes Pepper Mint
  • #5
Do you mean index metadata is redundant or maybe not normalized?
 
  • #6
jim mcnamara said:
Do you mean index metadata is redundant or maybe not normalized?
I only find constraint information is still obtainable even without sys.key_constraints.
 

Related to Unique_index_id Value in sys.key_constraints & is_unique Column in sys.indexes

1. What is the purpose of the Unique_index_id value in sys.key_constraints?

The Unique_index_id value in sys.key_constraints is used to identify the unique index for a specific constraint. This value is unique within a database and is assigned by the system when the constraint is created.

2. How is the Unique_index_id value related to the is_unique column in sys.indexes?

The Unique_index_id value is related to the is_unique column in sys.indexes because it is used to identify the unique index for a specific constraint. The is_unique column in sys.indexes indicates whether the index is unique or not.

3. Can there be multiple Unique_index_id values for a single constraint?

No, there can only be one Unique_index_id value for a single constraint. This value is unique within a database and is assigned by the system when the constraint is created.

4. How does the Unique_index_id value impact the performance of a database?

The Unique_index_id value does not directly impact the performance of a database. It is simply used as a means of identifying the unique index for a specific constraint.

5. Can the Unique_index_id value be changed or modified?

No, the Unique_index_id value cannot be changed or modified. It is assigned by the system when the constraint is created and remains constant for the life of the constraint.

Similar threads

  • Programming and Computer Science
Replies
7
Views
618
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
4
Views
510
  • Programming and Computer Science
Replies
8
Views
974
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
4
Views
966
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
1
Views
701
  • Programming and Computer Science
Replies
3
Views
863
  • Programming and Computer Science
Replies
5
Views
2K
Back
Top