+ Structured Query Language Part 2 KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall.

Slides:



Advertisements
Similar presentations
(wrapping up from last week)
Advertisements

Database Design Chapter Five DATABASE CONCEPTS, 6th Edition
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 7 th Edition.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Structured Query Language Chapter Three Part 3 – Inserts, Updates, Deletes.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Structured Query Language Part II Chapter Three CIS 218.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Structured Query Language Part I Chapter Three CIS 218.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
David M. Kroenke and David J
Getting Started Chapter One DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Concepts of Database Management Sixth Edition
Why Databases.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
Structured Query Language
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
Getting Started Chapter One DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Working with Queries in Microsoft Access The Access Workbench: Section Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 3 rd Edition.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
2440: 141 Web Site Administration Database Management Using SQL Professor: Enoch E. Damson.
Database Basics CPSC 4670/ Purpose of a Database The purpose of a database is to keep track of things Unlike a list or spreadsheet, a database.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
Database Design IST210 Class Lecture
SQL (DDL & DML Commands)
Concepts of Database Management Seventh Edition
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
STRUCTURED QUERY LANGUAGE SQL-II IST 210 Organization of Data IST210 1.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
+ Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Structured Query Language
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
+ Midterm Review. + Notes from the Midterm When updating, deleting records Make sure you have a WHERE statement that only will give you the row(s) you.
+ Complex SQL Week 9. + Today’s Objectives TOP GROUP BY JOIN Inner vs. Outer Right vs. Left.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
+ Structured Query Language Part 2 KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
 CONACT UC:  Magnific training   
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Fundamentals of DBMS Notes-1.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Structured Query Language
CSIS 115 Database Design and Applications for Business
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
David M. Kroenke and David J
The Relational Model Chapter Two DATABASE CONCEPTS, 3rd Edition
Chapter 4 Relational Databases
David M. Kroenke and David J
Introduction To Structured Query Language (SQL)
Structured Query Language
Introduction To Structured Query Language (SQL)
Getting Started Chapter One DATABASE CONCEPTS, 5th Edition
The University of Akron College of Applied Science & Technology Dept
Manipulating Data Lesson 3.
Presentation transcript:

+ Structured Query Language Part 2 KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Review and Questions Topics from last lecture Terminology Questions?

