Al-Imam University Girls Education Center Collage of Computer Science 1 ST Semester, 1432/1433H Chapter 8 Part 4 SQL-99 Schema Definition, Constraints,

Slides:



Advertisements
Similar presentations
COMPANY schema EMPLOYEE
Advertisements

Basic Queries. 2 Retrieval Queries in SQL SQL has one basic statement for retrieving information from a database; the SELECT statement This is not the.
Your Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Instructor: Mr. Ahmed Al Astal Chapter 8 (Cont.) SQL-99: Schema Definition,
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
METU Department of Computer Eng Ceng 302 Introduction to DBMS SQL-99: Schema Definition, Basic Constraints, and Queries by Pinar Senkul resources: mostly.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 1.
Copyright © 2004 Pearson Education, Inc.. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries.
Database Systems Chapter 8 ITM 354. Data Definition, Constraints, and Schema Changes Used in SQL to Create, Drop, and Alter the descriptions of the tables.
SQL The relational DB Standard CS-450 Dr. Ali Obaidi.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1 CREATE/DROP/ALTER TABLE Data types : char, varchar, decimal, date CREATE TABLE DEPARTMENT.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: Constraints, and Queries and Views.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
Chapter 3 MORE SQL Copyright © 2004 Pearson Education, Inc.
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
1 CSE 480: Database Systems Lecture 11: SQL. 2 SQL Query SELECT FROM WHERE –In MySQL, FROM and WHERE clauses are optional –Example:
SQL: Schema Definition, Constraints, & Queries and Views.
Relational Algebra - Chapter (7th ed )
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL.
 Employee (fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno)  Department (dname, dnumber, mgrssn, mgrstartdate) 
Database Management Systems. NESTING OF QUERIES  Some queries require that existing values in the database be retrieved and then used in a comparison.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
Chapter 3 MORE SQL Copyright © 2004 Pearson Education, Inc.
Copyright © 2004 Pearson Education, Inc.. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries.
SQL-99: SchemaDefinition, Constraints, and Queries and Views.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
Copyright © 2004 Pearson Education, Inc.. Lecture-7 Chapter 8 SQL: Schema Definition, Basic Constraints, and Queries.
Chapter 7 SQL HUANG XUEHUA. AGGREGATE FUNCTIONS Include COUNT, SUM, MAX, MIN, and AVG Query 15: Find the maximum salary, the minimum salary, and the.
Copyright © 2004 Pearson Education, Inc. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries.
1 CSE 480: Database Systems Lecture 12: SQL (Nested queries and Aggregate functions)
Slide 8- 1 THE HAVING-CLAUSE Provides a condition on the summary information Sometimes we want to retrieve the values of these functions for only those.
Structured Query Language
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
Copyright © 2004 Pearson Education, Inc.. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries.
Structured Query Language (2) The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems,
Announcements Written Homework 1 due Nov 2 –See course web page –Exercises 5.12, 5.15, 6.17, 6.20, 6.22 (a,c,f only). Today –SQL (chapter 8) –Instructional.
Faculty of Information Science and Technology Mahanakorn University of Technology Topic 8 SQL-99: Schema Definition, Basic Constraints, and Queries.
SQL SQL-99: a. Schema Definition b. Basic Constraints c. Queries.
Chapter 11 SQL DML. Retrieval Queries in SQL SQL has one basic statement for retrieving information from a database; the SELECT statement This is not.
1 Chapter 5 The SQL Language Data Definition Language The Data Definition Language (DDL) is used to create and destroy databases and database.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Chapter SQL DML. Retrieval Queries in SQL SQL has one basic statement for retrieving information from a database; the SELECT statement This is not the.
SQL-99: SchemaDefinition, Constraints, and Queries and Views.
COMP163 Database Management Systems September 18, 2008 Lecture 8 – Sections SQL Queries.
Chapter 6 The Relational Algebra Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 20 A First Course in Database Systems.
ISC321 Database Systems I Chapter 5: SQL: Advanced Queries, Assertions, Triggers, and Views Fall 2015 Dr. Abdullah Almutairi.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 (SQL Basics) Lecture # 9 July 7,2012.
1 COMP 1100 Basic SQL David J. Stucki. Outline SQL Overview Retrievals Schema creation Table creation Constraints Inserts Updates 2.
Lecture # 25 Chapter 8 SQL-99: Schema Definition, Constraints, and Queries and Views Muhammad Emran Database Systems.
Copyright © 2004 Pearson Education, Inc. Schema Definition, Basic Constraints, and Queries.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
CS580 Advanced Database Topics Chapter 8 SQL Irena Pevac.
Chapter 4 Basic SQL.
Retrieval Queries in SQL(DML)
Subject Name: DATA BASE MANAGEMENT SYSTEM Subject Code: 10cs54
11/9/2018.
Session - 6 Sequence - 2 SQL: The Structured Query Language:
Chapter 4 Basic SQL. Chapter 4 Basic SQL Chapter 4 Outline Overview of SQL SQL Data Definition (DDL) for Specifying a Relational Database Schema CREATE.
SQL-99: Schema Definition, Constraints, and Queries and Views
SQL Grouping, Ordering & Arithmetics Presented by: Dr. Samir Tartir
Presentation transcript:

Al-Imam University Girls Education Center Collage of Computer Science 1 ST Semester, 1432/1433H Chapter 8 Part 4 SQL-99 Schema Definition, Constraints, Queries, and Views

