Database Design and Programming



Similar documents
Chapter 1: Introduction. Database Management System (DBMS) University Database Example

types, but key declarations and constraints Similar CREATE X commands for other schema ëdrop X name" deletes the created element of beer VARCHARè20è,

CSE 132A. Database Systems Principles

Database Systems. Lecture 1: Introduction

Relational Database Basics Review

Overview of Data Management

Chapter 1: Introduction

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. Introduction to Databases. Why databases? Why not use XML?

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

Introduction. Introduction: Database management system. Introduction: DBS concepts & architecture. Introduction: DBS versus File system

Overview of Database Management

INTRODUCTION DATABASE MANAGEMENT SYSTEMS

History of Database Systems

How To Create A Table In Sql (Ahem)

Introduction: Database management system

Transactions, Views, Indexes. Controlling Concurrent Behavior Virtual and Materialized Views Speeding Accesses to Data

4 Logical Design : RDM Schema Definition with SQL / DDL

1 File Processing Systems

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

A Brief Introduction to MySQL

Java and Databases. COMP514 Distributed Information Systems. Java Database Connectivity. Standards and utilities. Java and Databases

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

2/3/04 Doc 7 SQL Part 1 slide # 1

EECS 647: Introduction to Database Systems

Database Management System Choices. Introduction To Database Systems CSE 373 Spring 2013

Technology Foundations. Conan C. Albrecht, Ph.D.

CSE 544 Principles of Database Management Systems. Magdalena Balazinska (magda) Spring 2006 Lecture 1 - Class Introduction

ICOM 6005 Database Management Systems Design. Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 August 23, 2001

Overview. Introduction to Database Systems. Motivation... Motivation: how do we store lots of data?

Introduction to Database Systems. Chapter 1 Introduction. Chapter 1 Introduction

Introductory Concepts

Modern Databases. Database Systems Lecture 18 Natasha Alechina

Databases 2011 The Relational Model and SQL

CSE 233. Database System Overview

Fundamentals of Database Design

The Relational Model. Why Study the Relational Model?

MS ACCESS DATABASE DATA TYPES

Discovering SQL. Wiley Publishing, Inc. A HANDS-ON GUIDE FOR BEGINNERS. Alex Kriegel WILEY

Conventional Files versus the Database. Files versus Database. Pros and Cons of Conventional Files. Pros and Cons of Databases. Fields (continued)

CSC 443 Data Base Management Systems. Basic SQL

CSE 544 Principles of Database Management Systems. Magdalena Balazinska (magda) Winter 2009 Lecture 1 - Class Introduction

Summary on Chapter 4 Basic SQL

David M. Kroenke and David J. Auer Database Processing 11 th Edition Fundamentals, Design, and Implementation. Chapter Objectives

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

Relational Database Concepts

B.1 Database Design and Definition

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

3. Relational Model and Relational Algebra

2. Background on Data Management. Aspects of Data Management and an Overview of Solutions used in Engineering Applications

CS 4604: Introduc0on to Database Management Systems

full file at

Database 2 Lecture I. Alessandro Artale

OBJECTS AND DATABASES. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 21

SQL Tables, Keys, Views, Indexes

Demystified CONTENTS Acknowledgments xvii Introduction xix CHAPTER 1 Database Fundamentals CHAPTER 2 Exploring Relational Database Components

Introduction to Databases

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Information Technology NVEQ Level 2 Class X IT207-NQ2012-Database Development (Basic) Student s Handbook

Database System Architecture & System Catalog Instructor: Mourad Benchikh Text Books: Elmasri & Navathe Chap. 17 Silberschatz & Korth Chap.

Databases. DSIC. Academic Year

Relational Algebra. Basic Operations Algebra of Bags

Information Systems SQL. Nikolaj Popov

Relational Databases for the Business Analyst

VBA and Databases (see Chapter 14 )

Contents RELATIONAL DATABASES


Logistics. Database Management Systems. Chapter 1. Project. Goals for This Course. Any Questions So Far? What This Course Cannot Do.

SQL Programming. CS145 Lecture Notes #10. Motivation. Oracle PL/SQL. Basics. Example schema:

n Assignment 4 n Due Thursday 2/19 n Business paper draft n Due Tuesday 2/24 n Database Assignment 2 posted n Due Thursday 2/26

5.1 Database Schema Schema Generation in SQL

SQL Server An Overview

Overview of Databases On MacOS. Karl Kuehn Automation Engineer RethinkDB

COSC 6397 Big Data Analytics. 2 nd homework assignment Pig and Hive. Edgar Gabriel Spring 2015

CSE 544 Principles of Database Management Systems. Magdalena Balazinska (magda) Fall 2007 Lecture 1 - Class Introduction

Complex Data and Object-Oriented. Databases

What is a database? COSC 304 Introduction to Database Systems. Database Introduction. Example Problem. Databases in the Real-World

Database Management Systems

How graph databases started the multi-model revolution

Advance DBMS. Structured Query Language (SQL)

ECS 165A: Introduction to Database Systems

Principles of Database Management Systems. Overview. Principles of Data Layout. Topic for today. "Executive Summary": here.

Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design

DATABASE MANAGEMENT SYSTEM

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

Data. Data and database. Aniel Nieves-González. Fall 2015

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia

Real SQL Programming 1

How To Improve Performance In A Database

Databases and BigData

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

Programming Database lectures for mathema

Using SQL Server Management Studio

CS 564: DATABASE MANAGEMENT SYSTEMS

Overview of Database Management Systems

Transcription:

Database Design and Programming Peter Schneider-Kamp DM 505, Spring 2012, 3 rd Quarter 1

Course Organisation Literature Database Systems: The Complete Book Evaluation Project and 1-day take-home exam, 7 scale Project Design and implementation of a database using PostgreSQL and JDBC Schedule 4/2 lectures a week, 2/4 exercises a week 2

Course Organisation Literature Database Systems: The Complete Book Chapters 1 & 2 available online Chapter 5.1 on Blackboard book available from SDU book store 3

(Preliminary) Course Schedule Week Room 05 06 07 08 09 10 11 Tue 14-16 Wed 10-12 Thu 14-16 U151 L Fri 12-14 U151 L L L L E E E E E E L Fri 08-10 U151 L E L E L E L some exercises in terminal room 1 st in Week 07 L L 4

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

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

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 7

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 8

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 9

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

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 11

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! 12

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 13

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

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 15

Data Model 16

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

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

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 19

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

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 21

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 22

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

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 24

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

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) 26

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 27

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 28

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 29

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) 30

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 31

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) ); 32

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 33