ds 1300 introduction to database systems
play

DS 1300 - Introduction to Database Systems Based on slides by Dan - PowerPoint PPT Presentation

DS 1300 - Introduction to Database Systems Based on slides by Dan Suciu Adapted by Michael Hahsler 1 / 16 Database What is a database? Physical storage: A collection of fjles storing related data. Logical: A collection of tables (or


  1. DS 1300 - Introduction to Database Systems Based on slides by Dan Suciu Adapted by Michael Hahsler 1 / 16

  2. Database What is a database? Physical storage: A collection of fjles storing related ● data. Logical: A collection of tables (or objects). ● Examples of databases Accounts database; payroll database; SMU’s students ● database; Amazon’s products database; airline reservation database. 2 / 16

  3. Database Management System What is a DBMS? ● A complicated (and often expensive) piece of software typically running on a large (remote) server written by someone else that allows us to manage effjciently a large database and allows it to persist over long periods of time. Examples of DBMS ● Commercial: DB2 (IBM), SQL Server (MS), Oracle, Sybase ● Open Source: MySQL, Postgres, SQLite, … ● Big Data: often NoSQL like MongoDB, Apache Cassandra, etc. 3 / 16

  4. Architecture: Using a DMBS “Client-server Architecture” connection (ODBC, JDBC) Database server Applications Data files running the DBMS running a client 4 / 16

  5. Operations: Query/Update Assume we have a database for movies and actors. Simple query: ● – In what year was ‘Star Wars’ produced? Multi-table query: Movies Actors ● – Find all movies with ‘Harrison Ford’ (combine actor and movie tables) Complex query: ● – For each actor, count her/his movies Updating ● – Insert a new movie; add an actor to a movie; etc 5 / 16

  6. Operations: Query/Update ● Files ( e.g., CSV) Simple queries Multi-table queries ● Spreadsheets (maybe) All ● DBMS Updates: generally OK 6 / 16

  7. Change the Structure of a DB Add Address to each Actor Very hard Files ( e.g., CSV) ● Yes Spreadsheets ● Yes DBMS ● 7 / 16

  8. Issue: Concurrent Access Multiple users access/update the data concurrently ● What can go wrong? – Lost update; resulting in inconsistent data ● How do we protect against that in OS? – Locks ● Databases need a similar concept to deal with concurrent updates. 8 / 16

  9. Issue: Recover from crashes Transfer $100 from account #4662 to #7199: ● X = Read(Accounts, 4662); X = Read(Accounts, 4662); X.amount = X.amount - 100; X.amount = X.amount - 100; Write(Accounts, 4662, X); Write(Accounts, 4662, X); CRASH ! Y = Read(Accounts, 7199); Y = Read(Accounts, 7199); Y.amount = Y.amount + 100; Y.amount = Y.amount + 100; Write(Accounts, 7199, Y); Write(Accounts, 7199, Y); 9 / 16 What is the problem ?

  10. Concurrency & Recovery: Transactions A transaction = sequence of statements that either all ● succeed, or all fail together. E.g., Transfer $100 ● BEGIN TRANSACTION ; BEGIN TRANSACTION ; UPDATE Accounts UPDATE Accounts SET amount = amount - 100 SET amount = amount - 100 WHERE number = 4662 WHERE number = 4662 UPDATE Accounts UPDATE Accounts SET amount = amount + 100 SET amount = amount + 100 WHERE number = 7199 WHERE number = 7199 COMMIT COMMIT 10 / 16

  11. Transactions Transactions have the ACID properties: All or nothing A = atomicity Valid state to valid state C = consistency Transactions are independent I = isolation D = durability No data loss after commit Transactions also allow rollbacks (undo). 11 / 16

  12. Relational Data Base = Collection of Tables Actors: Movie_Actors: id fName lName id mid 15901 Harrison Ford 15901 130128 . . . . . . Movies: mid Title Year 130128 Star Wars 1977 . . . 12 / 16

  13. Create/Store Large Datasets Use SQL to create and populate tables: CREATE TABLE Actors ( CREATE TABLE Actors ( INSERT INTO Actors fName CHAR(30), INSERT INTO Actors fName CHAR(30), VALUES('Harrison', 'Ford', . . .) lName CHAR(30), VALUES('Harrison', 'Ford', . . .) lName CHAR(30), . . . ) . . . ) Physical organization of the data is handled by DBMS We focus on modeling the database! 13 / 16

  14. Querying ● Find all movies with ‘Harrison Ford’ SELECT title SELECT title FROM Movies, Actors, Movie_Actors FROM Movies, Actors, Movie_Actors WHERE Actors.lname = ‘Ford’ and WHERE Actors.lname = ‘Ford’ and Actors.fname = ‘Harrison’ and Actors.fname = ‘Harrison’ and Movies.mid = Movie_Actors.mid and Movies.mid = Movie_Actors.mid and Movie_Actors.id = Actors.id Movie_Actors.id = Actors.id ● What happens behind the scene ? – The DBMS uses indices and optimizes automatically the query... 14 / 16

  15. Change the Structure of a Table Add Address to each Actor ALTER TABLE Actor ALTER TABLE Actor ADD address CHAR(50) ADD address CHAR(50) DEFAULT ‘unknown’ DEFAULT ‘unknown’ 15 / 16

  16. What comes next? 1) Using a DBMS 2) Using SQL to Query Databases 3) Designing a Database 16 / 16

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend