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 (sumaverage 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. INSERTUPDATE, 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 Code
CREATE 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?的更多相关文章

  1. 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. 2.1-2.2 Hive 中数据库(Table、Database)基本操作

    官网文档:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL 一.create table 1.官方字段 # # C ...

  3. 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 ...

  4. Azure SQL Database (19) Stretch Database 概览

    <Windows Azure Platform 系列文章目录>  Azure SQL Database (19) Stretch Database 概览      Azure SQL Da ...

  5. 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 ...

  6. 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 ...

  7. 使用duplicate target database ... from active database复制数据库

    使用duplicate target database ... from active database复制数据库 source db:ora11auxiliary db:dupdb 1.修改监听文件 ...

  8. Teradata Delete Database and Drop Database

    DELETE DATABASE and DELETE USER statements delete all data tables, views, and macros from a database ...

  9. Cannot connect to database because the database client

    问题描述: arcgis server10.1  arcgis sde10出现下面问题 Cannot connect to  database because the database client ...

随机推荐

  1. .NET4.5可以给所有线程设置默认的Culture了

    How to set CurrentCulture for all threads in a domain in .NET 4.5 Before .NET 4.5 if we wanted to se ...

  2. Viewport Resizer下载 谷歌前端自适应开发工具

    原文链接:http://www.phpbiji.cn/article/index/id/107/cid/6.html Viewport Resizer下载 谷歌前端自适应开发工具 在前端开发过程中,随 ...

  3. php读取html并截取字符串

    一般php采集代码能用的到,这里只是简单的实现代码. <?php $title='脚本学堂'; $hello='jbxue.com!'; $file=file_get_contents('htt ...

  4. jQuery对Select操作大集合

    介绍了jQuery对Select的操作进行了详细的汇总. 1.jQuery添加/删除Select的Option项: 2.$("#select_id").append("& ...

  5. VB最新使用教程

    Visual Basic是一种由 微软公司开发的结构化的.模块化的.面向对象的.包含协助开发环境的事件驱动为机制的可视化程序设计语言.这是一种可用于微软自家产品开发的语言.它源自于BASIC编程语言. ...

  6. 栈帧%ebp,%esp详解

    首先应该明白,栈是从高地址向低地址延伸的.每个函数的每次调用,都有它自己独立的一个栈帧,这个栈帧中维持着所需要的各种信息.寄存器ebp指向当前的栈帧的底部(高地址),寄存器esp指向当前的栈帧的顶部( ...

  7. 【Ajax】脑补一下 ajax 的options

    问题是因为粉红色部分引起的 ,想搞明白 put delete 的应用场景,发现ajax的一些属性也没有完全用过. 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. t ...

  8. Careercup - Facebook面试题 - 5179916190482432

    2014-05-01 00:45 题目链接 原题: input [,,,] output [,,,] Multiply all fields except it's own position. Res ...

  9. [转载]非常完善的Log4net详细说明

    前言 此篇文章是我见过写得最好的一片关于Log4Net的文章,内容由简入难,而且面面俱到,堪称入门和精通的佳作,特从懒惰的肥兔的转载过来. 1.概述 log4net是.Net下一个非常优秀的开源日志记 ...

  10. org.apache.commons.dbutils.QueryRunner 执行sqlserver的存储过程

    执行不带输出参数的存储过程与 执行普通update  sql没有什么区别,直接调用即可: 示例代码: public Boolean startResidentialInfoStatistics(Str ...