FEN 2014-02-071  Queries: SELECT  Data Manipulation: INSERT, UPDATE, DELETE SQL: Structured Query Language – Part 2.

Slides:



Advertisements
Similar presentations
Fundamentals of Database Systems Fourth Edition El Masri & Navathe
Advertisements

SQL DESIGN AND IMPLEMENTATION CONTENT SOURCES: ELAMSARI AND NAVATHE, FUNDAMENTALS OF DATABASE MANAGEMENT SYSTEMSELAMSARI AND NAVATHE, FUNDAMENTALS OF.
The Relational Calculus
COMPANY schema EMPLOYEE
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.
Displaying Data from Multiple Tables. EMPNO DEPTNO LOC NEW YORK CHICAGO NEW YORK DALLAS
Database technology Lecture 2: Relational databases and SQL
FEN More about SELECT, Nested selects GROUP BY, HAVING, ORDER BY Other joins Aggregate functions Views More about SQL.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1.
1 CSE 480: Database Systems Lecture 10: SQL - DML Reference: Read Chapter 4 of the textbook.
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 Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
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. Selection SELECT * FROM r WHERE A=B AND D>5.
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 Slide 8- 1.
Chapter 3 MORE SQL Copyright © 2004 Pearson Education, Inc.
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.
CS 380 Introduction to Database Systems (Chapter 8: SQL-99: Schema Definition, Constraints, Queries, and Views)
 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.
Announcements Written Homework 1 due Friday –If you have fourth edition make sure you do the right problems Program 3 out today, due next Friday Nov 10.
Chapter 3 MORE SQL Copyright © 2004 Pearson Education, Inc.
Copyright © 2004 Pearson Education, Inc.. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries.
莊裕澤資料庫基本概念 1 Yuh-Jzer Joung 莊 裕 澤 Dept. of Information Management National Taiwan University February, 2002 資料庫管理與資訊科技.
SQL-99: SchemaDefinition, Constraints, and Queries and Views.
NOEA/IT - FEN: Databases/SQL1 SQL – part 1 SQL: DDL and DML.
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.
Chapter 8 Part 2 SQL-99 Schema Definition, Constraints, Queries, and Views.
Copyright © 2004 Pearson Education, Inc. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries.
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.
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.
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.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
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.
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 –continue with SQL (chapter.
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.
Introduction to Database Systems
FEN Introduction to the database field:  SQL: Structured Query Language Seminar: Introduction to relational databases.
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.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 16 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.
SQL- Updates, Assertions and Views. Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Structured Query Language (3) The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems,
6/22/2018.
376a. Database Design Dept. of Computer Science Vassar College
Company Requirements.
Session - 6 Sequence - 2 SQL: The Structured Query Language:
SQL: Set Operations & Nested Queries. Presented by: Dr. Samir Tartir
Presentation transcript:

FEN  Queries: SELECT  Data Manipulation: INSERT, UPDATE, DELETE SQL: Structured Query Language – Part 2

2 VW: new database FEN Look at this database:..\lektion03 (SQL2)\vwDatabase.pdf..\lektion03 (SQL2)\vwDatabase.pdf Create the database. These scripts may be helpful.scripts

SQL: Data Manipulation Language SELECT UPDATE INSERT DELETE FEN All work on tables

Queries: SELECT Syntax: SELECT FROM [WHERE ] [GROUP BY ] [HAVING ] [ORDER BY ] [...]:WHERE, GROUP BY, HAVING and ORDER BY may be omitted. FEN

Examples: Company (Q0): Row and column selection: SELECTBdate, Address FROMEmployee WHEREFname= ’John’ AND Minit = ’B’ AND Lname = ’Smith’ All attributes: SELECT * --- FEN

Examples: Company (Q1): JOIN: SELECT Fname, Lname, Address FROMEmployee, Department WHEREDname = ’Research’ AND Dno = Dnumber Last term in the WHERE-clause is the join-condition. If omitted the result will be the Cartesian product. Alternative syntax is possible. FEN

Examples: Company (Q2): JOIN several tables: SELECTPnumber, Dnum, Lname, Address FROMProject, Employee, Department WHEREPlocation = ’Stafford’ AND Dnum = Dnumber AND Ssn = Mgrssn Note: Two join-conditions in the WHERE-clause. FEN

Examples: Company (Q8): Ambiguous attribute names and aliases: SELECTE.Fname, E.Lname, S.Fname, S.Lname FROMEmployee E, Employee S WHEREE.Superssn= S.Ssn Employee is joined with itself using the aliases E and S. ’.’ (”dot”)-notation may also be used to resolve ambiguous attribute Names (remember Minibank?). FEN

Examples: Company SQL-tables are NOT sets (in the mathematical sense of the word set): ( Q11):SELECT Salary FROM Employee (Q11A):SELECT DISTINCT Salary FROM Employee FEN

Examples: Company SQL-tables are NOT sets in general, but in set operations (UNION, INTERSECT and EXCEPT) they are: (SELECT PNUMBER FROM PROJECT, DEPARTMENT, EMPLOYEE WHERE LNAME = ’Smith’ AND DNUM = DNUMBER AND MGRSSN = SSN ) UNION (SELECT PNUMBER FROM PROJECT, WORKS_ON, EMPLOYEE WHERE LNAME = ’Smith’ AND PNO = PNUMBER AND ESSN = SSN) FEN

Updates i SQL: Updates: Inserting rows:INSERT Deleting rows:DELETE Updating row values:UPDATE As SELECT they work on tables. FEN

Examples: Company Inserting a single row: INSERT INTO EMPLOYEE VALUES (’Richard’,’K’,’Marini’,’ ’, ’30-DEC-52’,’98 Oak Forest, Katy, ’TX’,’M’,37000,’ ’,4) Inserting a single row, selected attributes: INSERT INTO EMPLOYEE(FNAME,LNAME,SSN) VALUES(’Richard’,’Marini’,’ ’) Is rejected if any of the other attributes is defined NOT NULL and doesn’t have defined a default value. FEN

Examples: Company Deleting rows: DELETE FROMEMPLOYEE WHERELNAME =’Brown’ DELETE FROMEMPLOYEE WHERESSN = ’ ’ DELETE FROMEMPLOYEE WHEREDNO IN (SELECTDNUMBER FROMDEPARTMENT WHEREDNAME = ’Research’) DELETE FROMEMPLOYEE (Not equivalent to: ´DROP TABLE EMPLOYEE’. Why not?) FEN

Examples: Company Updating rows: UPDATEPROJECT SETPLOCATION = ’Bellaire’, DNUM = 5 WHEREPNUMBER = 10 UPDATEEMPLOYEE SETSALARY = SALARY*1.1 WHEREDNO IN(SELECTDNUMBER FROMDEPARTMENT WHEREDNAME = ’Research’) Note, that it is only possible to affect one table in one UPDATE statement. FEN

Exercises 1.Try out some of the SQL queries on the previous slides. FEN

16 Company: Exercise FEN Do Exercise 2, phase 4 on CompanyExercise.pdf CompanyExercise.pdf

17 Exercise: VW-database FEN Look at this database:..\lektion03 (SQL2)\vwDatabase.pdf..\lektion03 (SQL2)\vwDatabase.pdf Do some of the queries in SQL