Transact SQL: Synchronization of Views to Tables [closed]
I have written the following code to do a comparision of a View and its corresponding production table. I am looking for better ways to write this code for efficiency, any pointers would be greatly appreciated. The code gives me the desired results, Now it's just a point of learning new approaches and concepts to it.
http://pastebin.com/pSTdCx3L
If you declare your view WITH SCHEMABINDING, you don't need this overhead.
I always use it. It disallows changes to base table used in the view (or udf). It also forces columns to be qualified and to use 2 part object names.
SCHEMABINDING
Binds the view to the schema of the underlying table or tables. When SCHEMABINDING is specified, the base table or tables cannot be modified in a way that would affect the view definition. The view definition itself must first be modified or dropped to remove dependencies on the table that is to be modified.
Although, you asked for a review, I am quite amused (read: "facepalm") by:
- your dynamic ALTER VIEW when you could just run "sp_refreshview" or sp_refreshsqlmodule
- your one to one table to view mapping. Why? It adds no value
精彩评论