Security, Transactions, and Views
Security <ul><li>Achieved through GRANT & REVOKE </li></ul><ul><li>Assumes the database can recognize its users and verify...
Views A view is representation of an existing table which corresponds to the SELECT statement that created it. The view ca...
Uses of a VIEW <ul><li>Hiding sensitive data from users </li></ul><ul><li>Preserving a previous table schema </li></ul><ul...
Creating a VIEW <ul><li>CREATE VIEW view_name [(col_name…)] AS SELECT _statement </li></ul>
Dropping a VIEW <ul><li>DROP VIEW view_name </li></ul><ul><li>Only drops the view… not the table. </li></ul>
More about Views <ul><li>The view displays like any table and the data you see is the actual data in the table(s). </li></...
Naming View Columns <ul><li>Column names are inherited from the underlying tables. </li></ul><ul><li>New names can be assi...
Formatting <ul><li>It is sometimes necessary to alter the output of a query for the sake of readability such as in report ...
SUBSTRING <ul><li>Returns a part of a character or binary string. </li></ul><ul><li>SUBSTRING (expression, start, length) ...
CONVERT <ul><li>Changes one datatype to another. </li></ul><ul><li>CONVERT(datatype[length], expression) </li></ul><ul><li...
Using them together... Select substring(title_id, 1, 2) as alpha convert(int, substring(title_id, 3, 4)) as num from titles
Transactions are... <ul><li>Transaction </li></ul><ul><li>- Logical unit of work </li></ul><ul><li>Transaction Management ...
Transactions <ul><li>A transaction is a set of SQL statements that represent a unit of work or a procedural operation. </l...
Why transactions? <ul><li>Transactions are necessary for the purpose of concurrency control and recovery </li></ul><ul><li...
Concurrency <ul><li>Lost-update problem </li></ul><ul><li>Locking </li></ul><ul><ul><li>database system puts a lock on acc...
Locking <ul><li>Since many users may be trying to access the same data simultaneously the DBMS has  a locking mechanism wh...
2 Types of Locks <ul><li>Exclusive - for UPDATE, INSERT, and DELETE (write operations) - no other transaction can acquire ...
Recovery <ul><li>Allows a database to bounce back after a system failure </li></ul><ul><li>must decide </li></ul><ul><ul><...
User-defined Transactions <ul><li>Allows user to define any number of SQL statements as a transaction and instruct the dat...
Defining a Transaction <ul><li>A transaction starts with the keyword BEGIN </li></ul><ul><li>BEGIN SQL statement SQL state...
Finishing the Transaction <ul><li>If the transaction goes successfully then the COMMIT command will commit the changes to ...
Upcoming SlideShare
Loading in …5
×

week10.ppt

