?
Solved

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

Posted on 2013-06-04
6
Medium Priority
?
288 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

743 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