If you need to rename a constraint after creating with typo or due to any other reason, you could follow the below steps.
--creating test table with PK constraint
CREATE TABLE dbo.RenameConstraintTest
(
ID int CONSTRAINT PKC_RenameConstraintTest PRIMARY KEY CLUSTERED
)
GO
--check the existance of the constraint
SELECT * FROM sys.key_constraints WHERE name='PKC_RenameConstraintTest'
GO
--rename the constraint
EXEC sp_rename N'[dbo].[RenameConstraintTest].[PKC_RenameConstraintTest]', N'PKC_RenameConstraintTest2', N'INDEX'
GO
--check the old constraint
SELECT * FROM sys.key_constraints WHERE name='PKC_RenameConstraintTest'
GO
--check the renamed constraint
SELECT * FROM sys.key_constraints WHERE name='PKC_RenameConstraintTest2'
GO
Subscribe to:
Post Comments (Atom)
How to interpret Disk Latency
I was analyzing IO stats in one of our SQL Servers and noticed that IO latency (Read / Write) are very high. As a rule of thumb, we know tha...
-
Do you know there is a new T-SQL command in SQL Server 2008 which facilitates you to insert several rows in single INSERT statement? This is...
-
I wanted build an expression to make a folder name dynamically. (Basically expressions are anyway dynamic in nature) So I simply used the ...
-
This can happen due to many factors like lack of indexes, out of dates statistics, if it returns a large number of records, etc. I observed...
No comments:
Post a Comment