Access Control & Views 控制访问和视图

本文讨论了在大型组织中数据库管理系统如何通过视图和权限控制不同用户对数据的访问,包括SQL的访问控制模型、权限授予、视图的使用与实现、限制以及如何访问其他用户对象。视图作为虚拟表,有助于细化访问控制、简化查询和维护数据库完整性,尽管存在一些使用限制和潜在性能问题。

The Importance of Views & Privileges • In large organisations, DBMSs are used by a range of staff: — directors, managers, analysts, engineers, personnel, secretarial, etc. • Consequently, access to data in different tables may need to be controlled to: — provide access to authorised users — restrict access to unauthorised users — enforce business rules or government regulations • Views & privileges can help implement access control...需要控制对不同表数据的访问需要 为授权用户提供访问权限 限制未授权用户访问权限 执行业务规则和政府法规 因此视图和权限便于控制访问

SQL’s Access Control Model • Access Control in SQL is similar to multi-user operating systems (e.g., Unix, Windows, ...) • A user supplies an Authorisation Id and password to the DBMS • The DBMS opens a session for the user • The DBMS runs SQL statements on behalf of the user • The user becomes the owner of any objects they create • By default, only the owner may access their objects • The owner may grant and revoke access privileges to other usersSQL的控制访问模型 用户向DBMS提供授权ID和密码 DBMS为用户打开绘画 DBMS代表用户执行SQL语句 用户成为创建的任何对象的所有者 在默认情况下只有所有者可以访问其对象 所有者可以授权和撤销其他用户访问权限

Granting Privileges授权f3f80376439742baacdb83c5ef9d9771.png

• where (typically): — ObjectName is a table — PrivilegeList may be a combination of: ◦ SELECT, INSERT, UPDATE, DELETE (can specify column names) ◦ REFERENCES (column names referenced by integrity constraints) ◦ USAGE (use of domain definitions) ObjectName是一个表 PrivilegeList是以下内容组合 ◦ SELECT、INSERT、UPDATE、DELETE(可指定列名) ◦ REFERENCES(通过完整性约束引用列名) ◦ USAGE(使用域定义)

0800a92ae47f46e5b16649af3151e179.pngWhat are Views? • A view is a virtual table, constructed from base tables • Only the definition of a view is stored permanently • A view is realised dynamically when it is first referenced • Views are manipulated like other DBMS objects:视图是一个虚拟表由基本表构成 只有视图的定义是永久存储的 首次引用视图时,视图动态实现 视图操作域DBMS对象一样b846a99e477742f5af845c26396a92d3.png

Creating Views – Horizontal Views创建水平视图b9b1df3c231e4bd69d34d8123a498776.pngCreating Views – Vertical Views创建垂直视图a55244bfd6c04ed9b8e78f9d39094461.pngGeneral Syntax290506a7965e4368b46f7893d897e1e6.png for Creating Views

• The SubSelect clause is called the defining query • To create a view, a user must have SELECT privilege on the base tables • Once created, views often behave like ordinary base tables... • Views can be used in SELECT or JOIN clauses • Views can be updated (with some restrictions)SubSelect子句-定义查询 需要基础表的SELECT权限 视图和基础表一样运行 视图在SELECT或JOIN子句中使用 视图受一定限制更新

Final Example Grouped & Joined Views • Views can be used to help simplify complex queries • Example: create a view showing the number of properties managed by each member of staff and the branches they work at:视图可以简化复杂查询cea2c9e03e404906aa4f21a572ae0d33.png

• Can now query StaffProperties as if its a base table6254f1bf6de241f78636af6c646d1328.png

How Are Views Implemented? • Most DBMSs implement views using view resolution: — SQL re-writes the view references back to the underlying base tables • The alternative is view materialisation: — SQL populates a temporary table when the view is first referenced — However, keeping the temporary table up-to-date can be difficult... • View materialisation is an active area of DB research通过视图解析实现视图 SQL可以将视图引用重写会底层基础表 还可以视图实体化--当视图被首次引用,SQL填充临时表但是临时表很难进行更新

Restrictions on Views • With views, some queries are not permitted: — Queries that resolve to nested aggregates — Queries that give aggregates in a WHERE clause • Views can be updated provided: — There are no aggregates in the columns to be updated — There are no GROUP BY or HAVING clauses — The view contains only one source table with no nested SELECTs对视图的限制 不允许使用一些查询——解析嵌套聚合查询或在WHERE子句中给出聚合的查询 视图可以更新但需要更新的列中没有聚合 GROUP BY或HAVING子句 只包含一个源表不嵌套SELECT

How to Access Other Users’ Objects访问其他用户的对象b704fc5bb0f04502bec2732efaa71a64.png

Updating Views An Important Subtlety • SQL allows a view to be updated provided the changed rows in the base tables still satisfy all of the conditions of the defining query’s WHERE clause • For example:SQL在基础表更改后仍满足定义查询后WHERE子句所有条件

614f7155ad7a49e48b81bb47b6b39401.png• This would fail because the modified row ( BranchNo = 'B005' ) would no longer be selected by the view definition ( WHERE BranchNo = 'B003' ) — View updates may not allow rows to migrate into or out of the view — Can exploit this behaviour to help enforce DB integrity — Put domain/business constraints into the view definition & only update views视图定义不选择已经修改后的行 视图更新可能不允许行迁出迁入视图 可以利用这个性质保证数据课完整性 在数据定义中加入域业务约束并只更新视图

Summary of Views • Advantages: — Views help provide granularity of access control — Views can help reduce complexity and improve access control — Views can help maintain DB integrity (e.g., by doing updates via views) • Disadvantages: — There are some restrictions on their use — Resolution method can cause a performance penalty — Materialisation method can cause consistency problems视图优点 有助于访问控制权限 降低复杂度并改进访问控制 维护数据库完整性 缺点 视图使用由限制 解析方法可能会导致性能下降 物化方法可能影响一致性

SQL – Overall Summary • SQL is a powerful relational DB query language • SQL is declarative, not procedural (e.g., no variables) • SQL is showing its age ... (e.g., quirky syntax, bolted-on features) • ANSI SQL resolves some inconsistencies between DBMS vendors • But despite being over 25 years old... • SQL remains THE ‘world-standard’ for DBMS

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值