©Silberschatz, Korth and Sudarshan4.1Database System Concepts SQL n מבנה שאילתה n פונקציות צבירה.

Slides:



Advertisements
Similar presentations
1 Today’s Class  Relational Model  SQL CS F212 Database Systems.
Advertisements

©Silberschatz, Korth and Sudarshan4.1Database System Concepts סכימה לדוגמא.
E-R Diagram for a Banking Enterprise
SQL Sangeeta Devadiga CS157A, Fall Outline Background Data Definition Basic Structure Set Operation.
SQL.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Ordering the Display of Tuples List in alphabetic order the names of all customers having.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Outer Join Aggregate Functions.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
SQL Structured Query Language Meizhen Huang. Content (4.1 – 4.4) Background Parts of SQL Basic Structure Set Operations Aggregate Functions.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL Database Management Systems I Alex Coman, Winter 2006.
חורף תשס " ג DBMS , שפות שאילתה : SQL ( א ') 1 סכמה SQL: מושגים טבלה, רלציה שורה, רשומה, n- יה עמודה, תכונה, שדה, אטריביוט.
DBMS , שפות שאילתה: SQL (ב')
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
SQL Neyha Amar CS 157A, Fall Inserting The insert statement is used to add a row of data into a table Strings should be enclosed in single quotes,
©Silberschatz, Korth and Sudarshan1.1Database System Concepts - 5 th Edition, May 23, 2005 Introduction to Database System Concepts.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL - part 2 - Database Management Systems I Alex Coman, Winter 2006.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Aandachtspunten Deadlines – alles op tijd inleveren! n Lees goed wat van je verwacht wordt!
MySQL Tutorial (2) Introduction to Database. Banking Example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-city)
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Calculus Objectives  Tuple Calculus  Domain Calculus  QBE & SQL  Related Examples.
CIS552SQL1 Data Definition Language Insertions Basic Query Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations.
Chapter 3: SQL Data Definition Language Data Definition Language Basic Structure of SQL Basic Structure of SQL Set Operations Set Operations Aggregate.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
Database System Concepts, 5th Ed. Bin Mu at Tongji University Chapter 3: SQL.
-- Introduction to database principles Maoying Wu March 11, 2013 Chapter 3: Basic SQL.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
SQL. Basic Structure SQL is based on set and relational operations with certain modifications and enhancements A typical SQL query has the form: select.
3.1 Chapter 3: SQL. 3.2 Chapter 3: SQL Basic Query Structure Set Operations Aggregate Functions Null Values Nested Subqueries Complex Queries Views Modification.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Null Values It is possible for tuples to have a null value for some of their attributes The.
Lecture 6 Structured Query Language SQL Lecture 6 Structured Query Language SQL Instructor: Haya Sammaneh.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
3.1 Chapter 3: SQL Schema used in examples p (omit 3.8.2, , 3.11)
Structured Query Language 2 Presented by: Annisa, M.Kom. Source: Database System Concepts 5 th edition.
Relational Model: Examples. Banking Example branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) account.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts (Schema) Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested.
Chapter 3: SQL. 3.2Unite International CollegeDatabase Management Systems Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate.
Chapter 3: SQL. 3.2Unite International CollegeDatabase Management Systems Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Relational Model.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts, 5 th Edition, Oct 5, 2006 SQL Data Definition Basic Query Structure Set Operations Aggregate.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 5 th Edition, Oct 5, 2006 Example.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join.
MySQL Tutorial Introduction to Database. Introduction of MySQL  MySQL is an SQL (Structured Query Language) based relational database management system.
Relational Algebra HW2 Turn in as a hardcopy at the start of next class period. You may work this assignment in groups.
ICOM 5016 – Introduction to Database Systems Lecture 6 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
2003B Q5 Suppliers(sid, sname, city) Select sid from suppliers where city=‘jerusalem’ or sname like ‘%Smith’ Select sid from suppliers where city=‘jerusalem’
1 Session 3 Welcome: To session 3-the fourth learning sequence “Relational algebra “ Recap : In the previous learning sequences, we discussed the four.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
ASET Relational Algebra continues…. ASET Rename Operation Allows us to name, and therefore to refer to, the results of relational-algebra expressions.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL Bambang.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
Structured Query Language
Structured Query Language (Data Manipulation Language)
Structured Query Language (SQL)
SQL בסיסי – הגדרה אינדוקטיבית
Chapter 3: SQL.
SQL SQL הינה השפה הדומיננטית לטיפול בבסיסי נתונים יחסיים, אך לא קיים סטנדרט SQL יחיד. ׁ(SQL92, SQL3 …) ניתן לחלק את פקודות SQL לארבע משפחות: פקודות להגדרת.
עבודה עם נתונים באמצעות ADO.NET
מודל היחסים (Relational Model)
Introduction to Database
Presentation transcript:

©Silberschatz, Korth and Sudarshan4.1Database System Concepts SQL n מבנה שאילתה n פונקציות צבירה

©Silberschatz, Korth and Sudarshan4.2Database System Concepts סכמת עבודה

©Silberschatz, Korth and Sudarshan4.3Database System Concepts מבנה בסיסי n צורת שאילתת SQL רגילה: select תכונה 1,,תכונה 2,..., תכונה n from טבלה 1, טבלה 2,..., טבלה m where תנאי n תוצאת שאילתה של SQL הינה טבלה בעצמה

©Silberschatz, Korth and Sudarshan4.4Database System Concepts משפט ה- select n משפט ה- select טומן בחובו את התכונות שיוצגו בתוצאה n לדוגמא: מצא את שמות כל הסניפים (branches) בטבלה loan select branch-name from loan

