* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Databases course of 2017-03-02
Survey
Document related concepts
Oracle Database wikipedia , lookup
Relational algebra wikipedia , lookup
Serializability wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Ingres (database) wikipedia , lookup
Functional Database Model wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Concurrency control wikipedia , lookup
ContactPoint wikipedia , lookup
Clusterpoint wikipedia , lookup
Transcript
Databases Dr. Ben Schroyen Prof. dr. Marc Nyssen Prof. dr. Frederik Questier Vrije Universiteit Brussel What's a database? Who uses it? For what? How? Filing cabinet with files and records database versus database system A database consists of an organized collection of data for one or more uses, typically in digital form. A database system is a system intended to organize store and retrieve large amounts of data easily. Example database Patients Patient Telephone number Charles Babbage +52 487 987 673 109 Ada Lovelace +52 477 879 999 678 John von Neumann +1 3456 792 805 805 Konrad Suze +49 278 999 777 010 Mitch Kapor +1 0101 010 101 010 Vinton Cerf +1 2379 994 783 111 Tim Berners-Lee +49 234 824 601 346 John Quartermann +1 4567 222 444 666 Robert Cailliau +32 488 234 456 678 Better example Patient First name Telephone number Babbage Charles +52 487 987 673 109 Lovelace Ada +52 477 879 999 678 von Neumann John +1 3456 792 805 805 Suze Konrad +49 278 999 777 010 Kapor Mitch +1 0101 010 101 010 Cerf Vinton +1 2379 994 783 111 Berners-Lee Tim +49 234 824 601 346 Quarterman John +1 4567 222 444 666 Cailliau Robert +32 488 234 456 678 How to store the data base? How to store? In Flat Text files? Example: ict-contact-list.txt (1 ”record” per line) Babbage#Charles#M#Prof. Dr.#Lovelace Castle##ICT dept.#Sussex#England Suze#Konrad#M#Dr.#Neustrasse#2##Giessen#Deutschland Disadvantages – File corruption risk if computer fails while updating a file. – Custom scripts necessary – What if many people at the same time want to update the data? – No security features How to store? In a spreadsheet? How to store? DBMS! DataBase Management System ➢ ➢ ➢ ➢ a software package that helps the use of integrated collection of data records and files known as databases. a set of computer programs that controls the creation, maintenance, and the use of a database. allows organizations to place control of database development in the hands of database administrators (DBAs) and other specialists. allows different user application programs to easily access the same database ACID Rules ➢ Atomicity: Either all the data changes in a transaction must happen, or none of them. The transaction must be completed, or else it must be undone (rolled back). ➢ Consistency: Every transaction must preserve the declared consistency rules for the database. ➢ Isolation: Two concurrent transactions cannot interfere with one another. Intermediate results within one transaction must remain invisible to other transactions. ➢ Durability: Completed transactions cannot be aborted later or their results discarded. They must persist through (for instance) DBMS restarts. ACID Rules Atomicity In a transaction involving two or more updates, – either all of the updates are committed – or none are (roll back). The DBMS helps with the Construction of the structure – but does not provide a good database model or scheme The data storage Access mechanisms – Network access Security Own responsability? Logging Backup Replication DBMS examples? DBMS examples ➢ Free Open Source Software ➢ Non-free, closed source Software Relational DBMS Data Organization Hierarchy Records and fields in a single file or table Relational model Concept: scheme First name name Tel.nr patient Relational model Concept: scheme COLUMN IN TABLE Name First name Tel.nr patient TABLE Relational model Unique key needed! Name FirstName TelNr StateNumber Babbage Charles +52 487 987 673 109 A2367995511 Lovelace Ada +52 477 879 999 678 B2537956789 von Neumann John +1 3456 792 805 805 A1234567890 Suze Konrad +49 278 999 777 010 A9876543210 Kapor Mitch +1 0101 010 101 010 A5647382910 Cerf Vinton +1 2379 994 783 111 Berners-Lee Tim +49 234 824 601 346 A2356842351 Quarterman John +1 4567 222 444 666 A5208525577 Cailliau Robert +32 488 234 456 678 A4810103578 A4538813932 Relational model table doctors FirstName Name DoctorNumber Louis Pasteur 123-456-789 Albert Schweitzer 456-789-012 Gregory House 789-123-456 Anne No 234-234-234 Andreas Vesalius 888-999-000 Relational model doctor is doctor of patient Relational model is doctor of Doctor number State number 888-999-000 B2537956789 789-123-456 A2356842351 234-234-234 A4538813932 456-789-012 A5647382910 456-789-012 A4810103578 Relational model Entity–relationship model StateNumber DoctorNumber doctors Name FirstName Is doctor of TelNr patients Name FirstName Name and StateNumber of Patients born in 1950? Name FirstName StateNumber BirthYear Babbage Charles A2367995511 1791 Lovelace Ada B2537956789 1815 von Neumann John A1234567890 1903 Suse Konrad A9876543210 1910 Kapor Mitch A5647382910 1950 Cerf Vinton A4538813932 1943 Berners-Lee Tim A2356842351 1955 Quarterman John A5208525577 1954 Cailliau Robert A4810103578 1947 Structured Query Language SQL Structured Query Language SQL Basic Query : SELECT list of table columns/fields in the result (or * for all) FROM WHERE (optional) the conditions about the tables list of tables to be queried and/or the relations between the tables Name and StateNumber of Patients born in 1950? Sql query: SELECT patients.Name, patients.StateNumber FROM patients WHERE patients.BirthYear = 1950 Name StateNumber Kapor A5647382910 Name and StateNumber of Patients born between 1940 and 1950? Sql query: SELECT patients.Name, patients.StateNumber FROM patients WHERE patients.BirthYear > 1940 AND patients.BirthYear < 1950 What are the Name and the StateNumber of the patients of Doctor Schweitzer? Patients Doctors Name FirstName TelNr StateNumber First Name Name DoctorNumber Babbage Charles +52 487 987 673 109 A2367995511 Louis Pasteur 123-456-789 Lovelace Ada +52 477 879 999 678 B2537956789 Albert Schweitzer 456-789-012 von Neumann John +1 3456 792 805 805 A1234567890 Gregory House 789-123-456 Suze Konrad +49 278 999 777 010 A9876543210 Anne No 234-234-234 Kapor Mitch +1 0101 010 101 010 A5647382910 Andreas Vesalius 888-999-000 Cerf Vinton +1 2379 994 783 111 A4538813932 Berners-Lee Tim +49 234 824 601 346 Quarterman John Cailliau Robert DoctorNumber StateNumber A2356842351 888-999-000 B2537956789 +1 4567 222 444 666 A5208525577 789-123-456 A2356842351 +32 488 234 456 678 A4810103578 234-234-234 A4538813932 456-789-012 A5647382910 456-789-012 A4810103578 Relations What are the Name and the StateNumber of the patients of Doctor Schweitzer? SELECT Patients.Name, Patients.StateNumber FROM Patients, Doctors, Relations WHERE Doctors.Name = 'Schweitzer' AND Doctors.DoctorNumber = Relations.DoctorNumber AND Patients.StateNumber = Relations.Statenumber Name StateNumber Kapor A5647382910 Calliau A4810103578 Excercise 1: SQL online See http://www.w3schools.com/sql/ Explore the examples of the following pages: ● Intro ● Syntax ● SELECT ● WHERE ● AND ● LIKE ● Wildcards and construct a query for: ● Show all customer names from Paris ● Show all customer names starting with m For each example: click on “Try it yourself” Click on 'Run SQL' Check the results for the query Change a similar query for our exercise phpMyAdmin: an easy general way to access data bases Mysql database Internet Apache webserver phpMyAdmin phpMyAdmin phpMyAdmin phpMyAdmin Excercise 2: phpMyAdmin demo Optional Or alternative if you cannot login for excercise 3 Explore this demo: http://demo.phpmyadmin.net/ – “Latest phpMyAdmin stable release; direct login” – Explore, databases, tables, sql queries, searches, ... Exercise 3: SQL in phpMyAdmin Step 0: Activate VUBnetID : https://www.vub.ac.be/tools/pam Step 1: Register database user: https://minf.vub.ac.be/john/mysql Step 2: Login at https://minf.vub.ac.be/MyAdmin/ Everyone has access to the 'student' database and 3 tables: – patients – doctors – <vubnetid>_medrec Construct a query for the name and address of the patients of doctor Medderie Excercise 4 Design a medical record table Modify the table vubnetid_medrec by changing the 3 initial fields and adding new relevant fields. Choose the field types (varchar, date, …) wisely. Design a relational database scheme. Maybe initially on paper, but finally digital, e.g. in LibreOffice Draw. Exercise 5: optional database driven websites Create webpages based on database queries Extend your website (course 2) with a standalone webpage that displays the query of the previous excercise. PHP templates in minf.vub.ac.be:/pcrw/WD-INF/VB_WEB/ References and sources Een introductie tot gegevensbanken, Kris Luyten, Tom Van Laerhoven, Expertisecentrum Digitale Media, Limburgs Universitair Centrum, Wetenschapsdagen 2002 http://bisi.vub.ac.be/minf/docs/db-Luyten-Van-Laerhoven.pdf Database systems, the complete book, HectorGarcia Molina, Jeffrey D. Ullman, Jennifer Widom, Prentice Hall 2002, ISBN 0-13-031995-3 Invitation to Computer Science, International Edition, 5th Edition (2009), by G. Michael Schneider, Judith L. Gersting, Course Technology, Cengage Learning