Schema bound views
michaeldye
Posts: 10 Bronze 2
in SQL Compare
Afternoon all,
After a quick search I thought I'd better just ask the question - it's probably obvious but...
I've been using SQL compare for years & am now considering SQL source control too; but one of the ongoing hiccups I face is schema bound views; and updates to the tables referenced in the [schema bound] view.
If I try and "just" use SQL compare it'll fail: it tries to update the table and can't (the schema bound stops the table update?).
So; I have a developed a 3-stage process to update a "target" database from a "source" one::
1. A "before" compare script that'll drop my schema bound views in my "target" database
2. Run SQL compare which will both catch the changes between "source" and "target" and also repair the damage done by #1
3. Then an "after" compare script which updates static data (lookups etc.)
This has been ok for years; but is a bit manual and I tend to find (maintaining 10+ "targets" in different places throughout the world) that even though my targets should all be the same I struggle to build a migration script for #2 above and end up doing snapshots of "target"; using SQL compare 'on-line' and often doing a 2 or 3 pass update (e.g. tables first, then views, then SQL SP's) as a single SQL compare pass will often fail. I'll do this for each target as it's reliable and works; but is manual (slow, prone to mistakes etc. etc.).
So: The question (!) - what am I doing wrong? Why do I:
a. Need to manually drop schema-bound views prior to compare?
b. Find that SQL compare can't cope with a 'reasonable' set of changes but needs to do tables, views, SQL SP's in three passes to be reliable?
Ta!
Dr. Michael Dye
After a quick search I thought I'd better just ask the question - it's probably obvious but...
I've been using SQL compare for years & am now considering SQL source control too; but one of the ongoing hiccups I face is schema bound views; and updates to the tables referenced in the [schema bound] view.
If I try and "just" use SQL compare it'll fail: it tries to update the table and can't (the schema bound stops the table update?).
So; I have a developed a 3-stage process to update a "target" database from a "source" one::
1. A "before" compare script that'll drop my schema bound views in my "target" database
2. Run SQL compare which will both catch the changes between "source" and "target" and also repair the damage done by #1
3. Then an "after" compare script which updates static data (lookups etc.)
This has been ok for years; but is a bit manual and I tend to find (maintaining 10+ "targets" in different places throughout the world) that even though my targets should all be the same I struggle to build a migration script for #2 above and end up doing snapshots of "target"; using SQL compare 'on-line' and often doing a 2 or 3 pass update (e.g. tables first, then views, then SQL SP's) as a single SQL compare pass will often fail. I'll do this for each target as it's reliable and works; but is manual (slow, prone to mistakes etc. etc.).
So: The question (!) - what am I doing wrong? Why do I:
a. Need to manually drop schema-bound views prior to compare?
b. Find that SQL compare can't cope with a 'reasonable' set of changes but needs to do tables, views, SQL SP's in three passes to be reliable?
Ta!
Dr. Michael Dye
Comments
It would be good to check if you have 'Deploy all dependencies' enabled in the deployment wizard - this behaviour won't work if that checkbox isn't checked.
If you're still having trouble it might be a bug in SQL Compare, in which case a more specific reproduction would be helpful - you can get in touch with support if you need to keep database details private.
Here's a failure I've just got by doing "everything" - i.e. just deploying all changes to the database schema; and including the dependencies
Basically the failure was because I guess it was creating SQL SP's referencing the full text index before said index existed.
So; I took a two-pass approach: select all tables (new and altered); deploy those changes *without* dependencies; then 2nd pass was everything else; again without dependencies. That worked great.
N.B. It also reported differences in an assembly and a certificate; well; there will be (?) I think; especially the certificate... I chose not to deploy them... [OK I could exclude them by a filter; but I want to know they're there; just the differences aren't as such...]
Hope that makes sense and explains a bit why I tend to avoid the "dependencies" checkbox and have to do some manual input into the compare/deploy strategy [which has all worked; which is great; just a bit manual].
Ta, Michael.