How to check if foreign key constraint exists

To check if a foreign key constraint exists on a table uses the system stored procedure named SP_FKEYS or view INFORMATION_SCHEMA.


Example

USE tempdb;
GO
EXEC sp_fkeys
@pktable_name = 'DEPARTMENTS',
@pktable_owner = 'dbo';

USE tempdb;
GO
EXEC sp_fkeys
@pktable_name = 'DEPARTMENTS',
@pktable_owner = 'dbo',
@pktable_qualifier = 'tempdb',
@fktable_name = 'EMPLOYEES',
@fktable_owner = 'dbo',
@fktable_qualifier = 'tempdb';
GO

select *
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where CONSTRAINT_TYPE='FOREIGN KEY';

See also: SP_FKEYS