The Relational Model and SQL
|
|
- Mae McDonald
- 5 years ago
- Views:
Transcription
1 Databases 2009 Michael I. Schwartzbach Computer Science, University of Aarhus 1
2 What is a Database? Main Entry: da ta base Pronunciation: \dā-tə-bās, da- also dä-\ Function: noun Date: circa 1962 : a usually large collection of data organized especially for rapid search and retrieval (as by a computer) database transitive verb Queries are much more general than searching Efficient, convenient, and safe storage of and multi-user access to massive amounts of persistent data 2 2
3 What is a Database? Main Entry: da ta base Pronunciation: \dā-tə-bās, da- also dä-\ Function: noun Date: circa 1962 : a usually large collection of data organized especially for rapid search and retrieval (as by a computer) database transitive verb Bank accounts Queries are much more general than searching Blog archives Efficient, convenient, and safe storage of and Human multi-user access to massive amounts of genome persistent data Google.com Amazon.com Student records 3 3
4 Data Models A (mathematical) representation of data: tables trees graphs Operations on data: insert, update, delete, query Constraints on data: datatypes uniqueness dependencies 4 4
5 The Relational Data Model Data are stored in tables (relations): name Joe Jacques Jose age city London Paris Madrid Simple but still covers many real scenarios 5 5
6 The Relational Data Model Data are stored in tables (relations) name age city row Joe 22 London Jacques 27 Paris Jose 34 Madrid 6 6
7 The Relational Data Model Data are stored in tables (relations): schema name age city Joe 22 London Jacques 27 Paris Jose 34 Madrid 7 7
8 The Relational Data Model Data are stored in tables (relations): name age city Joe Jacques London Paris column Jose 34 Madrid 8 8
9 The Relational Data Model Data are stored in tables (relations): name age city attribute Joe 22 London Jacques 27 Paris Jose 34 Madrid 9 9
10 The Relational Data Model Data are stored in tables (relations): name age city Joe 22 London Jacques 27 Paris attribute value Jose 34 Madrid 10 10
11 The Relational Data Model Data are stored in tables (relations): name Joe Jacques Jose age city London Paris Madrid Abstract tables: invariant under permutation of rows and columns no information is stored in the order May or may not allow duplicate rows 11 11
12 The Relational Data Model Data are stored in tables (relations): city Madrid London Paris name Jose Joe Jacques age Abstract tables: invariant under permutation of rows and columns no information is stored in the order May or may not allow duplicate rows 12 12
13 NULL Values An attribute value may be NULL: it is currently unknown it is not relevant in this row animal lion crocodile Tyrannosaurus Rex polar bear color yellow green NULL white zoo Copenhagen London NULL Berlin NULL values are often treated specially 13 13
14 Advantages of The Relational Model A simple, intuitive model Often convenient for real-life data but richer models are also needed, e.g. XML An elegant mathematical foundation the relational algebra Allows efficient algorithms Industrial strength implementations are available 14 14
15 Schemas Relation schema: name of the relation names of the attributes types of the attributes constraints Database schema: collection of all relation schemas 15 15
16 A Running Example The database behind a tiny calendar system: Rooms People Meetings Participants Equipment 16 16
17 Rooms room Turing-222 Ada-333 Aud-E capacity room: the name of a room capacity: the number of people that it will hold 17 17
18 People userid name group office mis Michael I. Schwartzbach vip Turing-222 doina Doina Bucur phd NULL bnielsen Kai Birger Nielsen tap Hopper-017 userid: unique user name name: ordinary name group: vip, tap, phd office: a room or NULL 18 18
19 Meetings meetid date slot owner what mis ddb mis ddb amoeller TA-meeting meetid: a unique id date: the date of the meeting slot: 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 owner: the userid of the owner what: a textual description 19 19
20 Participants meetid pid Store-Aud mis sigurd status a a d meetid: the id of the meeting pid: a userid or a room status: u(nknown), a(ccept), d(ecline) 20 20
21 Equipment room Store-Aud Store-Aud Hopper-017 type projector whiteboard mini-fridge room: the name of a room type: the type of equipment 21 21
22 SQL Structured Query Language Invented by IBM in the 1970s (many versions) Declarative, no low-level manipulations Algebraic foundations Representations, operations, constraints Query optimization DB2, Oracle, SQL Server, MySQL 22 22
23 Declaring Tables (1/3) CREATE TABLE Rooms ( room VARCHAR(15), capacity INT ); CREATE TABLE People ( name VARCHAR(40), office VARCHAR(15), userid VARCHAR(15), group CHAR(3) ); 23 23
24 Declaring Tables (2/3) CREATE TABLE Meetings ( meetid INT, date DATE, slot INT, owner VARCHAR(15), what VARCHAR(40) ); 24 24
25 Declaring Tables (3/3) CREATE TABLE Participants ( meetid INT, pid VARCHAR(15), status CHAR(1) ); CREATE TABLE Equipment ( room VARCHAR(15), type VARCHAR(20) ); 25 25
26 SQL Types INT 217 CHAR(2) 'aa', 'ab', '12', '++' VARCHAR(5) '', '12345', 'foo', 'x''y' FLOAT 3.14, 42, DATE ' ' TIME '14:15:00' CLOB a text file BLOB a movie XML an XML document 26 26
27 Refinements NOT NULL the value cannot be NULL DEFAULT value a default value is specified UNIQUE the value is unique in the table unless it is NULL PRIMARY KEY the value is unique in the table the value is never NULL 27 27
28 Refined Tables (1/3) CREATE TABLE Rooms ( room VARCHAR(15) PRIMARY KEY NOT NULL, capacity INT NOT NULL ); CREATE TABLE People ( name VARCHAR(40) NOT NULL, office VARCHAR(15), userid VARCHAR(15) PRIMARY KEY NOT NULL, group CHAR(3) ); 28 28
29 Declaring Tables (2/3) CREATE TABLE Meetings ( meetid INT PRIMARY KEY NOT NULL, date DATE, slot INT, owner VARCHAR(15) NOT NULL, what VARCHAR(40) ); 29 29
30 Declaring Tables (3/3) CREATE TABLE Participants ( meetid INT NOT NULL, pid VARCHAR(15) NOT NULL, status CHAR(1) DEFAULT 'u' ); CREATE TABLE Equipment ( room VARCHAR(15) PRIMARY KEY NOT NULL, type VARCHAR(20) NOT NULL ); 30 30
31 SELECT-FROM FROM-WHERE The basic form of an SQL query SELECT desired attributes FROM one or more tables WHERE condition about the involved rows 31 31
32 Simple Example Which kind of meetings have Michael arranged? SELECT what FROM Meetings WHERE owner = 'mis'; what ddb ddb 32 32
33 Loop Semantics for Single Table Loop through all rows in the table Check if the condition is true Project the rows onto the desired attributes Note that duplicates still are kept
34 Renamings in SELECT The selected attributes can be given new names SELECT name, group AS category FROM People WHERE office = 'Hopper-223'; name Kari Rye Schougaard Nørgaard Mikkel Baun Kjærgaard category phd phd 34 34
35 Expressions in SELECT The attributes may have computed values SELECT owner, date, slot*60 AS minute FROM Meetings WHERE owner = 'mis'; owner mis mis date minute
36 Conditions in WHERE AND, OR, NOT, =, <>, <, >, <=, >=, LIKE,... SELECT owner, what FROM Meetings WHERE slot >= 12 AND slot < 16 AND what LIKE '%beer%'; owner amoeller amoeller amoeller what Afternoon beer Belgian beer testing Return empty beer bottles 36 36
37 3-Valued Logic Any comparison with NULL yields unknown This gives 3 truth values: true, false, unknown Boolean connectives are defined appropriately: AND tt ff u OR tt ff u NOT tt tt ff u tt tt tt tt tt ff ff ff ff ff ff tt ff u ff tt u u ff u u tt u u u u The WHERE clause accepts if the result is true 37 37
38 A Surprise? People: userid name group office mis Michael Schwartzbach vip Turing-222 doina Doina Bucur phd NULL bnielsen Kai Birger Nielsen tap Hopper-017 SELECT userid FROM People WHERE office='turing-222' OR office<>'turing-222'; userid mis bnielsen 38 38
39 Testing for NULL People: userid name group office mis Michael Schwartzbach vip Turing-222 doina Doina Bucur phd NULL bnielsen Kai Birger Nielsen tap Hopper-017 SELECT userid FROM People WHERE office IS NULL; userid doina 39 39
40 Multiple Relations Which people have booked meetings this day? SELECT name FROM People, Meetings WHERE date = ' ' AND owner = userid; The relations are joined 40 40
41 General Loop Semantics Loop through all rows in all tables For each combination: check if the condition is true project the rows onto the desired attributes Note that duplicates still are kept
42 Prefixing Attribute Variables Avoid possible name clashes: SELECT People.name FROM People, Meetings WHERE Meetings.date = ' ' AND Meetings.owner = People.userid; 42 42
43 Naming Row Variables Enables self-joins: SELECT p1.name AS roomie1, p2.name AS roomie2 FROM People p1, People p2 WHERE p1.office = p2.office AND p1.userid <> p2.userid; A table of all roommates
44 Avoiding Symmetric Pairs SELECT p1.name AS roomie1, p2.name AS roomie2 FROM People p1, People p2 WHERE p1.office = p2.office AND p1.userid < p2.userid; 44 44
45 Aggregation The SELECT clause may involve aggregations: SUM AVG COUNT MIN MAX NULLs are ignored in these computations Except that count(*) counts all rows 45 45
46 Requirements Aggregation of a column computes: a 1 a 2 a 3... a n for some operator x a 1 a 2 This is only well-formed if is: commutative: a b = b a associative: (a b) c = a (b c) since the rows may be permuted a 3... a n 46 46
47 Simple Example What is the average capacity of a room? SELECT AVG(capacity) AS average FROM Rooms; average
48 Avoiding Duplicates SELECT DISTINCT removes duplicates This is expensive! But sometime necessary... What kinds of equipment do we have? SELECT DISTINCT type FROM Equipment; 48 48
49 Avoiding Duplicates in Aggregation How many kinds of equipment do we have? SELECT COUNT(DISTINCT type) as number FROM Equipment; number
50 Scalar Functions Lots of useful functions are available: integer and float functions string functions calendar functions... SELECT CHARACTER_LENGTH(name,CODEUNITS16), UPPER(group) FROM People; 50 50
51 Subqueries Any query in parentheses can be used in: FROM clauses WHERE clauses A query may be used as a value: if it returns only one row and one column otherwise, a run-time error occurs 51 51
52 Simple Example Who shares an office with Brian? SELECT name FROM People WHERE office = (SELECT office FROM People WHERE userid='bbc'); 52 52
53 Membership Tests IN and NOT IN test membership in tables Who has someone arranged to meet? SELECT pid FROM Participants WHERE meetid IN (SELECT meetid FROM Meetings WHERE owner='mis') AND pid NOT IN (SELECT room FROM Rooms); 53 53
54 Correlated Subqueries Which meetings exceed the capacity of a room? SELECT meetid FROM Meetings WHERE (SELECT COUNT(DISTINCT pid) FROM Participants WHERE meetid=meetings.meetid AND status<>'d' AND pid NOT IN (SELECT room FROM Rooms) ) > (SELECT capacity FROM Rooms, Participants WHERE room=pid AND meetid=meetings.meetid) ; 54 54
55 Correlated Subqueries Which meetings exceed the capacity of a room? SELECT meetid FROM Meetings static nested scope rules WHERE (SELECT COUNT(DISTINCT pid) FROM Participants WHERE meetid=meetings.meetid AND status<>'d' AND pid NOT IN (SELECT room FROM Rooms) ) > (SELECT capacity FROM Rooms, Participants WHERE room=pid AND meetid=meetings.meetid) ; 55 55
56 EXISTS and NOT EXISTS Check for emptiness or non-emptiness of a table Who is alone in an office? SELECT name FROM People p1 WHERE NOT EXISTS ( SELECT * FROM People WHERE office = p1.office AND userid <> p1.userid ); 56 56
57 ANY and ALL Allow comparisons against: any row in a subquery all rows in a subquery Which are the latest meetings that are planned? SELECT what FROM Meetings WHERE date >= ALL( SELECT date FROM Meetings ); 57 57
58 UNION, INTERSECT, and EXCEPT Treats tables with the same schema as sets: removes duplicates (unless ALL is added) computes,, and \ Who do not participate in a meeting they have themselves arranged? (SELECT owner AS userid, meetid FROM Meetings) EXCEPT (SELECT pid AS userid, meetid FROM Participants); 58 58
59 The JOIN Operator T1 JOIN T2 ON condition is syntactic sugar for: SELECT * FROM T1,T2 WHERE condition 59 59
60 Dangling Rows and FULL JOIN T1 JOIN T2 ON condition A row in T1 or T2 that does not match a row in the other table is dangling An ordinary JOIN throws away dangling rows A FULL JOIN preserves dangling rows by padding them with NULL values A LEFT or RIGHT JOIN preserves dangling rows from one argument only 60 60
61 Simple Example In which offices are meetings planned? All offices with meetings or NULL: SELECT office,meetid FROM People LEFT JOIN Participants ON pid=office; Only those offices with meetings: SELECT office,meetid FROM People JOIN Participants ON pid=office; 61 61
62 Grouping SELECT-FROM-WHERE-GROUP BY Rows are grouped by a list of attributes Aggregations in SELECT are done for each group The attributes in SELECT must be either: aggregated mentioned in the GROUP BY list 62 62
63 Simple Example How many meetings have each person arranged? SELECT owner, COUNT(meetid) as number FROM Meetings GROUP BY owner; owner amoeller kjensen mis number
64 Advanced Example What is the average number of invitations for the meetings that each person has arranged? SELECT owner, AVG(pidno) AS average FROM (SELECT owner, m.meetid, COUNT(pid) as pidno FROM Meetings m, Participants p WHERE m.meetid = p.meetid GROUP BY owner, m.meetid) GROUP BY owner; 64 64
65 HAVING A HAVING clause may eliminate some groups Which offices have more than one occupant? SELECT office FROM People GROUP BY office HAVING COUNT(*) > 1; Attributes in HAVING must be aggregated or mentioned in GROUP BY 65 65
66 Modifications SQL commands may change the database Three kinds of modifications: insert one or more rows delete one or more rows update existing rows or columns Modifications do not return a result 66 66
67 Inserting a Single Row INSERT INTO table VALUES ( list of values ); INSERT INTO Participants VALUES (42432, 'mis', 'a'); Optionally specify attribute names: INSERT INTO Participants(pid, status, meetid) VALUES ('mis', 'a', 42432); Missing values are NULL or defaults 67 67
68 Inserting a Subquery Invite everyone Anders meets with to his Belgian beer tasting: INSERT INTO Participants ( SELECT AS meetid, pid, 'u' AS status FROM Meetings, Participants WHERE Meetings.meetid=Participants.meetid AND owner = 'amoeller' AND pid <> 'amoeller' AND pid NOT IN (SELECT room FROM Rooms)); 68 68
69 Deleting Some Rows DELETE FROM table WHERE condition; Delete Michael's office: DELETE FROM Rooms WHERE room='turing-222'; Delete all offices: DELETE FROM Rooms; 69 69
70 Deleting a Subquery Delete all people with a roommate: DELETE FROM People p WHERE EXISTS( SELECT * FROM People WHERE office = p.office AND userid <> p.userid ); 70 70
71 Meaning of Deletion First the condition is computed for all rows Then the deletions are performed Otherwise the last person in a multi-person office would not be deleted! 71 71
72 Update UPDATE table SET attribute assignments WHERE condition; Move Anders to a smaller office: UPDATE People SET office = 'Turing-213' WHERE userid = 'amoeller'; 72 72
73 SQL is Everywhere 73 73
Databases 2011 The Relational Model and SQL
Databases 2011 Christian S. Jensen Computer Science, Aarhus University What is a Database? Main Entry: da ta base Pronunciation: \ˈdā-tə-ˌbās, ˈda- also ˈdä-\ Function: noun Date: circa 1962 : a usually
More informationDatabases 2012 Constraints, Triggers, and Views
Databases 2012 Christian S. Jensen Computer Science, Aarhus University Constraints Enforced relationships among data single-attribute keys multi-attribute keys foreign keys attribute constraints row constraints
More informationDatabases Normalization. Christian S. Jensen Computer Science, Aarhus University
Databases 2010 Christian S. Jensen Computer Science, Aarhus University Acknowledgments: revised version of slides developed by Michael I. Schwartzbach Database Anomalies Redundancy anomaly information
More informationQuerying Data with Transact SQL
Course 20761A: Querying Data with Transact SQL Course details Course Outline Module 1: Introduction to Microsoft SQL Server 2016 This module introduces SQL Server, the versions of SQL Server, including
More informationChapter 3: Introduction to SQL. Chapter 3: Introduction to SQL
Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of The SQL Query Language Data Definition Basic Query
More informationIntroduction to SQL. Select-From-Where Statements Multirelation Queries Subqueries
Introduction to SQL Select-From-Where Statements Multirelation Queries Subqueries 122 Why SQL? SQL is a very-high-level language. Say what to do rather than how to do it. Database management system figures
More informationSQL Queries. for. Mere Mortals. Third Edition. A Hands-On Guide to Data Manipulation in SQL. John L. Viescas Michael J. Hernandez
SQL Queries for Mere Mortals Third Edition A Hands-On Guide to Data Manipulation in SQL John L. Viescas Michael J. Hernandez r A TT TAddison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco
More informationWhy SQL? SQL is a very-high-level language. Database management system figures out best way to execute query
Basic SQL Queries 1 Why SQL? SQL is a very-high-level language Say what to do rather than how to do it Avoid a lot of data-manipulation details needed in procedural languages like C++ or Java Database
More informationSQL. The Basics Advanced Manipulation Constraints Authorization 1. 1
SQL The Basics Advanced Manipulation Constraints Authorization 1. 1 Table of Contents SQL 0 Table of Contents 0/1 Parke Godfrey 0/2 Acknowledgments 0/3 SQL: a standard language for accessing databases
More informationMidterm Review. Winter Lecture 13
Midterm Review Winter 2006-2007 Lecture 13 Midterm Overview 3 hours, single sitting Topics: Relational model relations, keys, relational algebra expressions SQL DDL commands CREATE TABLE, CREATE VIEW Specifying
More informationThe SQL data-definition language (DDL) allows defining :
Introduction to SQL Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query Structure Additional Basic Operations Set Operations Null Values Aggregate Functions Nested Subqueries
More informationPrinciples of Data Management
Principles of Data Management Alvin Lin August 2018 - December 2018 Structured Query Language Structured Query Language (SQL) was created at IBM in the 80s: SQL-86 (first standard) SQL-89 SQL-92 (what
More informationDatabase Systems SQL SL03
Inf4Oec10, SL03 1/52 M. Böhlen, ifi@uzh Informatik für Ökonomen II Fall 2010 Database Systems SQL SL03 Data Definition Language Table Expressions, Query Specifications, Query Expressions Subqueries, Duplicates,
More informationDatabase Systems SQL SL03
Checking... Informatik für Ökonomen II Fall 2010 Data Definition Language Database Systems SQL SL03 Table Expressions, Query Specifications, Query Expressions Subqueries, Duplicates, Null Values Modification
More informationWHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints
SQL KEREM GURBEY WHAT IS SQL Database query language, which can also: Define structure of data Modify data Specify security constraints DATA DEFINITION Data-definition language (DDL) provides commands
More informationSQL: Data Manipulation Language. csc343, Introduction to Databases Diane Horton Winter 2017
SQL: Data Manipulation Language csc343, Introduction to Databases Diane Horton Winter 2017 Introduction So far, we have defined database schemas and queries mathematically. SQL is a formal language for
More informationSQL: csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Sina Meraji. Winter 2018
SQL: csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Sina Meraji Winter 2018 Introduction So far, we have defined database schemas and queries mathematically. SQL is a
More informationAnnouncements (September 14) SQL: Part I SQL. Creating and dropping tables. Basic queries: SFW statement. Example: reading a table
Announcements (September 14) 2 SQL: Part I Books should have arrived by now Homework #1 due next Tuesday Project milestone #1 due in 4 weeks CPS 116 Introduction to Database Systems SQL 3 Creating and
More informationChapter 3: Introduction to SQL
Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query
More informationIntroduction to SQL SELECT-FROM-WHERE STATEMENTS SUBQUERIES DATABASE SYSTEMS AND CONCEPTS, CSCI 3030U, UOIT, COURSE INSTRUCTOR: JAREK SZLICHTA
Introduction to SQL SELECT-FROM-WHERE STATEMENTS MULTIRELATION QUERIES SUBQUERIES 1 SQL SQL is a standard language for accessing databases. SQL stands for Structured Query Language. SQL lecture s material
More informationChapter 3: Introduction to SQL
Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query
More informationSQL. Lecture 4 SQL. Basic Structure. The select Clause. The select Clause (Cont.) The select Clause (Cont.) Basic Structure.
SL Lecture 4 SL Chapter 4 (Sections 4.1, 4.2, 4.3, 4.4, 4.5, 4., 4.8, 4.9, 4.11) Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Modification of the Database
More informationMariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney.
MariaDB Crash Course Ben Forta A Addison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Cape Town Sydney Tokyo Singapore Mexico City
More informationCS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen
CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen LECTURE 10: INTRODUCTION TO SQL FULL RELATIONAL OPERATIONS MODIFICATION LANGUAGE Union, Intersection, Differences (select
More informationMissing Information. We ve assumed every tuple has a value for every attribute. But sometimes information is missing. Two common scenarios:
NULL values Missing Information We ve assumed every tuple has a value for every attribute. But sometimes information is missing. Two common scenarios: Missing value. E.g., we know a student has some email
More informationRelational Model, Relational Algebra, and SQL
Relational Model, Relational Algebra, and SQL August 29, 2007 1 Relational Model Data model. constraints. Set of conceptual tools for describing of data, data semantics, data relationships, and data integrity
More informationIntroduction to SQL. Select-From-Where Statements Multirelation Queries Subqueries. Slides are reused by the approval of Jeffrey Ullman s
Introduction to SQL Select-From-Where Statements Multirelation Queries Subqueries Slides are reused by the approval of Jeffrey Ullman s 1 Why SQL? SQL is a very-high-level language. Say what to do rather
More informationRelational Algebra and SQL
Relational Algebra and SQL Computer Science E-66 Harvard University David G. Sullivan, Ph.D. Example Domain: a University We ll use relations from a university database. four relations that store info.
More informationToday s topics. Null Values. Nulls and Views in SQL. Standard Boolean 2-valued logic 9/5/17. 2-valued logic does not work for nulls
Today s topics CompSci 516 Data Intensive Computing Systems Lecture 4 Relational Algebra and Relational Calculus Instructor: Sudeepa Roy Finish NULLs and Views in SQL from Lecture 3 Relational Algebra
More informationQuerying Data with Transact-SQL
Course 20761A: Querying Data with Transact-SQL Page 1 of 5 Querying Data with Transact-SQL Course 20761A: 2 days; Instructor-Led Introduction The main purpose of this 2 day instructor led course is to
More informationAdministrivia. The Relational Model. Review. Review. Review. Some useful terms
Administrivia The Relational Model Ramakrishnan & Gehrke Chapter 3 Homework 0 is due next Thursday No discussion sections next Monday (Labor Day) Enrollment goal ~150, 118 currently enrolled, 47 on the
More informationIntroduction to SQL Part 2 by Michael Hahsler Based on slides for CS145 Introduction to Databases (Stanford)
Introduction to SQL Part 2 by Michael Hahsler Based on slides for CS145 Introduction to Databases (Stanford) Lecture 3 Lecture Overview 1. Aggregation & GROUP BY 2. Set operators & nested queries 3. Advanced
More informationPart I: Structured Data
Inf1-DA 2011 2012 I: 92 / 117 Part I Structured Data Data Representation: I.1 The entity-relationship (ER) data model I.2 The relational model Data Manipulation: I.3 Relational algebra I.4 Tuple-relational
More informationChapter 4: SQL. Basic Structure
Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Joined Relations Data Definition Language Embedded SQL
More informationRelational Databases
Relational Databases Jan Chomicki University at Buffalo Jan Chomicki () Relational databases 1 / 49 Plan of the course 1 Relational databases 2 Relational database design 3 Conceptual database design 4
More informationChapter 6 The database Language SQL as a tutorial
Chapter 6 The database Language SQL as a tutorial About SQL SQL is a standard database language, adopted by many commercial systems. ANSI SQL, SQL-92 or SQL2, SQL99 or SQL3 extends SQL2 with objectrelational
More informationQuerying Data with Transact SQL Microsoft Official Curriculum (MOC 20761)
Querying Data with Transact SQL Microsoft Official Curriculum (MOC 20761) Course Length: 3 days Course Delivery: Traditional Classroom Online Live MOC on Demand Course Overview The main purpose of this
More informationDatabase Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 7 Introduction to Structured Query Language (SQL) Objectives In this chapter, students will learn: The basic commands and
More informationSilberschatz, Korth and Sudarshan See for conditions on re-use
Chapter 3: SQL Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested
More informationChapter 3: SQL. Chapter 3: SQL
Chapter 3: SQL Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested
More informationSQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas
SQL SQL Functionality stands for Structured Query Language sometimes pronounced sequel a very-high-level (declarative) language user specifies what is wanted, not how to find it number of standards original
More informationSQL Data Querying and Views
Course A7B36DBS: Database Systems Lecture 04: SQL Data Querying and Views Martin Svoboda Faculty of Electrical Engineering, Czech Technical University in Prague Outline SQL Data manipulation SELECT queries
More informationSQL Overview. CSCE 315, Fall 2017 Project 1, Part 3. Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch
SQL Overview CSCE 315, Fall 2017 Project 1, Part 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch SQL Structured Query Language Database language used to manage and query relational
More informationMANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)
Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 6 Professional Program: Data Administration and Management MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9) AGENDA
More informationSQL functions fit into two broad categories: Data definition language Data manipulation language
Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition Chapter 7 Beginning Structured Query Language (SQL) MDM NUR RAZIA BINTI MOHD SURADI 019-3932846 razia@unisel.edu.my
More informationDATABASE TECHNOLOGY - 1MB025
1 DATABASE TECHNOLOGY - 1MB025 Fall 2004 An introductory course on database systems http://user.it.uu.se/~udbl/dbt-ht2004/ alt. http://www.it.uu.se/edu/course/homepage/dbastekn/ht04/ Kjell Orsborn Uppsala
More informationInformation Systems Engineering. SQL Structured Query Language DML Data Manipulation (sub)language
Information Systems Engineering SQL Structured Query Language DML Data Manipulation (sub)language 1 DML SQL subset for data manipulation (DML) includes four main operations SELECT - used for querying a
More informationSubqueries. Must use a tuple-variable to name tuples of the result
Subqueries A parenthesized SELECT-FROM-WHERE statement (subquery) can be used as a value in a number of places, including FROM and WHERE clauses Example: in place of a relation in the FROM clause, we can
More informationDATABASTEKNIK - 1DL116
1 DATABASTEKNIK - 1DL116 Spring 2004 An introductury course on database systems http://user.it.uu.se/~udbl/dbt-vt2004/ Kjell Orsborn Uppsala Database Laboratory Department of Information Technology, Uppsala
More informationChapter 3: SQL. Database System Concepts, 5th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use
Chapter 3: SQL Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested
More informationCS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13
CS121 MIDTERM REVIEW CS121: Relational Databases Fall 2017 Lecture 13 2 Before We Start Midterm Overview 3 6 hours, multiple sittings Open book, open notes, open lecture slides No collaboration Possible
More informationDatabase Design and Programming
Database Design and Programming Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net Example: EXISTS Set of beers with the same manf as b1, but not the same beer SELECT name FROM Beers b1
More informationCS143: Relational Model
CS143: Relational Model Book Chapters (4th) Chapters 1.3-5, 3.1, 4.11 (5th) Chapters 1.3-7, 2.1, 3.1-2, 4.1 (6th) Chapters 1.3-6, 2.105, 3.1-2, 4.5 Things to Learn Data model Relational model Database
More informationSQL: Data Querying. B0B36DBS, BD6B36DBS: Database Systems. h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 4
B0B36DBS, BD6B36DBS: Database Systems h p://www.ksi.m.cuni.cz/~svoboda/courses/172-b0b36dbs/ Lecture 4 SQL: Data Querying Mar n Svoboda mar n.svoboda@fel.cvut.cz 20. 3. 2018 Czech Technical University
More information618 Index. BIT data type, 108, 109 BIT_LENGTH, 595f BIT VARYING data type, 108 BLOB data type, 108 Boolean data type, 109
Index A abbreviations in field names, 22 in table names, 31 Access. See under Microsoft acronyms in field names, 22 in table names, 31 aggregate functions, 74, 375 377, 416 428. See also AVG; COUNT; COUNT(*);
More informationRelational Algebra and SQL
Relational Algebra and SQL Relational Algebra. This algebra is an important form of query language for the relational model. The operators of the relational algebra: divided into the following classes:
More informationCSC 261/461 Database Systems Lecture 5. Fall 2017
CSC 261/461 Database Systems Lecture 5 Fall 2017 MULTISET OPERATIONS IN SQL 2 UNION SELECT R.A FROM R, S WHERE R.A=S.A UNION SELECT R.A FROM R, T WHERE R.A=T.A Q 1 Q 2 r. A r. A = s. A r. A r. A = t. A}
More informationCourse Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course:
Course Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course: 20762C Developing SQL 2016 Databases Module 1: An Introduction to Database Development Introduction to the
More informationIntroduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 2: Relations and SQL. September 5, Lecturer: Rasmus Pagh
Introduction to Databases, Fall 2005 IT University of Copenhagen Lecture 2: Relations and SQL September 5, 2005 Lecturer: Rasmus Pagh Today s lecture What, exactly, is the relational data model? What are
More informationChapter # 7 Introduction to Structured Query Language (SQL) Part II
Chapter # 7 Introduction to Structured Query Language (SQL) Part II Updating Table Rows UPDATE Modify data in a table Basic Syntax: UPDATE tablename SET columnname = expression [, columnname = expression]
More information20461: Querying Microsoft SQL Server 2014 Databases
Course Outline 20461: Querying Microsoft SQL Server 2014 Databases Module 1: Introduction to Microsoft SQL Server 2014 This module introduces the SQL Server platform and major tools. It discusses editions,
More informationCIS 330: Applied Database Systems
1 CIS 330: Applied Database Systems Lecture 7: SQL Johannes Gehrke johannes@cs.cornell.edu http://www.cs.cornell.edu/johannes Logistics Office hours role call: Mondays, 3-4pm Tuesdays, 4:30-5:30 Wednesdays,
More informationWhy Relational Databases? Relational databases allow for the storage and analysis of large amounts of data.
DATA 301 Introduction to Data Analytics Relational Databases Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca DATA 301: Data Analytics (2) Why Relational Databases? Relational
More informationAdvanced SQL Tribal Data Workshop Joe Nowinski
Advanced SQL 2018 Tribal Data Workshop Joe Nowinski The Plan Live demo 1:00 PM 3:30 PM Follow along on GoToMeeting Optional practice session 3:45 PM 5:00 PM Laptops available What is SQL? Structured Query
More informationSql Server Syllabus. Overview
Sql Server Syllabus Overview This SQL Server training teaches developers all the Transact-SQL skills they need to create database objects like Tables, Views, Stored procedures & Functions and triggers
More informationCGS 3066: Spring 2017 SQL Reference
CGS 3066: Spring 2017 SQL Reference Can also be used as a study guide. Only covers topics discussed in class. This is by no means a complete guide to SQL. Database accounts are being set up for all students
More informationDatabases Relational algebra Lectures for mathematics students
Databases Relational algebra Lectures for mathematics students March 5, 2017 Relational algebra Theoretical model for describing the semantics of relational databases, proposed by T. Codd (who authored
More informationRELATIONAL ALGEBRA II. CS121: Relational Databases Fall 2017 Lecture 3
RELATIONAL ALGEBRA II CS121: Relational Databases Fall 2017 Lecture 3 Last Lecture 2 Query languages provide support for retrieving information from a database Introduced the relational algebra A procedural
More informationLecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University
Lecture 3 SQL Shuigeng Zhou September 23, 2008 School of Computer Science Fudan University Outline Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views
More informationRelational Algebra. Procedural language Six basic operators
Relational algebra Relational Algebra Procedural language Six basic operators select: σ project: union: set difference: Cartesian product: x rename: ρ The operators take one or two relations as inputs
More informationDatabase Management
Database Management - 2011 Model Answers 1. a. A data model should comprise a structural part, an integrity part and a manipulative part. The relational model provides standard definitions for all three
More informationDATABASE TECHNOLOGY - 1MB025
1 DATABASE TECHNOLOGY - 1MB025 Fall 2005 An introductury course on database systems http://user.it.uu.se/~udbl/dbt-ht2005/ alt. http://www.it.uu.se/edu/course/homepage/dbastekn/ht05/ Kjell Orsborn Uppsala
More information12. MS Access Tables, Relationships, and Queries
12. MS Access Tables, Relationships, and Queries 12.1 Creating Tables and Relationships Suppose we want to build a database to hold the information for computers (also refer to parts in the text) and suppliers
More informationCOSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 304 Introduction to Database Systems SQL DDL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Overview Structured Query Language or SQL is the standard query language
More informationSQL Data Query Language
SQL Data Query Language André Restivo 1 / 68 Index Introduction Selecting Data Choosing Columns Filtering Rows Set Operators Joining Tables Aggregating Data Sorting Rows Limiting Data Text Operators Nested
More informationQUERYING MICROSOFT SQL SERVER COURSE OUTLINE. Course: 20461C; Duration: 5 Days; Instructor-led
CENTER OF KNOWLEDGE, PATH TO SUCCESS Website: QUERYING MICROSOFT SQL SERVER Course: 20461C; Duration: 5 Days; Instructor-led WHAT YOU WILL LEARN This 5-day instructor led course provides students with
More informationCIS 330: Applied Database Systems. ER to Relational Relational Algebra
CIS 330: Applied Database Systems ER to Relational Relational Algebra 1 Logical DB Design: ER to Relational Entity sets to tables: ssn name Employees lot CREATE TABLE Employees (ssn CHAR(11), name CHAR(20),
More informationEXTENDED RELATIONAL ALGEBRA OUTERJOINS, GROUPING/AGGREGATION INSERT/DELETE/UPDATE
More SQL EXTENDED RELATIONAL ALGEBRA OUTERJOINS, GROUPING/AGGREGATION INSERT/DELETE/UPDATE 1 The Extended Algebra δ = eliminate duplicates from bags. τ = sort tuples. γ = grouping and aggregation. Outerjoin
More informationDatabase Management Systems,
Database Management Systems SQL Query Language (3) 1 Topics Aggregate Functions in Queries count sum max min avg Group by queries Set Operations in SQL Queries Views 2 Aggregate Functions Tables are collections
More informationBasic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition
Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition Language 4.1 Schema Used in Examples
More informationCSCB20 Week 4. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017
CSCB20 Week 4 Introduction to Database and Web Application Programming Anna Bretscher Winter 2017 Last Week Intro to SQL and MySQL Mapping Relational Algebra to SQL queries Focused on queries to start
More informationLecture 3 SQL - 2. Today s topic. Recap: Lecture 2. Basic SQL Query. Conceptual Evaluation Strategy 9/3/17. Instructor: Sudeepa Roy
CompSci 516 Data Intensive Computing Systems Lecture 3 SQL - 2 Instructor: Sudeepa Roy Announcements HW1 reminder: Due on 09/21 (Thurs), 11:55 pm, no late days Project proposal reminder: Due on 09/20 (Wed),
More informationQQ Group
QQ Group: 617230453 1 Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join 2 Generalized Projection Extends the projection operation by allowing arithmetic functions
More informationAfter completing this course, participants will be able to:
Querying SQL Server T h i s f i v e - d a y i n s t r u c t o r - l e d c o u r s e p r o v i d e s p a r t i c i p a n t s w i t h t h e t e c h n i c a l s k i l l s r e q u i r e d t o w r i t e b a
More informationApplied Databases. Sebastian Maneth. Lecture 7 Simple SQL Queries. University of Edinburgh - February 1 st, 2016
Applied Databases Lecture 7 Simple SQL Queries Sebastian Maneth University of Edinburgh - February 1 st, 2016 Outline 2 1. Structured Querying Language (SQL) 2. Creating Tables 3. Simple SQL queries SQL
More informationSQL QUERIES. CS121: Relational Databases Fall 2017 Lecture 5
SQL QUERIES CS121: Relational Databases Fall 2017 Lecture 5 SQL Queries 2 SQL queries use the SELECT statement General form is: SELECT A 1, A 2,... FROM r 1, r 2,... WHERE P; r i are the relations (tables)
More informationQuerying Microsoft SQL Server
Querying Microsoft SQL Server 20461D; 5 days, Instructor-led Course Description This 5-day instructor led course provides students with the technical skills required to write basic Transact SQL queries
More informationCOURSE OUTLINE: Querying Microsoft SQL Server
Course Name 20461 Querying Microsoft SQL Server Course Duration 5 Days Course Structure Instructor-Led (Classroom) Course Overview This 5-day instructor led course provides students with the technical
More information1) Introduction to SQL
1) Introduction to SQL a) Database language enables users to: i) Create the database and relation structure; ii) Perform insertion, modification and deletion of data from the relationship; and iii) Perform
More informationSimple SQL Queries (2)
Simple SQL Queries (2) Review SQL the structured query language for relational databases DDL: data definition language DML: data manipulation language Create and maintain tables CMPT 354: Database I --
More informationNested Queries. Dr Paolo Guagliardo. Aggregate results in WHERE The right way. Fall 2018
Nested Queries Dr Paolo Guagliardo dbs-lecturer@ed.ac.uk Fall 2018 Aggregate results in WHERE The right way Account Number Branch CustID Balance 111 London 1 1330.00 222 London 2 1756.00 333 Edinburgh
More informationSet Operations, Union
Set Operations, Union The common set operations, union, intersection, and difference, are available in SQL. The relation operands must be compatible in the sense that they have the same attributes (same
More informationLecture 6 - More SQL
CMSC 461, Database Management Systems Spring 2018 Lecture 6 - More SQL These slides are based on Database System Concepts book and slides, 6, and the 2009/2012 CMSC 461 slides by Dr. Kalpakis Dr. Jennifer
More informationCarnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview - rel. model. Overview - detailed - SQL
Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications Faloutsos Lecture#6: Rel. model - SQL part1 General Overview - rel. model Formal query languages rel algebra and calculi Commercial
More informationKeys, SQL, and Views CMPSCI 645
Keys, SQL, and Views CMPSCI 645 SQL Overview SQL Preliminaries Integrity constraints Query capabilities SELECT-FROM- WHERE blocks, Basic features, ordering, duplicates Set ops (union, intersect, except)
More informationRAQUEL s Relational Operators
Contents RAQUEL s Relational Operators Introduction 2 General Principles 2 Operator Parameters 3 Ordinary & High-Level Operators 3 Operator Valency 4 Default Tuples 5 The Relational Algebra Operators in
More informationAn Introduction to Structured Query Language
An Introduction to Structured Query Language Grant Weddell Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Winter 2017 CS 348 (Intro to DB Mgmt) SQL
More informationMore SQL. Extended Relational Algebra Outerjoins, Grouping/Aggregation Insert/Delete/Update
More SQL Extended Relational Algebra Outerjoins, Grouping/Aggregation Insert/Delete/Update 1 The Extended Algebra δ = eliminate duplicates from bags. τ = sort tuples. γ = grouping and aggregation. Outerjoin
More informationB.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1
Basic Concepts :- 1. What is Data? Data is a collection of facts from which conclusion may be drawn. In computer science, data is anything in a form suitable for use with a computer. Data is often distinguished
More informationAn Introduction to Structured Query Language
An Introduction to Structured Query Language Grant Weddell David R. Cheriton School of Computer Science University of Waterloo CS 348 Introduction to Database Management Spring 2012 CS 348 (Intro to DB
More information