Database Design and Programming Jan Baumbach Adopted from previous slides of Peter Schneider-Kamp.

Slides:



Advertisements
Similar presentations
Tallahassee, Florida, 2014 COP4710 Database Systems Relational Model Fall 2014.
Advertisements

Chapter 7 Notes on Foreign Keys Local and Global Constraints Triggers.
Constraints and Triggers Foreign Keys Local and Global Constraints Triggers.
Fall 2001Arthur Keller – CS 1808–1 Schedule Today Oct. 18 (TH) Schemas, Views. u Read Sections u Project Part 3 extended to Oct. 23 (T). Oct.
1 More SQL Defining a Database Schema Views. 2 Defining a Database Schema uA database schema comprises declarations for the relations (“tables”) of the.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
Winter 2002Arthur Keller – CS 1809–1 Schedule Today: Jan. 31 (TH) u Constraints. u Read Sections , Project Part 3 due. Feb. 5 (T) u Triggers,
Winter 2002Judy Cushing8–1 Schedule Jan. 30 (Wed) u Modifications, Schemas, Views. Read Sections This Week (Feb 4ff) u Constraints Read Sections.
Ch1: File Systems and Databases Hachim Haddouti
Fall 2001Arthur Keller – CS 1809–1 Schedule Today Oct. 23 (T) Constraints. u Read Sections Assignment 4 due. Project Part 3 due Oct. 24 (W). Oct.
CPSC-608 Database Systems Fall 2008 Instructor: Jianer Chen Office: HRBB 309B Phone: Notes #3.
Chapter 12 Representing Data Elements By Yue Lu CS257 Spring 2008 Instructor: Dr.Lin.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #2.
Data Base Management System
DB Modifications Modification = insert + delete + update. Insertion of a Tuple INSERT INTO relation VALUES (list of values). Inserts the tuple = list of.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
The Relational Model These slides are based on the slides of your text book.
Introduction. 
1 CS351 Introduction to Database systems
1 CS 430 Database Theory Winter 2005 Lecture 1: Introduction.
SCUHolliday - coen 1789–1 Schedule Today: u Constraints, assertions, triggers u Read Sections , 7.4. Next u Triggers, PL/SQL, embedded SQL, JDBC.
CSCE 520- Relational Data Model Lecture 2. Relational Data Model The following slides are reused by the permission of the author, J. Ullman, from the.
SCUHolliday6–1 Schedule Today: u SQL Queries. u Read Sections Next time u Subqueries, Grouping and Aggregation. u Read Sections And then.
Databases : SQL-Introduction 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman distributes.
Winter 2006Keller Ullman Cushing8–1 Turning in Assignments Please turn in hard copy (use only in the direst of circumstances). I am not your secretary.
1 CE223 Database Systems Introduction DBMS Overview, Relational Model, Schemas, SQL Semistructured Model, XML.
1 Lecture 1 Introduction Based on
Constraints on Relations Foreign Keys Local and Global Constraints Triggers Following lecture slides are modified from Jeff Ullman’s slides
Databases 1 Fourth lecture. Rest of SQL Defining a Database Schema Views Foreign Keys Local and Global Constraints Triggers 2.
Winter 2006Keller, Ullman, Cushing9–1 Constraints Commercial relational systems allow much more “fine-tuning” of constraints than do the modeling languages.
1 CS1368 Introduction* Relational Model, Schemas, SQL Semistructured Model, XML * The slides in this lecture are adapted from slides used in Standford's.
RELATIONAL DATA MODEL 1. 2 What is a Data Model? 1.Mathematical representation of data. wExamples: relational model = tables; semistructured model = trees/graphs.
1 Introduction Relational Model, Schemas, SQL Semistructured Model, XML The slides were made by Jeffrey D. Ullman for the Introduction to Databases course.
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
1 Database Systems Defining Database Schema Views.
Lu Chaojun, SJTU Relational Data Model 1. Lu Chaojun, SJTU What’s a Data Model? A notation (collection of conceptual tools) for describing data as seen.
CSCE 520- Relational Data Model Lecture 2. Oracle login Login from the linux lab or ssh to one of the linux servers using your cse username and password.
1 CSCE Database Systems Anxiao (Andrew) Jiang The Database Language SQL.
Databases : SQL-Schema Definition and View 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey.
ASET 1 Amity School of Engineering & Technology B. Tech. (CSE/IT), III Semester Database Management Systems Jitendra Rajpurohit.
Chapter 1: Introduction. 1.2 Database Management System (DBMS) DBMS contains information about a particular enterprise Collection of interrelated data.
SCUHolliday - coen 1789–1 Schedule Today: u Constraints, assertions, triggers u Read Sections , 7.4. Next u Embedded SQL, JDBC. u Read Sections.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
uses of DB systems DB environment DB structure Codd’s rules current common RDBMs implementations.
1 Introduction to Database Systems, CS420 SQL Constraints.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
1. 2 Design of databases. E/R model (entity-relationship model) Relational model (tables) UML (unified modeling language) Database programming. SQL, Relational.
CMPT 354 Database Systems I
CPSC-310 Database Systems
Relational Data Model Lu Chaojun, SJTU.
CS320 Web and Internet Programming SQL and MySQL
Introduction to Database Systems, CS420
Introduction to Database Systems, CS420
Database Design and Programming
CPSC-608 Database Systems
CS 440 Database Management Systems
Database Models Relational Model
CPSC-310 Database Systems
SQL OVERVIEW DEFINING A SCHEMA
Defining a Database Schema
CS3220 Web and Internet Programming SQL and MySQL
CPSC-608 Database Systems
CS3220 Web and Internet Programming SQL and MySQL
CPSC-608 Database Systems
CMSC-461 Database Management Systems
CE223 Database Systems Introduction
Presentation transcript:

