Solved

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

Posted on 2013-06-04
6
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 40

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

726 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