* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Week2 Database Fundamentals(3)
Survey
Document related concepts
Microsoft SQL Server wikipedia , lookup
Microsoft Access wikipedia , lookup
Serializability wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Oracle Database wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Ingres (database) wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Functional Database Model wikipedia , lookup
Concurrency control wikipedia , lookup
Relational model wikipedia , lookup
Clusterpoint wikipedia , lookup
Transcript
Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s Database Design Concepts IMAT1408 Lecture 2 Database Fundamentals HNDComputing – DeMontfort University DeMontfort University 2011 wk2 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s Database Design Concepts IMAT1408 Lecture 2 Database Fundamentals HNDComputing – DeMontfort University DeMontfort University 2011 wk2 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Objectives To introduce: • The three layers of data abstraction (ways of viewing/handling data) • The terms physical and logical data independence • Table types and associated terms. HNDComputing – DeMontfort University DeMontfort University 2011 3 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Is this a database? Is this Organised? Efficient? Easily accessible? Flexible? …… HNDComputing – DeMontfort University DeMontfort University 2011 4 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Paper based databases •Have been around for a long time •Data is organised and quickly accessible So is easier to maintain – fewer errors •But is not all that flexible – things are filed in one place only (why would it not be a good idea to have duplicates?). HNDComputing – DeMontfort University DeMontfort University 2011 5 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Computer based databases • Are managed by a Moves data to and from physical data files Manages multiple users Manages transactions: ‘all or nothing’ units of work Supports a Query Language to retrieve data from the database Manages back ups Provides security mechanisms. HNDComputing – DeMontfort University DeMontfort University 2011 6 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s Typical Example of a Database Internet Architecture wk2 Internet Explorer Browser INTERNET Firefox Browser MAPPING APACHE WEB-SERVER Logical Shema (Relational communicates with the web users Tables) PHP or ASP.NET MySQL ODBC/API communicates with DB DATABASE Database Server HNDComputing – DeMontfort University DeMontfort University 2011 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Layers of data abstraction • Databases are obviously very complicated pieces of software • How do we understand how they work? • They are divided into 3 layers – known as the 3 layer architecture • We can look at each layer in turn…… HNDComputing – DeMontfort University DeMontfort University 2011 8 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 External layer What the user sees Logical layer How the database organises the data for viewing Physical layer How the computer’s operating system stores the data HNDComputing – DeMontfort University DeMontfort University 2011 9 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 The DBMS enables multi-user access to the same data at the same time EXTERNAL layer Userview 2 Userview 1 LOGICAL layer MAPPING Logical Schema MAPPING INTERNAL layer DATA HNDComputing – DeMontfort University DeMontfort University 2011 INDEXES Database Fundamentals External layer User View 2 User View 1 Logical layer User View …. Logical Data independence Conceptual Schema Physical Data independence Physical layer HNDComputing – DeMontfort University DeMontfort University 2011 Database File Database File Database File Database File Database File D a t a b a s e D e s i g n C o n c e p t s wk2 11 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 The Physical Layer • The files that actually contain the data • Data could be stored over multiple disk drives – maximise performance by running in parallel • Microsoft Access stores everything in one physical file. This limits the number of concurrent users and so it cannot be used for large enterprises • The DBMS works with the computer’s Operating System (OS) to efficiently manage the file storage • The user of the database does not need to know how the DBMS does this. 12 HNDComputing – DeMontfort University DeMontfort University 2011 Database Fundamentals User View 2 User View 1 User View …. Logical Data independence Conceptual Schema Physical Data independence HNDComputing – DeMontfort University DeMontfort University 2011 Database File Database File Database File Database File Database File D External layer a t a b a s e Logical D layer e s i g n C o Physical n layer c e p t s wk2 13 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Logical Layer • The logical layer provides a structure for the data which is known as the conceptual schema • This structure needs to meet the requirements of the users. This is what we will work on when we design databases. • It makes the data available to any application (or several at once) without the designer needing to know the exact location of the data – the data is therefore independent of the applications. For example a customer database record could be used in many different applications - for billing invoices, posting out publicity flyers about new products, sending on-line questionnaires etc.,etc.. HNDComputing – DeMontfort University DeMontfort University 2011 14 Database Fundamentals External D layer User View 2 User View 1 User View …. Logical Data independence Conceptual Schema Physical Data independence HNDComputing – DeMontfort University DeMontfort University 2011 Database File Database File Database File Database File Database File a t a b a s e D Logical e layer s i g n C o n c Physical layer e p t s wk2 15 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 External Layer • This is the layer where users interact with the database and issue queries • The DBMS selects items from the logical layer to form a user view • Different user views can be set up to meet different people’s needs • These user views can be stored for future use, or may be used only temporarily and then discarded – an ad hoc query. HNDComputing – DeMontfort University DeMontfort University 2011 16 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 The 3 layers and database design • We need to look at each user’s requirements • These give us the external views required • You will learn to create the conceptual schema so that these external views can be produced from it. One method we will use is Entity Relationship Modelling • We will leave the DBMS to take care of the physical layer. HNDComputing – DeMontfort University DeMontfort University 2011 17 Database Fundamentals External layer User View 2 User View 1 Logical layer User View …. Logical Data independence Conceptual Schema Physical Data independence Physical layer HNDComputing – DeMontfort University DeMontfort University 2011 Database File Database File Database File Database File Database File D a t a b a s e D e s i g n C o n c e p t s wk2 18 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Data Independence - the big advantage of databases • Physical data independence means you can change the way the data is stored without having to change all the programs that use the data. This saves time and money. HNDComputing – DeMontfort University DeMontfort University 2011 19 Database Fundamentals External layer User View 2 User View 1 Logical layer User View …. Logical Data independence Conceptual Schema Physical Data independence Physical layer HNDComputing – DeMontfort University DeMontfort University 2011 Database File Database File Database File Database File Database File D a t a b a s e D e s i g n C o n c e p t s wk2 20 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Logical Data Independence • The ability to make changes to the logical layer without disrupting existing users and processes • This means we can: – Add a new database object eg a table – Add data items to an existing object. HNDComputing – DeMontfort University DeMontfort University 2011 21 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Design components: Entity • To create a useful database we must study the business’s activities and identify the data that needs to be stored • We look for entities • Just about anything that can be named can be an entity …but we only consider things of interest to the users of our database. HNDComputing – DeMontfort University DeMontfort University 2011 22 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 • A very common entity that is found in many business oriented databases is the CUSTOMER This represents all the customers in the database ……… an individual customer is known as an occurrence of the entity. HNDComputing – DeMontfort University DeMontfort University 2011 23 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Attributes • “An attribute is a unit fact that characterises or describes an entity in some way” (Oppel, 2004) • Attributes are the smallest units of information that are stored in a database • Examples could be the customer’s last name, post code, telephone number. HNDComputing – DeMontfort University DeMontfort University 2011 24 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Unique identifiers • An entity will be described using the attributes. For example a student could have last name, first name and several address attributes • The problem is we need to distinguish one student from another • Most students can be identified by their name but sometimes two students have the same name • How do I make sure I don’t award marks to the wrong student? HNDComputing – DeMontfort University DeMontfort University 2011 25 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 • I do this by using an attribute known as the primary key • This is a unique identifier so each student will have a different value for this attribute • What is your unique identifier? • Remember these unique identifiers are often invented so are not always known to the person concerned. HNDComputing – DeMontfort University DeMontfort University 2011 26 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Examples of unique identifiers^ • • • • • • National insurance number Passport number Membership number Order number Vehicle registration number Bank account number. HNDComputing – DeMontfort University DeMontfort University 2011 27 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Tables • Main method of storage in the relational model is the table • A two dimensional structure composed of rows and columns • Each row represents one occurrence (instance) of the entity (or record) • Each column represents one attribute of that entity. HNDComputing – DeMontfort University DeMontfort University 2011 28 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Table Types • We show a table’s structure by showing its table type • Eg Student (studentno, name, address, courseno) Table Name Primary Key Attributes Foreign Key Each Student record will have the same structure but different values. HNDComputing – DeMontfort University DeMontfort University 2011 29 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Foreign Key • The foreign key is the primary key of another table • It creates a link between the two tables • courseno in our example will be the key field of a course table • Course (courseno, title) • This allows us to look up the title of the course each student is taking. HNDComputing – DeMontfort University DeMontfort University 2011 30 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 Summary You should be able to explain: – Database Management System – Physical, logical and external layers (and draw a diagram of them) – Physical and logical data independence – Entity (more on this next week) – Attribute – Primary key/unique identifier – Table type – Foreign key. HNDComputing – DeMontfort University DeMontfort University 2011 31 Database Fundamentals D a t a b a s e D e s i g n C o n c e p t s wk2 References • Databases Demystified by Andy Oppel (Published by McGraw-Hill, ISBN 0-07-225364-9) • Data Analysis for Database Design by David Howe (Published by Arnold. Second edition.) HNDComputing – DeMontfort University DeMontfort University 2011 32