By the way, please don't use date literals like this:
'MM/DD/YY'
This might will not work on system which use other language settings (or datetime settings) than english.
Please always use the ISO literals like this instead:
'YYYYMMDD'
They do work. Always: http://www.karaszi.com/SQLServer/info_datetime.asp
Peter H (7/10/2012)
For those who are looking for an easier way out, I put together this sql that (hopefully) will identify the views that are older than the last table modify date, and call for only them to be refreshed. I also added the schema name, because not everything is always "DBO". Someone could wrap this in a cursor and execute directly, say every night, or after each prod release, to ensure that no views were missed
Even if you have a complete picture of the downstream impact to changing the structure of the base-table I'd advise against automating the refresh.
First of all, sys.sql_dependencies is only good to one level deep. What happens when the view needing to be refreshed is referenced by another object in your data layer such as another view or stored procedure? Obviously you could redesign the script to recurse through every dependency level but you have to consider if that does you any favours.
If there are dependencies on the refreshed objects outside the data layer these will most like require editing too (a SSIS package, for example, would require its source meta data updated at the very least).
If these external dependencies haven't been accommodated when the change to the base-table is deployed, an automated refresh is simply cascading the inconsistency downstream. If the inconsistency is a show-stopper, you'll be looking at a rollback - which will probably be more bother than refreshing the dependencies manually!
That said, if you are fortunate enough to have a complete lineage-impact matrix of your entire solution and can accommodate all downstream dependencies, a suitable script would be a valuable addition to your deployment packages.
I'd still not automate it though.
That said, if you are fortunate enough to have a complete lineage-impact matrix of your entire solution and can accommodate all downstream dependencies, a suitable script would be a valuable addition to your deployment packages.
Funny, that is what I was also thinking about before work this morning!
Argue for your limitations, and sure enough they're yours (Richard Bach, Illusions)
To gain another perspective, and method to "refresh/update" the views meta data may I suggest looking at an older QOD at:
http://www.sqlservercentral.com/questions/Views/88916/
What happens behind the scene, so to speak, is shown in the Execution plans (posted as support for the correct answer(s) to the QOD.
e-ghetto (7/11/2012)
By the way, please don't use date literals like this:
'MM/DD/YY'
This might will not work on system which use other language settings (or datetime settings) than english.
Please always use the ISO literals like this instead:
'YYYYMMDD'
They do work. Always: http://www.karaszi.com/SQLServer/info_datetime.asp
What is I use 'YYYY-MM-DD'?
What is I use 'YYYY-MM-DD'?
I can't promise 'YYYY-MM-DD' will work regardless of your current settings.
'YYYYMMDD' does always work. Just stick to this little rule, it doesn't hurt and you won't be disappointed
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply