Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.

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.
COMPANY schema EMPLOYEE
OUTLINE OF THE LECTURE PART I GOAL: Understand the Data Definition Statements in Fig 4.1 Step1: Columns of the Tables and Data types. Step2: Single column.
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.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Your Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Instructor: Mr. Ahmed Al Astal Chapter 8 (Cont.) SQL-99: Schema Definition,
Fall 2005 ICS184/EECS116 – Notes 08 1 ICS 184/EECS116: Introduction to Data Management Lecture Note 8 SQL: Structured Query Language -- DDL.
Database technology Lecture 2: Relational databases and SQL
Data Definition Languages Atif Farid Mohammad UNCC.
Dept. of Computer & Information Sciences
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.
Exploring Microsoft Access 2003 Chapter 4 Proficiency: Relational Databases, External Data, Charts, Pivot, and the Switchboard.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
Introduction to Structured Query Language (SQL)
SQL SQL (Structured Query Language) is used to define, query, and modify relational databases Every relational database system understands SQL SQL is standard:
CS 104 Introduction to Computer Science and Graphics Problems Introduction to Database (2) Basic SQL 12/05/2008 Yang Song.
SQL Winter 2006Ron McFadyen Outline: SQL DDL - creating schemas - modifying schemas DML - select-from-where clause - group by, having, order by.
Jyh-haw Yeh Dept. of Computer Science Boise State University
SQL Jan. 2012Yangjun Chen ACS Outline: SQL Chapter 8 – 3rd ed. (Chap. 8 – 4 th, 5 th ed.; Chap. 4, 5, 6 th ed.) DDL - creating schemas - modifying.
SQL The relational DB Standard CS-450 Dr. Ali Obaidi.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 8- 1 CREATE/DROP/ALTER TABLE Data types : char, varchar, decimal, date CREATE TABLE DEPARTMENT.
Al-Imam University Girls Education Center Collage of Computer Science 1 ST Semester, 1432/1433H Chapter 8 Part 4 SQL-99 Schema Definition, Constraints,
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: SchemaDefinition, Constraints, and Queries and Views.
FEN  Queries: SELECT  Data Manipulation: INSERT, UPDATE, DELETE SQL: Structured Query Language – Part 2.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 8 SQL-99: Schema Definition, Constraints, and Queries and Views.
Final Review Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
SQL: Schema Definition, Constraints, & Queries and Views.
Relational Algebra - Chapter (7th ed )
Onsdag The concepts in a relation data model SQL DDL DML.
CS 380 Introduction to Database Systems (Chapter 8: SQL-99: Schema Definition, Constraints, Queries, and Views)
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.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
NOEA/IT - FEN: Databases/SQL1 SQL – part 1 SQL: DDL and DML.
DatabaseDatabase cs453 Lab5 1 Ins.Ebtesam AL-Etowi.
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.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
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
1 Chapter 5 The SQL Language Data Definition Language The Data Definition Language (DDL) is used to create and destroy databases and database.
DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Introduction to Database Systems
COP-5725 Practice Exercises
FEN Introduction to the database field:  SQL: Structured Query Language Seminar: Introduction to relational databases.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
1 COMP 1100 Basic SQL David J. Stucki. Outline SQL Overview Retrievals Schema creation Table creation Constraints Inserts Updates 2.
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) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Dept. of Computer & Information Sciences
The SQL Database Grammar
Chapter 4 Basic SQL.
CS580 Advanced Database Topics
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Structured Query Language (3)
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
SQL Updating Database Contents Presented by: Dr. Samir Tartir
SQLPLUS: Oracle SQL Interface
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Presentation transcript:

Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems (Chapter 8 & 9 Tutorial)

Chapter 8 & 9 Tutorial1 COMPANY Schema Given the following schema for a COMPANY database: EMPLOYEE DEPARTMENT FNAMEMINITLNAMESSNSALARYDNO DNAMEDNUMBERLOCATION

Chapter 8 & 9 Tutorial2 SQL*Plus Open SQL*Plus, enter appropriate name, password, & host string scott psu stddata

