Sql-server – SQL Server Designers, Failed Saves, and Generated Scripts

sql serverssms

I am a big fan of the simple diagramming tool that comes with SSMS, and use it frequently. When I save changes to the model, I have it configured to automatically generate the change scripts that go along with the save. I then save (and source control) the resulting change script. This works great and an important piece of the process my team(s) uses.

What occasionally happens is that a save fails, and I still get the option to save my change script. I then fix the problem and save again (which results in another change script).

I'm never clear what I need to do at this point to maintain a consistent set of change scripts. There seems to be overlap between the two scripts (the failed and the successful), but they are not identical.

If I want to continue to use this feature, what should I be doing with the resulting script as soon as I get a failed save of the model?

Best Answer

I would not rely on the scripts generated by SSMS as they are not 100% accurate. SSMS is not the right tool to generate changes for the database, though it has functionality to do it.

Same functionality can be achieved using native or open source or third party tools .

Native tools :

  • tablediff Utility available from SQL 2005 and up. TableDiff was intended for replication but can easily apply to any scenario where you need to compare data and schema. And it is command line, so can be easily used for automation of generating scripts. It is one of the top 10 hidden gems in sql 2005 and up.
  • Using Powershell and SMO.

Open Source :

Third Party :

IMHO, rather than just relying on SSMS to generate change scripts for databases, you should look into some sort of deployment framework that can be tweaked as per your need and can be automated. Refer to : Deploying Database Changes with PowerShell

Read up on :