What is the difference between database table and database view?
The database table has a physical existence in the database. A view is a virtual table, that is one that does not actually exist. View is made up of a query on one or many tables in a database.
In database theory, a view is the result set of a stored query on the data, which the database users can query just as they would in a persistent database collection object. This pre-established query command is kept in the database dictionary. Unlike ordinary base tables in a relational database, a view does not form part of the physical schema: as a result set, it is a virtual table computed or collated from data in the database, dynamically when access to that view is requested. Changes applied to the data in a relevantunderlying table are reflected in the data shown in subsequent invocations of the view. In some NoSQL databases, views are the only way to query data.
Views can provide advantages over tables:
- Views can represent a subset of the data contained in a table; consequently, a view can limit the degree of exposure of the underlying tables to the outer world: a given user may have permission to query the view, while denied access to the rest of the base table.
- Views can join and simplify multiple tables into a single virtual table
- Views can act as aggregated tables, where the database engine aggregates data (sum, average etc.) and presents the calculated results as part of the data
- Views can hide the complexity of data; for example a view could appear as Sales2000 or Sales2001, transparently partitioning the actual underlying table
- Views take very little space to store; the database contains only the definition of a view, not a copy of all the data which it presents
- Depending on the SQL engine used, views can provide extra security
Read-only vs. updatable views
Database practitioners can define views as read-only or updatable. If the database system can determine the reverse mapping from the view schema to the schema of the underlying base tables, then the view is updatable. INSERT, UPDATE, and DELETE operations can be performed on updatable views. Read-only views do not support such operations because the DBMS cannot map the changes to the underlying base tables. A view update is done by key preservation.
Some systems support the definition of INSTEAD OF triggers on views.(insert/delete view 必须为其定义trigger) This technique allows the definition of other logic for execution in place of an insert, update, or delete operation on the views. Thus database systems can implement data modifications based on read-only views. However, an INSTEAD OF trigger does not change the read-only or updatable property of the view itself.
In order to insert (update & delete) data to views created using multiple tables, you need to use an ‘Instead of trigger’.
**Please note that ‘After Triggers’ cannot be created for views.
Let’s create an instead of trigger using the following syntax.
Collapse | Copy CodeCREATE TRIGGER TRGI_VW_PAYMENT ON VW_LAST_PAYMENT_DETAILS
INSTEAD OF INSERT
AS
BEGIN
INSERT INTO STUDENT_PAYMENT
SELECT STD_ID,PAY_AMT,PAY_DATE
FROM INSERTED
END
Now using the above insert syntax, you can insert data without getting any error. If you inspect the ‘STUDENT_PAYMENT’ table you can see that the data has been inserted successfully.
What is the difference between database table and database view?的更多相关文章
- How do I see what character set a database / table / column is in MySQL?
Q: How do I see what the character set that a MySQL database, table and column are in? Is there some ...
- 2.1-2.2 Hive 中数据库(Table、Database)基本操作
官网文档:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL 一.create table 1.官方字段 # # C ...
- SAP技术 - How to create a CDS redirect view for a given database table
Scenario Suppose we have a database table A, and then we create a CDS redirect view B for it, then e ...
- Azure SQL Database (19) Stretch Database 概览
<Windows Azure Platform 系列文章目录> Azure SQL Database (19) Stretch Database 概览 Azure SQL Da ...
- Oracle® Database Patch 19121551 - Database Patch Set Update 11.2.0.4.4 (Includes CPUOct2014) - 傲游云浏览
Skip Headers Oracle® Database Patch 19121551 - Database Patch Set Update 11.2.0.4.4 (Includes CPUOct ...
- Oracle Database 12c Using duplicate standby database from active database Created Active DataGuard
primary database db_name=zwc, db_unique_name=zwc standby database db_name=zwc, db_unique_name=standb ...
- 使用duplicate target database ... from active database复制数据库
使用duplicate target database ... from active database复制数据库 source db:ora11auxiliary db:dupdb 1.修改监听文件 ...
- Teradata Delete Database and Drop Database
DELETE DATABASE and DELETE USER statements delete all data tables, views, and macros from a database ...
- Cannot connect to database because the database client
问题描述: arcgis server10.1 arcgis sde10出现下面问题 Cannot connect to database because the database client ...
随机推荐
- Struts2+Hibernate4+Spring4整合
jar包 配置文件 web.xml文件 <!-- needed for ContextLoaderListener --> <context-param> <param- ...
- 一步一步学习C++
根据<C++ primer>第五版 总结学习心得. 在实践中,不必全面地使用C++语言的各种特性,而应根据工程的实际情况,适当取舍(譬如动态类型信息,虚拟继承.异常等特性的使用,很值得商榷 ...
- C++模板实例化(1)
On-Demand实例化 当C++编译器遇到模板特化的时候,他会利用所给的实参替换对应的模板参数,从而产生该模板的特化.该过程是自动进行的.有时候也会被称为隐式实例化,或者是自动实例化. on-dem ...
- JS增删改HTML表格
要求如下: 写一个html页面,里面有一个表格,储存用户信息,包括:用户名,密码,姓名,邮箱,电话,qq,身份证号. 现在要通过js对表格进行动态的增删改查(只是内存操作即可): 首先,加载页面时用j ...
- ant条件逻辑
<condition property="sdk-folder" value="E:\android\android-sdk\adt-bundle-windows- ...
- javascript里面技巧整理
web develop tools secrets: http://jinlong.github.io/blog/2013/08/29/devtoolsecrets/ 1.Date new Date( ...
- C#多线程与UI响应 跨线程更新UI
最近在写一个TCP通信程序,自定义了一个通信类TCPclient,用于客户端异步接收和发送网络消息. TCPclient中定义了一个接收到新的网络消息事件: //收到新消息事件 public dele ...
- jQuery 添加元素和删除元素
jQuery - 添加元素 append() - 在被选元素的结尾插入内容 prepend() - 在被选元素的开头插入内容 after() - 在被选元素之后插入内容 before() - 在被选元 ...
- Android 中 shape 图形的使用
转载于:http://kofi1122.blog.51cto.com/2815761/521605 Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shap ...
- PHP中strtotime函数使用方法分享
在PHP中有个叫做strtotime的函数.strtotime 实现功能:获取某个日期的时间戳,或获取某个时间的时间戳.strtotime 将任何英文文本的日期时间描述解析为Unix时间戳[将系统时间 ...