Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Microsoft Jet Database Engine wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Relational algebra wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Clusterpoint wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Healthcare Cost and Utilization Project wikipedia , lookup
Databases Content What is a database? What is a relational database? Concept and terminology An introduction by example Relational algebra: the key of success Introduction to SQL (Structured Query Language) Teaching Lectures (5 h), Course work (4 h), Practical work (6 h) Written test (1 h 30) 2 Introduction A database is a collection of related data name, phone number, address of people you know A database is a logically consistent collection of data with some inherent meaning A database is designed, built and populated with data for a specific purpose A database can be of any size and of varying complexity 3 From Files to Databases A file is a set of objects of the same type stored on a physical support. Information system example: Social Network Members Name Nickname Email Password Jane's friends Dan's friends Jane's friends Dan's friends Name Nickname Email Relationship Name Nickname Email Relationship Name Nickname Email James Bond jb007 Clark Kent superman [email protected] coworker Lois Lane lolo lola123 [email protected] coworker Tarzan kikoo68 [email protected] engaged Name Nickname doedoe [email protected] Relationship Email [email protected] friend Relationship brother Bill Gates bill_gates [email protected] boss Clark Kent superman [email protected] friend [email protected] friend Lois Lane 4 lola123 Using Files? Several files with the same data: Redundancy of information Volume, access time, validity, duplicates Difficult to update Change email in all files Difficult to retrieve data Problem for finding information, reading (e.g., how can one read the file when it is being updated), etc. File Programme The application depends on the way the data is stored Report 5 Beyond Files? Make programmes independant from the way data is stored Data Base Management System (DBMS) DB1 DB2 DBn ... One DBMS DBMS Ap1 Ap2 Many databases Apk Many applications Can access many different databases The structure of data is stored in the DBMS directory separately from the access programs Concrete data storage is “hidden” 6 What is a DBMS? A programme that allows users to create and maintain a database Defining: data types (numbers, text, dates, etc.) Constructing: populating the database Manipulating: updating, inserting, deleting (e.g., add/remove a friend) Retrieving data according to criteria (e.g., “give me all my friends that have developped a Facebook application and that are less than 18 year old”) Manage access rights (e.g., not all users can access passwords) 7 Role of a DBMS Avoiding redundancy Sharing of data Restricting unauthorized accesses Enforcing integrity constraints Providing multiple interfaces Providing backup and recovery 8 Role of a DBMS (contd.) Avoiding redundancy Redundant data mean: Duplication of effort Wasted storage space Possible inconsistency during updates (one has to update all the duplicates) 9 Role of a DBMS (contd.) Sharing of data Multi-user context (sometimes ~1,000 users at the same time) There must be concurrency control What if two people try to update the same data? Ensure the result of the updates is correct 10 Role of a DBMS (contd.) Restricting unauthorized accesses Privacy of data (postal address, birthday, etc) Security of sensitive data (passwords, confidential data, etc) Some users are not authorized to access all information in the database Some users are allowed only to retrieve data whereas others are allowed to both retrieve and update Students: read their own marks after the exams Teachers: read and update all marks for their own students 11 Role of a DBMS (contd.) Enforcing integrity constraints To ensure consistency of data: Specify a data type for each data item The birthday must be a date before the current day The value of the name data item must be a string of no more than 30 characters Referential integrity A record in one file must be related to records in other files (e.g., a friend must be an existing member of the social network) Uniqueness constraint An identifier must be unique (e.g., the login) 12 Role of a DBMS (contd.) Providing multiple interfaces Menu-driven interfaces for newbies First computer-based practical works Query language for casual computer scientists (SQL) Second computer-based practical works Programming language interfaces for programmers Beyond the scope of this course 13 Role of a DBMS (contd.) Providing backup and recovery For many companies, data is vital: they must not lose the data! There are many ways to lose data Hardware crashes Programme bugs Viruses Hackers Earthquakes, floods, hurricane, tornado... Facilities for recovering from failures 14 Some relational DBMS Toy DBMSs Access (Microsoft) Base (OpenOffice, free and open source) Perfect for your stamp collection Medium DBMSs MySQL Good for a small and medium size enterprise Professional DBMSs Oracle Large and very large databases 15 Relational Databases “All is table” 1 table == 1 relation e.g., table User is a relation between a login, a password, an email, a name, etc... (n-ary relations) Created by Edgar CODD (late 1960s) Set of operations on tables (relational algebra) In order to combine information from different tables Language to query the database (SQL) To retrieve information from the tables 16 Tables / Relations Song(Title, Artist, Album, Release-date, Composer) Song Title Artist Album Aphex Twin Drukqs ... Cocorosie Noah's Ark ... Christmas Song Mogwai EP + 2 ... I Luv The Valley OH! Xiu Xiu Fabulous Muscles ... Vordhosbn Beautiful Boyz 17 ... Tables / Relations Song(Title, Artist, Album, Release-date, Composer) 1 column == 1 attribute Song Title Artist Album Aphex Twin Drukqs ... Cocorosie Noah's Ark ... Christmas Song Mogwai EP + 2 ... I Luv The Valley OH! Xiu Xiu Fabulous Muscles ... Vordhosbn Beautiful Boyz 18 ... Tables / Relations Song(Title, Artist, Album, Release-date, Composer) Song Title Artist Album Aphex Twin Drukqs ... Cocorosie Noah's Ark ... Christmas Song Mogwai EP + 2 ... I Luv The Valley OH! Xiu Xiu Fabulous Muscles ... Vordhosbn Beautiful Boyz 1 row == 1 tuple 19 ... Concepts of relational databases (1) A table or relation: a set of rows Think n-ary relations A row is called tuple1: set of values about a thing (object, person, events, etc) In table Song, each row represents fact about a particular song All rows have the same structure 1 The term “tuple” comes from the sequence quadruple, quintuple, sextuple, septuple, octuple, etc. 20 Concepts of relational databases (2) A column is the set of values concerning a property All values in a column are of the same data type (e.g., integer, date, character string, text) A column name is called an attribute (or a field). The attribute Release-date represents the song's release date A column can have an unknown value (Null) A column could be an identifier (e.g., Song-ID) to avoid ambiguity in naming 21 Concepts of relational databases (3) The data type describing the type of values that appears in each column is called a domain A domain is a set of atomic values e.g., release date: set of dates (not including day time) number of tracks: a value between 1 and 99 (the limit for an audio CD) Null values represent attributes whose values are unknown or do not exist for some tuples 22 Concepts of relational databases (4) A relation schema defines the attributes of a table A relation schema R is denoted: R(A1, A2,…, An) R is the name of the table, A1, A2,…, An are the attributes e.g., Song(Title, Artist, Album, Release-date, Composer) Each tuple t is an ordered list of n values t = (v1, v2, …, vn) ("Vordhosbn", "Aphex Twin", "Drukqs", 2001, "R. D. James") 23 Concepts of relational databases (5) One of the attributes, or the association of several attributes, has the role of identifying a tuple uniquely. It is called the primary key of the table. It must not be Null e.g., social security number, car plate, student number Song(SongID, Title, Artist,...) The same value for a primary key cannot be used in two different tuples The key allows the access to a unique row 24 Concepts of relational databases (6) A foreign key is a key which is referenced in another table Song(SongID, Title, ArtistID, AlbumID ...) Artist(ArtistID, ArtistName, RealName, Birthday, ...) Album(AlbumID, Title, ReleaseDate, Label, ...) Referential constraints: the value of a foreign key in a table should exist in the table in which this attribute is a key 25