Database Design and Programming Jan Baumbach Adopted from previous slides of Peter Schneider-Kamp.

2 Course Organisation  Evaluation  Project and 24h-day take-home exam, 7 scale  Project  Design and implementation of a database using PostgreSQL and JDBC  Schedule  Find schedule and class rooms in online course description  505&periode=f2016&lang=en

3 Deadlines  NAT:  Project: April 6, 2016  24h-take-home exam: April 13-14, 2016  TEK:  Project: April 6, 2016  24h-take-home exam: June 1-2, 2016  Re-exam: August 1-2, 2016

4 Course Organisation  Literature  Chapters 1 & 2 available online  book available from SDU book store Hector Garcia-Molina; Jeffrey D. Ullman; Jennifer Widom: Database Systems: The Complete Book. Prentice Hall, ademic/product/0,3110, ,00.html

ATTENTION!  For this course, the 2008 edition of “DATABASE SYSTEMS - The Complete Book” is used  man_The_Complete_Book.pdf  Link is also on the website 5 Course Organisation

6  Regularly check the teaching page:  + click at “Teaching”  Slides, exercises, schedule changes

7 And here we go…  I offer you the following: 1.I explain all needed concepts (as often as needed) 2.I try to be available and always willing to help you 3.I guide your learning by assigning exercises

8 And here we go…  From you I expect the following: 1.You ask questions, when something is unclear 2.You contact me (or a TA), when you need help 3.You practice early and often!

Databases 9

10 Where are Databases used? It used to be about boring stuff:  Corporate data  payrolls, inventory, sales, customers, accounting, documents,...  Banking systems  Stock exchanges  Airline systems ...

11 Where are Databases used? Today, databases are used in all fields:  Web backends:  Web search (Google, Live, Yahoo,...)  Social networks (Facebook,...)  Blogs, discussion forums ...  Integrating data (data warehouses)  Scientific and medical databases ...

12 Why are Databases used?  Easy to use  Flexible searching  Efficiency  Centralized storage, multi-user access  Scalability (large amounts of data)  Security and consistency  Abstraction (implementation hiding)  Good data modeling

13 Why learn about Databases?  Very widely used  Part of most current software solutions  DB expertise is a career asset  Interesting:  Mix of different requirements  Mix of different methodologies  Integral part of data driven development  Interesting real world applications

14 Short History of Databases  Early 60s: Integrated Data Store, General Electric, first DBMS, network data model  Late 60s: Information Management System, IBM, hierarchical data model  1970: E. Codd: Relational data model, relational query languages, Turing prize  Mid 70s: First relational DBMSs (IBM System R, UC Berkeley Ingres,...)  80s: Relational model de facto standard

15 Short History of Databases  1986: SQL standardized  90s: Object-relational databases, object-oriented databases  Late 90s: XML databases  1999: SQL incorporates some OO features  2003, 2006: SQL incorporates support for XML data ...