289 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
289
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • This illustrates these definitions
  • The 4 main yntx operation we wil be performing in query and data manipulation. **Go through these
  • The 4 main yntx operation we wil be performing in query and data manipulation. **Go through these
  • The database is a piece of software that provides an interface to stored data. The interface we work with in a relational database is the table. This is a paradigm in that we work with it to directly manipulate data without every knowing the true format of the data.
  • Definition that will be used in this class
  • This illustrates these definitions
  • week10.ppt

    1. 1. Security, Transactions, and Views
    2. 2. Security <ul><li>Achieved through GRANT & REVOKE </li></ul><ul><li>Assumes the database can recognize its users and verify their identity </li></ul><ul><li>can also be controlled through the use of views - subsets of data </li></ul><ul><li>usually maintained by the database administrator or DBA </li></ul>
    3. 3. Views A view is representation of an existing table which corresponds to the SELECT statement that created it. The view can then be manipulated much like an actual table. A view is not a separate table or entity. It’s more like a mask of the actual table.
    4. 4. Uses of a VIEW <ul><li>Hiding sensitive data from users </li></ul><ul><li>Preserving a previous table schema </li></ul><ul><li>Presenting data to users in a desired format. </li></ul><ul><li>Simplify a complex query </li></ul>
    5. 5. Creating a VIEW <ul><li>CREATE VIEW view_name [(col_name…)] AS SELECT _statement </li></ul>
    6. 6. Dropping a VIEW <ul><li>DROP VIEW view_name </li></ul><ul><li>Only drops the view… not the table. </li></ul>
    7. 7. More about Views <ul><li>The view displays like any table and the data you see is the actual data in the table(s). </li></ul><ul><li>A view is more for viewing rather than updating since an update could disqualify a record from the view. </li></ul><ul><li>Updates made to a view are made to the table(s) and any changes made to the table(s) are reflected in the view. </li></ul>
    8. 8. Naming View Columns <ul><li>Column names are inherited from the underlying tables. </li></ul><ul><li>New names can be assigned </li></ul><ul><li>Columns must be renamed when using arithmetic expressions or when more than one column has the same name. </li></ul>
    9. 9. Formatting <ul><li>It is sometimes necessary to alter the output of a query for the sake of readability such as in report generation. This can also be applied to a view creation which users will share. </li></ul>
    10. 10. SUBSTRING <ul><li>Returns a part of a character or binary string. </li></ul><ul><li>SUBSTRING (expression, start, length) </li></ul><ul><li>SUBSTRING (‘SQL Programming’, 1, 3) = SQL </li></ul>
    11. 11. CONVERT <ul><li>Changes one datatype to another. </li></ul><ul><li>CONVERT(datatype[length], expression) </li></ul><ul><li>CONVERT(char(2), ‘SQL’) = SQ </li></ul><ul><li>CONVERT(int, ‘10’) = 10 </li></ul>
    12. 12. Using them together... Select substring(title_id, 1, 2) as alpha convert(int, substring(title_id, 3, 4)) as num from titles
    13. 13. Transactions are... <ul><li>Transaction </li></ul><ul><li>- Logical unit of work </li></ul><ul><li>Transaction Management </li></ul><ul><li>- ensuring that a set of SQL statements is treated as a unit - an indivisible entity </li></ul>
    14. 14. Transactions <ul><li>A transaction is a set of SQL statements that represent a unit of work or a procedural operation. </li></ul><ul><li>A transaction is not complete unless all off its steps are followed through. </li></ul><ul><li>This can be critical to maintaining data integrity such as when an account must be credited while debiting another. </li></ul>
    15. 15. Why transactions? <ul><li>Transactions are necessary for the purpose of concurrency control and recovery </li></ul><ul><li>concurrency control - allowing multiple users simultaneous access </li></ul><ul><li>recovery - allowing the database system to return the database to a reliable state after a failure. </li></ul>
    16. 16. Concurrency <ul><li>Lost-update problem </li></ul><ul><li>Locking </li></ul><ul><ul><li>database system puts a lock on accessed data so it cannot be altered until lock is released. </li></ul></ul>
    17. 17. Locking <ul><li>Since many users may be trying to access the same data simultaneously the DBMS has a locking mechanism which locks data which is in use. </li></ul><ul><li>This provides a solution to concurrency problems which would arise if locking were not available. </li></ul>
    18. 18. 2 Types of Locks <ul><li>Exclusive - for UPDATE, INSERT, and DELETE (write operations) - no other transaction can acquire lock until original is released </li></ul><ul><li>Shared - applied during non-update or read operations - usually SELECT - prevents write operations from acquiring lock - allows other read operations to share lock </li></ul>
    19. 19. Recovery <ul><li>Allows a database to bounce back after a system failure </li></ul><ul><li>must decide </li></ul><ul><ul><li>what transactions are incomplete </li></ul></ul><ul><ul><li>which transactions completed but were not written and must be redone </li></ul></ul>
    20. 20. User-defined Transactions <ul><li>Allows user to define any number of SQL statements as a transaction and instruct the database to process them as one unit. </li></ul>
    21. 21. Defining a Transaction <ul><li>A transaction starts with the keyword BEGIN </li></ul><ul><li>BEGIN SQL statement SQL statement SQL statement </li></ul><ul><li>COMMIT </li></ul>
    22. 22. Finishing the Transaction <ul><li>If the transaction goes successfully then the COMMIT command will commit the changes to the database. </li></ul><ul><li>However, if an error occurs the ROLLBACK command can be used to restore the database to its state prior to the transaction. </li></ul>

    ×