1/31
Looks like no tags are added yet.
Structured Query Language
Acronym: SQL
Originally developed by IBM as the SEQUEL language in the 1970s
SQL-92 is an ANSI national standard adopted in 1992
SQL 2011 is current standard
SQL defined
SQL is not a programming language, but rather a data sublanguage
SQL is compromised of:
Data definition language (DDL): which is used to define database structures
Data manipulation language (DML): Data definition and updating, data retrieval (Queries)
SQL/Persistent Stored Modules (SQL/PSM): Procedural programming capabilities
Transaction Control Language (TCL): control transaction behavior
Data Control Language (DLC): Grant and revoke database permissions
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
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 creation
Feed information to another query (as a sub query)
SQL for Data Retrieval: Displaying all columns
To show all of the column values for the rows that match the specified criteria, use an asterisk (*)
SQL for Data Retrieval: Showing each row only once
The DISTINCT keyword may be added to the SELECT statement to inhibit duplicate rows from displaying
SQL for Data Retrieval: Specifying search criteria
The WHERE clause stipulates the matching criteria for the record that is to be displayed
SQL for Data Retrieval: Specifying columns and rows 1
Display the FirstName, LastName, Phone and Department values of employees in the finance department
SQL for Data Retrieval: Specifying columns and rows 2
AND: Representing an intersection of the data sets
OR: Representing a union of the data sets
SQL for Data Retrieval: Specifying columns and rows 3
The use of IN and NOT IN
IN: the column may equal to any of the values in the list
NOT IN: the column must not be equal to all the values in the list
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
SQL for Data retrieval: Comparison operators
The WHERE clause operators may include
Equals to “=”
Not Equal to “<>”
Greater than “>”
Less than “<“
Greater than or Equal to “>=”
Less than or Equal to “<=”
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 (_)
SQL for Data Retrieval: Sorting the Results
Query results may be sorted using the ORDER BY clause
COUNT
counts the number of rows that match the specified criteria
MIN
Finds the minimum value for a specific column for those rows matching the criteria
MAX
Finds the maximum value for a specific column for those rows matching the criteria
SUM
calculates the sum for a specific column for those rows matching the criteria
AVG
Calculates the numerical average of a specific column for those rows matching the criteria
GROUP BY
Subtotals can be calculated using this clause
HAVING
This clause can be used to restrict which data is displayed
Subqueries
The result of a query is a relation. As a result, a query may feed another query.
Joins
Another way of combining data is by using a join
Join (also called an Inner Join)
Left Outer Join
Right Outer Join
Outer join
this syntax can be used to obtain data that exists in one table without matching data in the other table
CREATE
to create database objects
ALTER
To modify the structure and/or characteristics of database objects
DROP
to delete database objects
Insert
will add a new row in a table
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
CHECK
this constraint can be used to create sets of values that restrict the values that can be used in a column
MSAccess doesn’t support this constraint
SQL View
its a virtual table created by a DBMS-stored SELECT statement which can combine access to data in multiple tables and even in other views
MSAccess doesn’t support Views