how to rename constraint from table

Eshwar Nakkala 106 Reputation points
2021-04-08T06:28:56.157+00:00

Hi,

Can any one help me with the SQL Syntax to rename constraint from table in Tsql (MSSM 2018)

Regards,
Eshwar Nakkala

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MelissaMa-MSFT 24,176 Reputation points
    2021-04-08T06:35:07.733+00:00

    Hi @Eshwar Nakkala

    Welcome to Microsoft Q&A!

    You could have a try with sp_rename using @objtype = 'OBJECT'.

    Syntax

    sp_rename [ @objname = ] 'object_name' , [ @newname = ] 'new_name'
    [ , [ @objtype = ] 'object_type' ]

    Please refer below example:

    EXEC sp_rename N'schema.old_constraint_name', N'new_constraint_name', N'OBJECT'  
    

    In addition, you could use below query to list out the CHECK constraints in the database.

    SELECT name,SCHEMA_NAME(schema_id) AS 'Schema',  
    OBJECT_NAME(parent_object_id) AS 'Table',definition  
    FROM sys.check_constraints;  
    

    Best regards
    Melissa


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments