Relational Databases

Similar documents
Relational Databases Lecture 2

Insertions, Deletions, and Updates

Selections. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 22, 2014

Views. Lecture 15. Robb T. Koether. Fri, Feb 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) Views Fri, Feb 16, / 28

Views. Lecture 15 Section 5.3. Robb T. Koether. Hampden-Sydney College. Mon, Feb 18, 2013

Views. Lecture 15 Section 5.3. Robb T. Koether. Hampden-Sydney College. Mon, Feb 18, 2013

Aggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014

PHP Queries and HTML Forms Lecture 23

PHP Querying. Lecture 21. Robb T. Koether. Hampden-Sydney College. Fri, Mar 2, 2018

Relational Algebra Part I. CS 377: Database Systems

XQuery FLOWR Expressions Lecture 35

Introduction to Databases

Basic PHP. Lecture 19. Robb T. Koether. Hampden-Sydney College. Mon, Feb 26, 2108

Introduction to Databases

XPath Lecture 34. Robb T. Koether. Hampden-Sydney College. Wed, Apr 11, 2012

Functional Dependencies and Normal Forms

Functional Dependencies and Normal Forms

The Critical-Path Algorithm

LR Parsing - Conflicts

The Decreasing-Time Algorithm

Part 1 on Table Function

Minimal Spanning Trees

XPath. Lecture 36. Robb T. Koether. Wed, Apr 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, / 28

MySQL Creating a Database Lecture 3

The Traveling Salesman Problem Brute Force Method

Recursive Descent Parsers

KINGDOM OF SAUDI ARABIA-JAZAN UNIVERSITY COLLEGE OF COMPUTER SCIENCE & INFORMATION SYSTEMS 221 INFS 3 DATABASE SYSTEMS-1 REVIEW QUESTIONS

Solving Recursive Sequences by Iteration

The Traveling Salesman Problem Nearest-Neighbor Algorithm

The Class Construct Part 1

The CYK Parsing Algorithm

CIS611 Lab Assignment 1 SS Chung

Triggers. Lecture 14. Robb T. Koether. Hampden-Sydney College. Wed, Feb 14, 2018

Relational Algebra & Calculus. CS 377: Database Systems

Magnification and Minification

Scope and Parameter Passing

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

XML. Lecture 29. Robb T. Koether. Fri, Mar 28, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XML Fri, Mar 28, / 23

Scheduling and Digraphs

DTDs and XML Attributes

The Pairwise-Comparison Method

CMPT 354: Database System I. Lecture 2. Relational Model

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

Density Curves Sections

The Plurality-with-Elimination Method

Basic PHP Lecture 17

Programming Languages

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Data Modeling with the Entity Relationship Model. CS157A Chris Pollett Sept. 7, 2005.

Sampling Distribution Examples Sections 15.4, 15.5

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

Recursive Linked Lists

Rotations and Translations

LR Parsing - The Items

Relational Calculus: 1

The Graphics Pipeline

Total Orders. Lecture 41 Section 8.5. Robb T. Koether. Hampden-Sydney College. Mon, Apr 8, 2013

Scope and Parameter Passing

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

Programming Languages

Friends and Unary Operators

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)

COSC344 Database Theory and Applications. σ a= c (P) S. Lecture 4 Relational algebra. π A, P X Q. COSC344 Lecture 4 1

AJAX. Lecture 26. Robb T. Koether. Fri, Mar 21, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) AJAX Fri, Mar 21, / 16

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)

Integer Overflow. Lecture 8 Section 2.5. Robb T. Koether. Hampden-Sydney College. Mon, Jan 27, 2014

Introduction to Databases CSE 414. Lecture 2: Data Models

E-R Diagram. Bagian I Entity Concept

Webpage Navigation. Lecture 27. Robb T. Koether. Hampden-Sydney College. Mon, Apr 2, 2018

SQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements,

Announcements. Using Electronics in Class. Review. Staff Instructor: Alvin Cheung Office hour on Wednesdays, 1-2pm. Class Overview

