Hand in: the database picture (png or jpeg or ) for question 2, the queries (as SQL statements) for question 4
|
|
- Bertina O’Brien’
- 6 years ago
- Views:
Transcription
1 Using PostgreSQL, USDA database: 1. Create the version of the USDA database that follows on subsequent pages. Note this has been taken from a site that lists this database as a PostgreSQL sample database. 2. Develop a database picture similar to Figure 5.7 that shows tables, primary keys, and foreign keys (and references to PKs). Include at least one non-key attribute from each table. You do not have to include all attributes, but PKs and FKs are a must. Using PostgreSQL, Company database: 3. Create database, insert data 4. Queries see last page Hand in: the database picture (png or jpeg or ) for question 2, the queries (as SQL statements) for question 4 via to 3902@acs.uwinnipeg.ca 1
2 USDA Food Database R18 Name: data_src; Type: TABLE; Schema: public; Owner: -; Tablespace: CREATE TABLE data_src ( datasrc_id character(6) NOT NULL, authors text, title text NOT NULL, "year" integer, journal text, vol_city text, issue_state text, start_page text, end_page text Name: datsrcln; Type: TABLE; Schema: public; Owner: -; Tablespace: CREATE TABLE datsrcln ( ndb_no character(5) NOT NULL, nutr_no character(3) NOT NULL, datasrc_id character(6) NOT NULL Name: deriv_cd; Type: TABLE; Schema: public; Owner: -; Tablespace: CREATE TABLE deriv_cd ( deriv_cd text NOT NULL, derivcd_desc text NOT NULL 2
3 Name: fd_group; Type: TABLE; Schema: public; Owner: -; Tablespace: CREATE TABLE fd_group ( fdgrp_cd character(4) NOT NULL, fddrp_desc text NOT NULL Name: food_des; Type: TABLE; Schema: public; Owner: -; Tablespace: CREATE TABLE food_des ( ndb_no character(5) NOT NULL, fdgrp_cd character(4) NOT NULL, long_desc text NOT NULL, shrt_desc text NOT NULL, comname text, manufacname text, survey character(1), ref_desc text, refuse integer, sciname text, n_factor double precision, pro_factor double precision, fat_factor double precision, cho_factor double precision Name: footnote; Type: TABLE; Schema: public; Owner: -; Tablespace: 3 CREATE TABLE footnote ( ndb_no character(5) NOT NULL, footnt_no character(4) NOT NULL,
4 footnt_typ character(1) NOT NULL, nutr_no character(3), footnt_txt text NOT NULL Name: nut_data; Type: TABLE; Schema: public; Owner: -; Tablespace: CREATE TABLE nut_data ( ndb_no character(5) NOT NULL, nutr_no character(3) NOT NULL, nutr_val double precision NOT NULL, num_data_pts double precision NOT NULL, std_error double precision, src_cd integer NOT NULL, deriv_cd text, ref_ndb_no character(5), add_nutr_mark character(1), num_studies integer, min double precision, max double precision, df integer, low_eb double precision, up_eb double precision, stat_cmt text, cc character(1) Name: nutr_def; Type: TABLE; Schema: public; Owner: -; Tablespace: 4 CREATE TABLE nutr_def ( nutr_no character(3) NOT NULL, units text NOT NULL, tagname text, nutrdesc text,
5 num_dec smallint, sr_order integer Name: src_cd; Type: TABLE; Schema: public; Owner: -; Tablespace: CREATE TABLE src_cd ( src_cd integer NOT NULL, srccd_desc text NOT NULL Name: weight; Type: TABLE; Schema: public; Owner: -; Tablespace: CREATE TABLE weight ( ndb_no character(5) NOT NULL, seq character(2) NOT NULL, amount double precision NOT NULL, msre_desc text NOT NULL, gm_wgt double precision NOT NULL, num_data_pts integer, std_dev double precision Name: data_src_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: ALTER TABLE ONLY data_src ADD CONSTRAINT data_src_pkey PRIMARY KEY (datasrc_id 5
6 Name: datsrcln_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: ALTER TABLE ONLY datsrcln ADD CONSTRAINT datsrcln_pkey PRIMARY KEY (ndb_no, nutr_no, datasrc_id Name: deriv_cd_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: ALTER TABLE ONLY deriv_cd ADD CONSTRAINT deriv_cd_pkey PRIMARY KEY (deriv_cd Name: fd_group_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: ALTER TABLE ONLY fd_group ADD CONSTRAINT fd_group_pkey PRIMARY KEY (fdgrp_cd Name: food_des_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: ALTER TABLE ONLY food_des ADD CONSTRAINT food_des_pkey PRIMARY KEY (ndb_no Name: nut_data_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: ALTER TABLE ONLY nut_data ADD CONSTRAINT nut_data_pkey PRIMARY KEY (ndb_no, nutr_no 6
7 Name: nutr_def_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: ALTER TABLE ONLY nutr_def ADD CONSTRAINT nutr_def_pkey PRIMARY KEY (nutr_no Name: src_cd_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: ALTER TABLE ONLY src_cd ADD CONSTRAINT src_cd_pkey PRIMARY KEY (src_cd Name: weight_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: ALTER TABLE ONLY weight ADD CONSTRAINT weight_pkey PRIMARY KEY (ndb_no, seq Name: datsrcln_datasrc_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: CREATE INDEX datsrcln_datasrc_id_idx ON datsrcln USING btree (datasrc_id Name: food_des_fdgrp_cd_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: CREATE INDEX food_des_fdgrp_cd_idx ON food_des USING btree (fdgrp_cd Name: footnote_ndb_no_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 7
8 CREATE INDEX footnote_ndb_no_idx ON footnote USING btree (ndb_no, nutr_no Name: nut_data_deriv_cd_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: CREATE INDEX nut_data_deriv_cd_idx ON nut_data USING btree (deriv_cd Name: nut_data_nutr_no_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: CREATE INDEX nut_data_nutr_no_idx ON nut_data USING btree (nutr_no Name: nut_data_src_cd_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: CREATE INDEX nut_data_src_cd_idx ON nut_data USING btree (src_cd Name: datsrcln_datasrc_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - ALTER TABLE ONLY datsrcln ADD CONSTRAINT datsrcln_datasrc_id_fkey FOREIGN KEY (datasrc_id) REFERENCES data_src(datasrc_id Name: datsrcln_ndb_no_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - ALTER TABLE ONLY datsrcln 8
9 ADD CONSTRAINT datsrcln_ndb_no_fkey FOREIGN KEY (ndb_no, nutr_no) REFERENCES nut_data(ndb_no, nutr_no Name: food_des_fdgrp_cd_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - ALTER TABLE ONLY food_des ADD CONSTRAINT food_des_fdgrp_cd_fkey FOREIGN KEY (fdgrp_cd) REFERENCES fd_group(fdgrp_cd Name: footnote_ndb_no_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - ALTER TABLE ONLY footnote ADD CONSTRAINT footnote_ndb_no_fkey FOREIGN KEY (ndb_no) REFERENCES food_des(ndb_no Name: footnote_nutr_no_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - ALTER TABLE ONLY footnote ADD CONSTRAINT footnote_nutr_no_fkey FOREIGN KEY (nutr_no) REFERENCES nutr_def(nutr_no Name: nut_data_deriv_cd_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - ALTER TABLE ONLY nut_data ADD CONSTRAINT nut_data_deriv_cd_fkey FOREIGN KEY (deriv_cd) REFERENCES deriv_cd(deriv_cd 9
10 Name: nut_data_ndb_no_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - ALTER TABLE ONLY nut_data ADD CONSTRAINT nut_data_ndb_no_fkey FOREIGN KEY (ndb_no) REFERENCES food_des(ndb_no Name: nut_data_nutr_no_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - ALTER TABLE ONLY nut_data ADD CONSTRAINT nut_data_nutr_no_fkey FOREIGN KEY (nutr_no) REFERENCES nutr_def(nutr_no Name: nut_data_src_cd_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - ALTER TABLE ONLY nut_data ADD CONSTRAINT nut_data_src_cd_fkey FOREIGN KEY (src_cd) REFERENCES src_cd(src_cd Name: weight_ndb_no_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - ALTER TABLE ONLY weight ADD CONSTRAINT weight_ndb_no_fkey FOREIGN KEY (ndb_no) REFERENCES food_des(ndb_no 10
11 11
12 Queries to develop for the Company database 1. Retrieve the last name and address of all employees who earn more than the average salary. Present the results in sequence by last name. SELECT lname, address FROM public.employee where salary > (select avg(salary) from employee) order by lname; 2. For each employee list their last name and the number of people they supervise. All employees must be listed (even those who do not supervise anyone). List the employees in sequence by the number of employees supervised. SELECT s.lname, count(e.ssn) FROM public.employee s left outer join employee e on (s.ssn = e.super_ssn) group by s.ssn, s.lname order by count(e.ssn 12
13 3. List all first names (fname in employee, dependent_name in dependent) with no duplicates. There is one column in the result list. SELECT fname FROM public.employee union select dependent_name from dependent; 4. List the last name (no duplicates) of employees who work on both project 1 and project 2. SELECT distinct lname from employee where ssn in (select essn FROM works_on where pno = 1) and ssn in (select essn from works_on where pno = 2 13
14 5. Retrieve the last name of each employee who has a spouse. List the employees in sequence by last name. Do this in 3 different ways: a. Use the IN operator. SELECT lname from employee where ssn in (select essn from dependent where relationship = 'Spouse') order by lname; b. Use a correlated subquery. SELECT lname from employee e where exists (select * from dependent d where e.ssn = d.essn and relationship = 'Spouse') order by lname; c. Use the EXISTS operator. SELECT lname from employee e where exists (select * from dependent d where e.ssn = d.essn and relationship = 'Spouse') order by lname; 6. List the names of projects that have 3 or more employees working on them. List the projects alphabetically. SELECT pname FROM project p inner join works_on w on (pnumber=pno) group by pnumber, pname having count(*)>=3 order by pname; 14
15 7. For each employee, who has a dependent, list their last name and the name of their oldest dependent. Display the results in sequence by dependent s name. SELECT lname, dependent_name FROM employee e inner join dependent d on (ssn = essn) where d.bdate = (select min(bdate) from dependent y where e.ssn=y.essn Results: Employee last names and children in sequence oldest to youngest 15
16 8. For each employee list their last name and the number of other employees who are older. All employees must be listed, even the oldest. Display the results in sequence by employee s birth date. SELECT e.lname, count(older.ssn) FROM employee e left join employee older on (e.bdate>older.bdate) group by e.ssn, e.lname, e.bdate order by e.bdate; 9. For each project list the project name and the total number of hours employees have contributed. The list must be sequenced by the total hours. SELECT pname, sum(hours) FROM project left join works_on on (pnumber = pno) group by pnumber, pname order by sum(hours) 16
17 10. For each employee list their last name, the number of dependents they have, the name of the department they work in, where the department is located, and the last name of their supervisor. All employees must be listed. The results must be in sequence by department name and then by employee last name. select e.lname, count(d.essn), dname, s.lname from (employee e left join dependent d on (e.ssn = d.essn)) inner join department dp on (dno=dp.dnumber) left join employee s on (s.ssn = e.super_ssn) group by e.ssn, e.lname, dname, s.lname order by dname, e.lname 17
Database design process
Database technology Lecture 2: Relational databases and SQL Jose M. Peña jose.m.pena@liu.se Database design process 1 Relational model concepts... Attributes... EMPLOYEE FNAME M LNAME SSN BDATE ADDRESS
More informationCopyright 2016 Ramez Elmasri and Shamkant B. Navathe
CHAPTER 7 More SQL: Complex Queries, Triggers, Views, and Schema Modification Slide 7-2 Chapter 7 Outline More Complex SQL Retrieval Queries Specifying Semantic Constraints as Assertions and Actions as
More informationA taxonomy of SQL queries Learning Plan
A taxonomy of SQL queries Learning Plan a. Simple queries: selection, projection, sorting on a simple table i. Small-large number of attributes ii. Distinct output values iii. Renaming attributes iv. Computed
More informationOverview Relational data model
Thanks to José and Vaida for most of the slides. Relational databases and MySQL Juha Takkinen juhta@ida.liu.se Outline 1. Introduction: Relational data model and SQL 2. Creating tables in Mysql 3. Simple
More informationIntroduction to SQL. ECE 650 Systems Programming & Engineering Duke University, Spring 2018
Introduction to SQL ECE 650 Systems Programming & Engineering Duke University, Spring 2018 SQL Structured Query Language Major reason for commercial success of relational DBs Became a standard for relational
More informationDatabase Technology. Topic 3: SQL. Olaf Hartig.
Olaf Hartig olaf.hartig@liu.se Structured Query Language Declarative language (what data to get, not how) Considered one of the major reasons for the commercial success of relational databases Statements
More informationMore SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries
More informationDatabase Technology. Topic 2: Relational Databases and SQL. Olaf Hartig.
Topic 2: Relational Databases and SQL Olaf Hartig olaf.hartig@liu.se Relational Data Model Recall: DB Design Process 3 Relational Model Concepts Relational database: represent data as a collection of relations
More informationSession Active Databases (2+3 of 3)
INFO-H-415 - Advanced Databes Session 2+3 - Active Databes (2+3 of 3) Consider the following databe schema: DeptLocation DNumber DLocation Employee FName MInit LName SSN BDate Address Sex Salary SuperSSN
More informationSlides by: Ms. Shree Jaswal
Slides by: Ms. Shree Jaswal Overview of SQL, Data Definition Commands, Set operations, aggregate function, null values, Data Manipulation commands, Data Control commands, Views in SQL, Complex Retrieval
More informationMore SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries
More informationECE 650 Systems Programming & Engineering. Spring 2018
ECE 650 Systems Programming & Engineering Spring 2018 Introduction to SQL Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Structured Query Language SQL Major reason for commercial
More informationCSC 742 Database Management Systems
CSC 742 Database Management Systems Topic #16: Query Optimization Spring 2002 CSC 742: DBMS by Dr. Peng Ning 1 Agenda Typical steps of query processing Two main techniques for query optimization Heuristics
More informationChapter 8. Joined Relations. Joined Relations. SQL-99: Schema Definition, Basic Constraints, and Queries
Copyright 2004 Pearson Education, Inc. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries Joined Relations Can specify a "joined relation" in the FROM-clause Looks like any other relation
More informationMore SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries
More informationSQL STRUCTURED QUERY LANGUAGE
STRUCTURED QUERY LANGUAGE SQL Structured Query Language 4.1 Introduction Originally, SQL was called SEQUEL (for Structured English QUery Language) and implemented at IBM Research as the interface for an
More informationChapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries
Copyright 2004 Pearson Education, Inc. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries Copyright 2004 Pearson Education, Inc. 1 Data Definition, Constraints, and Schema Changes Used
More informationL130 - DATABASE MANAGEMENT SYSTEMS LAB CYCLE-1 1) Create a table STUDENT with appropriate data types and perform the following queries.
L130 - DATABASE MANAGEMENT SYSTEMS LAB CYCLE-1 1) Create a table STUDENT with appropriate data types and perform the following queries. Roll number, student name, date of birth, branch and year of study.
More informationSQL: Advanced Queries, Assertions, Triggers, and Views. Copyright 2012 Ramez Elmasri and Shamkant B. Navathe
SQL: Advanced Queries, Assertions, Triggers, and Views Copyright 2012 Ramez Elmasri and Shamkant B. Navathe NULLS IN SQL QUERIES SQL allows queries that check if a value is NULL (missing or undefined or
More informationChapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Chapter 5 Outline More Complex SQL Retrieval
More informationSQL-99: Schema Definition, Basic Constraints, and Queries. Create, drop, alter Features Added in SQL2 and SQL-99
SQL-99: Schema Definition, Basic Constraints, and Queries Content Data Definition Language Create, drop, alter Features Added in SQL2 and SQL-99 Basic Structure and retrieval queries in SQL Set Operations
More informationCOSC344 Database Theory and Applications. Lecture 6 SQL Data Manipulation Language (1)
COSC344 Database Theory and Applications Lecture 6 SQL Data Manipulation Language (1) COSC344 Lecture 56 1 Overview Last Lecture SQL - DDL This Lecture SQL - DML INSERT DELETE (simple) UPDATE (simple)
More informationSQL. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe
SQL Copyright 2013 Ramez Elmasri and Shamkant B. Navathe Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations) of a database Copyright
More informationCOSC344 Database Theory and Applications. σ a= c (P) S. Lecture 4 Relational algebra. π A, P X Q. COSC344 Lecture 4 1
COSC344 Database Theory and Applications σ a= c (P) S π A, C (H) P P X Q Lecture 4 Relational algebra COSC344 Lecture 4 1 Overview Last Lecture Relational Model This Lecture ER to Relational mapping Relational
More informationAnnouncement5 SQL5. Create%and%drop%table5. Basic%SFW%query5. Reading%a%table5. TDDD37%% Database%technology% SQL5
Announcement %% Database%technology% SQL Fang%Wei9Kleiner fang.wei9kleiner@liu.se hbp://www.ida.liu.se/~ Course%registration:%system%problems%from%registration% office.%be%patient. Registration%for%the%lab:%possible%without%being%
More informationStructured Query Language (SQL)
Structured Query Language (SQL) SQL Chapters 6 & 7 (7 th edition) Chapters 4 & 5 (6 th edition) PostgreSQL on acsmysql1.acs.uwinnipeg.ca Each student has a userid and initial password acs!
More informationECE 650 Systems Programming & Engineering. Spring 2018
ECE 650 Systems Programming & Engineering Spring 2018 Relational Databases: Tuples, Tables, Schemas, Relational Algebra Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Overview
More informationOutline. Note 1. CSIE30600 Database Systems More SQL 2
Outline More Complex SQL Retrieval Queries Specifying Constraints as Assertions and Actions as Triggers Views (Virtual Tables) in SQL Schema Change Statements in SQL CSIE30600 Database Systems More SQL
More informationSQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT
SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT Contents 1 The COMPANY Database 2 SQL developments: an overview 3 DDL: Create, Alter, Drop 4 DML: select, insert, update, delete 5 Triggers The
More informationAlgorithms for Query Processing and Optimization. 0. Introduction to Query Processing (1)
Chapter 19 Algorithms for Query Processing and Optimization 0. Introduction to Query Processing (1) Query optimization: The process of choosing a suitable execution strategy for processing a query. Two
More informationSQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT
SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT Contents 1 The COMPANY Database 2 SQL developments: an overview 3 DDL: Create, Alter, Drop 4 DML: select, insert, update, delete 5 Triggers The
More informationCS 338 Nested SQL Queries
CS 338 Nested SQL Queries Bojana Bislimovska Spring 2017 Exercises 2. A database for an organization that shelters animals, and people can go and adopt animals that they shelter, has the following set
More informationChapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement
Chapter 4 Basic SQL Basic SQL SQL language Considered one of the major reasons for the commercial success of relational databases SQL Structured Query Language Statements for data definitions, queries,
More informationBasic SQL II. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation
Basic SQL II Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation Lab 1 Review
More informationDBMS LAB SESSION PAVANKUMAR MP
DBMS LAB SESSION Pavan Kumar M.P B.E,M.Sc(Tech) by Research,(Ph.D) Assistant Professor Dept of ISE J.N.N.College Of Engineering Shimoga http://pavankumarjnnce.blogspot.in Consider the schema for Company
More informationChapter 3. Algorithms for Query Processing and Optimization
Chapter 3 Algorithms for Query Processing and Optimization Chapter Outline 1. Introduction to Query Processing 2. Translating SQL Queries into Relational Algebra 3. Algorithms for External Sorting 4. Algorithms
More informationChapter 19 Query Optimization
Chapter 19 Query Optimization It is an activity conducted by the query optimizer to select the best available strategy for executing the query. 1. Query Trees and Heuristics for Query Optimization - Apply
More informationSimple SQL Queries (contd.)
Simple SQL Queries (contd.) Example of a simple query on one relation Query 0: Retrieve the birthdate and address of the employee whose name is 'John B. Smith'. Q0: SELECT BDATE, ADDRESS FROM EMPLOYEE
More informationSQL Queries. COSC 304 Introduction to Database Systems SQL. Example Relations. SQL and Relational Algebra. Example Relation Instances
COSC 304 Introduction to Database Systems SQL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Queries Querying with SQL is performed using a SELECT statement. The general
More informationCIS611 Lab Assignment 1 SS Chung
CIS611 Lab Assignment 1 SS Chung 1. Creating a Relational Database Schema from ER Diagram, Populating the Database and Querying Over the database with SQL 2. Automatic Creation and Maintenance of Database
More informationCOSC 304 Introduction to Database Systems SQL. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 304 Introduction to Database Systems SQL Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca SQL Queries Querying with SQL is performed using a SELECT statement. The general
More informationCS 348 Introduction to Database Management Assignment 2
CS 348 Introduction to Database Management Assignment 2 Due: 30 October 2012 9:00AM Returned: 8 November 2012 Appeal deadline: One week after return Lead TA: Jiewen Wu Submission Instructions: By the indicated
More informationOutline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2
Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features of SQL Textbook Chapter 6 CSIE30600/CSIEB0290
More informationCSIE30600 Database Systems Basic SQL 2. Outline
Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features of SQL CSIE30600 Database Systems
More informationAdvanced Databases. Winter Term 2012/13. Prof. Dr. Dietmar Seipel University of Würzburg. Advanced Databases Winter Term 2012/13
Advanced Databases Winter Term 2012/13 Prof. Dr. Dietmar Seipel University of Würzburg Prof. Dr. Dietmar Seipel Minit FName LName Sex Adress Salary N WORKS_FOR 1 Name Number Locations Name SSN EMPLOYEE
More informationPES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II
PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore 560100 ) Solution Set - Test-II Sub: Database Management Systems 16MCA23 Date: 04/04/2017 Sem & Section:II Duration:
More informationIntroduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe
Introduction to Query Processing and Query Optimization Techniques Outline Translating SQL Queries into Relational Algebra Algorithms for External Sorting Algorithms for SELECT and JOIN Operations Algorithms
More informationBasic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation
Basic SQL Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation MIDTERM EXAM 2 Basic
More informationCS 338 Basic SQL Part II
CS 338 Basic SQL Part II Bojana Bislimovska Spring 2017 Major research Outline Basic Retrieval Queries Exercises Ambiguous Attribute Names Major research Same name can be used for two or more attributes
More informationMIT Database Management Systems Lesson 03: ER-to-Relational Mapping
MIT 22033 Database Management Systems Lesson 03: ER-to-Relational Mapping By S. Sabraz Nawaz Senior Lecturer in MIT Department of Management and IT, SEUSL Chapter Outline ER-to-Relational Mapping Algorithm
More informationRef1 for STUDENT RECORD DB: Ref2 for COMPANY DB:
Lect#5: SQL Ref1 for STUDENT RECORD DB: Database Design and Implementation Edward Sciore, Boston College ISBN: 978-0-471-75716-0 Ref2 for COMPANY DB: Fund. of Database Systems, Elmasri, Navathe, 5th ed.,
More informationNESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)
1 NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE More Complex SQL Retrieval Queries Self-Joins Renaming Attributes and Results Grouping, Aggregation, and Group Filtering
More informationChapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA
Chapter 6: Relational Data Model and Relational Algebra 1 Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA RELATIONAL MODEL CONCEPTS The relational model represents the database as a collection
More informationTranslation ER/EER to relational
Database technology Lecture 4: Mapping of EER model to relations Jose M. Peña jose.m.pena@liu.se Translation ER/EER to relational Migrate from mini world model to a model understandable by a DBMS. 1 EER
More informationPart 1 on Table Function
CIS611 Lab Assignment 1 SS Chung 1. Write Table Functions 2. Automatic Creation and Maintenance of Database from Web Interface 3. Transforming a SQL Query into an Execution Plan in Relational Algebra for
More informationData Definition Language (DDL)
Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Database Lab (ECOM 4113) Lab 6 Data Definition Language (DDL) Eng. Mohammed Alokshiya November 11, 2014 Database Keys A key
More informationRELATIONAL DATA MODEL
RELATIONAL DATA MODEL 3.1 Introduction The relational model of data was introduced by Codd (1970). It is based on a simple and uniform data structure - the relation - and has a solid theoretical and mathematical
More informationDatabase Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra
Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra Relational Data Model and Relational Constraints Part 1 A simplified diagram to illustrate the main
More informationNESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)
1 NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E) 2 LECTURE OUTLINE More Complex SQL Retrieval Queries Self-Joins Renaming Attributes and Results Grouping, Aggregation, and Group Filtering
More informationTopics. CSCI 403 Database Management DISTINCT. JOIN Clause 2/4/2019 DISTINCT JOINS. 12 Miscellaneous Topics
Topics CSCI 403 Database Management 12 Miscellaneous Topics This lecture is for stuff I forgot or didn t have time to cover so far Miscellaneous SELECT DISTINCT JOIN clause and outer joins SET operations
More informationChapter 6 - Part II The Relational Algebra and Calculus
Chapter 6 - Part II The Relational Algebra and Calculus Copyright 2004 Ramez Elmasri and Shamkant Navathe Division operation DIVISION Operation The division operation is applied to two relations R(Z) S(X),
More informationBasic SQL. Basic SQL. Basic SQL
Basic SQL Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation Basic SQL Structured
More informationCopyright 2016 Ramez Elmasri and Shamkant B. Navathe
CHAPTER 6 Basic SQL Slide 6-2 Chapter 6 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features
More informationChapter 18 Strategies for Query Processing. We focus this discussion w.r.t RDBMS, however, they are applicable to OODBS.
Chapter 18 Strategies for Query Processing We focus this discussion w.r.t RDBMS, however, they are applicable to OODBS. 1 1. Translating SQL Queries into Relational Algebra and Other Operators - SQL is
More informationPractical Project Report
Practical Project Report May 11, 2017 I. People: II. Roles: Effort in both coding PL/SQL and writing III. Introduction: The topic of my project is DB queries using Oracle PL/SQL. This is my first time
More informationCS5300 Database Systems
CS5300 Database Systems Views A.R. Hurson 323 CS Building hurson@mst.edu Note, this unit will be covered in two lectures. In case you finish it earlier, then you have the following options: 1) Take the
More informationRelational Model. CS 377: Database Systems
Relational Model CS 377: Database Systems ER Model: Recap Recap: Conceptual Models A high-level description of the database Sufficiently precise that technical people can understand it But, not so precise
More informationChapter 8: Relational Algebra
Chapter 8: elational Algebra Outline: Introduction Unary elational Operations. Select Operator (σ) Project Operator (π) ename Operator (ρ) Assignment Operator ( ) Binary elational Operations. Set Operators
More informationChapter 8: The Relational Algebra and The Relational Calculus
Ramez Elmasri, Shamkant B. Navathe(2017) Fundamentals of Database Systems (7th Edition),pearson, isbn 10: 0-13-397077-9;isbn-13:978-0-13-397077-7. Chapter 8: The Relational Algebra and The Relational Calculus
More informationSQL Introduction. CS 377: Database Systems
SQL Introduction CS 377: Database Systems Recap: Last Two Weeks Requirement analysis Conceptual design Logical design Physical dependence Requirement specification Conceptual data model (ER Model) Representation
More informationAggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014
Aggregation Lecture 7 Section 5.1.7-5.1.8 Robb T. Koether Hampden-Sydney College Wed, Jan 29, 2014 Robb T. Koether (Hampden-Sydney College) Aggregation Wed, Jan 29, 2014 1 / 17 1 Aggregate Functions 2
More informationCOSC344 Database Theory and Applications. COSC344 Lecture 15 1
COSC344 Database Theory and Applications Lecture 15 Views & NULL COSC344 Lecture 15 1 Lecture Schedule Lecture 15 Views and Null Lecture 16 DBMS Architecture and System Catalog Lecture 17 Transactions
More informationCS430 Final March 14, 2005
Name: W#: CS430 Final March 14, 2005 Write your answers in the space provided. Use the back of the page if you need more space. Values of questions are as indicated. 1. (4 points) What are the four ACID
More informationAdvanced Databases (SE487) Prince Sultan University College of Computer and Information Sciences
Advanced Databases (SE487) Prince Sultan University College of Computer and Information Sciences ER to Relational Mapping Anis Koubaa Chapter 9 Outline } Relational Database Design Using ER-to-Relational
More informationCOSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1
COSC344 Database Theory and Applications Lecture 5 SQL - Data Definition Language COSC344 Lecture 5 1 Overview Last Lecture Relational algebra This Lecture Relational algebra (continued) SQL - DDL CREATE
More informationSQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements,
SQL: A COMMERCIAL DATABASE LANGUAGE Data Change Statements, Outline 1. Introduction 2. Data Definition, Basic Constraints, and Schema Changes 3. Basic Queries 4. More complex Queries 5. Aggregate Functions
More informationQuery Processing & Optimization. CS 377: Database Systems
Query Processing & Optimization CS 377: Database Systems Recap: File Organization & Indexing Physical level support for data retrieval File organization: ordered or sequential file to find items using
More informationA subquery is a nested query inserted inside a large query Generally occurs with select, from, where Also known as inner query or inner select,
Sub queries A subquery is a nested query inserted inside a large query Generally occurs with select, from, where Also known as inner query or inner select, Result of the inner query is passed to the main
More informationNote that it works well to answer questions on computer instead of on the board.
1) SELECT pname FROM Proj WHERE budget > 250000; 2) SELECT eno FROM Emp where salary < 30000; 3) SELECT DISTINCT resp from WorksOn; 4) SELECT ename FROM Emp WHERE bdate > DATE 1970-07-01' and salary >
More informationRelational Algebra 1
Relational Algebra 1 Motivation The relational data model provides a means of defining the database structure and constraints NAME SALARY ADDRESS DEPT Smith 50k St. Lucia Printing Dilbert 40k Taringa Printing
More informationSQL- Updates, Asser0ons and Views
SQL- Updates, Asser0ons and Views Data Defini0on, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descrip0ons of the tables (rela0ons) of a database CREATE TABLE In SQL2, can use the
More informationSQL Data Query Language
SQL Data Query Language André Restivo 1 / 68 Index Introduction Selecting Data Choosing Columns Filtering Rows Set Operators Joining Tables Aggregating Data Sorting Rows Limiting Data Text Operators Nested
More informationChapter 7 Relational Database Design by ER- and EERR-to-Relational Mapping
Chapter 7 Relational Database Design by ER- and EERR-to-Relational Mapping Copyright 2004 Pearson Education, Inc. Chapter Outline ER-to-Relational Mapping Algorithm Step 1: Mapping of Regular Entity Types
More informationOutline. Note 1. CSIE30600 Database Systems ER/EER to Relational Mapping 2
Outline ER-to-Relational Mapping Algorithm Step 1: Mapping of Regular Entity Types Step 2: Mapping of Weak Entity Types Step 3: Mapping of Binary 1:1 Relation Types Step 4: Mapping of Binary 1:N Relationship
More informationIntegrity Coded Relational Databases (ICRDB) - Protecting Data Integrity in Clouds
Integrity Coded Relational Databases (ICRDB) - Protecting Data Integrity in Clouds Jyh-haw Yeh Dept. of Computer Science, Boise State University, Boise, Idaho 83725, USA Abstract 1 Introduction Database-as-a-service
More informationDatabase Systems CSE 303. Outline. Lecture 06: SQL. What is Sub-query? Sub-query in WHERE clause Subquery
Database Systems CSE 303 Lecture 06: SQL 2016 Subquery Outline What is a Subquery Subquery in WHERE clause >ALL, >ANY, >=ALL,
More informationQuerying Data with Transact SQL
Course 20761A: Querying Data with Transact SQL Course details Course Outline Module 1: Introduction to Microsoft SQL Server 2016 This module introduces SQL Server, the versions of SQL Server, including
More informationCS W Introduction to Databases Spring Computer Science Department Columbia University
CS W4111.001 Introduction to Databases Spring 2018 Computer Science Department Columbia University 1 in SQL 1. Key constraints (PRIMARY KEY and UNIQUE) 2. Referential integrity constraints (FOREIGN KEY
More informationDatabase Management Systems,
Database Management Systems SQL Query Language (3) 1 Topics Aggregate Functions in Queries count sum max min avg Group by queries Set Operations in SQL Queries Views 2 Aggregate Functions Tables are collections
More informationUNIT-V SQL Explain insert, delete and update statements in SQL with example.
UNIT-V SQL 2 1. Explain insert, delete and update statements in SQL with example. 8 Marks (Dec/Jan 2013 & June/July 2015) The Insert Operation This operation can violate all constraints in a relational
More informationQuerying Data with Transact-SQL
Querying Data with Transact-SQL Course: 20761 Course Details Audience(s): IT Professional(s) Technology: Microsoft SQL Server 2016 Duration: 24 HRs. ABOUT THIS COURSE This course is designed to introduce
More informationCourse Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course:
Course Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course: 20762C Developing SQL 2016 Databases Module 1: An Introduction to Database Development Introduction to the
More informationMTA Database Administrator Fundamentals Course
MTA Database Administrator Fundamentals Course Session 1 Section A: Database Tables Tables Representing Data with Tables SQL Server Management Studio Section B: Database Relationships Flat File Databases
More informationTHE ENTITY- RELATIONSHIP (ER) MODEL CHAPTER 7 (6/E) CHAPTER 3 (5/E)
THE ENTITY- RELATIONSHIP (ER) MODEL CHAPTER 7 (6/E) CHAPTER 3 (5/E) 2 CHAPTER 7 OUTLINE Using High-Level, Conceptual Data Models for Database Design Entity-Relationship (ER) model Popular high-level conceptual
More informationQuery 2: Pnumber Dnum Lname Address Bdate 10 4 Wallace 291 Berry, Bellaire, TX Wallace 291 Berry, Bellaire, TX
5.11 No violation, integrity is retained. Dnum = 2 does not exist. This can be solved by adding a foreign key referencing the department table, so the operation does not execute. Dnum = 4 already exists,
More informationWentworth Institute of Technology COMP2670 Databases Spring 2016 Derbinsky. Physical Tuning. Lecture 12. Physical Tuning
Lecture 12 1 Context Influential Factors Knobs Database Design Denormalization Query Design Outline 2 Database Design and Implementation Process 3 Factors that Influence Attributes w.r.t. Queries/Transactions
More informationChapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 4 Basic SQL Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries
More informationQuerying a Relational Database COMPANY database For Lab4, you use the Company database that you built in Lab2 and used for Lab3
CIS30/530 Lab Assignment SS Chung Querying a Relational Database COMPANY database For Lab, you use the Company database that you built in Lab2 and used for Lab3 1. Update the following new changes into
More informationData Manipulation Language (DML)
In the name of Allah Islamic University of Gaza Faculty of Engineering Computer Engineering Department ECOM 4113 DataBase Lab Lab # 3 Data Manipulation Language (DML) El-masry 2013 Objective To be familiar
More information