views:

29

answers:

3

I'm seeing an interesting behavior difference between my instance and my boss's instance of SSMS. When he uses Tasks->Generate Scripts... for tables, it puts guards around the triggers for that table (If exists...) but when I do the same thing using the same options SSMS doesn't put the guards around the triggers so I get errors if I run the script it generates more than once. Any idea how I can get SSMS to generate the guards around the triggers for me?

+2  A: 

Did you set the "Include If NOT EXISTS" option on the Choose Script Options page to "True"? It is "False" by default.

Joe Stefanelli
I sure did. No dice :(
Cody C
+2  A: 

In SSMS, review the (menu) Tools / Options dialog, in the "Scripting" section. The setting of "Include IF NOT EXISTS clause" may differ between your two systems, but it may be something similar but more obscure.

Philip Kelley
+2  A: 

In SSMS, click Tools, Options, SQL Server Object Explorer, Scripting, Object Scripting Options, Include IF NOT EXISTS clause. Your boss may have it set to true, yours false.

Brent Ozar
It's set to true for me. The thing is, for stored procs, it puts the guards in. Not so for triggers.
Cody C
Make sure you're on the latest version of SSMS then with the cumulative updates: http://sqlserverpedia.com/wiki/SQL_Server_Release_Date_Calendar
Brent Ozar