Course Notes www.eeng.dcu.ie/~ee221. Books. • Fundamentals of Database
Systems, Elmasri and Navathe. • An Introduction to Database Systems, C.J. Date.
EE221 Part I - Database Systems
Course Notes www.eeng.dcu.ie/~ee221
Books •
Fundamentals of Database Systems, Elmasri and Navathe
•
An Introduction to Database Systems, C.J. Date
•
Database Analysis and Design, I.T. Hawryszkiewycz
•
An Introduction to Database Systems, B.P. Desai
Course Outline •
Introduction to Database Systems and Architecture
•
The Relational Model
•
Data Modelling and Entity-Relationship Diagrams
•
Relational Languages
•
Relational Design and Functional Dependency
•
Normal Forms and Decomposition
Database Systems (EE221) - Page 1
Why Databases?
Single User Case A wine list is an example Using a database for a very small list does not show advantages Consider a large off licence chain – the wine lists could be very large and could change frequently
Advantages of Databases Compactness – compared to paper Speed – Fast updates Less Drudgery – paper is tedious Currency – up-to-date and accurate
Multi-user Case More complex databases Same advantages as above + multiple simultaneous users Single point of control for a large enterprise
Database Systems (EE221) - Page 2
A First Database Example – A Wine List Database
RELATION: WINELIST Bin# 2 21 22 30 43 45 48 50 51 52 58 64 12
Wine Chardonnay Fume Blanc Fume Blanc Gewurztram. Cab. Sauv. Cab. Sauv. Cab. Sauv. Pinot Noir Pinot Noir Pinot Noir Merlot Zinfandel Riesling
Producer Buena Vista Ch. St. Jean Robt. Mondavi Ch. St. Jean Windsor Geyser Peak Robt. Mondavi Gary Farrell Fetzer Dehlinger Clos du Bois Cline Jekel
Year 1997 1997 1996 1998 1991 1994 1993 1996 1993 1995 1994 1994 1998
Bottles 1 4 2 3 12 12 12 3 3 2 9 9 1
Ready 1999 1999 1998 1999 2000 2002 2004 1999 2000 1998 2000 2003 1999
Retrieving Data: SELECT BIN#, WINE, PRODUCER FROM WINELIST WHERE Ready=2000;
This query statement would result in the following output: Bin# 43 51 58
Wine Cab. Sauv. Pinot Noir Merlot
Producer Windsor Fetzer Clos du Bois
Inserting New Data: INSERT INTO WINELIST (BIN#, WINE, PRODUCER, YEAR, BOTTLES, READY) VALUES (53, ‘Pinot Noir’, Sainsbury, 1997, 6, 2001);
This query statement would add a new row to the table. Changing Existing Data: UPDATE WINELIST SET Bottles=3 WHERE BIN# = 21;
Deleting Existing Data: DELETE FROM WINELIST WHERE BIN# = 2; Database Systems (EE221) - Page 3
Introduction to Database Systems Databases are essential to an organisation’s information systems and help to support an organisation’s critical functions. Databases maintain the data for the information systems and enable users to access and interpret the data. The database takes a central role in an organisation’s decision-making processes. Examples of databases which assist in the management of critical functions within an organisation are: • • • •
Stock control (in factories, libraries, etc.) Warehouse management Accounting software Schedulers and logistics, managing mass transportation e.g. airports, train schedules • Reservations packages • Telecoms network management A database may be considered as a computerised record keeping system. It can be regarded as a repository for a collection of computerised data files. The user of the system is provided with facilities by the Database Management System (DBMS) to perform a variety of operations on these records, such as: • • • • •
Adding new files to the database Inserting new data into existing files Retrieving data from or updating data in existing files Deleting data from existing files Removing existing files permanently from the database.
Data Administration Data is one of an enterprise’s most valuable assets. In large organisations: The Data Manager should be a senior management person. They determine the database layout (database schema), interfaces, policy and upgrades. They determine who can access the data (security policy) and what permissions they have (e.g. read only, update, delete). The Database Administrator implements the technical processes of installing, configuring and maintaining the database.
Database Systems (EE221) - Page 4
Requirements for Modern Database Systems Early databases usually supported one organisational function only, so there would have been separate databases for the accounts function in a company, for the inventory system and so on. This is no longer a useful approach and all modern databases must be able to maintain a number of different files containing information about different (but possibly interrelated) functions of an organisation. Multiple users must be able to request information from a database simultaneously, each user via their own personalised user-database interface. For example, an accountant will need to see and manipulate different information than is visible to a store manager. Therefore, the database management system must contain the functionality to allow multiple different user interfaces to be created, each with a link to the relevant parts of the database. Also the structure of the database management system must be such that if the structure of the database is altered at a low level (e.g. the data location is changed on the storage medium), the users’ perspective of the system will not be changed. Other criteria which must be met by modern databases are derived from the fact that information is distributed across numerous files in the database. It is necessary to: Reduce or eliminate data redundancy – the same information should not be stored in multiple files, but should be kept in one place, with links created to it where necessary. This ensures consistency of the data. Maintain complex relationships among data elements – in order to successfully minimise redundancy, it must be possible to keep track of a complex system of links and relationships between data at various locations in the database. Support a large variety of decision needs – allow the user to specify a number of interrelated criteria for the selection of specific data from various places in the database. For example, a courier control system manager many want to retrieve the names of all drivers under the age of 35 who are currently driving trucks which are filled to more than half capacity and travelling to France. This would involve checking the employee file, the stock file and the travel file of the courier control database. We need a structured language to from these types of complex queries. Reduce database access time - if the database contains many large files, it may take quite some time to find a particular data item. This delay may be reduced through the use of keys and indices allowing data tables and relations between data to be traversed efficiently.
Database Systems (EE221) - Page 5
Avoid any data inconsistency - if the same data is stored in two different files, it must be ensured that if the data is updated in one location, the data in the other location remains consistent with the change. Otherwise, conflicting data will exist within the database for the same information. If this does occur, the database is said to be inconsistent and may provide incorrect or conflicting information to its users. Note how this requirement is related to the requirement to reduce redundancy. Provision for security restrictions - the database manager must be able to put security checks in place to ensure that all users are accessing the database through the proper channels. It may also be required to protect sensitive information from unauthorised access. Security is vital in a large database system, as there is usually a core set of data, which, if tampered with could potentially result in the destruction of the database, and which must therefore be restricted from general access.
Database Systems (EE221) - Page 6
Database Architecture A data-independent architecture is divided into three general levels, as follows: • The internal level is the one closest to physical storage - i.e. it is the one concerned with the way the data is actually stored; • The external level is the one closest to the users - i.e. it is the one concerned with the way the data is viewed by individual users; • The conceptual level is a 'level of indirection' between the other two.
User View
User View
User View
External Level
Community User View
Conceptual Level
Storage View
Internal Level
The Database Architecture
If the external level is concerned with individual user views, the conceptual level may be regarded as being concerned with a community user view. In other words, there will be many distinct external views, each consisting of a more or less abstract representation of some portion of the total database, and there will be precisely one conceptual view of a similarly abstract representation of the database in its entirety. The storage view shows how the data is actually stored in reality - in bits and bytes on some storage unit.
Database Systems (EE221) - Page 7
An example, using relational database structures would appear as shown below. The tables shown on the conceptual level represent the structures of two relational files. In the external views, new tables are created by mapping fields of the conceptual tables onto a new structure defined specifically for that user view. Similarly, the data in the fields of the conceptual view are acquired through a mapping to the actual location of that data on the storage medium.
ID
Dept
Name
Role
01
Dept
Smith
Tech
02
Dept
Kelly
Mngr
07
Dept
Brown
Tech
External View
ID
Name
Salary
Dept
01
Smith
28000
Maint
02
Kelly
35000
Maint
07
Brown
30000
Test
01
Smith
02
Kelly
07
Brown
28000
Conceptual View
35000
ID
Role
01
Tech
02
Mngr
07
Tech
30000
Storage View
The strength of this architecture is contained in the mappings between the levels. If it is desired to create a new user view or alter an existing view, it is only necessary to define the mappings from the conceptual level. Also, in a similar fashion, if the administrator wishes to alter the location (or data type, size in bytes etc.) of data in the database, it is not necessary to alter the conceptual view – a change in the mapping from conceptual to internal level (if necessary) will allow the conceptual view to remain the same, with the mapping pointing to the new data location.
Database Systems (EE221) - Page 8
The DBMS The Database Management System (DBMS) is the software which handles all database access. Therefore, all users of external views read and manipulate data by sending requests to the DBMS. The DBMS then examines the external views, conceptual view and mappings to evaluate the operations which need to be carried out on the actual data in storage. It is also through the DBMS that the database administrator creates new external views, adapts the conceptual or storage view and manipulates mappings. Therefore, the system architecture may be amended as shown below to show that the DBMS touches on all levels of the architecture, and that therefore, all manipulation of the structure of the database or the information in it must be done through the DBMS.
User View
External / Conceptual Mapping
User View
User View
Community User View DBMS
Conceptual / Internal Mapping Storage View
The Database Management System
Database Systems (EE221) - Page 9