Topic 07
Topic 07
ICT285 Databases
ICT394 Business Intelligence
Application Development
Dr Danny Toohey
About this topic
READING
• Text, Chapter 6: section on Data Types
• Text, Chapter 7: SQL for Database Construction and Application
Processing (to p371, down to “Embedding SQL in Program Code”). We
have covered much of this already in Topic 3 and the labs.
• Text, Chapter 9: section on Database Security p472-477
Other resources:
• Oracle documentation at
https://docs.oracle.com/database/121/CNCPT/intro.htm#CNCPT001
(much more than you need!)
In this week’s lab we return to Oracle as we start to look aspects of physical database design and
implementation. We’ll consider the data types available in Oracle, views, and access permissions using
GRANT.
•Steps from Connolly & Design Design file organizations and indexes
Begg
Design Design user views
Practice In practice, this will be an iterative process as most steps involve tradeoffs of some sort
A physical database design
methodology - steps
•This topic
•Next topic
Steps from Connolly & Begg
2. Translate logical design to physical design in target DBMS
Translate logical design to physical
design in target DBMS
Aim is to select a system that permits expansion and enables speedier, easier application
development balanced against costs, that fulfils the requirements of the system
Need to:
• Undertake analysis of user requirements (done as part of the system development
process)
• Define objectives and scope of research - what criteria will be used for evaluation,
etc
• Identify possible products
• Shortlist products against criteria
• Evaluate products more thoroughly - vendor demonstrations, benchmarking tests
etc
• Recommend selection
Can use evaluation matrix to compare on weighted criteria (e.g. see ICT284)
Types of selection criteria
From http://www-
css.fnal.gov/dsg/ex
ternal/freeware/my
sql-vs-pgsql.html
(link now dead)
17
Design base tables
Include:
• VARCHAR2 (variable length)
• CHAR (fixed length character)
• NUMBER (including precision and scale)
• DATE
• … and many others
19
VARCHAR2
• Use VARCHAR2 when character data of indeterminate
length is required, e.g. names, addresses, etc
• Also when numeric data is used in an non-numeric way,
e.g. phone numbers, credit card numbers
• Will never need to do arithmetic on them
• Can also store formatting information
• Can filter records using LIKE, etc to select for regions
• Expandable, e.g. to international numbers
20
CHAR
• CHAR always stores the same length field no matter the
length of the contents – any unused space is padded with
blanks
• This can have some benefits in storage efficiency (although
not storage space) and simpler updating
• However VARCHAR is generally more flexible and more
straightforward to deal with in queries and applications
21
NUMBER
• Use for numeric values that are used as numbers, rather
than character strings
• Can define precision (total number of digits)
• And scale (number of digits to right of decimal)
12345.67
NUMBER(7,2)
• If scale is not specified, it is zero, e.g. NUMBER(2)
• Oracle doesn’t have INTEGER and will convert INTEGER to
NUMBER(38)
22
DATE
23
Other Oracle data types
24
Oracle integrity constraints
• NOT NULL
• UNIQUE Key
• PRIMARY KEY
• Referential Integrity constraints (FOREIGN KEY)
• CHECK integrity constraints
We have discussed these already in earlier topics and labs – refer
back to them as you need to
See https://docs.oracle.com/database/121/CNCPT/datainte.htm#CNCPT021
25
Implementing constraints
30
Derived data
Store?
• Additional storage cost of the derived data
• Must re-calculate continually to keep it consistent with
operational data it is derived from (e.g. use a trigger)
Calculate?
• Cost to calculate it each time it is required
Derived data: Store or Calculate?
Considerations
• Views are ‘virtual’ tables – unlike the base tables they are
derived from, they do not contain any actual data
• However, in some cases the base table(s) can be updated
through the view, using exactly the same SQL commands
(insert, delete, update) as for tables – when this can occur the
view is said to be updateable
• The rules for view updateability are complex and DBMS-
dependent, but basically the update must provide an
unambiguous result on the base table(s)
Updateable views (simply)
Updateable:
• Views based on a single table with no computed columns and all non-null
columns present in the view
Not updateable:
• Where the view contains a computed or aggregate column
• Views based on some joins
Possibly updateable:
• If based on a single table, primary key in view, some required columns
missing from view – update and delete may be allowed, insert not
• If based on multiple tables, updates may be allowed on the most
subordinate table in the view if rows of that table can be uniquely identified
SQL: CREATE VIEW… WITH CHECK OPTION
There are many tools that can be used for analysing transactions,
e.g.
• Transaction/ Relation Cross Reference Matrix (CRUD)
• Shows Create (C), Read (R), Update (U), and Delete (D) data accesses
to tables
• Transaction Usage Map (TUM)
• Shows the pattern of data accesses and their frequency
These analyses can be presented in a transaction analysis report
as part of the logical or physical design documentation
Part
Project
Invoice
Supplier
CRUD matrix
Invoice Line
R
R
R
Create Invoice
CRU
CRU
R
R
R
Accounts Payable
RU
R
R
Inventory
U
R
R
R
Project Management
U
R
R
R
R
R
•Involves:
•Create Invoice details
•Create invoice
•Check project exists
•Add Invoice Line details
•Create invoice line
•Check invoice exists
•Check part exists
•Check Supplier exists
49
Access Refs per Peak
TUM: Example Step Name type
1 Create new invoice C
Trans.
1
Refs/Hr
97.5
2 Project R 1 97.5
3 New Invoice Line C 10-15 1462.5
4 Part R 10-15 1462.5
5 Supplier R 10-15 1462.5
6 Invoice R 10-15 1462.5
Total References: 42-62 4582.5
51
The take-aways…
55
When would denormalisation be
appropriate?
• Denormalisation can provide better efficiency, but remember
that:
• It makes implementation more complex – to maintain consistency
• It can sacrifice flexibility
• It may speed up retrievals but slow down updates
• As a general principle, if performance is unsatisfactory and the tables
involved are updated infrequently but queried a lot, it may be worth
denormalising
56
Examples of denormalisation
strategies
57
Denormalisation:
Including repeating groups in the parent
table
• New table will potentially have many nulls (wasted space) if few
staff have next of kin – balance against improved performance
in retrievals
60
Denormalisation:
Creating a single table from a
generalisation hierarchy
M M
Emp Emp
EmpNo EmpNo
EmpName EmpName
DeptNo DeptNo
DeptName
• Run DBMS behind a firewall, but plan as though the firewall has been breached
• Apply the latest OS and DBMS service packs and fixes
• Use the least functionality possible
• Support the fewest network protocols possible
• Delete unnecessary or unused system stored procedures
• Disable default logins and guest users, if possible
• Unless required, never allow all users to log on to the DBMS interactively
• Protect the computer that runs the DBMS
• No user allowed to work at the computer that runs the DBMS
• DBMS computer physically secured behind locked doors
• Access to the room containing the DBMS computer should be recorded in a log
Copied from Fig 9-16 in Kroenke, D.M., and Auer, D.J., 2016, Database Processing: Fundamentals,
Design and Implementation, 14th Edition, Pearson.
DBMS Security Guidelines 2
• Planning
• Develop a security plan for preventing and detecting security problems
• Create procedures for security emergencies and practice them
Copied from Fig 9-16 in Kroenke, D.M., and Auer, D.J., 2016, Database Processing: Fundamentals,
Design and Implementation, 14th Edition, Pearson.
Authentication, authorisation and
access control
• Authentication
• Verifying that someone (or something) is who they say they are
• DBMS, OS authentication or a combination
• Authorisation
• Determining what a user is and isn’t allowed to do
• Certain Subjects have access to certain actions on certain objects
• Access control
• How you make that happen in practice
Access controls
Copied from Fig 9-15in Kroenke, D.M., and Auer, D.J., 2016, Database Processing: Fundamentals,
Design and Implementation, 14th Edition, Pearson.
DAC and MAC
Granting to PUBLIC
• Grants the privilege to any user who can log into the DBMS
• Should be exercised with caution!
• When might this be a good thing to do?
• Database Objects
- User can create database structures such as databases,
tables, triggers, etc
• System Privileges
- User can execute certain system commands such as start and
shutdown, start traces, manage storage
- Usually reserved for DBA
• Program and Procedures
- Users can execute programs or stored procedures
REVOKE
REVOKE [GRANT OPTION FOR]{PrivilegeList|ALL PRIVILEGES}
ON ObjectName
FROM {AuthorisationList|PUBLIC}[RESTRICT|CASCADE]
85
Topic learning outcomes
In the next topic we look more closely at how the data in the database is physically held on
secondary storage.
One of the responsibilities of the DBA is to determine the optimal file organisations and
indexes that are required to achieve acceptable performance for the important transactions.
These work together with the inbuilt query optimisation techniques of the DBMS to provide
efficient processing.