Does v9 support both "ALTER" & "If exists .. DROP + CREATE"?
fred
Posts: 5
Can the user choose (for at least Stored Procs & Functions) to choose an update script that either has ALTER or IF EXISTS DROP/CREATE for objects with differences - as has been promised so many times in the past?
Comments
It would be helpful if we could better understand your motivation for doing this. What problem would this solve for you?
David Atkinson
Product Manager
Red Gate Software
Product Manager
Redgate Software
It seems like a pretty basic feature. We are software developers & need to ship incrementatl db updates to our clients. We manage table structure changes tightly and only occasionally use generated code to effect changes - however for SPs & UDFs we want to ship to the latest version consistent with the table structure; and we want this update process to be solid - i.e. we want to drop if exists prior to create.
So we would only use on SPs/UDFs & without it - no matter how nice your product looks - we can't consider it (which is a shame since you have some nice features - e.g. compare db vs .bak).
Regards.
Fred
Can I ask you what you mean by 'solid'? How do you get into a situation where an ALTER would fail and a IF EXISTS DROP/CREATE would succeed?
We're currently working on an improved way to manage differing schema versions, and how to migrate between them in a more controlled way. If you're interested in improvements in this area, please help us by filling in the following survey:
http://www.surveymk.com/s/migrations
David
Product Manager
Redgate Software
There are many reasons why our Product database SPs/UDFs may differ from an individual client's SPs/UDFs - even when all at the same product version. For example custom reports often require a custom SP to drive the report content - or a new Excel import template would require a new SP to normalise the data prior to update etc ....
This means that when we issue an interim product update to any given client we know the main table structure (we control this separately) but not necessarily which specific SPs/UDFs. So - for us - ALTER would not be guaranteed to work - whereas IF EXISTS ... DROP before CREATE does (i.e. the latter approach is solid).
Regards.
Fred
I have a requirement to be able to re-run scripts without it failing.
The check for existence before the drop would solve this for me.
I have to provide deployment scripts to a large number of databases that are outside my control and require more fault tolerant scripts that allow for this sort of minor anomalies.
Cheers,
Dave
It's a feature in their product and may sway my organisation that way, which would be a pity because I've liked the Redgate toolbelt for a while now.
Cheers,
Dave
If the script tries to alter a table, and it doesn't exist on the target, what would you expect to happen? Should it just ignore this fact and carry on? Would this count as 'not failing'?
If you describe to me the differences between your target databases that you need it to account for, it will help a lot.
David
Product Manager
Redgate Software
I'm currently working on building a data dictionary into the schema using extended properties. So that is my immediate need.
So I guess from your application point of view, the option only applies if you turn of "Modify" and do drop, creates.
Cheers,
Dave
Maybe next time.
Fred
So if this 'rerunnable scripts' option is enabled, would it force a rebuild of all tables that need to be altered along with the existence check? Would the potential performance impact be acceptable to you?
David
Product Manager
Redgate Software
It's not going to solve everything, but would go a long way in eliminating the amount of manual scripting required to make a script re-runable.
And that's why we buy these tools.
There are many reasons why databases these scripts are run against may not be identical in nature (selective release of patches, hot fixes, etc), and these scripts need to cater for that in an elegant way.
Thanks for the clarification.
David
Product Manager
Redgate Software
A feature like that will improve the efficiency of our updates distribution.
Thanks,
Thanks for the request. Could you specify exactly which object types this behavior should work with?
Product Manager
Redgate Software
In our case, is more likely to happen with the SP's. About 95% of the times when we need to install modifications before the official upgrade are SP’s. The other 5% splits between tables, views and functions.
I hope that help.
I'm getting to the point where I need to get some tools for my team. Can you please tell me if this feature will be in the next release or not?
If not, then I'll go with ApexSQL as we intend to fill in the data dictionary within the schema and I don't feel like wrapping if exists... around all the extended property drops .
Cheers,
Dave
Sorry that I can't be any more specific.
Regards,
David
Product Manager
Redgate Software
Create a scalar UDF, perform a sync. then, change the scalar UDF to an inline UDF (keeping the same name). sql compare attempts to alter it, but this doesn't work:
Cannot perform alter on 'dbo.testes' because it is an incompatible object type.
Here, doing an if exists... drop... create would solve the problem (and yes i know it's the most common scenario!)
This avoids the case of unnecessarily dropping an object along with its permissions, which could be undesirable.
This, sadly, wouldn't fix your issue. Have you emailed this problem to support@red-gate.com so it can be addressed via a fix?
David
Product Manager
Redgate Software
There are 2 main reasons to support this feature:
1. Occasionnaly, some databases receive "private" hot fixes that would create new tables/Sps/Indexes etc.. When the official service pack is published, it fails if any private hot fixes have been previousely applied. This is a major limitation for using red Gate for our purposes and a major source of frustration.
2. The ALTER statement doesn't modify the system creation date for the affected object. Databases are often audited for SOX (and other) compliance purposes and all changes to the databases have to be documented. It it much easier to document such changes when the creation date can be crearly visible at the database level. To take this statement one step further, I'd like to see the option to use DROP/CREATE instead of ALTER for the entire synchronization script.
Thanks,
-Martin
The advantage of ALTER is that these are maintained.
David
Product Manager
Redgate Software
As far as permissions on dropped objects go, that is not an issue for us since our clients run a "post update" which rebuilds permissions on all objects anyway.
I really hope this enhancement can make it into 9.5 as you mentioned. Thanks!
Say, we recently had to implement several SPs as an urgent fix somewhere several versions back. Now we will need to fix some latest scripts.
Having either CREATE proc and then ALTER or checks with IF EXISTS DROP
will help us a lot.
Product Manager
Redgate Software
Just curious if this has been scheduled for 9.5? We really need this feature. If it's just for server side code (stored procedures, functions), that's totally fine. Thanks!
David
Product Manager
Redgate Software
or
to this...
Of course there may be additional permissions implications concerning this, but for me personally, I don't care. All permissions get rebuilt later on in a post-update section we append to the generated sql compare scripts. Thanks.
if exists('procedure x') drop procedure x
go
create procedure x...