Some different database system architectures. (a) Shared nothing architecture.

CS 377 Database Systems

Boxplots. Lecture 17 Section Robb T. Koether. Hampden-Sydney College. Wed, Feb 10, 2010

Relational Model. CS 377: Database Systems

XML Attributes. Lecture 33. Robb T. Koether. Hampden-Sydney College. Wed, Apr 25, 2018

Function Definition Syntax Tree

Implementing Linked Lists

List Iterator Implementation

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe Slide 25-1

Building the Abstract Syntax Trees

Slides by: Ms. Shree Jaswal

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

L130 - DATABASE MANAGEMENT SYSTEMS LAB CYCLE-1 1) Create a table STUDENT with appropriate data types and perform the following queries.

Query 2: Pnumber Dnum Lname Address Bdate 10 4 Wallace 291 Berry, Bellaire, TX Wallace 291 Berry, Bellaire, TX

Dynamic Allocation of Memory

Recognition of Tokens

Introduction to Compiler Design

Chapter 6 - Part II The Relational Algebra and Calculus

Relational Algebra 1

Department of Computer Science University of Cyprus. EPL342 Databases. Lab 2

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Mon, Jan 20, 2014

SQL Simple Queries. Chapter 3.1 V3.01. Napier University

ECE 650 Systems Programming & Engineering. Spring 2018

Transcription:

Relational Databases Lecture 2 Chapter 3 Robb T. Koether Hampden-Sydney College Fri, Jan 18, 2013 Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 1 / 26

1 Types of Databases 2 Relational Databases 3 Queries 4 Schemas 5 Primary Keys 6 Assignment Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 2 / 26

Outline 1 Types of Databases 2 Relational Databases 3 Queries 4 Schemas 5 Primary Keys 6 Assignment Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 3 / 26

Types of Databases Originally, databases were simply collections of data, arranged in whatever way the programmer saw fit. The DBMS was simply a program that could process the data. Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 4 / 26

Types of Databases In the early 1970s, the concept of a relational database (RDB) was introduced. Its data were organized into tables of rows and columns. Queries were organized into select, insert, delete, and update. Given the standardized forms, queries could be highly optimized by the DBMS. Today, SQL (Structured Query Language) is the standard for relational databases. Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 5 / 26

Types of Databases Item Price Stock 123 456 3.99 6.99 1000 1500 Cust Item Qty Alice Bob 123 123 : : : : : : 2 4 Catalog of Items Sales A Relational Database (SQL) Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 6 / 26

Types of Databases More recently, other forms have appeared, most notably Extensible Markup Language (XML). An XML database is structured hierarchically. The underlying theory is less mature. The supporting software is less extensive. The queries are less optimized. On the other hand, the structure is much more flexible. Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 7 / 26

Types of Databases Company Catalog Sales...... Item1 Item2... Cust1 Cust2... Price Stock Item Qty A Hierarchical Database (XML) Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 8 / 26

Outline 1 Types of Databases 2 Relational Databases 3 Queries 4 Schemas 5 Primary Keys 6 Assignment Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 9 / 26

Relational Databases A relational database is a database in which the data are stored in tabular form, arranged in rows and columns. Traditionally, rows are called records and columns are called fields. In modern terminology, rows are called tuples and columns are called attributes. Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 10 / 26

Relational Databases Consider a database of company employees. fname lname ssn bdate sex salary dept Alice Smith 123456789 1968-05-22 F 35000.00 2 Barbara Brown 135792468 1985-10-12 F 40000.00 3 James Green 246813579 1974-02-15 F 100000.00 1 Jennifer Wallace 321549876 1985-12-02 F 50000.00 2.... Employees table... Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 11 / 26

Relational Databases In the example, the tuples are (Alice, Smith, 123456789, 1968-05-22,... ) (Barbara, Brown, 135792468, 1985-10-12,... ) etc. The attributes are fname lname ssn bdate etc. Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 12 / 26

