+ 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
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 7 th Edition.
Advertisements

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.
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.
Introduction to Structured Query Language (SQL)
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.
Getting Started Chapter One DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Getting Started with Microsoft SQL Server 2012 Express Edition Appendix A DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Concepts of Database Management Sixth Edition
Why Databases.
Getting Started with Microsoft Access The Access Workbench: Section One DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
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 Part 2 KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall.
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.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
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.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 3 rd Edition.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Database Design IST210 Class Lecture
SQL (DDL & DML Commands)
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Chapter 4 Database Processing Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall 4-1.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
© 2002 by Prentice Hall 1 Database Processing with Microsoft Access David M. Kroenke Database Concepts 1e Appendix A.
Database Processing with Microsoft Access Appendix DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
STRUCTURED QUERY LANGUAGE SQL-II IST 210 Organization of Data IST210 1.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
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.
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.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
 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
The Relational Model Chapter Two DATABASE CONCEPTS, 3rd Edition
SQL.
David M. Kroenke and David J
CIS16 Application Programming with Visual Basic
Structured Query Language
Getting Started Chapter One DATABASE CONCEPTS, 5th Edition
The University of Akron College of Applied Science & Technology Dept
Presentation transcript:

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

+ Virtual Machines IT should have created a machine for everyone. Login attempt: Open Management Studio, Server name: upsql Use Windows authentication & your username KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Midterm Basics Thursday OCTOBER 15 during Class Class on Tuesday October 13 – Review Session Come prepared with questions and topics you want to 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

+ Final Project What we’re looking for: We want you to create a hypothetical database from start to finish Can be something practical, or even something not as practical You will need: A data diagram To actually build a database and fill it with data Run SQL SELECT statements on your database, and more Provide a front-end interface for your database (website, or other) A final, brief report on the functions of your database KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Final Project: Example I like the NFL. I’m going to make a database that tracks teams and players. I might create two tables. A PLAYERS table and a TEAM table. I would create a data diagram of all of the columns within each table that I would want, and include any primary and foreign keys. I would then create this database in SQL Management studio based on my data diagram using SQL statements Then, I would load player data and team data into the tables I would write example statements that would allow me to access parts of the data like: SELECT PlayerName FROM PLAYERS WHERE rushYards > 500; KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Final Project: Example Then, I would create some kind of visual front-end where I could construct these queries on the fly. This could take the form of a website, or something else. We will discuss how to do this in November. Finally, I would write or create another form of a brief report discussing how this database works. That’s it! KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall

+ Review and Questions Topics from last lecture Questions?

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

+ SQL for Data Definition – On Repeat 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

+ 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

+ 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 – END REVIEW 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

+ 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. What if we’re selecting from more than one column? 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