View

zhaozj2021-02-16  101

1, separation logic and business data.

As we all know, in the design of the application system with the database, we often separated its operational behavior. Of course, this first step is to require not to use database sensitive controls, the second is to display and operation separation, the best way That is to adopt a view, such as we have the following needs.

A, check the details of a document

B, edit the details

Although the demand is simple, if it is necessary to consider the change of the demand, we need to reach the way you often reach the way, because the editing operation is fixed, the user may want to display the document while displaying some other data At this time, if you only change some settings only on the server, it is very ok, we will add the operation of the connection to the view, of course, ask our display to be a patchwork SQL statement.

2, the query is used.

If you want to save a query generated by an existing query condition as a new query, how to do it, of course, all the existing conditions and the display data set are made as a new view, and then as long as the new view is performed Operation is OK.

3, reduce the error rate of writing code

If the write storage process is more, it will definitely encounter the following similar issues, often Exec ('update' @tablename set DID = 10 '), if it is just a single table, pour a point, if it is a multi-table It is very troublesome. The scattered SQL statement is very difficult to understand, the format is troublesome, the second is to use the MSSQL automatic syntax error tool. At this time, if we built a "temporary" view, everything is good, Of course, pay attention to multi-users and isolation problems.

If Exists ..... Drop View Temporary view name, Exec ('Create View Temporary View SELECT * FROM' @tablename), in the future, you can prevent simple syntax errors

转载请注明原文地址:https://www.9cbs.com/read-11392.html

New Post(0)