View the database again -- (2) view and database view

Source: Internet
Author: User

View the database again -- (2) view and database view
Concept

* It is from the user's point of view on using the database.

* Exported from one or more tables (Views)

* A virtual table or a query table


Why use a view?

FirstSimpleAnd you can see what you need. A view not only simplifies users' understanding of data, but also simplifies their operations. Frequently Used queries can be defined as views, so that you do not have to specify all the conditions for each subsequent operation.

SecondSecurityYou can only query and modify the data that they can see through the view, but cannot grant permissions to specific rows and columns of the database. Through views, users can be restricted to different subsets of data: the permission can be restricted to one subset of another view, or some views and subsets after the merging of the base table.

ThirdLogical Data independence. View helps you avoid the impact of changes in the real table structure.

In summary, because users can only query and modify the data they can see through the view, the operation is naturally much simpler and more secure. This is also involved in the advantages of the view.

Operation:
Create:

Method 1:









Execution result:


Method 2:

With T-SQL statement:

Use niunangocreate view View_Test1 -- content to be queried -- as select name, title, content, createtime -- Query table -- from category, news -- Query condition -- where category. id = news. categoryId

Correspondingly, modification and deletion of views can also be directly performed in the object Resource Manager, which is not described here.

Modify:

Use niunango -- view to be modified, with the column name in parentheses -- alter view View_Test (name, createTime) -- The format is the same as select name, titlefrom category, newswhere category when creating the view. id = news. categoryId


Delete:

drop view View_Test


Advantages:

It simplifies the operation of adding, deleting, and modifying tables. Using views, we can search for data from two tables at the same time. Without views, we need to query data one by one, which is troublesome and error-prone. To a certain extent, the complexity of the database is reduced and data sharing is more convenient. On the other hand, users can only view and modify the data they can see through the view, simplifying the management of user permissions.

Views and tables:

Only the table definitions are stored in the view, but the data corresponding to the view is not stored. The data is still stored in the original data table. Taking the example above, the newly created view does not contain actual news content, category names, and other data. They are all stored in the original news and category tables.

Views can be added, deleted, modified, and queried like tables.


How to update all views in the database? Only single or multi-entity table ing in a view does not have actual data. You need to update the new data in the object table for each access.
Update means that the view ing logic is changed, and the view is deleted and rebuilt.
Role view of the database view: exports virtual tables from or to several basic tables (or views)
Purpose: 1. view can simplify user operations
2. views allow users to view the same data within minutes
3. Views provide a certain degree of logical independence for restructured Databases
4. view provides security protection for confidential data
5. Use the view to clearly express the query

6. Difference Between int and Integer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.