Chapter 8 & 9 Tutorial3 Exercise 1 Write appropriate SQL DDL statements to declare the COMPANY schema. CREATE TABLE DEPARTMENT ( DNAMEVARCHAR2(20)NOT NULL UNIQUE, DNUMBERNUMBER(2), LOCATIONVARCHAR2(20), CONSTRAINT DEPT_PKEY PRIMARY KEY (DNUMBER)); CREATE TABLE EMPLOYEE ( FNAMEVARCHAR2(15)NOT NULL, MINIT CHAR, LNAMEVARCHAR2(15)NOT NULL, SSNCHAR(9), SALARYNUMBER(10,2)NOT NULL, DNONUMBER(2), CONSTRAINT EMP_PKEY PRIMARY KEY (SSN), CONSTRAINT EMP_FKEY FOREIGN KEY (DNO) REFERENCES DEPARTMENT (DNUMBER)); save company.SQL save company.SQL append

Chapter 8 & 9 Tutorial4 Exercise 2 Display the structure of your tables. describe DEPARTMENT describe EMPLOYEE

Chapter 8 & 9 Tutorial5 Exercise 3 Add the following columns to the EMPLOYEE table: ADDRESS SEX ALTER TABLE EMPLOYEE ADD ( ADDRESSVARCHAR2(30), SEXCHARCHECK (SEX IN ('M', 'F')));

Chapter 8 & 9 Tutorial6 Exercise 4 Insert the following tuple into the DEPARTMENT table: DNAME = ‘Project’ DNUMBER = 5 DLOCATION = ‘Houston’ INSERT INTO DEPARTMENT VALUES ('Project', 5, 'Houston');

Chapter 8 & 9 Tutorial7 Exercise 5 Write an INSERT statement in which each time it is run, the user will be prompted for a new set of values (DEPARTMENT table) INSERT INTO DEPARTMENT VALUES ('&D_NAME', &D_NUMBER, '&D_LOCATION'); Execute the previous statement twice, and insert the following values: D_NAME = Administration D_NUMBER = 4 D_LOCATION = Stafford D_NAME = Headquarters D_NUMBER = 1 D_LOCATION = Bellaire

Chapter 8 & 9 Tutorial8 Exercise 6 Write an SQL statement to modify the name of department number 5 to ‘Research’. UPDATE DEPARTMENT SET DNAME='Research' WHEREDNUMBER=5;

Chapter 8 & 9 Tutorial9 Exercise 7 Open the “data.SQL” file and execute all the SQL statements. (This file includes SQL statements to fill the EMPLOYEE table with data) Start data.SQL

Chapter 8 & 9 Tutorial Exercise 8 Write the following query in SQL: “Retrieve the names of all female employees who work in the ‘Research’ department” SELECTFNAME, LNAME FROMEMPLOYEE, DEPARTMENT WHEREDNO=DNUMBER AND SEX='F' AND DNAME='Research'; 10

Chapter 8 & 9 Tutorial11 Exercise 9 Write the following query in SQL: “Retrieve the names and addresses of all employees who do not work in department number 5” SELECTFNAME, LNAME, ADDRESS FROMEMPLOYEE MINUS SELECTFNAME, LNAME, ADDRESS FROMEMPLOYEE WHEREDNO=5;

Chapter 8 & 9 Tutorial12 Exercise 10 Write the following query in SQL: “Retrieve the total salary of the male employees who work in department number 5” SELECTSUM(SALARY) FROMEMPLOYEE WHERESEX='M' AND DNO=5;

Chapter 8 & 9 Tutorial13 Exercise 11 Write the following query in SQL: “For each department, list the department name (Ascending order) and the number of its employees” SELECTDNAME, COUNT(*) FROMEMPLOYEE, DEPARTMENT WHEREDNO=DNUMBER GROUP BYDNAME ORDER BYDNAME;

Chapter 8 & 9 Tutorial14 Exercise 12 Specify the following view in SQL: “A view that has the department name and the number of employees (per department)” CREATE VIEW EMP_DEPT (DEPT_NAME, DEPT_EMP) AS SELECTDNAME, COUNT(*) FROMEMPLOYEE, DEPARTMENT WHEREDNO=DNUMBER GROUP BYDNAME;

Chapter 8 & 9 Tutorial15 Exercise 13 Write the following query in SQL (using the previous view): “For each department, list the department name (Ascending order) and the number of its employees” SELECTDEPT_NAME, DEPT_EMP FROMEMP_DEPT ORDER BYDEPT_NAME;

Chapter 8 & 9 Tutorial16 Exercise 14 Exit SQL*Plus with committing any outstanding changes to the database. quit