Database Theory, Fall Semester MMXV: Week #3
|
|
|
- Shanon Byrd
- 10 years ago
- Views:
Transcription
1 Database Theory, Fall Semester MMXV: Week #3 Any Questions on anything from last week? Which relational operators did I call basic? Why did I distinguish between basic and defined operators? If you haven t handed in homework 1 yet, bring it to the front of the room now! More defined relations: Joins. A. Natural Joins (operator written ): 1. Consider again Section: Dept Crs# Sect Smstr Yr Instr Registration: Stdnt# Dept Crs# Sect Smstr Yr Grade 2. Registration Section is a relation with 13 attributes, listing every possible pair of registration data and section data. Estimate #tuples for UC with 10 years data. 3. Often don t want tuples for unmatched courses! The common attributes in the 2 relations are Dept, Crs#, Sect, Smstr, and Yr. The natural join of the 2 relations is like the Cartesian product, but it picks only the tuples where the values of those attributes are the same in both relations, and it stores only one copy of those attributes in the result. 4. So Registration Section has just 8 attributes. Stdnt# Dept Crs# Sect Smstr Yr Grade Instr 1
2 It lists all courses all students are registered for, their grades, and the instructors of those courses. 5. How do you define R S using only basic operators? 6. Why do we choose to use natural joins in SQL? (a) Easier to program don t need to do all that renaming & selection! (b) Easier for someone else to understand the program! (c) SQL implementations typically have special logic to compute joins without doing the renaming and forming the full Cartesian products avoiding creating some huge intermediate tables. B. Theta Joins: Read in book. We won t discuss them or use them in class. There are other variants of joins too. We won t discuss them here either, but if you do a lot of SQL programming you ll want to explore them. 2
3 More Examples: Write queries to answer the following questions, using natural joins (and perhaps other operators) for the schema Student(LastName, FirstName, Student#, Class, Major) Course(CrsName, Dept, Crs}, CredHrs) Section(Dept, Crs#, Sect, Smstr, Yr, Instr) Registration (Student#, Dept, Crs#, Sect, Smstr, Yr, Grade) 1. Give names (first and last) of all students who have ever taken a class not taught by Professor Schlipf. 2. Give names (first and last) of all pairs of students who have ever been in a class together. 3. Give names (first and last) of all (lucky?) students who have never taken a class taught by Professor Schlipf. 3
4 Nastier examples on enlarged Schema: Student: LastName FirstName Student# Class Major Course: CrsName Dept Crs# CredHrs Section: Dept Crs# Sect Smstr Yr Instr Registration: Student# Dept Crs# Sect Smstr Yr Grade Prerequisite: Dept Crs PrereqDept# PrereqCrs 1. List all pairs of students who have taken classes from exactly the same professors. 2. List those students by name. 3. List all tuples (Stdnt#, Dept, Crs# where the student is currently taking the course but has not passed ( ) one of its prerequisites. 4. List those students and courses by name rather than by number. 4
5 Aside: Monotonicity. A relational database schema D, A set of constraints Q All possible relational databases R for D and Q all possible relations for those relation schemas obeying the constraints. Notation: For Q a query in relational database schema D and R a relational database for D, Q(R) is the answer Q over R i.e., (in relational algebra terms), the value of expression Q evaluated over database R. Definition: A query Q is monotonic if, whenever R 1 R 2, Q(R 1 ) Q(R 2 ), i.e., we cannot delete any tuples from the answer by simply adding tuples to the database. Theorem: Every relational algebra query whose only operators are,, π, σ,, and ρ is monotonic. Practical Consequence: You re going to have to use, probably more often than you d at first expect, when you write queries. This is especially frequent when the English statement involves words like every and not. In particular, putting a NOT into the condition for selection often won t get you what you want. 5
6 DATALOG translation of all this: 1. I shall do all the syntax in terms of the system clingo. 2. To make the programming easier, we ll concatenate, into 1 big file, original database ( facts, or extensional database, or EDB ), queries ( rules, or intensional database, or IDB ), 3. Running: In UNIX/LINUX/MAC) clingo file.lp. Output is to the screen. Try it as soon as you can. Output SATISFIABLE says queries can all be answered. Later you ll see ways to get UNSATISFIABLE. 4. The Extensional Database EDB : List all tuples in all relations the facts. (abbreviations to fit more on one line in this font) stdnt("palooka", "Joe", "MD1234", 3, english). stdnt("warbucks", "Annie", "MD7654", 1, mngmnt). course("database Theory", cs, 6051, 3). course("history of Comics", engl, 227, 3). sect(cs, 6051, 1, fall, 2015, "Schlipf"). regstr("md1234", cs, 6051, 1, fall, 2015, "N"). Notes: (a) Identify attributes by position, not by attribute name. (b) Prolog format: Variable symbols start in upper case. Everything else (except constants inside quotation marks) is in lower case. (c) Period (. ) at the end of every fact. (d) As with Prolog, if you also write stdnt( palooka, joe, english, 3), with 4 argument places instead of 5, this stdnt is treated as just a different relation! Don t do that in this class! 6
7 5. The Intentional Database IDB: Rules defining additional relations or giving constraints. hastaken(fname, LName, StdntNo, Dept, Crs) :- regstr(stdntno, Dept, Crs, Sect, Smstr, Yr, Gr), stdnt(lname, FName, StdntNo, ProgYr, Major). mystery(fname, LName, StdntNo, Dept, Crs) :- regstr(stdntno, Dept, Crs, Sect, Smstr, Yr, Gr), stdnt(lname, FName, StdntNo, ProgYr, Major), LName < Major, ProgYr > 2. mystery2(fname, LName, StdntNo, Dept, Crs) :- regstr(stdntno, Dept, Crs, Sect, Smstr, Yr, Gr), stdnt(lname, FName, StdntNo, ProgYr, Major), not stdnt(smstr, Yr, Gr, ProgYr, Major). Notes: (a) Definition: Rule: A statement with a :- symbol. (But some people use the word rule to include facts too.) (b) Period at the end of each rule. (c) The comma at the end of line 2 means and. (d) Vocabulary: head body s(x,y) :- r(x,y,z), q(z,a,x) Z>17. (positive) relational subgoal) (e) Interpretation of :-: if the body is true, the head is too. Semantics: define hastaken to be the set of all tuples (FName, LName, StdntNo, Dept, Crs) where, for some rule with hastaken it its head, and for for some of attribute values for the variables, the rule body is true in the database ( negation by failure ). 7
8 (f) Look at the first rule: hastaken(fname, LName, StdntNo, Dept, Crs) :- regstr(stdntno, Dept, Crs, Sect, Smstr, Yr, Gr), stdnt(lname, FName, StdntNo, ProgYr, Major). Several variable names, e.g., Gr and Major, appear in the body but not in the head. The result is like a projection. (g) Also in that rule: I use the same variable symbol StdntNo in lines 2 and 3. That means that I m looking for tuples in regstr and stdnt where the first attribute from regstr is the same as the third attribute value from stdnt. Thus it s similar to a natural join but regulated by common variable name in the rule (h) Scope of a variable symbol is one rule so, for example, in each rule, each occurrence of FName must be interpreted by the same string. The implication is to consider this inference rule for each possible choice of values for the variables. The choices for these values are anything explicitly mentioned in the program e.g., Palooka, 3, or cs. 8
9 (i) DATALOG : not can be applied to subgoals in the body. tuitionproblycvrd(stdnt, Dpt, Crs, Sec, Smst, Yr) :- regstr(stdnt, Dpt, Crs, Sec, Smstr, Yr, Gr), onugs(stdnt,smstr,yr), Crs >= 6000, not (Smstr == "summer"), not oweslibraryfine(stdnt). (j) Safety Rule: Every variably symbol appearing anywhere in a rule must appear in one of the positive relational subgoals. Why that restriction? Related: why relational algebra has a difference operator ( ) but not a complemenet. Consider an unsafe rule prblycvrtuit(stdnt, Dpt, Crs, Sec, Smst, Yr) :- regstr(stdnt, Dpt, Crs, Sec, Smstr, Yr, Gr), onugs(stdnt,smstr,yr), Crs >= 6000, not (Smstr == "summer"), not oweslibraryfine(stdnt2), Who is Stdnt2? It looks as if I m asking clingo to consider infinitely many things. Restricting where Stdnt2 came from also helps us ensure adding irrelevant facts (and constants thus new objects) doesn t change meaning of program. Challenge: find what other anomalies could occur if, say Stdnt2 also appeared in the head of the rule? 9
10 (k) Recursive programs: Direct positive recursion: r(x,y) :- s(x), s(y), X<Y. r(x,y) :- t(x,z), r(y,z). Indirect positive recursion: r(x,y) :- s(x), s(y), X<Y. r(x,y) :- a(x,y), s(x), s(y), X<Y. a(x,y) :- t(x,z), r(y,z), not q(z). Negative recursion: r(x,y) :- s(x), s(y), X<Y. r(x,y) :- a(x,y), s(x), s(y), X<Y. a(x,y) :- t(x,z), r(y,z), not q(z). q(z) :- r(x,z). q(z) :- a(z,x). i. For now, we ll be concerned with non-recursive programs. ii. Adding recursion lets us define relations that are not definable in relational algebra. Standard Example: Transitive closures. ancestorof(x,y) :- fatherof(x,y). ancestorof(x,y) :- motherof(x,y). ancestorof(x,z) :- ancestorof(x,y), ancestorof(y,z). iii. Recursion where some of the recursion is through negative subgoals (negative recursion) is more complicated than positive recursion. 10
11 Upcoming Theorem: The queries we can state in relational algebra are exactly the same as the queries we can state in non-recursive DATALOG. Work Through Example: Facts: stdnt("palooka", "Joe", md , 3, english). stdnt("warbcks", "Annie", md , 1, management). stdnt("twist", "Oliver", md , 4, cs). stdnt("heap", "Uriah", md , 2, cs). stdnt("jahan", "Shah", md , 6, history). stdnt("mahal", "Mumtaz", md , 6, cs). course("database Theory", cs, 6051, 3). course("history of Comics", engl, 2027, 3). course("data Structures", cs, 2028, 4). course("software Engineering", eece, 4095, 4). course("ai", cs, 6033, 3). course("info Retrieval", cs, 6054, 3). course("adv. Algorithms I", cs, 7081, 3). course("russian Empire", hist, 7021, 3). sched(cs, 6051, 001, fall, 2015, "Schlipf"). sched(engl, 2027, 067, spring, 2015, "Capp"). sched(cs, 6051, 001, fall, 2015, "Hamad"). sched(cs, 6054, 001, fall, 2015, "Cheng"). sched(cs, 7081, 001, fall, 2015, "Berman"). regist(md , cs, 6051, 001, fall, 2015, "N"). regist(md , cs, 6051, 001, fall, 2015, "N"). regist(md , engl, 2027, 067, spring, 2015, "B-"). regist(md , hist, 7021, 001, spring, 2015, "A"). prereq4(hist, 7021, cs, 1021). prereq4(cs, 7081, cs, 6051). 11
12 Query: Names of students currently now both cs 7890 and engl 7890 weird(lname, FName) :- stdnt(lname,fname, Mnmbr, Year, Major), regist(mnmbr, cs, 7890, SectNo, fall, 2015, Grd), regist(mnmbr, engl, 7890, SectNo, fall, 2015, Grd). Query: Names of students currently now cs 7890 or engl 7890 ambitious(lname, FName) :- stdnt(lname,fname, Mnmbr, Year, Major), regist(mnmbr, cs, 7890, SectNo, fall, 2015, Grd). ambitious(lname, FName) :- stdnt(lname,fname, Mnmbr, Year, Major), regist(mnmbr, engl, 7890, SectNo, fall, 2015, Grd). Query: Names of students who have taken both cs 7890 and engl 7890 since 2010 semiweird(lname, FName) :- stdnt(lname,fname, Mnmbr, Year, Major), regist(mnmbr, cs, 7890, SectNo, Smstr1, Yr1, Grd), Yr1 >= 2010, regist(mnmbr, engl, 7890, SectNo, Smstr2, Yr2, Grd), Yr2 >= Query: Order all the semesters in registration history by time. (I pretend all UC classes were in fall, spring, or summer semesters and assume all 3 semesters were offered each year UC existed.) earliersmstr(smstr1, Yr1, Smstr2, Yr2) :- regist(mn1, D1, CN1, SN1, Smstr1, Yr1, G1), regist(mn2, D2, CN2, SN2, Smstr2, Yr2, G2), Yr1 < Yr2. earliersmstr(spring, Yr, summer, Yr) :- regist(mn, D, CN, SN, Smstr, Yr, G1). earliersmstr(summer, Yr, fall, Yr) :- regist(mn, D, CN, SN, Smstr, Yr, G1). earliersmstr(spring, Yr, fall, Yr) :- regist(mn, D, CN, SN, Smstr, Yr, G1). 12
13 Query: All pairs of students who have taken exactly the same courses (but possibly not the same semester or the same section). hasevertaken(stdnt,dpt,crs) :- regist(stdnt, Dpt, Crs, _, _, _, _). hasevertakenmore(stdnt1,stdnt2) :- hasevertaken(stdnt1, Dpt, Crs), not hasevertaken(stdnt2, Dpt,Crs). mnmbrused(stdnt) :- stdnt (_, _, Stdnt, _, _). havetakensamecourses(stdnt1, Stdnt2) :- mnmbrused(stdnt1), mnmbrused(stdnt2), not hastakenmore(stdnt1, Stdnt2), not hastakenmore(stdnt2, Stdnt1). A Simple Constraint: We may not have 2 students with the same number. The only way we can interpret this is to say that if 2 students have the same student number, they must be identical in everything else except, possibly, major. A blank to the left of the :- symbol means infer false i.e., the rule body must be false. :- stdnt (LName1, _, Mnmbr, _, _), stdnt(lname2, _, Mnmbr, _, _), LName1!= LName2. :- stdnt (_, FName1, Mnmbr, _, _), stdnt(_, FName2, Mnmbr, _, _), FName1!= FName2. :- stdnt (_, _, Mnmbr, ClssYr1, _), stdnt(_, _, Mnmbr, ClssYr2, _), ClssYr1!= ClssYr2. 13
14 Homework for 1 week from today: Redo Homework 1, but in clingo instead of relational algebra. your solution to me before 4:00 that day. I ll write a test data file (to try to trick your programs, of course) and run your programs together with my test data file. Of course, change relation and constant names in homework 1 to start with lower-case letters. Store your answers in relations answer1 (a unary relation), answer2 (binary), answer3 (ternary), and answer4 (binary). Give any additional relations names that I can easily figure out. Note that clingo requires all rules to be safe. You don t need recursion, so try to avoid using it. 14
15 Database Anomalies: Basic idea of a problem I saw in my programming days: The company stored prices for items sold. But how were the prices set? By item type? By item type and date of order? By individual negotiation with purchasers, item-type by itemtype? By individual negotiation with purchasers, individual item by individual item? Their answer was Yes. Natural solution might have 2 tables: Item# PeriodStart PeriodEnd Price Item# Cust# PeriodStart PeriodEnd BargainedPrice Unfortunately,..., in their solution, when one customer bargained a new (higher or lower) price, that price was also reported for other items. ( Government accounting?) Anomalies: Errors in the data caused by updating data not apparently related to the data. Incidentally, would you if the customer is charged the regular price, what would you do with the BargainedPrice attribute value? 15
16 Insertion Anomaly: Inconsistency in data created by inserting new data. Deletion Anomaly: Loss of data created by deleting basically irrelevant data. Modification Anomaly: Inconsistency in or loss of data created by chainging data. Emp# FName LName Hours Prod# ProdName ProdLoc John Smith Dingbat Bellaire John Smith Gizmo Sugarland John Smith DooDad Houston Rex Bhatnagar Dingbat Bellaire Franklin Wong DooDad Houston Franklin Wong Thresh80 Stafford Alicia Zelaya Magic007 Stafford Alicia Zelaya Thresh80 Stafford Jennifer Wallace Reorg. Houston Jennifer Wallace Progress! Stafford Ramesh Narayan DooDad Houston Joyce English Dingbat Bellaire Joyce English Gizmo Sugarland Ahmad Jabbar Thresh80 Stafford Ahmad Jabbar Magic007 Stafford James Borg Reorg. Houston John Smith Dingbat Bellaire 1. What s a likely key to the above relation? 2. What could go wrong if I added another labor record for Alicia Zelaya? 16
17 Fortunately, the cure to avoiding anomalies often generally saves space but it does normally increase access time to answer queries. What is a good relational schema? Captures semantics of the attributes Reduces redundancy and update anomalies Reduces null values Disallows spurious tuples 17
The Relational Algebra
The Relational Algebra Relational set operators: The data in relational tables are of limited value unless the data can be manipulated to generate useful information. Relational Algebra defines the theoretical
Lab Assignment 0. 1. Creating a Relational Database Schema from ER Diagram, Populating the Database and Querying over the database with SQL
SS Chung Lab Assignment 0 1. Creating a Relational Database Schema from ER Diagram, Populating the Database and Querying over the database with SQL 1. Creating the COMPANY database schema using SQL (DDL)
Introduction to SQL: Data Retrieving
Introduction to SQL: Data Retrieving Ruslan Fomkin Databasdesign för Ingenjörer 1056F Structured Query Language (SQL) History: SEQUEL (Structured English QUery Language), earlier 70 s, IBM Research SQL
Exercise 1: Relational Model
Exercise 1: Relational Model 1. Consider the relational database of next relational schema with 3 relations. What are the best possible primary keys in each relation? employ(person_name, street, city)
Files. Files. Files. Files. Files. File Organisation. What s it all about? What s in a file?
Files What s it all about? Information being stored about anything important to the business/individual keeping the files. The simple concepts used in the operation of manual files are often a good guide
VIEWS virtual relation data duplication consistency problems
VIEWS A virtual relation that is defined from other preexisting relations Called the defining relations of the view A view supports multiple user perspectives on the database corresponding to different
Data Integration and Exchange. L. Libkin 1 Data Integration and Exchange
Data Integration and Exchange L. Libkin 1 Data Integration and Exchange Traditional approach to databases A single large repository of data. Database administrator in charge of access to data. Users interact
Figure 14.1 Simplified version of the
Figure. Simplified version of the COMPANY relational database schema. EMPLOYEE f.k. ENAME SSN BDATE ADDRESS DNUMBER DEPARTMENT f.k. DNAME DNUMBER DMGRSSN DEPT_LOCATIONS f.k. DNUMBER DLOCATION PROJECT f.k.
CHAPTER 8: SQL-99: SCHEMA DEFINITION, BASIC CONSTRAINTS, AND QUERIES
Chapter 8: SQL-99: Schema Definition, Basic Constraints, and Queries 1 CHAPTER 8: SQL-99: SCHEMA DEFINITION, BASIC CONSTRAINTS, AND QUERIES Answers to Selected Exercises 8. 7 Consider the database shown
Schema Mappings and Data Exchange
Schema Mappings and Data Exchange Phokion G. Kolaitis University of California, Santa Cruz & IBM Research-Almaden EASSLC 2012 Southwest University August 2012 1 Logic and Databases Extensive interaction
CHAPTER 7 GENERAL PROOF SYSTEMS
CHAPTER 7 GENERAL PROOF SYSTEMS 1 Introduction Proof systems are built to prove statements. They can be thought as an inference machine with special statements, called provable statements, or sometimes
Once the schema has been designed, it can be implemented in the RDBMS.
2. Creating a database Designing the database schema... 1 Representing Classes, Attributes and Objects... 2 Data types... 5 Additional constraints... 6 Choosing the right fields... 7 Implementing a table
3. Relational Model and Relational Algebra
ECS-165A WQ 11 36 3. Relational Model and Relational Algebra Contents Fundamental Concepts of the Relational Model Integrity Constraints Translation ER schema Relational Database Schema Relational Algebra
Lecture 1. Basic Concepts of Set Theory, Functions and Relations
September 7, 2005 p. 1 Lecture 1. Basic Concepts of Set Theory, Functions and Relations 0. Preliminaries...1 1. Basic Concepts of Set Theory...1 1.1. Sets and elements...1 1.2. Specification of sets...2
The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1
The Relational Model Ramakrishnan&Gehrke, Chapter 3 CS4320 1 Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. Legacy systems in older models
History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)
Relational Database Languages Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG) Domain relational calculus QBE (used in Access) History of SQL Standards:
Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems
CSC 74 Database Management Systems Topic #0: SQL Part A: Data Definition Language (DDL) Spring 00 CSC 74: DBMS by Dr. Peng Ning Spring 00 CSC 74: DBMS by Dr. Peng Ning Schema and Catalog Schema A collection
Database Design and Normal Forms
Database Design and Normal Forms Database Design coming up with a good schema is very important How do we characterize the goodness of a schema? If two or more alternative schemas are available how do
Lecture 6. SQL, Logical DB Design
Lecture 6 SQL, Logical DB Design Relational Query Languages A major strength of the relational model: supports simple, powerful querying of data. Queries can be written intuitively, and the DBMS is responsible
Data exchange. L. Libkin 1 Data Integration and Exchange
Data exchange Source schema, target schema; need to transfer data between them. A typical scenario: Two organizations have their legacy databases, schemas cannot be changed. Data from one organization
Chapter 10. Functional Dependencies and Normalization for Relational Databases
Chapter 10 Functional Dependencies and Normalization for Relational Databases Chapter Outline 1 Informal Design Guidelines for Relational Databases 1.1Semantics of the Relation Attributes 1.2 Redundant
Cal Answers Analysis Training Part I. Creating Analyses in OBIEE
Cal Answers Analysis Training Part I Creating Analyses in OBIEE University of California, Berkeley March 2012 Table of Contents Table of Contents... 1 Overview... 2 Getting Around OBIEE... 2 Cal Answers
Database 2 Lecture I. Alessandro Artale
Free University of Bolzano Database 2. Lecture I, 2003/2004 A.Artale (1) Database 2 Lecture I Alessandro Artale Faculty of Computer Science Free University of Bolzano Room: 221 [email protected] http://www.inf.unibz.it/
Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB
Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB Outline Database concepts Conceptual Design Logical Design Communicating with the RDBMS 2 Some concepts Database: an
CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University
CS 377 Database Systems Database Design Theory and Normalization Li Xiong Department of Mathematics and Computer Science Emory University 1 Relational database design So far Conceptual database design
www.gr8ambitionz.com
Data Base Management Systems (DBMS) Study Material (Objective Type questions with Answers) Shared by Akhil Arora Powered by www. your A to Z competitive exam guide Database Objective type questions Q.1
Relational Database Design: FD s & BCNF
CS145 Lecture Notes #5 Relational Database Design: FD s & BCNF Motivation Automatic translation from E/R or ODL may not produce the best relational design possible Sometimes database designers like to
CSE 530A Database Management Systems. Introduction. Washington University Fall 2013
CSE 530A Database Management Systems Introduction Washington University Fall 2013 Overview Time: Mon/Wed 7:00-8:30 PM Location: Crow 206 Instructor: Michael Plezbert TA: Gene Lee Websites: http://classes.engineering.wustl.edu/cse530/
Chapter 1: Introduction. Database Management System (DBMS) University Database Example
This image cannot currently be displayed. Chapter 1: Introduction Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Database Management System (DBMS) DBMS contains information
Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Query optimization. DBMS Architecture. Query optimizer. Query optimizer.
DBMS Architecture INSTRUCTION OPTIMIZER Database Management Systems MANAGEMENT OF ACCESS METHODS BUFFER MANAGER CONCURRENCY CONTROL RELIABILITY MANAGEMENT Index Files Data Files System Catalog BASE It
SQL-99: Schema Definition, Basic Constraints, and Queries
8 SQL-99: Schema Definition, Basic Constraints, and Queries The SQL language may be considered one of the major reasons for the success of relational databases in the commercial world. Because it became
SQL Query Evaluation. Winter 2006-2007 Lecture 23
SQL Query Evaluation Winter 2006-2007 Lecture 23 SQL Query Processing Databases go through three steps: Parse SQL into an execution plan Optimize the execution plan Evaluate the optimized plan Execution
SUBQUERIES AND VIEWS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 6
SUBQUERIES AND VIEWS CS121: Introduction to Relational Database Systems Fall 2015 Lecture 6 String Comparisons and GROUP BY 2! Last time, introduced many advanced features of SQL, including GROUP BY! Recall:
A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX
ISSN: 2393-8528 Contents lists available at www.ijicse.in International Journal of Innovative Computer Science & Engineering Volume 3 Issue 2; March-April-2016; Page No. 09-13 A Comparison of Database
Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations
1 Topics for this week: 1. Good Design 2. Functional Dependencies 3. Normalization Readings for this week: 1. E&N, Ch. 10.1-10.6; 12.2 2. Quickstart, Ch. 3 3. Complete the tutorial at http://sqlcourse2.com/
Relational Database Basics Review
Relational Database Basics Review IT 4153 Advanced Database J.G. Zheng Spring 2012 Overview Database approach Database system Relational model Database development 2 File Processing Approaches Based on
Course: CSC 222 Database Design and Management I (3 credits Compulsory)
Course: CSC 222 Database Design and Management I (3 credits Compulsory) Course Duration: Three hours per week for 15weeks with practical class (45 hours) As taught in 2010/2011 session Lecturer: Oladele,
Schema Refinement, Functional Dependencies, Normalization
Schema Refinement, Functional Dependencies, Normalization MSCI 346: Database Systems Güneş Aluç, University of Waterloo Spring 2015 MSCI 346: Database Systems Chapter 19 1 / 42 Outline 1 Introduction Design
The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3
The Relational Model Chapter 3 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase,
Tutorial 5 Creating Advanced Queries and Enhancing Table Design
Tutorial 5 Creating Advanced Queries and Enhancing Table Design Microsoft Access 2013 Objectives Session 5.1 Review object naming standards Use the Like, In, Not, and & operators in queries Filter data
How To Create A Table In Sql 2.5.2.2 (Ahem)
Database Systems Unit 5 Database Implementation: SQL Data Definition Language Learning Goals In this unit you will learn how to transfer a logical data model into a physical database, how to extend or
3.GETTING STARTED WITH ORACLE8i
Oracle For Beginners Page : 1 3.GETTING STARTED WITH ORACLE8i Creating a table Datatypes Displaying table definition using DESCRIBE Inserting rows into a table Selecting rows from a table Editing SQL buffer
Database Design--from E-R Diagram to SQL Statement
Database Design--from E-R Diagram to SQL Statement Problem Set 3 In problem set 3 * you will: Create an entity-relationship diagram for a database Construct a simple database design Input records into
SAMPLE FINAL EXAMINATION SPRING SESSION 2015
SAMPLE FINAL EXAMINATION SPRING SESSION 2015 School of Computing, Engineering and Mathematics Student family name: Student given name/s: Student ID number: Course: Unit Name (In Full): Database Design
COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries
COMP 5138 Relational Database Management Systems Week 5 : Basic COMP5138 "Relational Database Managment Systems" J. Davis 2006 5-1 Today s Agenda Overview Basic Queries Joins Queries Aggregate Functions
CS2Bh: Current Technologies. Introduction to XML and Relational Databases. Introduction to Databases. Why databases? Why not use XML?
CS2Bh: Current Technologies Introduction to XML and Relational Databases Spring 2005 Introduction to Databases CS2 Spring 2005 (LN5) 1 Why databases? Why not use XML? What is missing from XML: Consistency
Relational Normalization: Contents. Relational Database Design: Rationale. Relational Database Design. Motivation
Relational Normalization: Contents Motivation Functional Dependencies First Normal Form Second Normal Form Third Normal Form Boyce-Codd Normal Form Decomposition Algorithms Multivalued Dependencies and
SQL Nested & Complex Queries. CS 377: Database Systems
SQL Nested & Complex Queries CS 377: Database Systems Recap: Basic SQL Retrieval Query A SQL query can consist of several clauses, but only SELECT and FROM are mandatory SELECT FROM
Foundations of Information Management
Foundations of Information Management - WS 2012/13 - Juniorprofessor Alexander Markowetz Bonn Aachen International Center for Information Technology (B-IT) Data & Databases Data: Simple information Database:
Relational Databases
Relational Databases Jan Chomicki University at Buffalo Jan Chomicki () Relational databases 1 / 18 Relational data model Domain domain: predefined set of atomic values: integers, strings,... every attribute
Introduction to SQL C H A P T E R3. Exercises
C H A P T E R3 Introduction to SQL Exercises 3.1 Write the following queries in SQL, using the university schema. (We suggest you actually run these queries on a database, using the sample data that we
Functional Dependencies and Finding a Minimal Cover
Functional Dependencies and Finding a Minimal Cover Robert Soulé 1 Normalization An anomaly occurs in a database when you can update, insert, or delete data, and get undesired side-effects. These side
Theory of Relational Database Design and Normalization
Theory of Relational Database Design and Normalization (Based on Chapter 14 and some part of Chapter 15 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3) 1 Informal Design Guidelines for
CS143 Notes: Normalization Theory
CS143 Notes: Normalization Theory Book Chapters (4th) Chapters 7.1-6, 7.8, 7.10 (5th) Chapters 7.1-6, 7.8 (6th) Chapters 8.1-6, 8.8 INTRODUCTION Main question How do we design good tables for a relational
Product: DQ Order Manager Release Notes
Product: DQ Order Manager Release Notes Subject: DQ Order Manager v7.1.25 Version: 1.0 March 27, 2015 Distribution: ODT Customers DQ OrderManager v7.1.25 Added option to Move Orders job step Update order
2. Conceptual Modeling using the Entity-Relationship Model
ECS-165A WQ 11 15 Contents 2. Conceptual Modeling using the Entity-Relationship Model Basic concepts: entities and entity types, attributes and keys, relationships and relationship types Entity-Relationship
14 Databases. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:
14 Databases 14.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define a database and a database management system (DBMS)
Lab Manual. Database Systems COT-313 & Database Management Systems Lab IT-216
Lab Manual Database Systems COT-313 & Database Management Systems Lab IT-216 Lab Instructions Several practicals / programs? Whether an experiment contains one or several practicals /programs One practical
Advance DBMS. Structured Query Language (SQL)
Structured Query Language (SQL) Introduction Commercial database systems use more user friendly language to specify the queries. SQL is the most influential commercially marketed product language. Other
Reading 13 : Finite State Automata and Regular Expressions
CS/Math 24: Introduction to Discrete Mathematics Fall 25 Reading 3 : Finite State Automata and Regular Expressions Instructors: Beck Hasti, Gautam Prakriya In this reading we study a mathematical model
Chapter 8. SQL-99: SchemaDefinition, Constraints, and Queries and Views
Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations) of a database
Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson
Mathematics for Computer Science/Software Engineering Notes for the course MSM1F3 Dr. R. A. Wilson October 1996 Chapter 1 Logic Lecture no. 1. We introduce the concept of a proposition, which is a statement
C HAPTER 4 INTRODUCTION. Relational Databases FILE VS. DATABASES FILE VS. DATABASES
INRODUCION C HAPER 4 Relational Databases Questions to be addressed in this chapter: How are s different than file-based legacy systems? Why are s important and what is their advantage? What is the difference
Database Systems. Lecture Handout 1. Dr Paolo Guagliardo. University of Edinburgh. 21 September 2015
Database Systems Lecture Handout 1 Dr Paolo Guagliardo University of Edinburgh 21 September 2015 What is a database? A collection of data items, related to a specific enterprise, which is structured and
Oracle Database 10g: Introduction to SQL
Oracle University Contact Us: 1.800.529.0165 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database technology.
SQL INJECTION ATTACKS By Zelinski Radu, Technical University of Moldova
SQL INJECTION ATTACKS By Zelinski Radu, Technical University of Moldova Where someone is building a Web application, often he need to use databases to store information, or to manage user accounts. And
COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model
COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model The entity-relationship (E-R) model is a a data model in which information stored
Automata and Formal Languages
Automata and Formal Languages Winter 2009-2010 Yacov Hel-Or 1 What this course is all about This course is about mathematical models of computation We ll study different machine models (finite automata,
CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model
CS2Bh: Current Technologies Introduction to XML and Relational Databases Spring 2005 The Relational Model CS2 Spring 2005 (LN6) 1 The relational model Proposed by Codd in 1970. It is the dominant data
Information Systems SQL. Nikolaj Popov
Information Systems SQL Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria [email protected] Outline SQL Table Creation Populating and Modifying
Relational Database Design
Relational Database Design To generate a set of relation schemas that allows - to store information without unnecessary redundancy - to retrieve desired information easily Approach - design schema in appropriate
What is Null and Why is it Important for Crystal Reports
What is Null and Why is it Important for Crystal Reports The concept of Null is frequently misunderstood by people who are new to working with databases. Simply put, Null means unassigned or no value.
Entity-Relationship Model
UNIT -2 Entity-Relationship Model Introduction to ER Model ER model is represents real world situations using concepts, which are commonly used by people. It allows defining a representation of the real
Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst
Outline Data Modeling Yanlei Diao UMass Amherst v Conceptual Design: ER Model v Relational Model v Logical Design: from ER to Relational Slides Courtesy of R. Ramakrishnan and J. Gehrke 1 2 Conceptual
Instant SQL Programming
Instant SQL Programming Joe Celko Wrox Press Ltd. INSTANT Table of Contents Introduction 1 What Can SQL Do for Me? 2 Who Should Use This Book? 2 How To Use This Book 3 What You Should Know 3 Conventions
Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys
Database Design Overview Conceptual Design. The Entity-Relationship (ER) Model CS430/630 Lecture 12 Conceptual design The Entity-Relationship (ER) Model, UML High-level, close to human thinking Semantic
7.1 The Information system
Chapter 7. Database Planning, Design and Administration Last few decades have seen proliferation of software applications, many requiring constant maintenance involving: correcting faults, implementing
Ad Hoc Advanced Table of Contents
Ad Hoc Advanced Table of Contents Functions... 1 Adding a Function to the Adhoc Query:... 1 Constant... 2 Coalesce... 4 Concatenate... 6 Add/Subtract... 7 Logical Expressions... 8 Creating a Logical Expression:...
How To Find Out What A Key Is In A Database Engine
Database design theory, Part I Functional dependencies Introduction As we saw in the last segment, designing a good database is a non trivial matter. The E/R model gives a useful rapid prototyping tool,
Foundations of Information Management
Foundations of Information Management - WS 2009/10 Juniorprofessor Alexander Markowetz Bonn Aachen International Center for Information Technology (B-IT) Alexander Markowetz Born 1976 in Brussels, Belgium
Chapter 9, More SQL: Assertions, Views, and Programming Techniques
Chapter 9, More SQL: Assertions, Views, and Programming Techniques 9.2 Embedded SQL SQL statements can be embedded in a general purpose programming language, such as C, C++, COBOL,... 9.2.1 Retrieving
The Entity-Relationship Model
The Entity-Relationship Model 221 After completing this chapter, you should be able to explain the three phases of database design, Why are multiple phases useful? evaluate the significance of the Entity-Relationship
An Innocent Investigation
An Innocent Investigation D. Joyce, Clark University January 2006 The beginning. Have you ever wondered why every number is either even or odd? I don t mean to ask if you ever wondered whether every number
Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.
The Entity- Relationship Model R &G - Chapter 2 A relationship, I think, is like a shark, you know? It has to constantly move forward or it dies. And I think what we got on our hands is a dead shark. Woody
Introduction to normalization. Introduction to normalization
Introduction to normalization Lecture 4 Instructor Anna Sidorova Agenda Presentation Review of relational models, in class exersise Introduction to normalization In-class exercises Discussion of HW2 1
Chapter 1: Introduction
Chapter 1: Introduction Database System Concepts, 5th Ed. See www.db book.com for conditions on re use Chapter 1: Introduction Purpose of Database Systems View of Data Database Languages Relational Databases
Language. Johann Eder. Universitat Klagenfurt. Institut fur Informatik. Universiatsstr. 65. A-9020 Klagenfurt / AUSTRIA
PLOP: A Polymorphic Logic Database Programming Language Johann Eder Universitat Klagenfurt Institut fur Informatik Universiatsstr. 65 A-9020 Klagenfurt / AUSTRIA February 12, 1993 Extended Abstract The
Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro
Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro, to your M: drive. To do the second part of the prelab, you will need to have available a database from that folder. Creating a new
Select the Crow s Foot entity relationship diagram (ERD) option. Create the entities and define their components.
Α DESIGNING DATABASES WITH VISIO PROFESSIONAL: A TUTORIAL Microsoft Visio Professional is a powerful database design and modeling tool. The Visio software has so many features that we can t possibly demonstrate
060010102 Database Management Systems 2015
Module 1- File Organization and Structure Short Questions: 1. How data differs from information? 2. What are the different types of cache memory? 3. List at least two devices where flash memory is used.
CS 1133, LAB 2: FUNCTIONS AND TESTING http://www.cs.cornell.edu/courses/cs1133/2015fa/labs/lab02.pdf
CS 1133, LAB 2: FUNCTIONS AND TESTING http://www.cs.cornell.edu/courses/cs1133/2015fa/labs/lab02.pdf First Name: Last Name: NetID: The purpose of this lab is to help you to better understand functions:
Database System Concepts
s Design Chapter 1: Introduction Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2008/2009 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth
Summary on Chapter 4 Basic SQL
Summary on Chapter 4 Basic SQL SQL Features Basic SQL DDL o Includes the CREATE statements o Has a comprehensive set of SQL data types o Can specify key, referential integrity, and other constraints Basic
Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise
Database Design Database Design I: The Entity-Relationship Model Chapter 4 Goal: specification of database schema Methodology: Use E-R R model to get a high-level graphical view of essential components
Schema Refinement and Normalization
Schema Refinement and Normalization Module 5, Lectures 3 and 4 Database Management Systems, R. Ramakrishnan 1 The Evils of Redundancy Redundancy is at the root of several problems associated with relational
Database Design. Goal: specification of database schema Methodology: E-R Model is viewed as a set of
Database Design Goal: specification of database schema Methodology: Use E-R model to get a high-level graphical view of essential components of the model and how they are related Convert E-R diagram to
Relational Algebra. Basic Operations Algebra of Bags
Relational Algebra Basic Operations Algebra of Bags 1 What is an Algebra Mathematical system consisting of: Operands --- variables or values from which new values can be constructed. Operators --- symbols
