---
title: "How can you rename a constraint on a table using SQL?"  
description: "How can you rename a constraint on a table using SQL?"  
author: "Utpal Vishwas"  
published: 2023-08-30  
updated: 2023-08-31  
canonical: https://www.mindstick.com/forum/159771/how-can-you-rename-a-constraint-on-a-table-using-sql  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# How can you rename a constraint on a table using SQL?

How can you [rename](https://www.mindstick.com/interview/23303/how-to-rename-extention-of-mdf-file) a [constraint](https://www.mindstick.com/articles/434/constraint-in-sql-server) on a [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) using [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database)?

## Replies

### Reply by Aryan Kumar

Sure, you can rename a constraint on a table using SQL using the `sp_rename` system stored procedure. The syntax for the `sp_rename` system stored procedure is:

SQL

```plaintext
sp_rename 'old_constraint_name', 'new_constraint_name';
```

The `old_constraint_name` is the name of the constraint that you want to rename. The `new_constraint_name` is the new name for the constraint.

For example, the following statement will rename the constraint `PK_Customers` to `Customers_PK`:

SQL

```plaintext
sp_rename 'PK_Customers', 'Customers_PK';
```

It is important to note that you cannot rename a constraint if it is being used by another object, such as a view or a stored procedure.

Here are some additional things to keep in mind when renaming a constraint:

- The `sp_rename` system stored procedure is a Transact-SQL statement. Transact-SQL statements are not reversible, so it is important to make sure that you are renaming the correct constraint.
- You cannot rename a constraint if it is being used by another object, such as a view or a stored procedure.
- If you are renaming a constraint that is a primary key or a unique constraint, you need to update the constraints on any tables that reference the original constraint.


---

Original Source: https://www.mindstick.com/forum/159771/how-can-you-rename-a-constraint-on-a-table-using-sql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
