Lecture 1: Relational Databases

Similar documents
Lecture 2: SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases. Brief Note on Naming Conventions. Our Running Example.

Lecture 3: More SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases. Single-Criterion WHERE Conditions. SQL Conditions.

Lecture 2: SQL Basics

Lecture 3: More SQL Basics

Data Definition and Data Manipulation. Lecture 5: SQL s Data Definition Language CS1106/CS5021/CS6503 Introduction to Relational Databases

Lecture 5: SQL s Data Definition Language

Lecture 7: Two-Table Queries

Lecture 4: SQL Data Manipulation Basics

CS143: Relational Model

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Data Base Concepts. Course Guide 2

Informatics 1: Data & Analysis

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

Relational Database Systems Part 01. Karine Reis Ferreira

SQL language. Jaroslav Porubän, Miroslav Biňas, Milan Nosáľ (c)

CS425 Fall 2016 Boris Glavic Chapter 1: Introduction

Chapter 4: SQL Basics

G64DBS Database Systems. Lecture 7 SQL SELECT. The Data Dictionary. Data Dictionaries. Different Sections of SQL (DDL) Different Sections of SQL (DCL)

Using Relational Databases for Digital Research

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

CGS 3066: Spring 2017 SQL Reference

CISC 3140 (CIS 20.2) Design & Implementation of Software Application II

DATABASE MANAGEMENT SYSTEMS. UNIT I Introduction to Database Systems

SQL DDL. Intro SQL CREATE TABLE ALTER TABLE Data types Service-based database in Visual Studio Database in PHPMyAdmin

Overview of Data Management

INFORMATION TECHNOLOGY NOTES

Instructor: Craig Duckett. Lecture 02: Thursday, March 29 th, 2018 SQL Basics and SELECT, FROM, WHERE

Chapter 1: Introduction

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

Database Systems CSE 303. Lecture 02

Database Systems CSE 303. Lecture 02

Introduction to SQL. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

Introduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 2: Relations and SQL. September 5, Lecturer: Rasmus Pagh

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

Introduction to Databases CSE 414. Lecture 2: Data Models

Overview of Data Management

COSC344 Database Theory and Applications. σ a= c (P) Lecture 3 The Relational Data. Model. π A, COSC344 Lecture 3 1

Introduction. Example Databases

SQL Data Definition Language: Create and Change the Database Ray Lockwood

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

Database Technology Introduction. Heiko Paulheim

Lecture 0: Overview of cs1106/cs6503

INTRODUCTION TO DATABASE

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

Introduction to Data Management CSE 344. Lecture 2: Data Models

Database Processing. Fundamentals, Design, and Implementation. Global Edition

COGS 121 HCI Programming Studio. Week 03 - Tech Lecture

Ø Last Thursday: String manipulation & Regular Expressions Ø guest lecture from the amazing Sam Lau Ø reviewed in section and in future labs & HWs

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1

Standard stuff. Class webpage: cs.rhodes.edu/db Textbook: get it somewhere; used is fine. Prerequisite: CS 241 Coursework:

The Relational Data Model. Data Model

Database Applications (15-415)

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

Outline. Database Management Systems (DBMS) Database Management and Organization. IT420: Database Management and Organization

The Relational Model Constraints and SQL DDL

Introduction to Relational Databases. Introduction to Relational Databases cont: Introduction to Relational Databases cont: Relational Data structure

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

Review. The Relational Model. Glossary. Review. Data Models. Why Study the Relational Model? Why use a DBMS? OS provides RAM and disk

CSC 355 Database Systems

Basant Group of Institution

U1. Data Base Management System (DBMS) Unit -1. MCA 203, Data Base Management System

Mahathma Gandhi University

DS Introduction to SQL Part 1 Single-Table Queries. By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)

Introduction to the Structured Query Language [ SQL ] (Significant Concepts)

The Relational Model. CS157A Chris Pollett Sept. 19, 2005.

پوهنتون کابل پوهنځی كمپيوترساینس

Relational Model. CSE462 Database Concepts. Demian Lessa. Department of Computer Science and Engineering State University of New York, Buffalo

Lecture 1. Monday, August 25, 2014

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

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p:// Lecture 3

Unit I. By Prof.Sushila Aghav MIT

CS275 Intro to Databases

user specifies what is wanted, not how to find it

Part I: Structured Data

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Introduction to SQL Part 1 By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)

Databases - Relations in Databases. (N Spadaccini 2010) Relations in Databases 1 / 16

CS317 File and Database Systems

2. An implementation-ready data model needn't necessarily contain enforceable rules to guarantee the integrity of the data.

Administrivia. The Relational Model. Review. Review. Review. Some useful terms

Outline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2

Part I: Structured Data

Course Outline and Objectives: Database Programming with SQL

EE221 Databases Practicals Manual

CS 2451 Database Systems: Relational Data Model

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

