Using Database Management Systems

advertisement
CChhaapptteerr 44
U
Ussiinngg D
Daattaabbaassee M
Maannaaggeem
meenntt SSyysstteem
mss
RReevviieew
wQ
Quueessttiioonn AAnnssw
weerrss
Section Review questions are labeled according to the sections where their answers can be found. For example,
the three questions labeled 4.1a all appear in section 4.1, part a.
Section 4.1 – Introduction
4.1 Section Review
a. Describe the nature of a relational database.
This is that nature of a relational database. We have a table for each entity, with a row for each instance of the
entity and a column for each attribute of the entity. A special attribute, called the primary key, uniquely identifies
each instance of the entity.
What are enterprise-wide databases and why are they important?
An enterprise-wide database is a single database with all of the data for an enterprise, such as a business, a
government agency, or some other kind of organization. The trend in modern computing is to have all of the
major operational software – accounting, sales, scheduling, personnel, and so on – store all of its data in one
centralized enterprise-wide database management system, which is administered by database professionals.
How is data different from metadata?
Data is the information stored in the database. Metadata is information about how that data is organized.
Information about how a database is organized – in other words, data about the data – is called metadata. The
metadata for a table tells us the name of each column in the table, the type of data in the column, and sometimes
the size of the column.
b. What is Structured Query Language?
Structured Query Language – SQL for short – is a language we can use to query a relational database. It
should be pronounced “S-Q-L” and not “sequel”, since Sequel is the name of a specific database management
software package. SQL is based on relational algebra and is both a data definition language (DDL) used is to
define the structure of a database, and a data manipulation language, (DML) used to manipulate data in a
database, including extracting data from a database
Who maintains standardized definitions of SQL?
A standard definition of the SQL language is maintained by the American National Standards Institute (ANSI)
and the International Organization for Standardization (ISO).
What is the technical definition of a query and what do many people generally use the word query to
mean?
Technically, any SQL statement is called a query, but people generally use the word query to specifically mean
statements that extract data from a database.
What are some of the most commonly used database management software packages today?
Some of the major relational database management systems in use today include The Oracle Database, MySQL,
Microsoft SQL Server, Ingres, and Microsoft Access.
CIS 103 Applied Computer Technology
Using Database Management Systems
page 2
c. What background is needed in order to design and build databases?
Well-educated professionals design and build the databases used by corporations, non-profit organizations, and
governmental agencies. To do so requires years of training in both database management software and the
underlying mathematics, such as relational algebra and relational calculus.
How do most people interact with large commercial databases?
Most people do not interat directly with a database, but through the use of specialized software, often with a
simple Web page as a user interface. For example, when you buy something online, such as books or music from
Amazon.com, you are using Web pages that are interacting with a database.
How can data be extracted from a Microsoft Access database?
Data can be extracted from a Microsoft Access database using SQL queries, the Access Query Wizard and Query
Design View.
4.2 Single Table Queries in SQL
4.2 Section Review
a. Describe the proper format for a basic SQL query to extract information from a relational
database table.
The proper format for a basic SQL query to extract information from a table is:
SELECT (attributes) FROM (table) WHERE (condition);
Give an example of such a query.
For example, if we wish to get a list of the names and phone numbers from our student table for all of the students
who live in New York, the proper SQL query would be:
SELECT first, last, phone FROM student WHERE state = "NY";
How is the result set from such a query formatted?
The result of an SQL query is in the format of a new table. A SELECT… FROM… WHERE… query uses the
criteria we specify to create and return a new table from existing tables in a database.
b. What is a data type?
The columns in a relational database each have a data type, which indicates how the computer should format the
data, and which operations it can perform on the data. The way columns are used in database queries depends on
their data types.
List and describe three of the most commonly used database data types.
The most common data types are text, numeric, and Boolean. Text data, also called character data, is simply a
string of text stored in a location in the database. Numeric data is a number stored in a database in a way that
allows computers to perform arithmetic with it. Boolean data is data that has a true or false value.
CIS 103 Applied Computer Technology
Using Database Management Systems
page 3
How are values with these three data types used in an SQL query?
Text data is used in database queries with quotes around it. Numeric data is used in database queries without
quotes around it. Comparisons are not needed for Boolean data, since it is already true or false, So, Boolean
attributes are used by themselves in logical conditions.
c. Describe the six logical comparison operators used in SQL queries and the symbols used for each.
Condition
A equals B
A is not equal to B
A is less than B
A is greater than B
A is less than or equal to B
A is greater than or equal to B
In SQL
A=B
A<> B
A<B
A>B
A <= B
A >= B
d. Describe the three Boolean operators used for compound conditions in an SQL query.
There are three basic functions in Boolean logic: AND, OR, and NOT. They are used to form compound logical
conditions from simple conditions. The AND operation is a binary operation, meaning that it needs two operands.
If both operands are true, then the result is true. Otherwise, the result is false. Both operands must be true for the
result to be true. The OR operation also has two operands. If either one of the operands is true, then the result is
true. Otherwise, the result is false. Both operands must be false for the result to be false. The NOT operation is a
unary operation, meaning that it has only one operand. It simply reverses the true or false value of its operand. If
the operand is true, then the result is false. If the operand is false, then the result is true.
e. Create SQL queries to extract the following from the house table, whose metadata is shown in
Figure 4-7:
column name
data type
ID
street
city
state
zip
bedrooms
Text
Text
Text
Text
Text
Number
bathrooms
value
first
last
sold
Number
Number
Text
Text
Boolean
Table: house
size
5
40
20
2
5
20
20
notes about the data
house ID number (primary key)
street address
5-digit zip codes only
number of bedrooms; integer
number of bathrooms; could end in .5
appraised value or sale price of house
first name of the listing or selling agent
last name of the listing or selling agent
true = sold ; false = not sold
Figure 4-7: metadata for a table of houses.
1. The House ID, street address, and value for houses in the 19140 zip code under $240,000.
SELECT House ID, street address, value
FROM house
WHERE zip = “19140” AND value < 240000;
CIS 103 Applied Computer Technology
Using Database Management Systems
page 4
2. The House ID, street address, and value for houses in the 19128 zip code with at least three
bedrooms and two bathrooms.
SELECT House ID, street address, value
FROM house
WHERE zip = “19140” AND bedrooms >= 3 AND bathrooms >= 2;
3. The House ID, street address, zip code and value for houses sold by Mark Jones.
SELECT House ID, street address, zip, value
FROM house
WHERE first = “Mark” AND last = “Jones”;
4. The street address, value, number of bedrooms and number of bathrooms for houses in the
19116 and 19154 zip codes.
SELECT street address, value, bedrooms. bathrooms
FROM house
WHERE zip = “19116” OR zip = “19154”;
5. The House ID, street address and value for house in the 19139 zip code that have not been sold.
SELECT House ID, street address, value
FROM house
WHERE zip = “19139” AND NOT(sold);
Note: This query works with or without parenthesis
Section 4.3 – Microsoft Access Queries
4.3 Section Review
a. What do the file extensions accdb and mdb indicate with regard to databases files?
The file extension for newer Access database files is .accdb. Versions of Access before Office Access 2007 used
database files with the file extension .mdb. We can still open .mdb files In Access 2007.
b. What is the difference between the datasheet view and the design view of an Access table?
The datasheet view, which allows us to see the data in the form of a table with rows and columns. Design view
gives us the metadata.
What is the difference between an Access query and an Access report?
Microsoft Access queries extract data from a database. Access reports tell the computer how to format the data so
that it looks good on the printed page.
c. How are SQL queries entered in Access?
First, open the Create ribbon in Access, then click the Query Design button. Select the table you wish to use or
close the Show Table dialog window, then click the SQL button in the top-left corner screen (on the Design
Ribbon). You can then enter and execute an SQL query.
How are existing queries run in Access?
To run an existing query in access, simply double-click the entry for the query in the list of items in the database
CIS 103 Applied Computer Technology
Using Database Management Systems
page 5
d. Describe how to create a query in the Access Query Wizard equivalent to the SQL query:
SELECT first, last, department, hours FROM payroll WHERE hours > 40;
First, open the Create ribbon and click the Query Wizard button. Click the OK button to select a simple query.
Make sure that Table:payroll is selected in the Table/Queries box. One at a time, double-click each of the four
fields we will use –, first, last, department, hours. Click the Next button. The Query Wizard will ask us if we want
a detailed or summary query. Detail is the default. It will show us the complete result set for our query. Leave it
as is and click the Next button.Name the query, Select Modify the query design from the options, then click the
Finish button. In Design View, type > 40 in the criteria field for hours, then save or run the query as desired.
What part of this query cannot be entered using the Access Query Wizard? Describe how it can be
added to the query.
The condition hours > 40 cannot be netered in the wizard, it must be entered in Design View, as described above.
e. How can a multiple-table query be created in Access using the Access Query Wizard?
First, open the Create ribbon and click the Query Wizard button. Click the OK button to select a simple query.
Select the first table in the Table/Queries box. One at a time, double-click each of the fields from this table
needed for your query. Then, select the next table in the Table/Queries box and one at a time, double-click each
of the fields from this table needed for your query. After this continue with the Query Wizard steps as described
above.
How can a query be copied in Access?
Right-click any one of the entries for the Teaching Assignments query, then select Copy from the menu that
appears. Right-click again any place in the list of items in the database and select Paste from the menu that
appears.
f. Describe how to export the result set from an Access query as a Microsoft Excel spreadsheet.
Right-click the entry for the Teaching Assignments query in the list of items in the database, then Select Export
from the menu that appears, then Excel,
Why would someone want to know how to do this rather than using the Access report generator?
Creating reports in Access can be tedious and time consuming, and the report cannot be edited after it is printed.
Knowing how to export Access data into an Excel spreadsheet will allow you to format, sort, print, etc., in Excel
as needed. You can also give the data to other people who know how to use Excel, as most people in and office
the workplace do.
What are some other formats that can be used for queries and tables exported from Access?
Access queries and tables can be exported as HTML, XML PDF and Word files as well as Excel files.
Right-click the entry for the Teaching Assignments query in the list of items in the database, then Select Export
from the menu that appears, then Excel,
Why would someone want to know how to do this rather than using the Access report generator?
Creating reports in Access can be tedious and time consuming, and the report cannot be edited after it is printed.
Knowing how to export Access data into an Excel spreadsheet will allow you to format, sort, print, etc., in Excel
as needed. You can also give the data to other people who know how to use Excel, as most people in and office
the workplace do.
What are some other formats that can be used for queries and tables exported from Access?
Access queries and tables can be exported as HTML, XML PDF and Word files as well as Excel files.
Download