Solved

In which order I should drop the constraints and recreate them?

Posted on 2013-06-04
6
281 Views
Last Modified: 2013-07-07
I've a database in which I would like to do bulk schema changes. The DB does not have FK.  I would like to delete following constraints and recreate them later point. In which order I could drop the constraints and in which order I could recreate them?

PK, Default, Unique, NOT NULL, and CHECK, Clustured index, Non clustured index, Triggers

Please assist. Thanks
0
Comment
Question by:Easwaran Paramasivam
  • 3
6 Comments
 
LVL 39

Accepted Solution

by:
lcohan earned 500 total points
ID: 39219259
May I ask why you need to drop and recreate constraints?
Triggers are not really SQL constraints so you can drop them at any time or better DISABLE.
If you really need to drop them here's what I would do:

Save definition for ALL constriants you will drop then drop in order - constraints (null,check, unique, etc), index, clustered index, PKeys.

Add them back - Clustered index (take the longest), PK, Index, then all the rest of constraints.
IF and ONLY IF data was NOT added or you know 100000% the data integrity is OK you could add them WITH NOCHECK so it will not take too long to add them back in.
0
 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 39219455
Actually speaking I get constraints from one database and run in another database (after dropping all constraints) in order to sync the two database in all respect. Please provide solution.
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39224563
Hi,

If you need to sync the db schema of two dbs you may check on some of third party tools available on the web. I have used DBGhost in the past and found it very helpful. You may define a source and a target db, and it will check for any schema differences. Then it will prompt for auto creating scripts to sync the target db.

Giannis
0
 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 39253692
@lcohan: Does below order correct?

Dropping order is null, check, unique, default, non clustered index, clustered index, PKeys.

Add them back - Clustered index, PK,  Non clustered Index, default, unique, check, Null
0
 
LVL 16

Author Closing Comment

by:Easwaran Paramasivam
ID: 39306278
Thanks
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question