Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Er. Nawaraj Bhandari
Topic 10
Supporting Transactions
Transactions
 A transaction is an operation carried out on the database.
 Transactions can generally be identified as retrievals, inserts, updates
and deletes. This is remembered by the acronym CRUD (Create,
Retrieve, Update and Delete).
 Transactions can be made up of one or more operations.
Identify Transactions
What do they do?
What tables do they affect?
What attributes do they affect?
How often do they run?
How many rows do they affect?
Transactions of Appointment System
Transaction 1 – Add a new patient
Transaction 2 – Delete a patient
Transaction 3 – Record a appointment
Transaction 4 – Show a detail list of patient and the appointments they
have had with the doctors
Transaction 5 – Show a list of patients
Transaction 6 – Update a patient record to change their address
 The tables required for this system are Patient, Appointment and
Doctor.
CRUD Matrix of Appointment System (Blank)
Transaction
Relation
Patient Appointment Doctor
T1
T2
T3
T4
T5
T6
CRUD Matrix of Appointment System
Transaction
Relation
Patient Appointment Doctor
T1 C
T2 D
T3 C
T4 R R R
T5 R
T6 U
Transactions in the Boat Hire System
a. Enter the details of all the boats. Update any details for boats. Delete boats.
b. Enter the details for customers. Update any details for customers.
c. Enter the details for hiring of boats.
d. Enter the details for any damage to boats.
e. List the details of all the boats.
f. List the details of all the customers; their hire and for which boats.
g. List the details for damage, to which boats, during which hire periods and for which
customers.
h. Provide a summary of the hires for a particular period.
The tables required for this system are Boat, Customer , Hire and Damage.
Transaction
Relation
Boat Customer Hire Damage
A
B
C
D
E
F
G
H
Blank CRUD Matrix
Transaction
Relation
Boat Customer Hire Damage
A C U D
B C U
C C
D C
E R
F R R R
G R R R R
H R
Completed CRUD Matrix
Literary agent
 Fill in the CRUD matrix below to show the following transactions.
Transaction 1. Add a new Author.
Transaction 2. Create a new agent and set up an appointment for her.
Transaction 3. Delete an author and all the appointments they have
had.
Transaction 4. Show a list of Agents details and the Appointments they
have had and with which Authors.
Transaction 5. Update an Agent’s address
Transaction 6. Delete an Appointment.
Roles in a System
 Not every user is the same.
 Users will need to access different parts of the system and access it
in different ways.
Boat Hire System - Roles
 Manager – should be able to access all parts of the system, because
their role means that they might have to add and delete any data and
be able to see anything.
 Admin Assistant – just carries out routine tasks, such as adding any
new customers and recording damage to boats.
Table/User Boat Customer Rental
Manager CRUD CRUD CRUD
Admin
Assistant
R CRU CRU
SQL Facilities to Manage Roles
 Grant – gives a particular role or user in the database system access
to an object (such as a table).
 Revoke – removes access to an object (such as a table) from a
particular role or user in the database system.
Grant
 GRANT CREATE ON Boat TO Admin;
This command will give the role of Admin the right to create data on
the table Boat.
 GRANT SELECT,INSERT,UPDATE,DELETE ON Boat TO smith;
 GRANT ALL ON Boat TO Manager;
This command will give the role of Manager the right to carry out any
operation on the table Boat.
Revoke
 REVOKE ALL ON Boat FROM Admin;
– this command will take away any access rights from the role of Admin
on the table Boat.
 REVOKE DELETE ON Boat FROM Manager;
– this command will take away the right to delete data from the Boat
table by the Manager.
Performance
 The term ‘Performance’ is generally used by database professionals to
refer to the way in which a query behaves when run against a
database.
 Increasingly, databases contain large amounts of data...
 The rate at which a query can return an answer can be slowed when it
has to sort though large numbers of records.
 Performance becomes an issue...
Indexes
 An index is a structure in a database that helps queries run more
quickly.
 An index is a data structure that stores the values for a specific
column in a table that makes easier to find a record.
 Improves performance
 Index can also be unique which will prevent a duplicate value from