16 Current Database Systems  DBMS = Database Management System  Many vendors (Oracle, IBM DB2, MS SQL Server, MySQL, PostgreSQL,... )  All rather similar  Very big systems, but easy to use  Common features:  Relational model  SQL as the query language  Server-client architecture

Transactions  Groups of statements that need to be executed together  Example:  Transferring money between accounts  Need to subtract amount from 1 st account  Need to add amount to 2 nd account  Money must not be lost!  Money should not be created! 17

ACID Required properties for transactions  “A“ for “atomicity“ – all or nothing of transactions  “C“ for “consistency“ – constraints hold before and after each transaction  “I“ for “isolation“ – illusion of sequential execution of each transaction  “D“ for “durability“ – effect of a completed transaction may not get lost 18

19 Database Develolpment  Requirement specification (not here)  Data modeling  Database modeling  Application programming  Database tuning

20 Database Course Contents  E/R-model for data modeling  Relational data model  SQL language  Application programming (JDBC)  Basic implementation principles  DB tuning Note: DM 505 ≠ SQL course Note: DM 505 ≠ PostgreSQL course

Data Model 21

22 What is a Data Model? 1.Mathematical representation of data  relational model = tables  semistructured model = trees/graphs ... 2.Operations on data 3.Constraints

23 A Relation is a Table namemanf Odense ClassicAlbani Erdinger WeißbierErdinger Beers Note: Order of attributes and rows is irrelevant (sets / bags) Attributes (column headers) Tuples (rows) Relation name

24 Schemas  Relation schema = relation name and attribute list  Optionally: types of attributes  Example: Beers(name, manf) or Beers(name: string, manf: string)  Database = collection of relations  Database schema = set of all relation schemas in the database

25 Why Relations?  Very simple model  Often matches how we think about data  Abstract model that underlies SQL, the most important database language today

26 Our Running Example Beers(name, manf) Bars(name, addr, license) Drinkers(name, addr, phone) Likes(drinker, beer) Sells(bar, beer, price) Frequents(drinker, bar)  Underline = key (tuples cannot have the same value in all key attributes)  Excellent example of a constraint

27 Database Schemas in SQL  SQL is primarily a query language, for getting information from a database  But SQL also includes a data-definition component for describing database schemas

28 Creating (Declaring) a Relation  Simplest form is: CREATE TABLE ( );  To delete a relation: DROP TABLE ;

29 Elements of Table Declarations  Most basic element: an attribute and its type  The most common types are:  INT or INTEGER (synonyms)  REAL or FLOAT (synonyms)  CHAR(n ) = fixed-length string of n characters  VARCHAR(n ) = variable-length string of up to n characters

30 Example: Create Table CREATE TABLE Sells ( barCHAR(20), beerVARCHAR(20), priceREAL );

31 SQL Values  Integers and reals are represented as you would expect  Strings are too, except they require single quotes  Two single quotes = real quote, e.g., ’Trader Joe’’s Hofbrau Bock’  Any value can be NULL  (like Objects in Java)

32 Dates and Times  DATE and TIME are types in SQL  The form of a date value is: DATE ’yyyy-mm-dd’  Example: DATE ’ ’ for February 4, 2009

33 Times as Values  The form of a time value is: TIME ’hh:mm:ss’ with an optional decimal point and fractions of a second following  Example: TIME ’15:30:02.5’ = two and a half seconds after 15:30

34 Declaring Keys  An attribute or list of attributes may be declared PRIMARY KEY or UNIQUE  Either says that no two tuples of the relation may agree in all the attribute(s) on the list  There are a few distinctions to be mentioned later

35 Declaring Single-Attribute Keys  Place PRIMARY KEY or UNIQUE after the type in the declaration of the attribute  Example: CREATE TABLE Beers ( nameCHAR(20) UNIQUE, manfCHAR(20) );

36 Declaring Multiattribute Keys  A key declaration can also be another element in the list of elements of a CREATE TABLE statement  This form is essential if the key consists of more than one attribute  May be used even for one-attribute keys

37 Example: Multiattribute Key  The bar and beer together are the key for Sells: CREATE TABLE Sells ( barCHAR(20), beerVARCHAR(20), priceREAL, PRIMARY KEY (bar, beer) );

38 PRIMARY KEY vs. UNIQUE 1.There can be only one PRIMARY KEY for a relation, but several UNIQUE attributes 2.No attribute of a PRIMARY KEY can ever be NULL in any tuple. But attributes declared UNIQUE may have NULL’s, and there may be several tuples with NULL