Chapter # 7 Introduction to Structured Query Language (SQL) Part I

Chapter 1: Introduction

Fundamentals of Information Systems, Seventh Edition

Database Management System 9

SQL Data Definition and Data Manipulation Languages (DDL and DML)

Relational model and basic SQL

The Relational Model. Database Management Systems

SQL DATA DEFINITION LANGUAGE

DBMS. Relational Model. Module Title?

Operating systems fundamentals - B07

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

Transcription:

Lecture 1: Relational Databases CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (12/09/17) Lecture 1: Relational Databases 2017-2018 1 / 1

Summary Relational databases: concepts and terminology. The SQL query language. Syntax of simple project-filter queries. KH (12/09/17) Lecture 1: Relational Databases 2017-2018 2 / 1

Relational Database Concept Relational Databases Predominant database concept since 1980s Conceptually organizes data into sets of two-dimensional tables Many relational DB software packages Open Source: MySQL, Postgres Proprietary: Oracle, Microsoft, IBM, Sybase and others Edgar Ted Codd (1923 2003), English computer scientist Introduced relational database concept c1970 Turing Award 1981 KH (12/09/17) Lecture 1: Relational Databases 2017-2018 3 / 1

Relational Database Concept Relations Organization Conceptually relational databases are based on tables modules mod code lecturer mod title cs1101 Morrison Systems Organisation cs1105 Brown Foundations of Computer Science cs1106 Herley Introduction to Relational Databases cs1107 Bowen Intro. to Multimedia Authoring Systems cs1108 Doherty Computing: Profession and Society cs1109 Bridge Programming and Web Development Benefits Conceptually intuitive, simple and elegant KH (12/09/17) Lecture 1: Relational Databases 2017-2018 4 / 1

Relational Database Concept Anatomy of a Relational Database Database Relation A database consists of a set of named relations (aka tables) A set of tuples (aka rows) with identical column structure Each column named with an attribute (must be distinct) Values in each column of uniform type drawn from some set (domain) such as integer, text, date and so on. KH (12/09/17) Lecture 1: Relational Databases 2017-2018 5 / 1

Relational Database Concept Anatomy of a Relational Database cont d students id number first name last name date of birth hometown course points 112345678 Aoife Ahern 1993-01-25 Cork ck401 500 112467389 Barry Barry 1980-06-30 Tralee ck402 450 112356489 Ciara Callaghan 1993-03-14 Limerick ck401 425 112986347 Declan Duffy 1993-11-03 Cork ck407 550 112561728 Eimear Early 1993-07-18 Thurles ck406 475 112836467 Fionn Fitzgerald 1994-06-13 Bandon ck405 485 KH (12/09/17) Lecture 1: Relational Databases 2017-2018 6 / 1

Relational Database Concept Some Technicalities According to relational model, all rows should be distinct; DB systems don t always enforce this however Values must be atomic ( elementary and unstructured ) Examples: integers, decimals, text, booleans, dates Can t have lists, sets, records, arrays as single values (Can represent lists etc. by other means later) Every relation has a key: some subset of attributes such that no two tuples in the relation can ever have teh same key value. KH (12/09/17) Lecture 1: Relational Databases 2017-2018 7 / 1

Relational Database Concept Schema and Instances students id number first name last name date of birth hometown course points 112345678 Aoife Ahern 1993-01-25 Cork ck401 500 112467389 Barry Barry 1980-06-30 Tralee ck402 450 112356489 Ciara Callaghan 1993-03-14 Limerick ck401 425 112986347 Declan Duffy 1993-11-03 Cork ck407 550 112561728 Eimear Early 1993-07-18 Thurles ck406 475 112836467 Fionn Fitzgerald 1994-06-13 Bandon ck405 485 Precise contents a database generally vary over time We distinguish between Database Schema the structure of the database in terms of constituent tables and the organization of each table in terms of attributes and domains and the interpretation of these in terms of the real-world situation the DB models; remains fixed over time Database Instance any specific collection of values populating the DB that conforms to the schema; changes as DB is modified When speaking of say the academic records database we generally mean the former KH (12/09/17) Lecture 1: Relational Databases 2017-2018 8 / 1

Relational Database Concept Brief Digression on Adjective Relational Binary Relations in Mathematics Let Z 2 = Z Z be the set of pairs of integers; Any subset of Z 2 is a binary relation For example L = {(x, y) : x, y Z such that x y} is the set of integer pairs where the first is no larger than the second Other Relations Can define relations with any number of components; Component values need not be restricted to integers Relations and DBs Can interpret elements of k-ary (i.e. k components) relation as rows of a table Mathematical underpinning useful in handling DB manipulations KH (12/09/17) Lecture 1: Relational Databases 2017-2018 9 / 1

SQL Our instructions to DBMS must be expressed in notation called SQL KH (12/09/17) Lecture 1: Relational Databases 2017-2018 10 / 1

