Relational Databases. Christopher Simpkins chris.simpkins@gatech.edu



Similar documents
CS 2316 Data Manipulation for Engineers

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

Fundamentals of Database Design

SQL. Short introduction

How To Create A Table In Sql (Ahem)

TIM 50 - Business Information Systems

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

Databases in Engineering / Lab-1 (MS-Access/SQL)

1. INTRODUCTION TO RDBMS

EECS 647: Introduction to Database Systems

Introduction to Computing. Lectured by: Dr. Pham Tran Vu

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

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

Databases What the Specification Says

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

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

IT2305 Database Systems I (Compulsory)

Financial Data Access with SQL, Excel & VBA

Intro to Databases. ACM Webmonkeys 2011

IT2304: Database Systems 1 (DBS 1)

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Tutorial on Relational Database Design

A Brief Introduction to MySQL

Databases and BigData

SQL, PL/SQL FALL Semester 2013

Database Query 1: SQL Basics

BCA. Database Management System

MySQL for Beginners Ed 3

Relational Database Concepts

Database Administration with MySQL

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

The Entity-Relationship Model


Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

Information Systems Modelling Information Systems I: Databases

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

Relational Database Basics Review

Relational Databases and SQLite

Foundations of Information Management

Database: SQL, MySQL

Basic Concepts of Database Systems

12 File and Database Concepts 13 File and Database Concepts A many-to-many relationship means that one record in a particular record type can be relat

A table is a collection of related data entries and it consists of columns and rows.

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

Information Systems SQL. Nikolaj Popov

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

Instant SQL Programming

- Eliminating redundant data - Ensuring data dependencies makes sense. ie:- data is stored logically

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

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

Data Modeling. Database Systems: The Complete Book Ch ,

Database 10g Edition: All possible 10g features, either bundled or available at additional cost.

Introducción a las bases de datos SQL Libro de referencia

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

Oracle Database 10g Express

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

Customer Bank Account Management System Technical Specification Document

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

7. Databases and Database Management Systems

DBMS / Business Intelligence, SQL Server

CHAPTER 2 DATABASE MANAGEMENT SYSTEM AND SECURITY

Database Setup. Coding, Understanding, & Executing the SQL Database Creation Script

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

Lecture 6. SQL, Logical DB Design

database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia

B.1 Database Design and Definition

Chapter 22 Database: SQL, MySQL,

Introduction to SQL and database objects

5.5 Copyright 2011 Pearson Education, Inc. publishing as Prentice Hall. Figure 5-2

not necessarily strictly sequential feedback loops exist, i.e. may need to revisit earlier stages during a later stage

Oracle Database: SQL and PL/SQL Fundamentals NEW

CSC 443 Data Base Management Systems. Basic SQL

Doing database design with MySQL

Oracle Database: SQL and PL/SQL Fundamentals

Once the schema has been designed, it can be implemented in the RDBMS.

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

Lesson 8: Introduction to Databases E-R Data Modeling

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

Ken Goldberg Database Lab Notes. There are three types of relationships: One-to-One (1:1) One-to-Many (1:N) Many-to-Many (M:N).

Introduction to Databases

Concepts Design Basics Command-line MySQL Security Loophole

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Learning MySQL! Angola Africa SELECT name, gdp/population FROM world WHERE area > !

Database Migration from MySQL to RDM Server

Part 2 - The Database Environment

Relational Database: Additional Operations on Relations; SQL

David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design and Implementation

Database Design and Programming

CSE 233. Database System Overview

Intro to Embedded SQL Programming for ILE RPG Developers

Database Design for the Uninitiated CDS Brownbag Series CDS

INTRODUCTION TO DATABASE SYSTEMS

Driver for JDBC Implementation Guide

Oracle Database 10g: Introduction to SQL

3. Relational Model and Relational Algebra

4 Logical Design : RDM Schema Definition with SQL / DDL

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

Physical Database Design Process. Physical Database Design Process. Major Inputs to Physical Database. Components of Physical Database Design

Transcription:

Relational Databases Christopher Simpkins chris.simpkins@gatech.edu

Relational Databases A relational database is a collection of data stored in one or more tables A relational database management system (RDBMS) is software that stores and updates a relational database and provides a query and manipulation interface to the data In this lecture we ll cover the two major RDBMS architectures basic relational database design basic SQL (structured query language) SQLite, one of the RDBMS systems we ll use in this course (SQLite and MySQL) Copyright Georgia Tech. All Rights Reserved.!2

Client-Server RDBMS Copyright Georgia Tech. All Rights Reserved. Server software provides a middleware layer between the database files and client applications Clients typically connect through network protocols Lots of configuration overhead, but powerful security, scalability, availability features Examples: MySQL, PostgreSQL, Oracle, IBM DB2, MS SQL Server!3

!4 Embedded RDBMS RDBMS engine is integrated with application program Data typically stored in a single file No configuration Much simpler, but less powerful SQLite is most popular example

!5 Relational Database Concepts Entities are real-world objects to be modeled in the database Entities can be related to other entities by one-to-one relationships one-to-many relationships many-to-many relationships A journal can have many articles, but an article can appear in only one journal An author can have many articles, and an article can have many authors Author N N Article N 1 Journal

!6 Tables Entities are stored in tables (a.k.a. relations) Each row of a table (a.k.a tuple) stores one record Each column of a table stores one attribute per record pubid title 1 Recursive Functions of Symbolic Expressions and Their Computation by Machine 2 The Unix Time-sharing System