+ Midterm Basics Wednesday February 27 during Class There will be no lab after the midterm Class on Monday February 25 – Review Session Possibly a sample test that if you take it you can earn extra credit of.5% on top of your over grade Come prepared with questions and topics you want to review. I will not have questions prepped if no one asks anything there will be no review. KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Midterm Topics General Topics ACID, Base and CAP Theorem General things about Big Data Acronym meanings Problems and Advantages with Lists KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Midterm Topics Database Design Analyzing Needs Writing Relations ER Diagrams & Crows Feet Diagram KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Midterm Topics SQL Create Tables Alter Tables Select Records Insert Records Update Records Delete Records Delete Tables KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL Take 2 KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Definition The SQL data definition statements include: CREATE To create database objects ALTER To modify the structure and/or characteristics of database objects DROP To delete database objects TRUNCATE To delete table data while keeping structure KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Create Table CREATE TABLE EMPLOYEE( EmpID Integer NOT NULL, EmpName Char(25) NOT NULL CONSTRAINT Emp_PK PRIMARY KEY(EmpID) ); CREATE TABLE EMPLOYEE( EmpID Integer PRIMARY KEY, EmpName Char(25) NOT NULL ); KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Create CREATE TABLE EMP_SKILL( EmpID Integer NOT NULL, SkillID Integer NOT NULL, SkillLevel IntegerNULL, CONSTRAINT EmpSkill_PK PRIMARY KEY(EmpID, SkillID) ); KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Create Table Activity Create the following tables DEPARTMENT (Department, DeptPhone) EMPLOYEE (EmployeeNumber, LastName, , Department) KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ ALTER Table ALTER TABLE EMPLOYEE ADD CONSTRAINT Emp_PK PRIMARY KEY(EmpID); ALTER TABLE EMP_SKILL ADD CONSTRAINT EmpSkill_PK PRIMARY KEY(EmpID, SkillID); KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ INSERT INSERT INTO EMPLOYEE VALUES(91, 'Smither', 12); INSERT INTO EMPLOYEE (EmpID, SalaryCode) VALUES (62, 11); KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Insert Activity Insert the following data KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Queries SELECT EmpName FROM EMPLOYEE WHEREEmpID = ; SELECT * FROM EMPLOYEE; KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Queries SELECT DISTINCT DeptID FROM EMPLOYEE; KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Drop Table DROP TABLE EMPLOYEE; KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Modifying Data using SQL Insert Will add a new row in a table (already discussed above) Update Will update the data in a table that matches the specified criteria Delete Will delete the data in a table that matches the specified criteria KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Modifying Data using SQL: Changing Data Values: UPDATE To change the data values in an existing row (or set of rows) use the Update statement. UPDATE EMPLOYEE SET Phone ' ' WHERE EmpID = 29; UPDATE EMPLOYEE SET DeptID = 44 WHERE EmpName LIKE 'Kr%'; KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Modifying Data using SQL: Deleting Data: DELETE To delete a row or set of rows from a table use the DELETE statement. DELETE FROM EMPLOYEE WHERE EmpID = 29; DELETE FROM EMPLOYEE WHERE EmpName LIKE ' Kr% ' ; KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Class Activity Drop the employee and the department tables Go to the class schedule and download the sql script called Sweeny Execute the sql script on your database KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Retrieval: Queries SELECT is the best known SQL statement. SELECT will retrieve information from the database that matches the specified criteria using the SELECT/FROM/WHERE framework. SELECT EmpName FROM EMPLOYEE WHEREEmpID = ; KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Retrieval: The Results of a Query Is a Relation A query pulls information from one or more relations and creates (temporarily) a new relation. This allows a query to: Create a new relation Feed information to another query (as a “sub- query”) KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Retrieval: Match Criteria The WHERE clause match criteria may include Equals “=” Not Equals “<>” Greater than “>” Less than “<” Greater than or Equal to “>=” Less than or Equal to “<=” KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Class Activity Write an SQL statement to list all columns and data from the Contact Table Write an SQL statement to list FirstName, LastName, and Phone for all the customers who live in Dallas KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Retrieval: Match Operators Multiple matching criteria may be specified using AND Representing an intersection of the data sets OR Representing a union of the data sets KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Retrieval: Operator Examples SELECT EmpName FROM EMPLOYEE WHERE DeptID < 7 OR DeptID > 12; SELECT EmpName FROM EMPLOYEE WHERE DeptID = 9 AND SalaryCode <= 23; KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Retrieval: A List of Values The WHERE clause may include the IN keyword to specify that a particular column value must be included in a list of values. SELECT EmpName FROM EMPLOYEE WHERE DeptID IN (4, 8, 9); KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Retrieval: The Logical NOT Operator Any criteria statement may be preceded by a NOT operator, which is to say that all information will be shown except that information matching the specified criteria SELECT EmpName FROM EMPLOYEE WHERE DeptID NOT IN (4, 8, 9); KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Retrieval: Finding Data in a Range of Values SQL provides a BETWEEN keyword that allows a user to specify a minimum and maximum value on one line. SELECT EmpName FROM EMPLOYEE WHERE SalaryCode BETWEEN 10 AND 45; KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Retrieval: Allowing for Wildcard Searches The SQL LIKE keyword allows searches on partial data values. LIKE can be paired with wildcards to find rows matching a string value. Multiple character wildcard character is a percent sign (%). Single character wildcard character is an underscore (_). KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Retrieval: Wildcard Search Examples SELECTEmpID FROM EMPLOYEE WHERE EmpName LIKE 'Kr%'; SELECT EmpID FROM EMPLOYEE WHERE Phone LIKE '616-___-____'; KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ SQL for Data Retrieval: Sorting the Results Query results may be sorted using the ORDER BY clause. SELECT * FROM EMPLOYEE ORDER BY EmpName; KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Class Activity Write an SQL statement to list FirstName, LastName, and Phone for all the customers who live in Dallas and have a lastname that begins with the letter T Write an SQL statement to list FirstName, LastName, ProductNumber and Description of product (list each combination of name and product only once.) who have purchased a video product (Hint: Video products have a ProductNumber that starts with VK.)