©Silberschatz, Korth and Sudarshan4.5Database System Concepts משפט ה- select SQL מרשה כפילויות בטבלאות וגם בתשובות לשאילתות n כדי לחייב דילול כל הכפילויות נשתמש בביטוי select distinct n מצא את שמות כל הסניפים בטבלה loan, והסר את הכפילויות select distinct branch-name from loan n אם נרצה לומר באופן מכוון לא לדלל כפילויות, נשתמש בביטוי select all select all branch-name from loan

©Silberschatz, Korth and Sudarshan4.6Database System Concepts משפט ה- select n כוכבית במשפט select משמעותה "כל התכונות" select * from loan במשפט ה- select ניתן להשתמש בביטוים חשבוניים הכוללים את הפעולות, +, –, *, /. n השאילתה: select loan-number, branch-name, amount  100 from loan תחזיר את הטבלה loan בדיוק עם נתוניה האמיתיים, אך תכונת ה- amount שלה תוכפל פי 100.

©Silberschatz, Korth and Sudarshan4.7Database System Concepts פסוקית ה- where n פסוקית ה – where מציינת את התנאים שהתוצאה מוכרחה לספק n כדי למצוא את כל מספרי ההלוואה (loan-number), עבור הלוואות אשר נעשו בסניף ירוחם, עם סכום הלוואה גדול מ-1200 ₪: select loan-number from loan where branch-name = ‘ ירוחם’ and amount > 1200 n ניתן באופן טבעי ליצור תנאים מורכבים עם האופרטורים and, or, או not.

©Silberschatz, Korth and Sudarshan4.8Database System Concepts פסוקית ה- where קיים ב- SQL אופרטור ההשוואה between לדוגמא: מצא את מספרי ההלוואה של ההלוואות שסכומן היה בין 90,000 ₪, לבין 100,000 ₪. (כלומר  $90,000 וגם  $100,000) select loan-number from loan where amount between and

©Silberschatz, Korth and Sudarshan4.9Database System Concepts פסוקית ה- from n פסוקית ה- from קובעת מאין ילקחו הנתונים. מצא את כל האפשרויות לחיבור בין borrower x loan select  from borrower, loan n מצא את השם, מספר ההלוואה, וסכום ההלוואה של כל הלקוחות אשר יש להם הלוואה בסניף ירוחם. select customer-name, borrower.loan-number, amount from borrower, loan where borrower.loan-number = loan.loan-number and branch-name = ‘ירוחם ’

©Silberschatz, Korth and Sudarshan4.10Database System Concepts פעולת שינוי שם SQL מרשה לנו לשנות את שמותיהן של תכונות וטבלאות ע"י שימוש בפסוקית as: old-name as new-name n מצא את שם, מספר ההלוואה, וסכום ההלוואה של כל הלקוחות; שנה את שם הטור loan-number לשם loan-id select customer-name, borrower.loan-number as loan-id, amount from borrower, loan where borrower.loan-number = loan.loan-number

©Silberschatz, Korth and Sudarshan4.11Database System Concepts שימוש בשמות חלופיים עבור טבלאות n מוגדר בתוך פסוקית ה- from תוך שימוש בפסוקית ה- as n מצא את שמות הלקוחות ואת מספרי ההלוואות שלהם עבור כל הלקוחות אשר להם יש הלוואה בסניף כלשהו select customer-name, T.loan-number, S.amount from borrower as T, loan as S where T.loan-number = S.loan-number

©Silberschatz, Korth and Sudarshan4.12Database System Concepts פעולות מחרוזתיות SQL מכיל אופרטור השוואה עבור מחרוזות. H כוכבית (*). התו * מתאים כל תת-מחרוזת.  סימן שאלה (?). התו ? מתאים כל תו יחיד. n מצא את שמות כל הלקוחות ששם הרחוב שלהם מכיל את תת המחרוזת "חן" select customer-name from customer where customer-street like ‘* חן * ’ SQL תומך במגוון פעולות מחרוזתיות כגון H שרשור (באמצעות התו &)  המרה מכתב גדול לקטן (ולהיפך) H מציאת אורך מחרוזת, חילוץ תת-מחרוזת

©Silberschatz, Korth and Sudarshan4.13Database System Concepts סידור הופעת הרשומות n סדר בסדר אלפביתי עולה את שמות כל הלקוחות אשר להם יש הלוואה בסניף ירוחם select distinct customer-name from borrower, loan where borrower loan-number = loan.loan-number and branch-name = ‘ ירוחם ’ order by customer-name n נוכל להגדיר סדר יורד באמצעות שימוש במילה desc  order by customer-name desc

©Silberschatz, Korth and Sudarshan4.14Database System Concepts פעולות על קבוצה n מצא את כל העובדים אשר להם הלוואה, חשבון, או שניהם: (select customer-name from depositor) union (select customer-name from borrower)

©Silberschatz, Korth and Sudarshan4.15Database System Concepts פונקציות צבירה n פונקציות אלה פועלות על קבוצה טורית של ערכים בטבלה, ומחזיר ערך avg: average value min: minimum value max: maximum value sum: sum of values count: number of values

©Silberschatz, Korth and Sudarshan4.16Database System Concepts פונקציות צבירה n מצא את ממוצע מאזני החשבונות (balance) בסניף ירוחם. מצא את מספר הרשומות בטבלת הלקוחות select avg (balance) from account where branch-name = ‘ירוחם ’ select count (*) from customer Select count(customer-name) from (Select distinct (customer-name) from depositor) מצא את מספר המפקידים בבנק

©Silberschatz, Korth and Sudarshan4.17Database System Concepts פונקציות צבירה – אחד לפי (group by) n מצא את מספר המפקידים בכל סניף select branch-name, count (customer-name) from depositor, account where depositor.account-number = account.account-number group by branch-name