!7 Keys The primary key of a relation is an attribute or (minimal) set of attributes (composite key) that uniquely identifies a record There may be many candidate keys A foreign key links one table to another via the other table s primary key pubid title venueid 1 Recursive Functions of Symbolic Expressions and Their Computation by Machine 2 The Unix Time-sharing System 2 1 venueid booktitle month year 1 Communications of the ACM April 1960 2 Communications of the ACM July 1974

Entity-Relationship Diagrams ER diagrams can show attributes, keys, and relationships Primary key is underlined Here s our publication-venue schema depicted in an ER diagram: publication pubid title venueid N 1 venue venueid booktitle month year Copyright Georgia Tech. All Rights Reserved.!8

!9 Many-to-many Relationships Many-to-many relationships modeled with a link table Link table has only foreign keys For example, here s a link between publications and authors (each pub can have many authors, each author can have many pubs) publication pubid title venueid N N pub_author pubid authorid N N author authorid name

Structured Query Language ANSI standard language (SQL92) for interacting with a database In practice every RDBMS has extensions Pronounced ess-que-ell, though many say sequel Declarative command language for creating, inserting data into, and getting data from a database Some RDBMSes define an additional imperative language for stored procedures Stored procedures should be avoided for two reasons:» Stored procedures are not even a little bit portable - they re all RDBMS-specific» Stored procedures encourage splitting application logic between database and main application code Copyright Georgia Tech. All Rights Reserved.!10

!11 SQL Data Languages SQL has four languages: Data definition language (DDL) for creating, modifying and deleting database tables. Typically run when a database is first created, often contained in a script Data manipulation language (DML) for inserting, updating, querying, and deleting data from tables Transaction control language (TCL) for creating transactions (atomic sequences of commands) Data control language (DCL) for controlling access to database resources and setting permissions SQLite does not support DCL. We ll deal with DDL and DML in this course

!12 CREATE TABLE General form CREATE TABLE table_name (! column_name column_type column_constraints...,! [...,]! table_constraints,! [...]! ); Example CREATE TABLE parts (! part_id INTEGER PRIMARY KEY,! stock INTEGER DEFAULT 0 NOT NULL,! desc TEXT CHECK( desc!= ) -- no empty strings! ); DROP TABLE table_name deletes a table.

!13 Data Types Attributes have data types, a.k.a. domains SQLite is manifest-typed, meaning it can store any type of value in any column, but most RDBMSes are statically typed SQLite has typed storage classes and type affinities for columns (a suggestion to convert data to specified type) SQLite supports the following type affinities: Text - NULL, text, or BLOB Numeric - integers, floats, NULLs, and BLOBs Integer - like numeric, but floats with no fractional part are converted to integers Float - like numeric, but integers are converted to floats None - no preference over storage class

!14 INSERT Creates new rows in a table INSERT INTO table_name (column_name [,...]) VALUES (new_value [,...]); Can leave off the column names to insert values positionally Example: INSERT INTO parts (stock, desc) values (42, ball bearings ) By the way, we can leave off the primary key like this because the PK is an integer and therefore automatically an autoincrement field

UPDATE Modify an existing row in a table UPDATE table_name SET column_name=new_value [,...] WHERE expression! Example: UPDATE parts SET price = 4.25, stock = 75 WHERE part_id = 454; Copyright Georgia Tech. All Rights Reserved.!15

!16 DELETE Delete one or more rows from a single table DELETE FROM table_name WHERE expression; Careful: if no WHERE clause, will delete all rows Example: DELETE FROM parts WHERE part_id >= 43 AND part_id <= 246;

!17 SELECT The big one. Used to extract data from a database The simple form: SELECT output_list FROM input_table WHERE row_filter;! The general form: SELECT [DISTINCT] select_heading! FROM source_tables! WHERE filter_expression! GROUP BY grouping_expressions! HAVING filter_expression! ORDER BY ordering_expressions! LIMIT count! OFFSET count We ll go over some examples and keep it simple

Creating and Seeding a Database Can run a script with the.read command We ll use two scripts: create-pubs.sql - will create the database schema seed-pubs.sql - will insert data into the tables Tips:.header on.mode column Copyright Georgia Tech. All Rights Reserved.!18

!19 create-pubs.sql and seed-pubs.sql create table if not exists author ( author_id integer primary key, first_name text, last_name text );! create table if not exists author_pub ( author_id integer not null references author(author_id), pub_id integer not null references publication(pub_id), author_position integer not null, -- first author, second, etc?! primary key (author_id, pub_id) );! create table if not exists publication ( pub_id integer primary key, title text, venue_id integer not null references venue(venue_id) );! create table if not exists venue ( venue_id integer primary key, booktitle text not null, month text, year integer not null ); insert into author values (1, "John", "McCarthy"); insert into author values (2, "Dennis", "Ritchie"); insert into author values (3, "Ken", "Thompson");! insert into publication values(1, "Recursive Functions of Symbolic...",1); insert into publication values(2, "The Unix Time-sharing System",2);! insert into author_pub values(1, 1, 1); insert into author_pub values(2, 2, 1); insert into author_pub values(3, 2, 2);! insert into venue values(1, "Communications of the ACM", "April", 1960); insert into venue values(2, "Communications of the ACM", "July", 1974); create-pubs.sql seed-pubs.sql