SQL What is SQL? Support Computer language for expressing management, manipulation and querying of relational databases Pronounced either as ess-qu-ell or sequel Good News Standard DB language; most common DBMSs support it; free open sources packages available Bad News Most DBMSs adopt their own dialects DB software is generally not completely portable between DBMSs KH (12/09/17) Lecture 1: Relational Databases 2017-2018 11 / 1

Why Computer Languages? Natural Languages English can be imprecise and ambiguous, so very difficult to write software to understand and carry out our instructions/intentions reliably Computer Languages Designed to be clear, concise and unambiguous Amenable to automatic interpretation and execution Can seem cryptic and error-intolerant Examples: SQL, HTML, PHP, Java,... KH (12/09/17) Lecture 1: Relational Databases 2017-2018 12 / 1

What SQL Allows Us to Express SQL incorporates several aspects Data Manipulation Language (DML) notation for expressing management of DB manipulations: adding/removing/updating tuples queries to interrogate DB Data Definition Language (DDL) notation for expressing DB structure (databases, tables, domains etc.) and so on We will focus on SQL queries for now KH (12/09/17) Lecture 1: Relational Databases 2017-2018 13 / 1

Some SQL Examples CREATE TABLE students ( id number CHAR(9), first name VARCHAR(20), last name VARCHAR(20), date of birth DATE, hometown VARCHAR(20), course CHAR(5), points INT, ); PRIMARY KEY (id number) Defines structure of students table SELECT first name, last name FROM students WHERE points >= 500; Seeks names of 500-point students KH (12/09/17) Lecture 1: Relational Databases 2017-2018 14 / 1

SQL Sample 2 SELECT first name, last name FROM students WHERE points >= 500; Meaning Extract names (first and last) of all students with at least 500 points Notes SELECT, FROM, WHERE are keywords Other words are names of table/columns >= means Terminate query with semicolon KH (12/09/17) Lecture 1: Relational Databases 2017-2018 15 / 1

SQL Sample 2 cont d Table students id number first name last name date of birth hometown course points 112345678 Aoife Ahern 1993-01-25 Cork ck401 500 112467389 Barry Barry 1980-06-30 Tralee ck402 450 112356489 Ciara Callaghan 1993-03-14 Limerick ck401 425 112986347 Declan Duffy 1993-11-03 Cork ck407 550 112561728 Eimear Early 1993-07-18 Thurles ck406 475 112836467 Fionn Fitzgerald 1994-06-13 Bandon ck405 485 SQL Query Result first name Aoife Declan SELECT first name, last name FROM students WHERE points >= 500; last name Ahern Duffy Result is a table (anonymous) Includes specified columns and rows only Original table left completely untouched KH (12/09/17) Lecture 1: Relational Databases 2017-2018 16 / 1

A Closer Look At That Query SELECT first name, last name / First bit / FROM students / Second bit / WHERE points >= 500; / Third bit / First bit specifies attributes of interest (note comma separators) Second bit specifies table the query applies to Third bit specifies criterion for rows of interest For each row, condition points >= 500 is true or false based on the points value in that row Only rows where condition is satisfied appear in result KH (12/09/17) Lecture 1: Relational Databases 2017-2018 17 / 1

A Closer Look cont d SELECT first name, last name / First bit / FROM students / Second bit / WHERE points >= 500; / Third bit / SQL is very picky about dotting of is and crossing of ts, so Spell keywords, names correctly ( SELECT not SELCT ) Take care of ordering of elements within query (don t alter order of bits) Use symbols (commas, semicolons etc. ) correctly (don t omit commas etc.) (Stuff inside /*... */ are comments annotations intended for human not computer consumption and have no bearing on meaning or execution of query) KH (12/09/17) Lecture 1: Relational Databases 2017-2018 18 / 1

Using SQL KH (12/09/17) Lecture 1: Relational Databases 2017-2018 19 / 1

Using SQL cont d Database server: machine that runs DBMS (e.g. MySQL ) provides database service to clients Clients may interact directly with DBMS 1 Client connects to DBMS (logs in) 2 Client types SQL query and submits 3 DBMS executes query and returns results to client 4 Repeat (2,3) at will; disconnect when done (Some computer programs can interact directly to DMBS without human intervention) KH (12/09/17) Lecture 1: Relational Databases 2017-2018 20 / 1

Using SQL With Other Programs Database application: program that talks to DB (via DBMS) Example: student transcript generator Program generates SQL queries, sends to DBMS DBMS services query, returns results to program Program manipulates results as needed Will see more on this in cs1109 later; uses PHP programs to interact with DB KH (12/09/17) Lecture 1: Relational Databases 2017-2018 21 / 1

Notes and Acknowledgements KH (12/09/17) Lecture 1: Relational Databases 2017-2018 22 / 1