Sunday, December 1, 2013

How to create, alter and Drop a Constraints in SQL SERVER

To alter a constraints we need to drop that constraints first.
then recreate that constraints.

Follow this syntax, to Drop Constraints.

ALTER TABLE [dbo].[TableName]  DROP CONSTRAINT [FK_Config_ConstraintsName]



Follow this syntax, to Create a new Constraints.

ALTER TABLE [dbo].[TableNameWITH CHECK ADD  CONSTRAINT [FK_Config_ConstraintsName] FOREIGN KEY([Company_Mapping_ID])
REFERENCES [dbo].[Template_Company_Table] ([Template_Company_Mapping_ID])
GO

ALTER TABLE [dbo].[TableName] CHECK CONSTRAINT [FK_Config_ConstraintsName]

GO

No comments:

SQL Optimization

  SQL Optimization  1. Add where on your query  2. If you remove some data after the data return then remove the remove condition in the sel...