Database Design and Programming

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
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.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
1 CS351 Introduction to Database systems
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.
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 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
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.
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
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.
Database Systems Lecture 1. In this Lecture Course Information Databases and Database Systems Some History The Relational Model.
Databases : SQL-Schema Definition and View 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey.
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.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Database Design and Programming Jan Baumbach Adopted from previous slides of Peter Schneider-Kamp.
1. 2 Design of databases. E/R model (entity-relationship model) Relational model (tables) UML (unified modeling language) Database programming. SQL, Relational.
CPSC 603 Database Systems Lecturer: Laurie Webster II, Ph.D., P.E.
CMPT 354 Database Systems I
CPSC-310 Database Systems
Database Design and Programming
Relational Data Model Lu Chaojun, SJTU.
Schedule Today: Jan. 28 (Mon) Jan. 30 (Wed) Next Week Assignments !!
CPSC-310 Database Systems
What is sql?.
CS320 Web and Internet Programming SQL and MySQL
COP4710 Database Systems Relational Model.
Chapter 1: Introduction
Chapter 1: Introduction
Foreign Keys Local and Global Constraints Triggers
Introduction to Database Systems, CS420
Chapter 1: Introduction
Introduction to Database Systems, CS420
CPSC-608 Database Systems
Introduction to Database Systems
CS 440 Database Management Systems
CPSC-608 Database Systems
Tools for Memory: Database Management Systems
Database Models Relational Model
CPSC-310 Database Systems
2018, Fall Pusan National University Ki-Joune Li
SQL OVERVIEW DEFINING A SCHEMA
IT 244 Database Management System
Defining a Database Schema
CMPT 354: Database System I
CMSC-461 Database Management Systems
SQL-1 Week 8-9.
CS3220 Web and Internet Programming SQL and MySQL
CS4433 Database Systems Relational Model.
Chapter 1: Introduction
SQL – Constraints & Triggers
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
Instructor: Zhe He Department of Computer Science
Select-From-Where Statements Multirelation Queries Subqueries
Presentation transcript:

Database Design and Programming Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net

Course Organisation Evaluation Project Schedule 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 http://www.baumbachlab.net/teaching

Deadlines NAT: TEK: Project: April 6, 2017 24h-take-home exam: April 26-27, 2017 Re-exam: oral (date TBD) TEK: Re-exam: August 1-2, 2017

Course Organisation Literature Available online Hector Garcia-Molina; Jeffrey D. Ullman; Jennifer Widom: Database Systems: The Complete Book. Prentice Hall, 2008. (second edition!) http://people.inf.elte.hu/sila/DB1Lect/Ullman_The_Complete_Book.pdf

Course Organisation ATTENTION! For this course, the 2008 edition (second edition) of “DATABASE SYSTEMS - The Complete Book” is used http://people.inf.elte.hu/sila/DB1Lect/Ullman_The_Complete_Book.pdf Link is also at the teaching website

Course Organisation Regularly check the teaching page: http://www.baumbachlab.net/teaching Slides, exercises, schedule changes

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

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

Databases

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 ...

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

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

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

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

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 ...

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 1st account Need to add amount to 2nd account Money must not be lost! Money should not be created!

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

Database Development Requirement specification (not here) Data modeling Database modeling Application programming Database tuning

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

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

A Relation is a Table name manf Odense Classic Albani Attributes (column headers) name manf Odense Classic Albani Erdinger Weißbier Erdinger Beers Note: Order of attributes and rows is irrelevant (sets / bags) Tuples (rows) Relation name

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

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

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

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

Creating (Declaring) a Relation Simplest form is: CREATE TABLE <name> ( <list of elements> ); To delete a relation: DROP TABLE <name>;

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

Example: Create Table CREATE TABLE Sells ( bar CHAR(20), beer VARCHAR(20), price REAL );

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)

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

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

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

Declaring Single-Attribute Keys Place PRIMARY KEY or UNIQUE after the type in the declaration of the attribute Example: CREATE TABLE Beers ( name CHAR(20) UNIQUE, manf CHAR(20) );

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

Example: Multiattribute Key The bar and beer together are the key for Sells: CREATE TABLE Sells ( bar CHAR(20), beer VARCHAR(20), price REAL, PRIMARY KEY (bar, beer) );

PRIMARY KEY vs. UNIQUE There can be only one PRIMARY KEY for a relation, but several UNIQUE attributes. 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.