Relational Databases The table expresses a relation, namely The employee fname lname has SS number ssn, was born on bdate, is sex, earns a salary of salary, and works in department dept. For example, the first row represents the statement The employee Alice Smith has SS number 123456789, was born on 1968-05-22, is female, earns a salary of $35000.00, and works in department #2. Thus, each tuple of the database represents a true statement, an instance of the relation. Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 13 / 26

Outline 1 Types of Databases 2 Relational Databases 3 Queries 4 Schemas 5 Primary Keys 6 Assignment Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 14 / 26

Relational Databases A query is a request that is sent to the DBMS. The DBMS parses the query, optimizes it, and sends it to the storage engine, which executes the query on the database. There are four basic types of query. Select Insert Delete Update Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 15 / 26

Relational Databases A selection query might request all employees in Dept #2. The result would be fname lname ssn bdate sex salary dept Alice Smith 123456789 1968-05-22 F 35000.00 2 Jennifer Wallace 321549876 1985-12-02 F 50000.00 2 Ernest Roth 642189753 1986-06-12 M 60000.00 2 John Kohler 789012345 1966-11-24 M 40000.00 2 Raymond Jones 963418527 1974-08-30 M 80000.00 2 Employees table Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 16 / 26

Relational Databases An insertion query might add the tuple (Susan, Lane, 654872109, 1959-03-31, F, 70000.00, 2). The result would be fname lname ssn bdate sex salary dept Alice Smith 123456789 1968-05-22 F 35000.00 2 Jennifer Wallace 321549876 1985-12-02 F 50000.00 2 Ernest Roth 642189753 1986-06-12 M 60000.00 2 John Kohler 789012345 1966-11-24 M 40000.00 2 Raymond Jones 963418527 1974-08-30 M 80000.00 2 Susan Lane 654872109 1959-03-31 F 70000.00 2 Employees table Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 17 / 26

Relational Databases A deletion query might delete the tuple with SSN 654872109. The result would be fname lname ssn bdate sex salary dept Alice Smith 123456789 1968-05-22 F 35000.00 2 Jennifer Wallace 321549876 1985-12-02 F 50000.00 2 Ernest Roth 642189753 1986-06-12 M 60000.00 2 John Kohler 789012345 1966-11-24 M 40000.00 2 Raymond Jones 963418527 1974-08-30 M 80000.00 2 Employees table Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 18 / 26

Relational Databases An update query might change the department number from 2 to 5. The result would be fname lname ssn bdate sex salary dept Alice Smith 123456789 1968-05-22 F 35000.00 5 Jennifer Wallace 321549876 1985-12-02 F 50000.00 5 Ernest Roth 642189753 1986-06-12 M 60000.00 5 John Kohler 789012345 1966-11-24 M 40000.00 5 Raymond Jones 963418527 1974-08-30 M 80000.00 5 Employees table Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 19 / 26

Outline 1 Types of Databases 2 Relational Databases 3 Queries 4 Schemas 5 Primary Keys 6 Assignment Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 20 / 26

Schemas Definition (Schema) A relation schema consists of the relation s name, a list of its attributes, and their domains, i.e., the set of legitimate values of each attribute. A database schema is a set of relation schemas. Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 21 / 26

Schemas The schema of the Employees relation is Employees ( fname string, lname string, ssn string, bdate date, sex string, salary float, dept integer ) Furthermore, 1 dept 5 and sex is M or F. Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 22 / 26

Outline 1 Types of Databases 2 Relational Databases 3 Queries 4 Schemas 5 Primary Keys 6 Assignment Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 23 / 26

Primary Keys Every table must have a primary key. The primary key is an attribute, or set of attributes, whose value, or values, is unique for each tuple. In a relation schema, we underline the attributes that comprise the primary key. What would serve as the primary key in the Employees table? Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 24 / 26

Outline 1 Types of Databases 2 Relational Databases 3 Queries 4 Schemas 5 Primary Keys 6 Assignment Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 25 / 26

Assignment Read Chapter 3. Robb T. Koether (Hampden-Sydney College) Relational Databases Fri, Jan 18, 2013 26 / 26