question

EshwarNakkala-4064 avatar image
0 Votes"
EshwarNakkala-4064 asked MelissaMa-msft commented

how to rename constraint from table

Hi,

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


Regards,
Eshwar Nakkala

sql-server-transact-sql
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @EshwarNakkala-4064

Could you please provide any update? Thanks.

Best regards
Melissa

0 Votes 0 ·

1 Answer

MelissaMa-msft avatar image
0 Votes"
MelissaMa-msft answered MelissaMa-msft edited

Hi @EshwarNakkala-4064

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.