How can I save (backup) view definitions?

I'm constantly modifying fairly complex views, so I try to back them up often in case I need to revert back.

In SSMS, "Tasks", "Generate Scripts" works great but is time consuming. Is there a better way to save view definitions?


Please check SMO objects in SQL Server

Using SMO objects and scripting language
you can do all administration tasks

My Scripting Language Preference

Hope this helps you !!!

Please let me know


1 Like

^^^ very concerning, worrisom that you have to do that so often

Just during development yosiasz, not PROD!

There we go! SMO might be the ticket - I'll check it out and see how far I get with it.

Thanks so much, harishgg1!

What about some kind of source code control? It's not less work. On the other hand you can see exactly what was changed and when. And especially, if you have more than one developer - by whom.

This would be the better option - but if not possible now then manually do this in the file system yourself. Create a folder where you keep copies of the scripts you are working that folder create a dated folder for today and save the script to that folder before making any changes...

As you make changes - save a copy in the root folder with a version indicator or timestamp or anything else to indicate a different version of the script.

if you need to roll back - then you have to version of the script(s) you saved in the folder for today. If you need to revert further back - you could pull the versions from the previously dated folders.

Either way - you need to manage the different versions...