Introduction to Databases 2 UNSPECIFIED WHERE-clause A missing WHERE-clause indicates no condition; hence, all tuples of the relations in the FROM-clause are selected  This is equivalent to the condition WHERE TRUE Query 9: Retrieve the SSN values for all employees. Q9: SELECT Ssn FROM EMPLOYEE; If more than one relation is specified in the FROM-clause and there is no join condition, then the CARTESIAN PRODUCT of tuples is selected Q10: SELECT Ssn, Dname FROM EMPLOYEE, DEPARTMENT;

Introduction to Databases 3

4 SELECT * FROM EMPLOYEE, DEPARTMENT

Introduction to Databases 5 SELECT * FROMEMPLOYEE, DEPARTMENT WHERE Dno=Dnumber;

Introduction to Databases 6 JOIN vs. CARTESIAN PRODUCT Cartesian Product AabAab B12B12 B113B113 CxyzCxyz R S AaaabbbAaaabbb B111222B B113113B Join CxyzxyzCxyzxyz AaaAaa B11B11 B11B11 CxyCxy Join condition is R.B = S.B  Both operations is used to combine tuples from two relations in a combinatorial fashion.  In CROSS PRODUCT the resulting relation state has one tuple for each combination of tuples one from R and one from S.  The JOIN operation is very important for any relational database, because it allows us combine related tuples from various relations  Generally, CROSS PRODUCT is not a meaningful operation

Introduction to Databases 7 USE OF ASTERISK * To retrieve all the attribute values of the selected tuples, a * is used, which stands for all the attributes Examples: Q1C:SELECT * FROMEMPLOYEE WHEREDno=5; Q1D:SELECT* FROMEMPLOYEE, DEPARTMENT WHEREDname='Research' AND Dno=Dnumber;

Introduction to Databases 8 USE OF DISTINCT SQL does not treat a relation as a set; duplicate tuples can appear To eliminate duplicate tuples in a query result, the keyword DISTINCT is used For example, the result of Q11 may have duplicate SALARY values whereas Q11A does not have any duplicate values Q11:SELECT ALL Salary FROMEMPLOYEE; Q11A: SELECT DISTINCT Salary FROMEMPLOYEE;

Introduction to Databases 9 SET OPERATIONS SQL has directly incorporated some set operations There is a union operation (UNION), and in some versions of SQL there are set difference (MINUS) and intersection (INTERSECT) operations The resulting relations of these set operations are sets of tuples; duplicate tuples are eliminated from the result The set operations apply only to union compatible relations; the two relations must have the same attributes and the attributes must appear in the same order

Introduction to Databases 10 SET OPERATIONS (contd.) Query 4: Make a list of all project numbers for projects that involve an employee whose last name is 'Smith' as a worker or as a manager of the department that controls the project. Q4:(SELECT Pnumber FROMPROJECT, DEPARTMENT, EMPLOYEE WHEREDnum=Dnumber AND Mgr_ssn=Ssn AND Lname='Smith') UNION (SELECT Pnumber FROMWORKS_ON, EMPLOYEE WHEREEssn=Ssn AND Lname='Smith');

Introduction to Databases 11 “COMPANY” Relational Database Schema

Introduction to Databases 12 SUBSTRING COMPARISON The LIKE comparison operator is used to compare partial strings Two reserved characters are used: '%' replaces an arbitrary number of characters, and '_' replaces a single arbitrary character Example: Query 25: Retrieve all employees whose address is in Houston, Texas. Here, the value of the ADDRESS attribute must contain the substring 'Houston,TX‘ in it. Q25:SELECT Fname, Lname FROMEMPLOYEE WHEREAddress LIKE '%Houston,TX%‘;

Introduction to Databases 13 Query 26: Retrieve all employees who were born during the 1950s. Here, '5' must be the third character of the string (according to our format for date), so the BDATE value is ‘_ _ 5_ _ _ _ _ _ _ ', with each underscore as a place holder for a single arbitrary character. Q26:SELECT Fname, Lname FROMEMPLOYEE WHEREBdate LIKE ‘_ _ 5_ _ _ _ _ _ _ ‘; SUBSTRING COMPARISON (contd.)

Introduction to Databases 14 ARITHMETIC OPERATIONS The standard arithmetic operators '+', '-'. '*', and '/' (for addition, subtraction, multiplication, and division, respectively) can be applied to numeric values in an SQL query result Query 27: Show the effect of giving all employees who work on the 'ProductX' project a 10% raise. Q27: SELECT Fname, Lname, 1.1*Salary AS Increased_sal FROMEMPLOYEE, WORKS_ON, PROJECT WHERESsn=Essn AND Pno=Pnumber AND Pname='ProductX’;

Introduction to Databases 15 ARITHMETIC OPERATIONS Another comparison operator that can be used is BETWEEN Query 14: Retrieve all employee in department 5 whose salary is between $30,000 and $40,000 Q27: SELECT * FROMEMPLOYEE WHERE(Salary BETWEEN 30,000 AND 40,000) AND Dno=5;

Introduction to Databases 16 Ordering of Query Results The ORDER BY clause is used to sort the tuples in a query result based on the values of some attribute. Query 28: Retrieve a list of employees and the projects each works in, ordered by the employee's department, and within each department ordered alphabetically by employee last name, first name. Q28: SELECT Dname, Lname, Fname, Pname FROM DEPARTMENT,EMPLOYEE,WORKS_ON,PROJECT WHERE Dnumber=Dno AND Ssn=Essn AND Pno=Pnumber ORDER BY Dname, Lname, Fname; The default order is in ascending order of values. We can specify the keyword DESC if we want a descending order; the keyword ASC can be used to explicitly specify ascending order, even though it is the default ORDER BYDname DESC, Lname ASC, Fname ASC;