320 likes | 384 Views
The relational model. INF08104: Database Systems Brian Davison , 2013/4. Agenda. Module introduction Sets and relations Keys and entity integrity Keys and relationships. Why you need to know about databases. Technical. Business. Improved data management E-business Data as a product
E N D
The relational model INF08104: Database Systems Brian Davison, 2013/4
Agenda • Module introduction • Sets and relations • Keys and entity integrity • Keys and relationships
Why you need to know about databases Technical Business Improved data management E-business Data as a product Employability • Speed • Maintainability • Security • Standardisation
What is a database? • An organized collection of data Wikipedia • A shared collection of logically related data, and a description of this data, designed to meet the information needs of an organisation Connolly & Begg • A component in a larger system http://netbeans.org
A little bit of history • Pre-1950: Negligible electronic data storage • 1950 – 1970: Application of computing to standard data problems • 1970: Edgar Codd, A Relational Model of Data for Large Shared Data Banks • 1970 – 1985: Massive growth in relational database use • 1985 – 2012: Experimentation with object-orientation, digital objects, etc.
The database approach Table name = EMP Schema Data
Database advantages • Data independence • Multi-user access • Data integration • Data integrity • Enforcement of standards • Security • Performance
Data integrity • Type checks • e.g. ensuring a numeric field is numeric and not a character • Redundancy checks • direct or indirect - this check may not be automatic and may have to be added by the database designer • Range checks • e.g. to ensure a data item value falls within a specified range of values, such as checking dates so that say (age > 15 AND age < 70). • Comparison checks • in this check a function of a set of data item values is compared against a function of another set of data item values. For example, the max salary for a given set of employees must be less than the min salary for the set of employees on a higher salary scale.
Roles • End users • Application programmers • Database administrator
Module structure • Theory • Standard architecture, security, concurrency • Design • Analysis, schema definition, diagrams • Use • SQL, embedded SQL • Administration • Backup & recovery, user management, scripting
Assessment • Coursework 50% • Details in week 4 • Database creation • SQL queries • Deadline week 9 – 1200, Friday 8th November • Exam 50% • Theory • SQL queries
Feedback from previous years • I was pleased with my overall performance with the coursework – it was a lot of work but it was rewarding to work on a long, challenging piece of work to good success • This was a challenging module that was extremely rewarding, very intense and I am now very confident with SQL and working with databases.
Entities and relationships This is a relation – also known as a table This is a relationship – not a relation
Two sets A ( P, Q, R, S ) B ( W, X, Y, Z )
A mathematical relation R = ( (P, W), (Q, Y), (R, X), (S, Z) )
A realistic example Room allocation = ( (Pete, 1), (Quincy, 3), (Rachel, 2), (Shonagh, 4) )
Domains • The set of possible values for a column • All values have the same datatype • Date • Variable length character string (Varchar) • Integer (eg -2, -1, 0, 1, 2, 3...) • Floating point number (Float – eg 1.23, 12035.65246371, etc.) • Datatype defines an infinite set of values • Domain defines a more restricted set • Domain may be implemented by constraints in the database
The degree of a table Employees (4) Offices (4) Extensions (10)
Keys and entity integrity • Entity integrity: the ability to uniquely identify one row in a table • Key: an attribute (or group or attributes) that differentiates the rows • eg matriculation number, country symbols (UK, FR, CN, etc) • Key determines the other values; other values are functionallydependent on the key • What makes a good key • Unique • Doesn’t change
Choosing a key • ni_number • ni_number, last_name • date_of_birth, office, first_name • first_name, last_name, date_of_birth • first_name, last_name, date_of_birth, extension
Types of key • Superkey • Uniquely identifies a row • Candidate key • Uniquely identifies a row and contains no redundant attributes • Primary key • Selected candidate key
Relationships and cardinality STUDENT PROGRAMME * enrols_on 1 staff PROGRAMME 1 leads 1 STUDENT module * studies *
Optionality staff PROGRAMME 1..1 leads 0..1 Optional One member of staff leads zero or one programmes Mandatory One programme is led by one and only one member of staff Cardinality & Optionality = Multiplicity