Vous êtes sur la page 1sur 20

Structured Query Language

(SQL)
John A. Springer, PhD
Assistant Professor
Department of Computer and Information Technology
College of Technology
Motivation
• Product Lifecycle Management (PLM) initiatives
frequently make extensive use of Product Data
Management (PDM) systems to manage product
information
• A PDM system typically uses a relational
database to store its information
• Software known as a Relational Database
Management System (RDBMS) manages
access to the relational database
• This module introduces a query language used
to retrieve data from a relational database
Traditional Life Cycle
Use of SQL
in Traditional Life Cycle
Database Development
Life Cycle
Database Development
Life Cycle
Relational Database Management
System (RDBMS)
• Controls access to the data stored in a relational
database
• Provides multi-version concurrency
– Concurrency dictates that multiple users are able to interact with
the database concurrently
– Multi-version dictates that each user has a consistent picture of
the database
• Ensures consistency of data in database
– Typically ensured by use of transactions
– Transactions are considered atomic units of related database
activities
• Provides data security and durability
• Allows the data to be queried via a query language
Standard Database Interaction
1. SUBMIT SQL
STATEMENT
DATABASE
CLIENT SERVER

3. RESPOND
WITH
RESULTS 2. READS/WRITES

DATABASE
ON DISK
SQL
• Structured Query Language
• American National Standards Institute
(ANSI) and International Organization for
Standardization (ISO) standards for SQL
• Versions
– SQL-86
– SQL-92 (SQL2)
– SQL-99 (SQL3)
– SQL 2003
SQL as Query Language
• Purpose is to query data from relational tables
• Declarative
– Instead of specifying how to retrieve the data, we
declare what data we want
• A combination of two formalisms known as
Relational Algebra and Relational Calculus
• Basic syntax is:
SELECT <list of one or more columns>
FROM <list of one or more tables>
WHERE <one or more conditions>
Operations in SQL
• Selection
• Projection
• Join
• Set Operations
– Union
– Intersect (set intersection)
– Except (set difference)
Additional Operations in SQL
• Duplicate Elimination
• Grouping
• Aggregation
– SUM
– MAX
– MIN
– COUNT
– AVG
Database Schema

Part

PK Number
NOTE: THE DBMS IN USE MAY
Name TREAT “NUMBER” AS A
Type RESERVED WORD (FOR
FK1 SKU INSTANCE, TO REPRESENT A
DATA TYPE). IN THESE CASES,
WE MUST USE A DIFFERENT
COLUMN NAME.
Database Instance
SKU Name Type
ABC Widget ABC Widget
XYZ Widget XYZ Widget
PQR Widget PQR Widget

Number Name Type SKU


1 Widget Part A A ABC
Part

PK Number
2 Widget Part B B ABC
Name 3 Widget Part A A XYZ
Type
FK1 SKU 4 Widget Part B B XYZ
5 Widget Part A A PQR
6 Widget Part B B PQR
An SQL Query
DENOTES ALL COLUMN;
SELECT * SHORTHAND FOR LISTING
SKU, Name, Type
FROM Product
WHERE Name = ‘Widget ABC’

Result:
SKU Name Type
ABC Widget ABC Widget
DUE TO PROPERTY OF
RELATIONAL CLOSURE,
ALL QUERIES RETURN
A RELATION
An SQL Query:
the Selection Operation
SELECT *
FROM Product
WHERE Name = ‘Widget ABC’
SELECT SPECIFIC ROWS
FROM THE PRODUCT TABLE
Result: THAT MATCH CRITERION
SKU Name Type
ABC Widget ABC Widget
An SQL Query:
the Projection Operation
SELECT SKU
FROM Product
WHERE Name = ‘Widget ABC’
PROJECT ONLY CERTAIN
COLUMNS FROM THE
Result: PRODUCT TABLE
SKU
ABC
An SQL Query:
the Join Operation
SELECT Number JOINING MULTIPLE TABLES
FROM Product, Part
WHERE Product.Name = ‘Widget ABC’
AND Product.SKU = Part.SKU

JOIN CONDITION
Result:
Number
1
2
References
• Elmasri, R., & Navathe, S. B. (2006).
Fundamentals of Database Systems. Boston:
Addison Wesley.
• Garcia-Molina, H., Ullman, J. D., & Widom, J.
(2001). Database Systems: The Complete Book.
Upper Saddle River, NJ: Pearson/Prentice-Hall.
• Ramakrishnan, R., & Gehrke, J. (2002).
Database Management Systems. New York:
McGraw-Hill.
Acknowledgments
The author wishes to acknowledge the
support from the Society for Manufacturing
Engineers - Education Foundation, SME-EF
Grant #5004 for “Curriculum Modules in
Product Lifecycle Management.”

Vous aimerez peut-être aussi