Simple SQL Queries (2)
|
|
- Brent Ryan
- 6 years ago
- Views:
Transcription
1 Simple SQL Queries (2)
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 -- Simple SQL (2) 2
3 Retrieving Data from a Table What do you want to retrieve from a table? Some tuples (e.g., some customer records, some movies, ) Some attributes about the tuples (e.g., the age, the title, ) Query results are still (conceptual) tables Query results can be used as the sources of other queries A simple and consistent model of data processing CMPT 354: Database I -- Simple SQL (2) 3
4 Queries and Results Name Gender Occupation Age Arbor M Student 23 Bob M Teacher 34 Cindy F Student 18 Daisy F Lawyer 47 Eddy M Doctor 41 Frank M Student 19 Greg M Sales 27 Helen F Police 28 Jenny F Banker 46 CMPT 354: Database I -- Simple SQL (2) 4
5 Queries and Results Name Gender Occupation Age Arbor M Student 23 Bob M Teacher 34 Cindy F Student 18 Daisy F Lawyer 47 Eddy M Doctor 41 Frank M Student 19 Greg M Sales 27 Helen F Police 28 Jenny F Banker 46 CMPT 354: Database I -- Simple SQL (2) 5
6 Queries and Results Name Gender Occupation Age Arbor M Student 23 Bob M Teacher 34 Cindy F Student 18 Daisy F Lawyer 47 Eddy M Doctor 41 Frank M Student 19 Greg M Sales 27 Helen F Police 28 Jenny F Banker 46 Gender Age M 23 F 18 M 19 CMPT 354: Database I -- Simple SQL (2) 6
7 Query Specification Data sources Attributes required Tuples interesting The SELECT-FROM-WHERE structure in SQL The idea has been borrowed by some other query languages, such as XQuery CMPT 354: Database I -- Simple SQL (2) 7
8 Basic Query Structure A typical SQL query has the form select A1, A2,..., An from r1, r2,..., rm where P Ai represents an attribute Ri represents a relation P is a predicate, filtering out unwanted tuples The result of an SQL query is a table CMPT 354: Database I -- Simple SQL (2) 8
9 The SELECT Clause List the attributes desired in the result of a query Example: find the names of all branches in the loan relation: select branch_name from loan SQL names are case insensitive You may use upper- or lower-case letters CMPT 354: Database I -- Simple SQL (2) 9
10 Duplicates SQL allows duplicates in relations and in query results To force the elimination of duplicates, use the keyword distinct or unique after keyword select UNIQUE is not supported in SQL Server 2005 Find the names of all branches in the loan relations, and remove duplicates select distinct branch_name from loan The keyword all specifies that duplicates are not be removed select all branch_name from loan CMPT 354: Database I -- Simple SQL (2) 10
11 Selecting All Attributes and More An asterisk in the select clause select * from loan Arithmetic expressions involving the operation, +,,, and /, and operating on constants or attributes of tuples select loan_number, branch_name, amount * 100 from loan CMPT 354: Database I -- Simple SQL (2) 11
12 The WHERE Clause Specify conditions that the result tuples must satisfy select loan_number from loan where branch_name = Perryridge and amount > 1200 Comparison results can be combined using the logical connectives and, or, and not Comparisons can be applied to results of arithmetic expressions CMPT 354: Database I -- Simple SQL (2) 12
13 Predicate Between Find the loan number of those loans with loan amounts between $90,000 and $100,000 select loan_number from loan where amount between and CMPT 354: Database I -- Simple SQL (2) 13
14 The FROM Clause List the relations involved in the query Find the name, loan number and loan amount of all customers having a loan at the Perryridge branch select customer_name, borrower.loan_number, amount from borrower, loan where borrower.loan_number = loan.loan_number and branch_name = Perryridge Schema borrower (customer_name, loan_number) loan (loan_number, branch_name, amount) CMPT 354: Database I -- Simple SQL (2) 14
15 The Rename Operation Renaming relations and attributes using the as clause old-name as new-name Find the name, loan number and loan amount of all customers; rename the column name loan_number as loan_id select customer_name, borrower.loan_number as loan_id, amount from borrower, loan where borrower.loan_number = loan.loan_number CMPT 354: Database I -- Simple SQL (2) 15
16 Tuple Variables Defined in the from clause via the use of the as clause Find the customer names and their loan numbers for all customers having a loan at some branch select customer_name,t.loan_number,s.amount from borrower as T, loan as S where T.loan_number = S.loan_number from borrower as T, loan as S can be written as from borrower T, loan S in SQL Server CMPT 354: Database I -- Simple SQL (2) 16
17 Using One Table Twice in a Query Find the names of all branches that have greater assets than some branch located in Brooklyn select distinct T.branch_name from branch as T, branch as S where T.assets > S.assets and S.branch_city = Brooklyn CMPT 354: Database I -- Simple SQL (2) 17
18 String Operations The operator like uses patterns that are described using two special characters The % character matches any substring The _ character matches any character Find the names of all customers whose street includes the substring Main select customer_name from customer where customer_street like %Main% How to match the name Main%? like Main\% escape \ CMPT 354: Database I -- Simple SQL (2) 18
19 More on String Operations SQL supports a variety of string operations such as Concatenation (using ) Converting from upper to lower case (and vice versa) Finding string length, extracting substrings, etc. Check them out by yourself CMPT 354: Database I -- Simple SQL (2) 19
20 Ordering the Display of Tuples List in alphabetic order the names of all customers having a loan in Perryridge branch select distinct customer_name from borrower, loan where borrower loan_number = loan.loan_number and branch_name = Perryridge order by customer_name desc for descending order or asc for ascending order, for each attribute Ascending order is the default. Example: order by customer_name desc CMPT 354: Database I -- Simple SQL (2) 20
21 Set Operations The set operations union, intersect, and except operate on relations Each of the above operations automatically eliminates duplicates To retain all duplicates use union all, intersect all and except all Suppose a tuple occurs m times in r and n times in s m + n times in r union all s min(m,n) times in r intersect all s max(0, m n) times in r except all s CMPT 354: Database I -- Simple SQL (2) 21
22 Set Operations Examples Find all customers who have a loan, an account, or both (select customer_name from depositor) union (select customer_name from borrower) Find all customers who have both a loan and an account (select customer_name from depositor) intersect (select customer_name from borrower) Find all customers who have an account but no loan (select customer_name from depositor) except (select customer_name from borrower) CMPT 354: Database I -- Simple SQL (2) 22
23 Basic Aggregate Functions avg: average value min: minimum value max: maximum value sum: sum of values count: number of values CMPT 354: Database I -- Simple SQL (2) 23
24 Aggregate Functions Examples Find the average account balance at the Perryridge branch select avg (balance) from account where branch_name = Perryridge Find the number of tuples in the customer relation select count (*) from customer Find the number of depositors in the bank select count (distinct customer_name) from depositor CMPT 354: Database I -- Simple SQL (2) 24
25 Group By Apply an aggregate function to groups of tuples Each group returns an aggregate value Find the number of depositors for each branch select branch_name, count (distinct customer_name) from depositor, account where depositor.account_number = account.account_number group by branch_name Attributes in select clause outside of aggregate functions must appear in the group by list CMPT 354: Database I -- Simple SQL (2) 25
26 Having Clause Constraints on Groups Selecting groups Find the names of all branches where the average account balance is more than $1,200 select branch_name, avg (balance) from account group by branch_name having avg (balance) > 1200 Predicates in the having clause are applied after the formation of groups Predicates in the where clause are applied before forming groups CMPT 354: Database I -- Simple SQL (2) 26
27 Null Values Predicate is null can be used to check for null values Find all loan number which appear in the loan relation with null values for amount select loan_number from loan where amount is null The result of any arithmetic expression involving null is null Example: 5 + null returns null CMPT 354: Database I -- Simple SQL (2) 27
28 Null Values and 3 Valued Logic Any comparison with null returns unknown Example: 5 < null, null <> null, null = null Three-valued logic using the truth value unknown OR: (unknown or true) = true, (unknown or false) = unknown, (unknown or unknown) = unknown AND: (true and unknown) = unknown, (false and unknown) = false, (unknown and unknown) = unknown NOT: (not unknown) = unknown P is unknown evaluates to true if predicate P evaluates to unknown Result of where clause predicate is treated as false if it evaluates to unknown CMPT 354: Database I -- Simple SQL (2) 28
29 Null Values and Aggregates Total all loan amounts select sum (amount ) from loan Ignore null amounts Result is null if there is no non-null amount All aggregate operations except count(*) ignore tuples with null values on the aggregated attributes Count(*) counts the number of tuples, including those of null values Count(amount) counts the number of tuples of non-null values on amount CMPT 354: Database I -- Simple SQL (2) 29
30 Summary Basic SELECT-FROM-WHERE structure Selecting from multiple tables String operations Set operations Aggregate functions and group-by queries Null values CMPT 354: Database I -- Simple SQL (2) 30
31 To-Do List Check out the string operations available in SQL Server 2005 Use the pubs database, write the following queries, and run them on SQL Server List all titles and the number of authors of each title For each author, find the most expensive title of the author Find all cities and states where there is an author or a publisher CMPT 354: Database I -- Simple SQL (2) 31
Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "
Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Data Definition! Basic Query Structure! Set Operations! Aggregate Functions! Null Values!
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 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 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 informationDATABASE DESIGN I - 1DL300
DATABASE DESIGN I - 1DL300 Fall 2010 An introductory course on database systems http://www.it.uu.se/edu/course/homepage/dbastekn/ht10/ Manivasakan Sabesan Uppsala Database Laboratory Department of Information
More informationDATABASE TECHNOLOGY. Spring An introduction to database systems
1 DATABASE TECHNOLOGY Spring 2007 An introduction to database systems Kjell Orsborn Uppsala Database Laboratory Department of Information Technology, Uppsala University, Uppsala, Sweden 2 Introduction
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 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 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 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 informationThe SQL database language Parts of the SQL language
DATABASE DESIGN I - 1DL300 Fall 2011 Introduction to SQL Elmasri/Navathe ch 4,5 Padron-McCarthy/Risch ch 7,8,9 An introductory course on database systems http://www.it.uu.se/edu/course/homepage/dbastekn/ht11
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 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 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 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 informationDatabase System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "
Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Data Definition! Basic Query Structure! Set Operations! Aggregate Functions! Null Values!
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 2: Relational Model
Chapter 2: Relational Model Database System Concepts, 5 th Ed. See www.db-book.com for conditions on re-use Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations
More informationDatabase System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "
Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Structure of Relational Databases! Fundamental Relational-Algebra-Operations! Additional
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 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 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 informationRelational Algebra. Relational Algebra. 7/4/2017 Md. Golam Moazzam, Dept. of CSE, JU
Relational Algebra 1 Structure of Relational Databases A relational database consists of a collection of tables, each of which is assigned a unique name. A row in a table represents a relationship among
More informationChapter 6: Formal Relational Query Languages
Chapter 6: Formal Relational Query Languages Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 6: Formal Relational Query Languages Relational Algebra Tuple Relational
More informationChapter 5: Other Relational Languages
Chapter 5: Other Relational Languages Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 5: Other Relational Languages Tuple Relational Calculus Domain Relational Calculus
More informationCS 582 Database Management Systems II
Review of SQL Basics SQL overview Several parts Data-definition language (DDL): insert, delete, modify schemas Data-manipulation language (DML): insert, delete, modify tuples Integrity View definition
More informationUpon completion of this Unit, students will be introduced to the following
Instructional Objectives Upon completion of this Unit, students will be introduced to the following The origins of the relational model. The terminology of the relational model. How tables are used to
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 informationOutline. Note 1. CSIE30600 Database Systems More SQL 2
Outline More Complex SQL Retrieval Queries Specifying Constraints as Assertions and Actions as Triggers Views (Virtual Tables) in SQL Schema Change Statements in SQL CSIE30600 Database Systems More SQL
More informationSQL (Structured Query Language)
Lecture Note #4 COSC4820/5820 Database Systems Department of Computer Science University of Wyoming Byunggu Yu, 02/13/2001 SQL (Structured Query Language) 1. Schema Creation/Modification: DDL (Data Definition
More informationOther Query Languages II. Winter Lecture 12
Other Query Languages II Winter 2006-2007 Lecture 12 Last Lecture Previously discussed tuple relational calculus Purely declarative query language Same expressive power as relational algebra Could also
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 informationINF1383 -Bancos de Dados
INF1383 -Bancos de Dados Prof. Sérgio Lifschitz DI PUC-Rio Eng. Computação, Sistemas de Informação e Ciência da Computação A LINGUAGEM SQL Última Parte Group By/Having e Visões Alguns slides são baseados
More informationCS352 - DATABASE SYSTEMS. To give you experience with developing a database to model a real domain
CS352 - DATABASE SYSTEMS Database Design Project - Various parts due as shown in the syllabus Purposes: To give you experience with developing a database to model a real domain Requirements At your option,
More informationTextbook: Chapter 6! CS425 Fall 2013 Boris Glavic! Chapter 3: Formal Relational Query. Relational Algebra! Select Operation Example! Select Operation!
Chapter 3: Formal Relational Query Languages CS425 Fall 2013 Boris Glavic Chapter 3: Formal Relational Query Languages Relational Algebra Tuple Relational Calculus Domain Relational Calculus Textbook:
More informationUNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL)
UNIT III INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) 3.1Data types 3.2Database language. Data Definition Language: CREATE,ALTER,TRUNCATE, DROP 3.3 Database language. Data Manipulation Language: INSERT,SELECT,UPDATE,DELETE
More informationCS352 - DATABASE SYSTEMS
CS352 - DATABASE SYSTEMS Database Design Project - Various parts due as shown in the syllabus Purposes: To give you experience with developing a database to model a real domain At your option, this project
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 informationSimple queries Set operations Aggregate operators Null values Joins Query Optimization. John Edgar 2
CMPT 354 Simple queries Set operations Aggregate operators Null values Joins Query Optimization John Edgar 2 Data Manipulation Language (DML) to Write queries Insert, delete and modify records Data Definition
More informationCSCC43H: Introduction to Databases. Lecture 4
CSCC43H: Introduction to Databases Lecture 4 Wael Aboulsaadat Acknowledgment: these slides are partially based on Prof. Garcia-Molina & Prof. Ullman slides accompanying the course s textbook. CSCC43: Introduction
More informationContents Contents Introduction Basic Steps in Query Processing Introduction Transformation of Relational Expressions...
Contents Contents...283 Introduction...283 Basic Steps in Query Processing...284 Introduction...285 Transformation of Relational Expressions...287 Equivalence Rules...289 Transformation Example: Pushing
More informationOther Relational Query Languages
APPENDIXC Other Relational Query Languages In Chapter 6 we presented the relational algebra, which forms the basis of the widely used SQL query language. SQL was covered in great detail in Chapters 3 and
More informationViews, assertions, and triggers
Views, assertions, and triggers Views are a mechanism for customizing the database; also used for creating temporary virtual tables Assertions provide a means to specify additional constraints Triggers
More informationCSC Web Programming. Introduction to SQL
CSC 242 - Web Programming Introduction to SQL SQL Statements Data Definition Language CREATE ALTER DROP Data Manipulation Language INSERT UPDATE DELETE Data Query Language SELECT SQL statements end with
More informationMore on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan
More on SQL Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan SELECT A1, A2,, Am FROM R1, R2,, Rn WHERE C1, C2,, Ck Interpreting a Query
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 informationCMPT 354: Database System I. Lecture 3. SQL Basics
CMPT 354: Database System I Lecture 3. SQL Basics 1 Announcements! About Piazza 97 enrolled (as of today) Posts are anonymous to classmates You should have started doing A1 Please come to office hours
More informationSQL OVERVIEW. CS121: Relational Databases Fall 2017 Lecture 4
SQL OVERVIEW CS121: Relational Databases Fall 2017 Lecture 4 SQL 2 SQL = Structured Query Language Original language was SEQUEL IBM s System R project (early 1970 s) Structured English Query Language Caught
More informationCSCC43H: Introduction to Databases. Lecture 3
CSCC43H: Introduction to Databases Lecture 3 Wael Aboulsaadat Acknowledgment: these slides are partially based on Prof. Garcia-Molina & Prof. Ullman slides accompanying the course s textbook. CSCC43: Introduction
More informationDatabase System Concepts
s Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth and Sudarshan. Chapter 2: Model Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2009/2010
More informationDatabase Systems CSE Comprehensive Exam Spring 2005
Database Systems CSE 5260 Spring 2005 Database Schema #1 Branch (Branch_Name, Branch_City, Assets) Customer (Customer_Name, SS#, Street, City, State, Zip_Code) Account (Account_Number, Branch_Name, Balance)
More informationOther Query Languages. Winter Lecture 11
Other Query Languages Winter 2006-2007 Lecture 11 Query Languages Previously covered relational algebra A procedural query language Foundation of the Structured Query Language (SQL) Supports wide variety
More information1. (a) Explain the Transaction management in a database. (b) Discuss the Query Processor of Database system structure. [8+8]
Code No: R059210506 Set No. 1 1. (a) Explain the Transaction management in a database. (b) Discuss the Query Processor of Database system structure. [8+8] 2. (a) What is an unsafe query? Give an example
More informationDatabase System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "
Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " SQL Data Types and Schemas! Integrity Constraints! Authorization! Embedded SQL! Dynamic
More informationChapter 5: Other Relational Languages.! Query-by-Example (QBE)! Datalog
Chapter 5: Other Relational Languages! Query-by-Example (QBE)! Datalog 5.1 Query-by by-example (QBE)! Basic Structure! Queries on One Relation! Queries on Several Relations! The Condition Box! The Result
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 informationCS34800 Information Systems. The Relational Model Prof. Walid Aref 29 August, 2016
CS34800 Information Systems The Relational Model Prof. Walid Aref 29 August, 2016 1 Chapter: The Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational
More informationChapter 14: Query Optimization
Chapter 14: Query Optimization Database System Concepts 5 th Ed. See www.db-book.com for conditions on re-use Chapter 14: Query Optimization Introduction Transformation of Relational Expressions Catalog
More informationDatabase Systems. Answers
Database Systems Question @ Answers Question 1 What are the most important directories in the MySQL installation? Bin Executable Data Database data Docs Database documentation Question 2 What is the primary
More informationCMSC 424 Database design Lecture 18 Query optimization. Mihai Pop
CMSC 424 Database design Lecture 18 Query optimization Mihai Pop More midterm solutions Projects do not be late! Admin Introduction Alternative ways of evaluating a given query Equivalent expressions Different
More informationDBMS: AN INTERACTIVE TUTORIAL
DBMS: AN INTERACTIVE TUTORIAL Organized & Prepared By Sharafat Ibn Mollah Mosharraf 12 th Batch (05-06) Dept. of Computer Science & Engineering University of Dhaka Table of Contents INTRODUCTION TO DATABASE
More informationChapter 3: Relational Model
Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational Calculus Extended Relational-Algebra-Operations Modification of the Database
More informationIntegrity and Security
C H A P T E R 6 Integrity and Security This chapter presents several types of integrity constraints, including domain constraints, referential integrity constraints, assertions and triggers, as well as
More informationRelational Database Management Systems for Epidemiologists: SQL Part I
Relational Database Management Systems for Epidemiologists: SQL Part I Outline SQL Basics Retrieving Data from a Table Operators and Functions What is SQL? SQL is the standard programming language to create,
More informationCSIT5300: Advanced Database Systems
CSIT5300: Advanced Database Systems L03: Structured Query Language (SQL) Part 2 Dr. Kenneth LEUNG Department of Computer Science and Engineering The Hong Kong University of Science and Technology Hong
More informationExplain in words what this relational algebra expression returns:
QUIZ: Relational Algebra Explain in words what this relational algebra expression returns: A: The names of all customers who have accounts at both the Downtown and uptown branches 3.1 Practice Exercise
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 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 informationRelational Model. Prepared by: Ms. Pankti Dharwa ( Asst. Prof, SVBIT)
2. Relational Model Prepared by: Ms. Pankti Dharwa ( Asst. Prof, SVBIT) Attribute Types Each attribute of a relation has a name The set of allowed values for each attribute is called the domain of the
More informationDatabase System Concepts
Chapter 14: Optimization Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2007/2008 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth and Sudarshan.
More informationYou can write a command to retrieve specified columns and all rows from a table, as illustrated
CHAPTER 4 S I N G L E - TA BL E QUERIES LEARNING OBJECTIVES Objectives Retrieve data from a database using SQL commands Use simple and compound conditions in queries Use the BETWEEN, LIKE, and IN operators
More informationUNIT 2 RELATIONAL MODEL
UNIT 2 RELATIONAL MODEL RELATIONAL MODEL CONCEPTS The relational Model of Data is based on the concept of a Relation. A Relation is a mathematical concept based on the ideas of sets. The strength of the
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 informationChapter 8: Relational Algebra
Chapter 8: elational Algebra Outline: Introduction Unary elational Operations. Select Operator (σ) Project Operator (π) ename Operator (ρ) Assignment Operator ( ) Binary elational Operations. Set Operators
More informationCPS 510 Data Base I. Query: find all SNRs whose scodes are greater than some SNRs whose name is CB.
11. ANY Query: find all SNRs whose scodes are greater than some SNRs whose name is CB. SQL: SELECT snr FROM s x WHERE scodes > ANY ( SELECT scode FROM s y WHERE y.sname= CB ); snr S2 S4 S5 12. ALL Query:
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 informationUNIT- II (Relational Data Model & Introduction to SQL)
Database Management System 1 (NCS-502) UNIT- II (Relational Data Model & Introduction to SQL) 2.1 INTRODUCTION: 2.1.1 Database Concept: 2.1.2 Database Schema 2.2 INTEGRITY CONSTRAINTS: 2.2.1 Domain Integrity:
More informationDesign Process Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to
Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to Relation Schemas Database Design UML A database can be modeled
More informationOracle Database 11g: SQL and PL/SQL Fundamentals
Oracle University Contact Us: +33 (0) 1 57 60 20 81 Oracle Database 11g: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn In this course, students learn the fundamentals of SQL and PL/SQL
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 informationSQL. Char (30) can store ram, ramji007 or 80- b
SQL In Relational database Model all the information is stored on Tables, these tables are divided into rows and columns. A collection on related tables are called DATABASE. A named table in a database
More informationASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql
ASSIGNMENT NO. 3 Title: Design at least 10 SQL queries for suitable database application using SQL DML statements: Insert, Select, Update, Delete with operators, functions, and set operator. Requirements:
More informationDatabase Languages. A DBMS provides two types of languages: Language for accessing & manipulating the data. Language for defining a database schema
SQL 1 Database Languages A DBMS provides two types of languages: DDL Data Definition Language Language for defining a database schema DML Data Manipulation Language Language for accessing & manipulating
More informationSet theory is a branch of mathematics that studies sets. Sets are a collection of objects.
Set Theory Set theory is a branch of mathematics that studies sets. Sets are a collection of objects. Often, all members of a set have similar properties, such as odd numbers less than 10 or students in
More informationCOMP 244 DATABASE CONCEPTS & APPLICATIONS
COMP 244 DATABASE CONCEPTS & APPLICATIONS Querying Relational Data 1 Querying Relational Data A query is a question about the data and the answer is a new relation containing the result. SQL is the most
More informationCSIE30600/CSIEB0290 Database Systems Relational Algebra and Calculus 2
Outline Relational Algebra Unary Relational Operations Relational Algebra Operations From Set Theory Binary Relational Operations Additional Relational Operations Examples of Queries in Relational Algebra
More informationChapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 4 Basic SQL Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries
More informationCOGS 121 HCI Programming Studio. Week 03 - Tech Lecture
COGS 121 HCI Programming Studio Week 03 - Tech Lecture Housekeeping Assignment #1 extended to Monday night 11:59pm Assignment #2 to be released on Tuesday during lecture Database Management Systems and
More informationLesson 2. Data Manipulation Language
Lesson 2 Data Manipulation Language IN THIS LESSON YOU WILL LEARN To add data to the database. To remove data. To update existing data. To retrieve the information from the database that fulfil the stablished
More informationOutline. CSIE30600 Database Systems Relational Algebra and Calculus 2
Outline Relational Algebra Unary Relational Operations Relational Algebra Operations From Set Theory Binary Relational Operations Additional Relational Operations Examples of Queries in Relational Algebra
More informationQuerying Data with Transact-SQL
Querying Data with Transact-SQL Course: 20761 Course Details Audience(s): IT Professional(s) Technology: Microsoft SQL Server 2016 Duration: 24 HRs. ABOUT THIS COURSE This course is designed to introduce
More informationInformation Systems and Software Systems Engineering (12CFU)
Information Systems and Software Systems Engineering (12CFU) The course is organized in two sections addressing different issues in the design of software systems. Information Systems (6CFU) Software Systems
More informationFull file at
David Kroenke's Database Processing: Fundamentals, Design and Implementation (10 th Edition) CHAPTER TWO INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) True-False Questions 1. SQL stands for Standard
More informationRELATIONAL ALGEBRA. CS121: Relational Databases Fall 2017 Lecture 2
RELATIONAL ALGEBRA CS121: Relational Databases Fall 2017 Lecture 2 Administrivia 2 First assignment will be available today Due next Thursday, October 5, 2:00 AM TAs will be decided soon Should start having
More informationData Manipulation Language (DML)
In the name of Allah Islamic University of Gaza Faculty of Engineering Computer Engineering Department ECOM 4113 DataBase Lab Lab # 3 Data Manipulation Language (DML) El-masry 2013 Objective To be familiar
More informationExample: specific person, company, event, plant
A database can be modeled as: a collection of entities, relationship among entities. An entity is an object that exists and is distinguishable from other objects. Example: specific person, company, event,
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 informationARTICLE RELATIONAL ALGEBRA
ARTICLE ON RELATIONAL ALGEBRA Tips to crack queries in GATE Exams:- In GATE exam you have no need to learn the syntax of different operations. You have to understand only how to execute that operation.
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 information