Error 546

Severity

16

Message text

Foreign key constraint violation occurred, dbname =  ’%.*s’, table name = ’%.*s’, constraint name = ’%.*s’.%S_EED

Explanation

Foreign key constraints are a form of integrity constraint which ensure that no insert or update on a foreign key table is performed without a matching value in the primary key table. Error 546 is raised when an integrity constraint is violated during execution of a query. For example, error 546 can be raised when Adaptive Server detects that the data inserted into a foreign key does not match any primary key value in the table referenced by the foreign key.

For example:

1> create table departments
2>   (d_id int primary key, d_name varchar(30))
3> create table employees
4>   (emp_id int, empname varchar(100), d_id int references departments)
5> go


1> insert departments values (1, ’sales’)
2> go

(1 row affected)

1> insert employees values (1, ’Fred Smith’, 1)
2> go
(1 row affected)

1> update employees set d_id = 2 where emp_id=1
2> go
Foreign key constraint violation occurred, dbname =  ’master’, table name =
’employees’, constraint name = ’employees_d_id_1824006498’.
Command has been aborted.
(0 rows affected)

In this example, error 546 is raised because the update command attempted to use a non-existent department.

Action

Check your query or application to determine the source of the constraint violation. You can examine the constraint by executing:

1> sp_helpconstraint <table_name>
2> go

Where <table_name> is the table appearing in the 546 message.

Versions in which this error is raised

All versions.