being added to that column.
Clustered Indexes
 A clustered index alters the way that the rows are physically stored.
 When you create a clustered index on a column (or a number of
columns), the database server sorts the table’s rows by that column(s).
 It is like a dictionary, where all words are sorted in an alphabetical order.
 (**) Note, that only one clustered index can be created per table i.e.
Primarary Key. It alters the way the table is physically stored, it couldn’t
be otherwise.
Non-Clustered Indexes
 It creates a completely different object within the table, that contains the
column(s) selected for indexing and a pointer back to the table’s rows
containing the data.
 It is like an index in the last pages of a book. All keywords are sorted and
contain a reference back to the appropriate page number. A non-
clustered index on the computer_id column, in the previous example,
would look like the table below:
De-Normalisation
 Normalising our data model means we will have the minimum amount
of redundancy.
 If we are running a query that joins tables, this will be slower than
running a query against a single table or view. This can have an effect
on performance.
 Denormalisation can be done by including an attribute in a table that
should not be there according to the rules of normalisation.
Improving Performance with the Use of Views
View of
selected rows
or columns of
these tables
Table 1
Table 2
Table 3
Query
View
 A view is a virtual table which
completely acts as a real table.
 The use of view as a way to improve
performance.
 Views can be used to combine tables,
so that instead of joining tables in a
query, the query will just access the
view and thus be quicker.
View
 We can perform different SQL queries.
 DESC department_worker_view;
References
 http://stackoverflow.com/questions/7605707/clustered-vs-non-
clustered
ANY QUESTIONS?
References
 http://rdbms.opengrass.net/2_Database%20Design/2.2_Normalisati
on/2.2.4_1NF%20Repeating%20Attributes.html
 http://rdbms.opengrass.net/2_Database%20Design/2.2_Normalisati
on/2.2.5_2NF-Partial%20Dependancy.html
 http://rdbms.opengrass.net/2_Database%20Design/2.2_Normalisati
on/2.2.6_3NF-Transitive%20Dependency.html
 http://en.wikipedia.org/wiki/Integrity_constraints
 http://www.jkinfoline.com/functional-dependency.html
 http://jcsites.juniata.edu/faculty/rhodes/dbms/funcdep.htm

More Related Content

