SQL (Standard Query Language) Yong Choi School of Business CSU, Bakersfield.

Slides:



Advertisements
Similar presentations
Multiple Table Queries
Advertisements

Chapter 4 Joining Multiple Tables
Yong Choi School of Business CSU, Bakersfield
Microsoft Access 3 Database Creation and Management.
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Microsoft Access 3 Database Creation and Management.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
SQL – Part II Yong Choi School of Business CSU, Bakersfield.
SQL – Part II Yong Choi School of Business CSU, Bakersfield.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Concepts of Database Management Sixth Edition
QUERYING A DATABASE By: Dr.Ennis-Cole. OBJECTIVES: Learn how to use the Query window in Design view Create, run and Save queries Define a relationship.
Introduction to Structured Query Language (SQL)
Databases Tutorial 2 Further Select Statements. Objectives for Week Data types Sort retrieved data Formatting output.
Chapter 3: SQL – Part I Yong Choi School of Business CSU, Bakersfield.
SQL – Part I Yong Choi School of Business CSU, Bakersfield.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Introduction to SQL Yong Choi School of Business CSU, Bakersfield.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Concepts of Database Management, Fifth Edition Chapter 4: The Relational Model 3: Advanced Topics.
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
SQL – Part II Yong Choi School of Business CSU, Bakersfield.
Microsoft Access 3 Database Creation and Management.
Concepts of Database Management Seventh Edition Chapter 4 Keys and Relationship.
Introduction to databases and SQL. What is a database?  A database is an organized way of holding together pieces of information  A database refers.
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
Chapter 5: Normalizing the DB. What to do with a bad database structure? How do we determine the right structure? How do we determine primary keys? Normalization.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
SQL – Part I Yong Choi School of Business CSU, Bakersfield.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Concepts of Database Management Seventh Edition
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
SQL – Part I Yong Choi School of Business CSU, Bakersfield.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Management Information Systems Introduction to Databases Lab Dr. Shankar Sundaresan.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Concepts of Database Management Seventh Edition Chapter 4 Keys and Relationship.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Web Systems & Technologies
Chapter 5 Introduction to SQL.
Introduction to Structured Query Language(SQL)
ATS Application Programming: Java Programming
ORACLE SQL Developer & SQLPLUS Statements
CIS16 Application Programming with Visual Basic
Yong Choi School of Business CSU, Bakersfield
Yong Choi School of Business CSU, Bakersfield
Yong Choi School of Business CSU, Bakersfield
Introduction To Structured Query Language (SQL)
Chapter 1 Introduction.
Chapter 1 Introduction.
The University of Akron College of Applied Science & Technology Dept
Presentation transcript:

SQL (Standard Query Language) Yong Choi School of Business CSU, Bakersfield

2 Study Objectives Understand the basic commands and functions of SQL Learn how to use SQL to query a database to extract useful information Practice SQL

3 Introduction to SQL Standard Query Language (SQL) is a computer language for the relational database model. SQL is a nonprocedural language (click here for the example). So, it is much easier to use.here –what is to be done without having to worry about how it's to be done. Procedural language (click here for the example)here –Must be programmed correctly and compiled –Java, C++, and Pascal. SQL is relatively easy to learn –SQL commands set has a basic vocabulary of less than 100 words. Go To Next Topic

4 SQL Example SELECT ID, L_Name, F_Name, Salary, Dept_No FROM Employee; ID L_Name F_Name Salary Dept_No Kim John Johnson Steve Jonson Paul Lee Jim Basinger Jon Stone Sharon rows selected. Back

5 JAVA Example public class JavaProgramming { public static void main ( String[] args ) { long payAmount; payAmount = 123; System.out.println("The variable contains: " + payAmount ); } Output: The Variable contains 123. Back

6 Basic SQL Commands Followings are the most frequently used commands –Use always SELECT FROM –Use when conditions must be specified WHERE HAVING ORDER BY GROUP BY

7 The SELECT and FROM Statement Need both commands almost always….. –The SELECT statement is used to select data from a table. –The FROM statement is used to select tables. Syntax: –SELECT column_name(s) –FROM table_name To select all columns (fields) from a table, use * symbol instead of column names: –SELECT * –FROM table_name

8 The WHERE Statement To conditionally select data from a table, a WHERE clause can be added to the SELECT statement. Syntax: –SELECT column –FROM table –WHERE column operator value See next slide for various operators

9 SQL Comparison Operators FOR WHERE clause AND logical operator OR logical operator NOT Warehouse =‘3’ LIKE: LIKE ‘a*’, LIKE ‘*s’, Like ‘*Oxford*’ BETWEEN AND 78000

10 Semicolon after SQL Statements? Semicolon is the standard way to a block of SQL statement in database systems. So, you must use a semicolon at the end of a block of SQL statement. –Access SQL commands are not case sensitive but try to follow exact names for better readability. Download SQL data file form the class web site. –SQL_300.mdb

11 CustomerNumCustomerNameStreetCityStateZipBalanceCreditLimitRepNum 148Al's Appliance and Sport 2837 Greenway FillmoreFL33336$6,550$7,50020 OrderNumPartNumNumOrderedQuotedPrice 21608AT9411$21.95 OrderNumOrderDateCustomerNum /20/ Customer OrderLine Orders PartNumDescriptionOnHandClassWarehousePrice AT94Iron50HW3$24.95 Part Rep RepNumLastNameFirstNameStreetCityStateZipCommissionRate 20KaiserValerie624 RandallGroveFL33321$20,

12 SQL Preparation Review tables and relationships first… –Review each table in both views Design view Datasheet view –Recognize PK and FK information –Examine Relationships information SQL using Access –Design view of query  Select SQL View using Style button –No need to add tables (unlike QBE)

13 SQL Sample I’d like to know the list of CustomerNum and CustomerName. –SELECT CustomerNum, CustomerName –FROM Customer; I’d like to know the list of PartNum, Description, RepNum, and LastName –SELECT PartNum, Description, RepNum, LastName –FROM Part, Rep;

14 SQL Example 1 & 2 Example 1: –I’d like to know a list of the Customer number, Customer name, and balance of all customers. –Save as SQL 1 Example 2: –I’d like to know a list of the Order number, Part number, Price and Order Date. –Save as SQL 2

15 SQL Example 3 Restriction requirements –Where command –Exact Match Example 3: –I’d like to know customer names who are located in the city of Grove –Save as SQL 3

16 SQL Query to Find All Customers in ‘Grove’

17 SQL Example 4 Restriction requirements –Where command –Comparison operator Example 4: –I’d like to know a list of the number, name, credit limit, and balance for customers with credit limits that exceed their balances. –Save as SQL 4

18 Query to find Customers with Credit Limit Exceeding Balance

19 SQL Example 5 Restriction requirements –Where command –Compound conditions Example 5: –List the description of all parts that are located in warehouse 3 and for which there are more than 20 units on hand. –Save as SQL 5

20 SQL Query with Compound Condition using ‘AND’

21 SQL Example 6 Default value of ORDER BY: ascending Example 6: –List the number, name, and credit limit of all customers. Sort the customers by name in ascending order. –Save as SQL 6

22 SQL Query to Sort Data