Database Systems SQL SL03
|
|
- Dulcie Franklin
- 5 years ago
- Views:
Transcription
1 Inf4Oec10, SL03 1/52 M. Böhlen, Informatik für Ökonomen II Fall 2010 Database Systems SQL SL03 Data Definition Language Table Expressions, Query Specifications, Query Expressions Subqueries, Duplicates, Null Values Modification of the Database
2 Inf4Oec10, SL03 2/52 M. Böhlen, Checking Assume R(A) = {(1),(2),(3)}. Write a relational algebra expression that determines the larges value in R. R1 A B R A R2 A B R3 A 3 R1 R ρ (B) (R) R2 σ A<B (R1) R3 R π A (R2)
3 Inf4Oec10, SL03 3/52 M. Böhlen, Checking Identify and fix mistakes in the following relational algebra expressions. Assume a relation with schema R(A,B). σ R.A>5 (R) R.A is not an attribute name. Fix: σ A>5 (R) σ A,B (R) Selection requires predicate. Fix: π A,B (R) R R Name clashes. Fix: ρ T (R ρ S(C,D) (R))
4 Inf4Oec10, SL03 4/52 M. Böhlen, History IBM Sequel language developed as part of System R project at the IBM San Jose Research Laboratory Renamed Structured Query Language (SQL) ANSI and ISO standard SQL: SQL-86 SQL-89 SQL-92 (also called SQL2) entry level: roughly corresponds to SQL-89 intermediate level: half of the new features of SQL-92 full level SQL:2003 (also called SQL3) Commercial systems offer most, if not all, SQL-92 features, plus varying feature sets from later standards and special proprietary features.
5 Inf4Oec10, SL03 5/52 M. Böhlen, Model and Terminology SQL is based on multisets (or bags) rather than sets. In a multiset an element may occur multiple times. SQL uses the terms table, column, and row. Comparison of terminology: SQL Algebra table relation column attribute row tuple query relational algebra expression In SQL there is no distinction between small and capital characters.
6 Inf4Oec10, SL03 6/52 M. Böhlen, Data Definition Language Allows the specification of not information about each table, including: The schema for each table. The domain associated with each column. Integrity constraints that all valid instances must satisfy. The set of indices to be maintained for each table. Security and authorization information for each table. The physical storage structure of each table on disk.
7 Inf4Oec10, SL03 7/52 M. Böhlen, Domain Types in SQL char(n) Fixed length character string, with user-specified length n. varchar(n) Variable length character strings, with user-specified maximum length n. integer Integer (a finite subset of the integers that is machine-dependent). smallint Small integer (a machine-dependent subset of the integer domain type). numeric(p,d) Fixed point number, with user-specified precision of p digits, with n digits to the right of decimal point. real, double precision Floating point and double-precision floating point numbers, with machine-dependent precision. float(n) Floating point number, with user-specified precision of at least n digits.
8 Inf4Oec10, SL03 8/52 M. Böhlen, Create Table Construct An SQL table is defined using the create table command: create table r( A 1 D 1,A 2 D 2,...,A n D n, (integrity-constraint 1 ),..., (integrity-constraint k )) r is the name of the table each Ai is a column name in the schema of table Di is the data type of values in the domain of column A i Example: create table branch( BranchName char(15) not null, branch city char(30), assets integer)
9 Inf4Oec10, SL03 9/52 M. Böhlen, Integrity Constraints in Create Table not null primary key (A 1,...,A n ) Example: Declare BranchName as the primary key for branch create table branch( BranchName char(15), BranchCity char(30), Assets integer, primary key (BranchName)) In SQL a primary key declaration on a column automatically ensures not null.
10 Inf4Oec10, SL03 10/52 M. Böhlen, Drop and Alter Table Constructs The drop table command deletes all information about the dropped table from the database. The alter table command is used to add columns to an existing table: alter table r add A D where A is the name of the column to be added to table r and D is the domain of A. All tuples in the table are assigned null as the value for the new column. The alter table command can also be used to drop columns of a table: alter table r drop A where A is the name of an column of table r Dropping of columns not supported by many databases
11 Inf4Oec10, SL03 11/52 M. Böhlen, Expressions and Predicates Powerful expressions and predicates make computer languages useful and convenient. Database vendors compete on the set of expressions and predicates they offer (functionality as well as speed). In databases the efficient evaluation of predicates is a major concern. Consider a table with 1 billion tuples and the following predicates: LastName = Miller LastName like %mann LastName like Ester% That is one of the reasons why additions of (user defined) functions and predicates to DBMS has been limited. We show some SQL expressions and predicates to give a rough idea of common database functionality.
12 Inf4Oec10, SL03 12/52 M. Böhlen, Structure of SQL Queries/1 SQL is based on relations and relational operations with certain modifications and enhancements. It is used very heavily in the real world. Note that SQL is much more than simple select-from-where queries such as the following: select * from Employee where LName = Bohr Many people Do not understand the concepts of SQL Do not really understand how to work with a declarative language and sets (this requires some practice and getting used to) Underestimate SQL
13 Structure of SQL Queries/2 A typical SQL query has the form: select clause from clause where clause group clause having clause table expression query specification union select clause from clause where clause group clause having clause table expression query specification query expression The result of an SQL query is a (virtual) table. Inf4Oec10, SL03 13/52 M. Böhlen, ifi@uzh
14 Inf4Oec10, SL03 14/52 M. Böhlen, Conceptual Evaluation of SQL Statements 1. Form the cross product of the tables in the from clause 2. Eliminate tuples that do not satisfy the where clause 3. Group the remaining tuples according to the group clause 4. Eliminate groups that do not satisfy the having clause 5. Evaluate the expressions in the select clause 6. One result tuple is produced for each group 7. Eliminate duplicates if distinct is specified 8. Compute query expressions independently and apply set operations (union, excpet, intersect) 9. Sort all result tuples according to order clause
15 Inf4Oec10, SL03 15/52 M. Böhlen, The from Clause The from clause lists the tables involved in the query Corresponds to the Cartesian product operation of the relational algebra. Cartesian product borrower loan from borrower, loan Customer names and loan numbers (all combinations): from borrower as T,loan as S Renaming can become necessary if the same table is used multiple times in the from clause.
16 Inf4Oec10, SL03 16/52 M. Böhlen, The where Clause The where clause specifies conditions that the result tuples must satisfy. The where clause takes the virtual table produced by the from clause and filters out those rows that do not satisfy the condition. Example: loan number of loans from the Perryridge branch with loan amounts greater than $1200. from loan where BraName = Perryridge and Amount > 1200 LoanNum BraName Amount L-260 Perryridge 1700 The where clause corresponds to the selection predicate. In SQL predicates can be combined using the logical connectives and, or, and not. The where clause can be used to specify join and selection conditions.
17 Inf4Oec10, SL03 17/52 M. Böhlen, The group Clause The group clause takes the table produced by the where clause and returns a grouped table. The group clause groups multiple tuples together. Conceptually, grouping yields multiple tables. Example: Accounts grouped by branch. from account group by BrName account AccNr BrName Balance A-101 Downtown 500 A-215 Perryridge 700 A-102 Perryridge 400 A-305 Perryridge 350 A-222 Perryridge 700 A-201 Brighton 900 A-217 Brighton 750
18 Inf4Oec10, SL03 18/52 M. Böhlen, The having Clause/1 The having clause takes a grouped table as input and returns a grouped table. The having condition is applied to each group. Only groups that fulfill the condition are returned. The having clause never returns individual tuples of a group. The having condition may include grouping columns or aggregated columns.
19 Inf4Oec10, SL03 19/52 M. Böhlen, The having Clause/2 Consider branches with more than one account only: from account group by BrName having count(accnr) > 1 This having clause returns all groups with more than one tuple: account AccNr BrName Balance A-215 Perryridge 700 A-102 Perryridge 400 A-305 Perryridge 350 A-222 Perryridge 700 A-201 Brighton 900 A-217 Brighton 750
20 Inf4Oec10, SL03 20/52 M. Böhlen, The select Clause/1 The select clause lists the columns that shall be in the result of a query. corresponds to the projection operation of the relational algebra Example: find the names of all branches in the loan table: select BraName from loan In the relational algebra, the query would be: π BraName (loan)
21 Inf4Oec10, SL03 21/52 M. Böhlen, The select Clause/2 SQL allows duplicates in tables as well as in query results. To force the elimination of duplicates, insert the keyword distinct after select. Find the names of all branches in the loan tables, and remove duplicates select distinct BraName from loan A * in the select clause denotes all columns select * from loan
22 Inf4Oec10, SL03 22/52 M. Böhlen, The select Clause/3 In the select clause aggregate functions can be used. avg: average value min: minimum value max: maximum value sum: sum of values count: number of values The aggregate functions operate on multiple rows. They process all rows of a group and compute an aggregated value for that group. Note: Columns in select clause outside of aggregate functions must appear in group by list
23 Inf4Oec10, SL03 23/52 M. Böhlen, The select Clause/4 Find the average account balance at the Perryridge branch. select avg(balance) from account where BrName = Perryridge Find the number of tuples in the customer table. select count( ) from customer Find the number of accounts per branch. select count(accnr), BrName from account group by BrName
24 Inf4Oec10, SL03 24/52 M. Böhlen, Checking Identify problem of the following SQL statements. Propose a fix. Determine for each branch where the largest balance is at least 500 the largest balance. select max(balance), BrName from account where max(balance) > 500 group by BrName The where clause does not permit aggregates (it filters tuples) select max(balance), BrName from account group by BrName having max(balance) > 500
25 Inf4Oec10, SL03 25/52 M. Böhlen, Checking Identify problem of the following SQL statements. Determine for each branch the account with the largest balance. select max(balance), AccNr, BrName from account group by BrName account AccNr BrName Balance A-101 Downtown 500 A-215 Perryridge 700 A-102 Perryridge 400 A-305 Perryridge 350 A-222 Perryridge 700 A-201 Brighton 900 A-217 Brighton 750 In the select clause only aggregates or grouped columns are allowed. The reason for this constraint is that exactly one tuple per group shall be computed. The above query must be solved with a subquery.
26 Inf4Oec10, SL03 26/52 M. Böhlen, SQL so far SQL versus relational algebra: SQL Algebra table relation column attribute row tuple query relational algebra expression A query specification in SQL has the following form: select clause from clause where clause group clause having clause table expression query specification
27 Inf4Oec10, SL03 27/52 M. Böhlen, Illustration of Evaluation of SQL Statements/1 1. FROM: form the cross product of the tables in the from clause FROM WHERE: eliminate tuples that do not satisfy the where clause... WHERE 3. GROUP BY: group tuples according to the group clause GROUP BY
28 Inf4Oec10, SL03 28/52 M. Böhlen, Illustration of Evaluation of SQL Statements/2 4. HAVING: eliminate groups that do not satisfy the having clause HAVING 5. SELECT: evaluate the expressions in the select clause and produce one result tuple for each group SELECT
29 Inf4Oec10, SL03 29/52 M. Böhlen, Query Expressions/1 The set operations union, intersect, and except operate on tables and correspond to the relational algebra operations,, Each of the above operations automatically eliminates duplicates; to retain all duplicates use the corresponding multiset versions union all, intersect all, and except all. Suppose a tuple occurs m times in r and n times in s, then, it occurs: 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
30 Inf4Oec10, SL03 30/52 M. Böhlen, Query Expressions/2 Find all customers who have a loan, an account, or both: (select CuName from depositor) union (select CstName from borrower) Find all customers who have both a loan and an account: (select CuName from depositor) intersect (select CstName from borrower) Find all customers who have an account but no loan: (select CuName from depositor) except (select CstName from borrower)
31 Inf4Oec10, SL03 31/52 M. Böhlen, Subqueries/1 SQL provides a mechanism for the nesting of subqueries. A subquery is a query expression that is nested within another query expression. A common use of subqueries is to perform tests for set membership, set comparisons, and set cardinality.
32 Inf4Oec10, SL03 32/52 M. Böhlen, Subqueries/2 Find all customers who have both an account and a loan at the bank. select distinct CstName from borrower where CstName in (select CuName from depositor) Find all customers who have a loan at the bank but do not have an account at the bank select distinct CstName from borrower where CstName not in (select CuName from depositor)
33 Inf4Oec10, SL03 33/52 M. Böhlen, Subqueries/3 Find all customers who have both an account and a loan at the Perryridge branch select distinct CstName from borrower, loan where borrower.loanno = loan.loannr and BraName = Perryridge and (BraName, CstName) in ( select BrName, CuName from depositor, account where depositor.accnr = account.accnr)
34 Inf4Oec10, SL03 34/52 M. Böhlen, Subqueries/4 Comparing sets: Find all branches that have greater assets than some branch located in Brooklyn. select distinct T.BranchName from branch as T,branch as S where T.Assets > S.Assets and S.BranchCity = Brooklyn Same query using > some clause select BranchName from branch where Assets > some (select Assets from branch where BranchCity = Brooklyn )
35 Inf4Oec10, SL03 35/52 M. Böhlen, Subqueries/5 F <comp> some r t r such that (F <comp> t) Where <comp> can be: <,,>,=, (5 < some ) = true (read: 5 < some tuple in the table) (5 < some 0 5 ) = false (5 = some 0 5 ) = true (5 some 0 5 ) = true (since 0 5) (= some) in However, ( some) not in
36 Inf4Oec10, SL03 36/52 M. Böhlen, Subqueries/6 Find the names of all branches that have greater assets than all branches located in Brooklyn. select BranchName from branch where assets > all (select assets from branch where BranchCity = Brooklyn )
37 Inf4Oec10, SL03 37/52 M. Böhlen, Subqueries/7 F <comp> all r t r (F <comp> t) (5 < all ) = false (5 < all (5 = all 6 10 ) = true 4 5 ) = false (5 all 4 6 ) = true (since 5 4 and 5 6) ( all) not in However, (= all) in
38 Inf4Oec10, SL03 38/52 M. Böhlen, Subqueries/8 The exists construct returns the value true if the argument subquery is nonempty. exists r r not exists r r = The exists (and not exists) subqueries are used frequently in SQL. Avoid in, all, any, some and use exists instead.
39 Inf4Oec10, SL03 39/52 M. Böhlen, Subqueries/9 Find all customers who have an account at all branches located in Brooklyn. select distinct S.CuName from depositor as S where not exists ( (select BranchName from branch where BranchCity = Brooklyn ) except (select R.BrName from depositor as T, account as R where T.AccNr = R.AccNr and S.CuName = T.CuName)) Note that X Y = X Y Note: Cannot write this query using = all and its variants
40 Inf4Oec10, SL03 40/52 M. Böhlen, Derived Tables SQL allows a subquery expression to be used in the from clause. That is important for orthogonality of a language. A derived table is defined by a query expression. Find the average account balance of those branches where the average account balance is greater than $1200. select BranchName, AvgBalance from (select BrName, avg(balance) from account group by account) as BranchAvg(BranchName, AvgBalance) where AvgBalance > 1200
41 Inf4Oec10, SL03 41/52 M. Böhlen, Duplicates/1 In tables with duplicates, SQL can define how many copies of tuples appear in the result. Multiset versions of some of the relational algebra operators - given multiset relations r 1 and r 2 : 1. σ b θ (r 1): If there are c 1 copies of tuple t 1 in r 1, and t 1 satisfies selections σ θ, then there are c 1 copies of t 1 in σ b θ(r 1 ). 2. π b A (r 1): For each copy of tuple t 1 in r 1, there is a copy of tuple π A (t 1 ) in π b A (r 1) where π A (t 1 ) denotes the projection of the single tuple t r 1 b r 2 : If there are c 1 copies of tuple t 1 in r 1 and r 2 copies of tuple t 2 in r 2, there are c 1 c 2 copies of the tuple t 1, t 2 in r 1 b r 2
42 Inf4Oec10, SL03 42/52 M. Böhlen, Duplicates/2 Example: Suppose multisets r 1 (A,B) and r 2 (C) are as follows: r 1 = {(1,a) (2,a)} r 2 = {(2), (3), (3)} Then π b B (r 1) would be {(a),(a)}, while π b B (r 1) r 2 would be SQL duplicate semantics: {(a,2), (a,2), (a,3), (a,3), (a,3), (a,3)} select A 1,A 2,...,A n from r 1,r 2,...,r m where P is equivalent to the multiset expression: π b A 1,A 2,...,A n (σ b P(r 1 b r 2 b... b r m ))
43 Inf4Oec10, SL03 43/52 M. Böhlen, Null Values/1 It is possible for tuples to have a null value, denoted by null, for some of their columns null signifies an unknown value or that a value does not exist. The predicate is null can be used to check for null values. Example: Find all loan number which appear in the loan relation with null values for Amount. select LoanNr from loan where Amount is null The result of any arithmetic expression involving null is null Example: 5+null returns null However, aggregate functions simply ignore nulls More on next slide
44 Inf4Oec10, SL03 44/52 M. Böhlen, Null Values/2 Any comparison with null returns unknown Example: 5 < null or null <> null or null = null Three-valued logic using the truth value unknown: OR AND NOT (unknown or true) = true, (unknown or false) = unknown (unknown or unknown) = unknown (true and unknown) = unknown, (false and unknown) = false (unknown and unknown) = unknown (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
45 Inf4Oec10, SL03 45/52 M. Böhlen, Null Values/3 Total all loan amounts select count(amount) from loan Above statement ignores null amounts Result is 0 if there is no non-null amount All aggregate operations, except count(*), ignore tuples with null values on the aggregated columns.
46 Inf4Oec10, SL03 46/52 M. Böhlen, Ordering the Display of Tuples List in alphabetic order the names of all customers having a loan in Perryridge branch select distinct CstName from borrower, loan where borrower.loanno = loan.loannr and BraName = Perryridge order by CstName We may specify desc for descending order or asc for ascending order, for each column; ascending order is the default. Example: order by CustName desc
47 Inf4Oec10, SL03 47/52 M. Böhlen, Deletions/1 Delete all account tuples at the Perryridge branch delete from account where BrName = Perryridge Delete all accounts at every branch located in the city Needham delete from account where BrName in (select BranchName from branch where BranchCity = Needham )
48 Inf4Oec10, SL03 48/52 M. Böhlen, Insertions/1 Add a new tuple to account insert into account values ( A 9732, Perryridge,1200) or equivalently insert into account(brname, Balance, AccNr) values ( Perryridge,1200, A 9732 ) Add a new tuple to account with balance set to null insert into account values ( A 9732, Perryridge,null)
49 Inf4Oec10, SL03 49/52 M. Böhlen, Updates/1 Increase all accounts with balances over $10,000 by 6%, all other accounts receive 5%. Write two update statements: update account set Balance = Balance 1.06 where Balance > update account set Balance = Balance 1.05 where Balance The order is important Can be done better with a single update statement that uses a case statement.
50 Inf4Oec10, SL03 50/52 M. Böhlen, Summary/1 DDL (data definition language) Used to create, alter, and drop tables. Table definitions include constraints (domain, not null, primary key, foreign key). Constraints ensure data quality, which in turn gives competitive advantages to businesses. Enforcing constraints is difficult and requires a focused effort. Data quality must be considered during data acquisition; the database system must enforce it; it cannot be fixed later. Expressions and predicates Database systems have been conservative since the efficient evaluation must be considered. The brute force evaluation of a condition on one billion tuples might not be good enough. Modern database systems are extensible with user defined functions.
51 Inf4Oec10, SL03 51/52 M. Böhlen, Summary/2 SQL SQL is used very heavily in practice; the intergalactic data speak [Michael Stonebraker]. The building block of the DML are query specifications and query expressions. SQL is more than simple select-from-where. The set based semantics of SQL requires some practice. Know the conceptual evaluation/semantics of query expressions. Form the cross product of the tables in the from clause Eliminate tuples that do not satisfy the where clause Group the remaining tuples according to the group clause Eliminate groups that do not satisfy the having clause Evaluate the expressions in the select clause With aggregation one result tuple is produced for each group Eliminate duplicates if distinct is specified Compute query expressions independently and apply set operations (union, excpet, intersect) Sort all result tuples of order clause is specified
52 Inf4Oec10, SL03 52/52 M. Böhlen, Summary/3 The difference between set and multisets (or bags) is relevant. Subqueries are natural and help the understanding; it is possible (and advisable) to only use exists and not exists. The SQL OLAP extensions (cf. Data Warehouse course) further extend SQL to better support report generation (cross tabs, moving averages, etc).
Database 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 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 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 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 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 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 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 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 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 - 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 informationCS425 Fall 2017 Boris Glavic Chapter 4: Introduction to SQL
CS425 Fall 2017 Boris Glavic Chapter 4: Introduction to SQL Modified from: Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 4: Introduction to SQL Overview of the
More informationOutline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2
Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features of SQL Textbook Chapter 6 CSIE30600/CSIEB0290
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 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 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 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 informationCSIE30600 Database Systems Basic SQL 2. Outline
Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features of SQL CSIE30600 Database Systems
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 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 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 informationChapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement
Chapter 4 Basic SQL Basic SQL SQL language Considered one of the major reasons for the commercial success of relational databases SQL Structured Query Language Statements for data definitions, queries,
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 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 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 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 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 informationChapter 12: Query Processing
Chapter 12: Query Processing Overview Catalog Information for Cost Estimation $ Measures of Query Cost Selection Operation Sorting Join Operation Other Operations Evaluation of Expressions Transformation
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 informationSQL - Basics. SQL Overview
SQL - Basics Davood Rafiei 1 SQL Overview Structured Query Language standard query language for relational system. developed in IBM Almaden (system R) Some features Declarative: specify the properties
More informationSlides by: Ms. Shree Jaswal
Slides by: Ms. Shree Jaswal Overview of SQL, Data Definition Commands, Set operations, aggregate function, null values, Data Manipulation commands, Data Control commands, Views in SQL, Complex Retrieval
More informationCopyright 2016 Ramez Elmasri and Shamkant B. Navathe
CHAPTER 6 Basic SQL Slide 6-2 Chapter 6 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features
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 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 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 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 Introduction SL01
Inf4Oec10, SL01 1/58 M. Böhlen, ifi@uzh Informatik für Ökonomen II Fall 2010 Database Systems Introduction SL01 Database Systems (5 weeks, Prof. Dr. M. Böhlen) Software Engineering (5 weeks, Prof. Dr.
More informationDatabase Management System 11
Database Management System 11 School of Computer Engineering, KIIT University 11.1 Language in which user requests information from the database are: Procedural language Nonprocedural language The categories
More informationCMP-3440 Database Systems
CMP-3440 Database Systems Relational DB Languages Relational Algebra, Calculus, SQL Lecture 05 zain 1 Introduction Relational algebra & relational calculus are formal languages associated with the relational
More informationBasant Group of Institution
Basant Group of Institution Visual Basic 6.0 Objective Question Q.1 In the relational modes, cardinality is termed as: (A) Number of tuples. (B) Number of attributes. (C) Number of tables. (D) Number of
More informationMahathma Gandhi University
Mahathma Gandhi University BSc Computer science III Semester BCS 303 OBJECTIVE TYPE QUESTIONS Choose the correct or best alternative in the following: Q.1 In the relational modes, cardinality is termed
More informationChapter 14 Query Optimization
Chapter 14 Query Optimization Chapter 14: Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming
More informationChapter 14 Query Optimization
Chapter 14 Query Optimization Chapter 14: Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming
More informationChapter 14 Query Optimization
Chapter 14: Query Optimization Chapter 14 Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming
More informationCSEN 501 CSEN501 - Databases I
CSEN501 - Databases I Lecture 5: Structured Query Language (SQL) Prof. Dr. Slim slim.abdennadher@guc.edu.eg German University Cairo, Faculty of Media Engineering and Technology Structured Query Language:
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 informationSQL. CS 564- Fall ACKs: Dan Suciu, Jignesh Patel, AnHai Doan
SQL CS 564- Fall 2015 ACKs: Dan Suciu, Jignesh Patel, AnHai Doan MOTIVATION The most widely used database language Used to query and manipulate data SQL stands for Structured Query Language many SQL standards:
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 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 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 informationChapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel
Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel 1 In this chapter, you will learn: The basic commands
More informationOverview of Query Processing and Optimization
Overview of Query Processing and Optimization Source: Database System Concepts Korth and Silberschatz Lisa Ball, 2010 (spelling error corrections Dec 07, 2011) Purpose of DBMS Optimization Each relational
More informationRelational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.
COSC 304 Introduction to Database Systems Relational Model and Algebra Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was
More informationDATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400)
1 DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400) Spring 2008 An introductury course on database systems http://user.it.uu.se/~udbl/dbt-vt2008/ alt. http://www.it.uu.se/edu/course/homepage/dbastekn/vt08/
More informationIan Kenny. November 28, 2017
Ian Kenny November 28, 2017 Introductory Databases Relational Algebra Introduction In this lecture we will cover Relational Algebra. Relational Algebra is the foundation upon which SQL is built and is
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 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 informationApplied Databases. Sebastian Maneth. Lecture 7 Simple SQL Queries. University of Edinburgh - February 6 st, 2017
Applied Databases Lecture 7 Simple SQL Queries Sebastian Maneth University of Edinburgh - February 6 st, 2017 Outline 2 1. Structured Querying Language (SQL) 2. Creating Tables 3. Simple SQL queries SQL
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 informationRelational Database: The Relational Data Model; Operations on Database Relations
Relational Database: The Relational Data Model; Operations on Database Relations Greg Plaxton Theory in Programming Practice, Spring 2005 Department of Computer Science University of Texas at Austin Overview
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 STRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGE SQL Structured Query Language 4.1 Introduction Originally, SQL was called SEQUEL (for Structured English QUery Language) and implemented at IBM Research as the interface for an
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 information2.2.2.Relational Database concept
Foreign key:- is a field (or collection of fields) in one table that uniquely identifies a row of another table. In simpler words, the foreign key is defined in a second table, but it refers to the primary
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 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 information2.3 Algorithms Using Map-Reduce
28 CHAPTER 2. MAP-REDUCE AND THE NEW SOFTWARE STACK one becomes available. The Master must also inform each Reduce task that the location of its input from that Map task has changed. Dealing with a failure
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 informationBasic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation
Basic SQL Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation MIDTERM EXAM 2 Basic
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 information