Databases Reference
In-Depth Information
Summary
Structured Query Language (SQL) is a language that is used to manipulate relational databases.
The basic form of an SQL query is SELECT-FROM-WHERE.
112
Use the CREATE TABLE command to describe a table's layout to the DBMS, which creates the table in the
databse.
In SQL retrieval commands, fields are listed after SELECT, tables are listed after FROM, and conditions are
listed after WHERE.
In conditions, character values must be enclosed in single quotation marks.
Compound conditions are formed by combining simple conditions using either or both of the following
operators: AND and OR.
Sorting is accomplished using the ORDER BY clause. The field on which the records are sorted is called the
sort key. When the data is sorted in more than one field, the more important field is called the major sort key
or primary sort key. The less important field is called the minor sort key or secondary sort key.
Grouping is accomplished in SQL by using the GROUP BY clause. To restrict the rows to be displayed, use
the HAVING clause.
Joining tables is accomplished in SQL by using a condition that relates matching rows in the tables to be
joined.
SQL has the built-in (also called aggregate) functions COUNT, SUM, AVG, MAX, and MIN.
One SQL query can be placed inside another. The subquery is evaluated first.
The union of the results of two queries is specified by placing the UNION operator between the two queries.
Calculated fields are specified in SQL queries by including the calculation, followed by the word AS , fol-
lowed by the name of the calculated field.
The INSERT command is used to add a new row to a table.
The UPDATE command is used to change existing data.
The DELETE command is used to delete records.
The INTO clause is used in a SELECT command to create a table containing the results of the query.
Key Terms
CHAR( n )
command
compound condition
CREATE TABLE
DATE
DECIMAL( p , q )
DELETE
FROM clause
GROUP BY clause
HAVING clause
INSERT
INTEGER
INTO clause
ORDER BY clause
reserved word
SELECT clause
simple condition
SMALLINT
SQL (Structured Query Language)
statement history
subquery
UPDATE
WHERE clause
Review Questions
1.
Describe the process of creating a table in SQL and the different data types you can use for fields.
2.
What is the purpose of the WHERE clause in SQL? Which comparison operators can you use in a
WHERE clause?
3.
How do you write a compound condition in an SQL query? When is a compound condition true?
 
 
Search WWH ::




Custom Search