How does Microsoft SQL Server Management Studio name the constraint for a unique key?
When I run the following sql command
INSERT INTO alert_template (object_type_id, object_id, alert_object_type_id, alert_object_id, monitor_type_bit_flags, name)
VALUES (5, null, 5, 0, 2147483647, 'alert-template-system-default');
I got the error message
Violation of UNIQUE KEY constraint 'u_alert_template_object_association'. Cannot insert duplicate key in object 'dbo.alert_template'.
Which unique key does the error message refer to?
I didn't find a constraint named u_alert_template_object_association
in the table dbo.alert_template
. Was the constraint created implicitly by SQL Server Management Studio? If yes, what is the convention that it uses to name the constraint?
Thanks.
updated
I just found the statement that created the table defines the constraint u_alert_template_object_association
. But i didn't find the constraint in SQL management studio's Object Explorer window, where the Constraints
under dbo.alert_template
doesn't list the constraint u_alert_template_object_association
, which was the cause of my confusion in my post. So is the Object Exploere window not supposed to show a constraint defined in the create statement of a table?
CREATE TABLE alert_template
(
id INT PRIMARY KEY IDENTITY,
object_type_id TINYINT NOT NULL REFERENCES object_type(id)
CONSTRAINT u_alert_template_object_type
CHECK (object_type_id = 5 or object_type_id = 17 or object_type_id = 18 or object_type_id = 26 or object_type_id = 27),
object_id BIGINT NULL,
alert_object_type_id TINYINT NOT NULL REFERENCES object_type(id)
CONSTRAINT u_alert_template_alert_object_type
CHECK (alert_object_type_id = 5 or alert_object_type_id = 37 or alert_object_type_id = 38),
alert_object_id TINYINT NOT NULL,
name NVARCHAR(128) NOT NULL
CONSTRAINT u_alert_template_name UNIQUE (object_type_id, object_id, name),
monitor_type_bit_flags INT NOT NULL
CONSTRAINT u_alert_template_object_association UNIQUE (object_type_id, object_id, alert_object_type_id, alert_object_id, monitor_type_bit_flags),
);