You can use the OBJECTPROPERTY()
function in SQL Server to check whether or not a table has one or more foreign key constraints.
To do this, pass the table’s object ID as the first argument, and TableHasForeignKey
as the second argument. The function returns a 1
or a 0
depending on whether or not it has a foreign key constraint.
A return value of 1
means that the table does have a foreign key constraint, and a value of 0
means that doesn’t. A return value of 1
applies regardless of how many foreign keys the table has (as long as it has at least one).
If you want an actual list of the foreign keys, see List All Foreign Keys on a Table in SQL Server.