---
title: "How can I list all foreign keys referencing a table in SQL Server?"  
description: "How can I list all foreign keys referencing a table in SQL Server?"  
author: "Revati S Misra"  
published: 2023-07-11  
updated: 2023-07-12  
canonical: https://www.mindstick.com/forum/159031/how-can-i-list-all-foreign-keys-referencing-a-table-in-sql-server  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# How can I list all foreign keys referencing a table in SQL Server?

How can I list all [foreign keys](https://www.mindstick.com/interview/33602/what-are-super-primary-candidate-and-foreign-keys) referencing a [table in SQL](https://www.mindstick.com/forum/205/find-the-all-column-with-schema-for-any-table-in-sql-server) [Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over)?

## Replies

### Reply by Aryan Kumar

There are a few ways to list all [foreign](https://yourviews.mindstick.com/story/2164/here-are-the-best-foreign-universities-for-higher-education) [keys](https://www.mindstick.com/articles/75385/full-product-keys) referencing a [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) in [SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server). Here are two of the most common methods:

- **Using the** `sys.foreign_keys` **table**

The `sys.foreign_keys` table contains a list of all foreign keys in a database. You can use this table to list all foreign keys referencing a table by using the following query:

SQL

```plaintext
SELECT *
FROM sys.foreign_keys
WHERE referenced_table_name = 'table_name';
```

For example, the following code will list all foreign keys referencing the `Customers` table:

SQL

```plaintext
SELECT *
FROM sys.foreign_keys
WHERE referenced_table_name = 'Customers';
```

- **Using the** `sp_fkeys` **stored procedure**

The `sp_fkeys` stored procedure is a system stored procedure that can be used to list all foreign keys referencing a table. To use the `sp_fkeys` stored procedure, you need to specify the name of the table that you want to list the foreign keys for. For example, the following code will list all foreign keys referencing the `Customers` table:

SQL

```plaintext
EXEC sp_fkeys 'Customers';
```

The `sp_fkeys` stored procedure will return a list of all foreign keys referencing the `Customers` table. The list will include the name of the foreign key, the name of the referenced table, and the name of the column in the referenced table that is referenced by the foreign key.


---

Original Source: https://www.mindstick.com/forum/159031/how-can-i-list-all-foreign-keys-referencing-a-table-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
