view corrupted when viewed using design feature

Yes, the view designer is a horribly crippled, buggy piece of garbage you shouldn't be using to "design" your views. It should be called the view destroyer, because it can do exactly what you've observed: re-write any non-standard T-SQL into what it thinks you meant. And by "any non-standard T-SQL" I mean anything not predicted by the two developers who likely spent about a day testing this "feature."

Always, always, always modify your views using Script View As > Alter to > New Query Editor Window.

See these related Connect items:

http://connect.microsoft.com/SQLServer/feedback/details/465498/ssms-designer-is-sending-incorrect-alter-statement-to-engine-when-we-have-geomerty-data-type

Where I mention in the workarounds:

Obviously a better approach is to right-click the view, script as alter to new window. I wonder when they'll admit defeat and ditch the visual designers altogether. They cause more problems than they solve, IMHO.

http://connect.microsoft.com/SQLServer/feedback/details/362679/ssms-right-click-on-a-view-to-edit

Where I do something similar, and

http://connect.microsoft.com/SQLServer/feedback/details/459202/no-edit-option-when-right-clicking-on-a-view-in-management-studio-2008

Where I ask:

Didn't Edit bring up the horrible graphic designer for views, which was riddled with bugs and lacked support for several basic T-SQL constructs? Isn't that what Design does now?


One thing that View Designer handles very badly is mixing of AND and OR in the WHERE clause, even when you have correctly bracketed everything to clearly show what you intended.

If you need a workaround for that situation to allow others to edit your view using View Destroyer, then

  • Make an extra copy of the entire SELECT statement with the ANDs and ORs for each permutation of the ORs
  • Edit each one to cover a single set of terms, i.e. the WHERE has only ANDs in it
  • Join each of these individual SELECTs together with UNIONs

Congratulations, your View is now miles/kilometers longer than it needs to be, but View Designer won't defecate all over it.