开发者

Transact SQL: Synchronization of Views to Tables [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorica开发者_JAVA百科l and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