title: Dropping and recreating Constraints in SQL Server
body: <p>I am doing the below SQL operation</p>
  
  <pre><code>insert Component values (201, 19, 1, 'Statements', 1, 10)
  </code></pre>
  
  <p>I have to revert it back using a script which I do as below</p>
  
  <pre><code>delete from Component where ComponentID = 201 and ComponentTypeID = 19
  </code></pre>
  
  <p>The issue is I am getting a error as below</p>
  
  <blockquote>
    <p>The DELETE statement conflicted with the REFERENCE constraint "FK_Component_ComponentType". The conflict occurred in database "Test", table "Component", column 'ComponentTypeID'.</p>
  </blockquote>
  
  <p>So what I am doing to solve this issue is dropping the constraint and adding it back when I am done deleting the row like below</p>
  
  <pre><code>alter table Component   drop
          FK_Component_ComponentType
  </code></pre>
  
  <p>and then adding it back</p>
  
  <pre><code>ALTER TABLE [dbo].[Component]  WITH CHECK ADD  CONSTRAINT [FK_Component_ComponentType] FOREIGN KEY([ComponentTypeID])
  REFERENCES [dbo].[ComponentType] ([ComponentTypeID])
  ALTER TABLE [dbo].[Component] CHECK CONSTRAINT [FK_Component_ComponentType]
  </code></pre>
  
  <p>My question is that is this the right way to do it and is there any harm in dropping and recreating the constraint? Will there be any data loss or any other issue in this operation?</p>