* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Physical Data Modelling
Survey
Document related concepts
Oracle Database wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Concurrency control wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Relational algebra wikipedia , lookup
Functional Database Model wikipedia , lookup
ContactPoint wikipedia , lookup
Clusterpoint wikipedia , lookup
Transcript
44271: Database Design & Implementation Physical Data Modelling Ian Perry Room: C49 Tel Ext.: 7287 E-mail: [email protected] http://itsy.co.uk/ac/0405/sem3/44271_DDI/ The ‘Data Modelling Stack’ Conceptual Overview of things Logical Physical Ian Perry that are perceived to be of ‘interest’ in the ‘real’ world. Data elements & the relationships between those elements in a tabular form. Actual data held in a database & the means to manipulate that data. Model of the Business System. (ER Model) Model of Data Storage Theory (Db Schema) Physical Implementation (RDBMS) 44271: Database Design & Implementation: Physical Data Modelling Slide 2 What is a Physical Data Model? The Physical Implementation (hardware & software) of a Logical Data Model: it is useless to progress to this stage of database development if your Logical Data Model is NOT demonstrably ‘robust’. Physical Data Model must enable: data to be stored (& maintained) in structured manner. retrieval of specific groupings of data (information?). an ‘accurate’ implementation of the logical data model. refer back to the original business requirements. There may be several software constraints: Ian Perry depending upon the software application chosen. 44271: Database Design & Implementation: Physical Data Modelling Slide 3 Our Physical ‘World’? RDBMS Software: Microsoft Access In this physical world we must be able to: Create Populate This Database with ‘test’ data. Query Ian Perry Translate our Relational Schema into a Database. Ask questions of the Database. 44271: Database Design & Implementation: Physical Data Modelling Slide 4 Properties of RDBMS Software Modification: To Schema: To Data: creating & deleting relations (i.e. Tables). adding attributes to, or removing attributes from, existing relations. creating & deleting tuples (i.e. Records) updating attribute values in a tuple (i.e. Data held in Fields) Interrogation: Ian Perry Relational Algebra Relational Calculus (SQL) 44271: Database Design & Implementation: Physical Data Modelling Slide 5 Logical => Physical i.e. translate our Relational Schema into a Database Storage Model: Schema Relations Attributes Domains Key Fields => Ian Perry => => => => Database Tables Field Names Data Type Field Size Input Mask Validation Rule etc. Relationships 44271: Database Design & Implementation: Physical Data Modelling Slide 6 The SSC Database ER Diagram Course M M Staff 1 M Student Relations Staff (StaffID, FirstName, SurName, ScalePoint, DOB) Student (EnrolNo, FirstName, SurName, OLevelPoints, Tutor) Course (CourseCode, Name, Duration) Team (CourseCode, StaffID) Pay (ScalePoint, RateOfPay) Ian Perry 44271: Database Design & Implementation: Physical Data Modelling Slide 7 Physical Implementation Ian Perry 44271: Database Design & Implementation: Physical Data Modelling Slide 8 Relational Algebra With most (all?) Relational DataBase Management Systems the means of database interrogation is based upon: Relational Algebra (E. F. Codd, 1972) As represented by the 3 primary functions of: Ian Perry SELECT PROJECT JOIN 44271: Database Design & Implementation: Physical Data Modelling Slide 9 Example Relations (Relational Algebra) Employee (EmpNo, EName, ESalary, Dept) EmpNo EName ESalary Dept Assignment (JName, EmpNo, Hours) JName EmpNo Hours Job (JName, Budget) JName Ian Perry Budget 44271: Database Design & Implementation: Physical Data Modelling Slide 10 SELECT Extracts TUPLES (Rows) from a relation subject to required conditions on attributes in that relation. e.g.: SELECT Employee WHERE ESalary > 13000 EmpNo EName ESalary Dept 146 468 Harvey Mendoza 15000 14000 Sales Planning NB. SELECT Employee WHERE ESalary > 13000 GIVING Temp1 Would ‘create’ a new relation, i.e. Temp1 Ian Perry 44271: Database Design & Implementation: Physical Data Modelling Slide 11 PROJECT Extracts COLUMNS from a relation in a named order by attribute. e.g.: PROJECT Employee OVER EName, Dept Ian Perry EName Dept Harvey Jones Mendoza Smith Sales Planning Planning Sales 44271: Database Design & Implementation: Physical Data Modelling Slide 12 JOIN COMBINES RELATIONS which have a common attribute to generate a temporary relation containing all of the attributes from both relations. e.g: JOIN Employee AND Assignment OVER EmpNo EmpNo EName ESalary 134 146 468 Smith 12000 Harvey 15000 Mendoza 14000 Dept JName Sales ProjB Sales ProjA Planning ProjB Hours 9.0 3.4 5.2 NB. This temporary relation contains only one instance of the ‘EmpNo’ Attribute. Ian Perry 44271: Database Design & Implementation: Physical Data Modelling Slide 13 Asking ‘Complex’ Questions What are the Names, Jobs and Hours worked by those in the Sales Dept? PROJECT ( SELECT ( JOIN Employee AND Assignment OVER EmpNo) WHERE Dept = 'Sales') OVER EName, JName, Hours EName JName Hours Smith Harvey ProjB ProjA 9.0 3.4 Ian Perry NB. The final relation is constructed by working from the innermost nesting outwards. 44271: Database Design & Implementation: Physical Data Modelling Slide 14 Structured Query Language SQL is the most often used method for accessing relational databases. Remember: A ‘software interpretation’ of Codd's Relational Algebra. SELECT - extracts TUPLES from a relation subject to required conditions on attributes in the relation. PROJECT - extracts COLUMNS from a relation in a named order by attribute. JOIN - COMBINES RELATIONS which have a common attribute to generate a temporary relation containing all of the attributes from both relations. SQL ‘works’ for all RDBMS applications: Ian Perry e.g. Access, Oracle, MySQL, etc. 44271: Database Design & Implementation: Physical Data Modelling Slide 15 The SQL ‘SELECT’ Statement SQL Syntax SELECT {column_name [, column_name, ... ] } FROM table_name [ table_alias ] [ WHERE condition [ AND/OR condition [, AND/OR condition, ... ] ] ] [ GOUP BY column_name [, column_name, ... ] [ HAVING condition ] ] [ ORDER BY {column_name/column_number [, ... ] } ] Don’t worry, it is not a frightening as it looks! Ian Perry 44271: Database Design & Implementation: Physical Data Modelling Slide 16 Example Relations (SQL) Staff (Surname, Name, Dept, Position, Age) Surname Name Dept Position Age Course (CourseNo, CourseName, Level, Surname) CourseNo Ian Perry CourseName Level Surname 44271: Database Design & Implementation: Physical Data Modelling Slide 17 The ‘simplest’ SELECT SELECT * FROM staff ; A SELECT of all Tuples (rows) from a Table called staff. Ian Perry 44271: Database Design & Implementation: Physical Data Modelling Slide 18 A ‘more useful’ SELECT SELECT name, surname, age, position FROM staff WHERE age > 35 OR position = 'CLERK' GROUP by age ; A PROJECT of specific columns of the staff Table (in a named order), with some SELECTion of conditions. Ian Perry 44271: Database Design & Implementation: Physical Data Modelling Slide 19 Previous SQL Statement Produces: Ian Perry 44271: Database Design & Implementation: Physical Data Modelling Slide 20 SELECTing from 2 Tables SELECT S.name, S.surname, S.age, C.courseno FROM staff S, course C WHERE S.surname = C.surname AND age > 50 ; JOINs the Tables staff and course to create a temporary table and PROJECTs columns from this new table based on the SELECTion criteria. Ian Perry 44271: Database Design & Implementation: Physical Data Modelling Slide 21 Previous SQL Statement Produces: Ian Perry 44271: Database Design & Implementation: Physical Data Modelling Slide 22 Query-By-Example (QBE) SQL can be difficult to learn, however, most RDBMS software has a QBE interface: Using this 'point-&-click' QBE interface, we don’t have to know (much) about: Field Names, Logical Operators, etc. can easily set up relationships between tables: which presents the user with ‘lists’ of things to choose from. Staff.SURNAME = Course.SURNAME and apply criteria for selection, e.g.: Ian Perry Staff.AGE > 50 44271: Database Design & Implementation: Physical Data Modelling Slide 23 This Week’s Workshop Provides a ‘gentle’ Introduction to Microsoft Access Showing you how to build, and then ask questions of, relatively simple Relational Databases. i.e.: Ian Perry Databases consisting of two, or three, Tables. 44271: Database Design & Implementation: Physical Data Modelling Slide 24