Transaction

  • 1. Er. Nawaraj Bhandari Topic 10 Supporting Transactions
  • 2. Transactions  A transaction is an operation carried out on the database.  Transactions can generally be identified as retrievals, inserts, updates and deletes. This is remembered by the acronym CRUD (Create, Retrieve, Update and Delete).  Transactions can be made up of one or more operations.
  • 3. Identify Transactions What do they do? What tables do they affect? What attributes do they affect? How often do they run? How many rows do they affect?
  • 4. Transactions of Appointment System Transaction 1 – Add a new patient Transaction 2 – Delete a patient Transaction 3 – Record a appointment Transaction 4 – Show a detail list of patient and the appointments they have had with the doctors Transaction 5 – Show a list of patients Transaction 6 – Update a patient record to change their address  The tables required for this system are Patient, Appointment and Doctor.
  • 5. CRUD Matrix of Appointment System (Blank) Transaction Relation Patient Appointment Doctor T1 T2 T3 T4 T5 T6
  • 6. CRUD Matrix of Appointment System Transaction Relation Patient Appointment Doctor T1 C T2 D T3 C T4 R R R T5 R T6 U
  • 7. Transactions in the Boat Hire System a. Enter the details of all the boats. Update any details for boats. Delete boats. b. Enter the details for customers. Update any details for customers. c. Enter the details for hiring of boats. d. Enter the details for any damage to boats. e. List the details of all the boats. f. List the details of all the customers; their hire and for which boats. g. List the details for damage, to which boats, during which hire periods and for which customers. h. Provide a summary of the hires for a particular period. The tables required for this system are Boat, Customer , Hire and Damage.
  • 8. Transaction Relation Boat Customer Hire Damage A B C D E F G H Blank CRUD Matrix
  • 9. Transaction Relation Boat Customer Hire Damage A C U D B C U C C D C E R F R R R G R R R R H R Completed CRUD Matrix
  • 10. Literary agent  Fill in the CRUD matrix below to show the following transactions. Transaction 1. Add a new Author. Transaction 2. Create a new agent and set up an appointment for her. Transaction 3. Delete an author and all the appointments they have had. Transaction 4. Show a list of Agents details and the Appointments they have had and with which Authors. Transaction 5. Update an Agent’s address Transaction 6. Delete an Appointment.
  • 11. Roles in a System  Not every user is the same.  Users will need to access different parts of the system and access it in different ways.
  • 12. Boat Hire System - Roles  Manager – should be able to access all parts of the system, because their role means that they might have to add and delete any data and be able to see anything.  Admin Assistant – just carries out routine tasks, such as adding any new customers and recording damage to boats. Table/User Boat Customer Rental Manager CRUD CRUD CRUD Admin Assistant R CRU CRU
  • 13. SQL Facilities to Manage Roles  Grant – gives a particular role or user in the database system access to an object (such as a table).  Revoke – removes access to an object (such as a table) from a particular role or user in the database system.
  • 14. Grant  GRANT CREATE ON Boat TO Admin; This command will give the role of Admin the right to create data on the table Boat.  GRANT SELECT,INSERT,UPDATE,DELETE ON Boat TO smith;  GRANT ALL ON Boat TO Manager; This command will give the role of Manager the right to carry out any operation on the table Boat.
  • 15. Revoke  REVOKE ALL ON Boat FROM Admin; – this command will take away any access rights from the role of Admin on the table Boat.  REVOKE DELETE ON Boat FROM Manager; – this command will take away the right to delete data from the Boat table by the Manager.
  • 16. Performance  The term ‘Performance’ is generally used by database professionals to refer to the way in which a query behaves when run against a database.  Increasingly, databases contain large amounts of data...  The rate at which a query can return an answer can be slowed when it has to sort though large numbers of records.  Performance becomes an issue...
  • 17. Indexes  An index is a structure in a database that helps queries run more quickly.  An index is a data structure that stores the values for a specific column in a table that makes easier to find a record.  Improves performance  Index can also be unique which will prevent a duplicate value from being added to that column.
  • 18. Clustered Indexes  A clustered index alters the way that the rows are physically stored.  When you create a clustered index on a column (or a number of columns), the database server sorts the table’s rows by that column(s).  It is like a dictionary, where all words are sorted in an alphabetical order.  (**) Note, that only one clustered index can be created per table i.e. Primarary Key. It alters the way the table is physically stored, it couldn’t be otherwise.
  • 19. Non-Clustered Indexes  It creates a completely different object within the table, that contains the column(s) selected for indexing and a pointer back to the table’s rows containing the data.  It is like an index in the last pages of a book. All keywords are sorted and contain a reference back to the appropriate page number. A non- clustered index on the computer_id column, in the previous example, would look like the table below:
  • 20. De-Normalisation  Normalising our data model means we will have the minimum amount of redundancy.  If we are running a query that joins tables, this will be slower than running a query against a single table or view. This can have an effect on performance.  Denormalisation can be done by including an attribute in a table that should not be there according to the rules of normalisation.
  • 21. Improving Performance with the Use of Views View of selected rows or columns of these tables Table 1 Table 2 Table 3 Query
  • 22. View  A view is a virtual table which completely acts as a real table.  The use of view as a way to improve performance.  Views can be used to combine tables, so that instead of joining tables in a query, the query will just access the view and thus be quicker.
  • 23. View  We can perform different SQL queries.  DESC department_worker_view;
  • 26. References  http://rdbms.opengrass.net/2_Database%20Design/2.2_Normalisati on/2.2.4_1NF%20Repeating%20Attributes.html  http://rdbms.opengrass.net/2_Database%20Design/2.2_Normalisati on/2.2.5_2NF-Partial%20Dependancy.html  http://rdbms.opengrass.net/2_Database%20Design/2.2_Normalisati on/2.2.6_3NF-Transitive%20Dependency.html  http://en.wikipedia.org/wiki/Integrity_constraints  http://www.jkinfoline.com/functional-dependency.html  http://jcsites.juniata.edu/faculty/rhodes/dbms/funcdep.htm

Editor's Notes

  1. Added Slide
  2. Added Slide
  3. Added Slide
  4. clustered index determines the physical order of the rows in the database
  5. clustered index determines the physical order of the rows in the database
  6. clustered index determines the physical order of the rows in the database