ch7

¡Supera tus tareas y exámenes ahora con Quizwiz!

) The ________ clause is used to combine the output from multiple queries into a single result table.

) UNION

What results would the following SQL statement produce? select owner, table_name from dba_tables where table_name = 'CUSTOMER';

A listing of the owner of the customer table

In which of the following situations would one have to use an outer join in order to obtain the desired results?

A report is desired that lists all customers, the total of their orders during the most recent month, and includes customers who did not place an order during the month (their total will be zero).

) All of the following are new data types added in SQL:200n EXCEPT:

BIT

________ use the result of the outer query to determine the processing of the inner query.

Correlated subqueries

The ________ DBA view shows information about all users of the database in Oracle.

DBA_USERS

) In order to embed SQL inside of another language, the ________ statement must be placed before the SQL in the host language

EXEC SQL

________ takes a value of true if a subquery returns an intermediate results table which contains one or more rows.

EXISTS

) A routine is a named set of SQL statements that are considered when a data modification occurs. Answer

FALSE

) A subquery in which processing the inner query depends on data from the outer query is called a codependent query.

FALSE

) It is better not to have a result set identified before writing GROUP BY and HAVING clauses for a query.

FALSE

) Transaction integrity commands are not used to identify whole units of database changes that must be completed in full for the database to retain integrity.

FALSE

An equi-join is a join in which one of the duplicate columns is eliminated in the result table.

FALSE

Combining a table with itself results in a faster query.

FALSE

DBA_USERS contains comments on all tables in an Oracle database.

FALSE

MULTISET is similar to the table datatype.

FALSE

Triggers can be used to ensure referential integrity, enforce business rules, create audit trails, replicate tables, but cannot call other triggers.

FALSE

User-defined functions can improve system performance because they will be processed as sets rather than individually, thus reducing system overhead.

FALSE

Using an outer join produces this information: rows that do not have matching values in common columns are not included in the result table.

FALSE

When a subquery is used in the FROM clause, it is called a denied table.

FALSE

) What strategies can be used to write queries that run more efficiently?

It makes sense to specify the attribute names rather than just * in the SELECT clause. If you are writing a query for a wide table, specifying only the attributes that are needed is going to save a great deal of processing time. Also, changes in the base table post-production could affect query results. Specifying the attribute names will make it easier to notice and correct for such errors. Use subqueries sparingly, since these increase processing time. If you have several separate reports which need data from one table, write one query to retrieve all of the data and use what you need in each report.

) All of the following are new data types added in SQL:200n EXCEPT:

MULTISET

A new set of analytical functions added in SQL:2008 is referred to as:

OLAP functions.

When is it better to use a subquery over using a join?

Often, a subquery and join will return the same results. Joining is most useful when data from several tables needs to be retrieved and there is no nesting. When relationships are nested, it is best to use a subquery. Also, some queries (such as some not in queries) could not be done with joins.

Extensions defined in SQL-99 that include the capability to create and drop modules of code stored in the database schema across user sessions are called: A) stored procedures.

Persistent Stored Modules.

) Discuss some of the SQL:2008 enhancements and extensions to SQL.

Several built-in functions were added in SQL:2008. These include ceiling, floor, SQRT, rank, dense_rank, rollup, cube, sample and window. Many operations, such as OLAP operations, can be done within the SQL SELECT statement. There were also three new data types: BIGINT, MULTISET and XML. In addition, the merge operation was added.

A correlated subquery is executed once for each iteration through the outer loop.

TRUE

A transaction is the complete set of closely related update commands that must all be done, or none of them done, for the database to remain valid.

TRUE

A trigger is a named set of SQL statements that are considered when a data modification occurs.

TRUE

An SQL query that implements an outer join will return rows that do not have matching values in common columns.

TRUE

SQL:2008 allows one to calculate linear regressions, moving averages and correlations without moving the data outside of the database. Answer: TRUE

TRUE

The advantages of SQL-invoked routines are flexibility, efficiency, shareability and applicability.

TRUE

Explain how to combine queries using the UNION clause.

The UNION clause is used to combine the output of multiple queries into one set of output. In order for the union to work, each query must return the same number of columns. Also, each output column must be union compatible, meaning it is of the same type. The CAST command can be used to convert from one datatype to another if need be. If you wish to order the output rows, you must specify an ORDER BY clause in the last query.

What is the difference between a trigger and a routine?

a trigger, once written and compiled, sits silently on the database server waiting for an event to happen. It is usually tied to one table and some action, such as insert, update or delete. Conversely, a routine has to be called even though it resides on the database server. It may access one, many or no tables in order to produce the desired results.

A procedure is:

all of the above.

SQL-invoked routines can be:

all of the above.

) The MERGE command:

allows one to combine the INSERT and UPDATE operations.

The UNION clause is used to:

combine the output from multiple queries into a single result table.

A join in which the joining condition is based on equality between values in the common columns is called a(n):

equi-join. , and natural join. (both A and C. )

The most commonly used form of join operation is the:

natural join.

While triggers run automatically, ________ do not and have to be called.

routines

A type of query that is placed within a WHERE or HAVING clause of another query is called a:

subquery

SQL provides the ________ technique, which involves placing an inner query within the WHERE or HAVING clause of an outer query.

subquery

) Establishing IF-THEN-ELSE logical processing within an SQL statement can be accomplished by:

using the CASE keyword in a statement.

RANK and DENSE-RANK are examples of:

window functions

) All of the following are guidelines for better query design EXCEPT:

write simple queries.

) Dynamic SQL:

) is used to generate appropriate SQL code on the fly as an application is processing.

All of the following are part of the coding structure for triggers EXCEPT:

) selection.

An interactive command that can be used to dynamically control a user session for appropriate integrity measures is:

) set autocommit.

What is a self-join and how is it used?

A self-join is a join of one table to itself. This is often used for unary relationships where you have a recursive foreign key. One possible use for this would be to produce a list of who is supervised by another staff member. Self-joins can be slow, so they should be used with caution.

Discuss the differences between an equi-join, natural join and outer join.

Both a natural join and an equi-join create a join based upon equality between some common columns. While the equi-join keeps the redundant columns that are used for the match, the natural join removes duplicates. There are situations where one table may contain information that is not in the other table. However, it is necessary to display both matching data as well as records which do not have a match in the second table. This situation is where we would use an outer join.

Specifying the attribute names in the SELECT statement will make it easier to find errors in queries and also correct for problems that may occur in the base system.

FALSE

Subqueries can only be used in the WHERE clause.

FALSE

The following query will execute without errors. select customer.customer_name, salesman.sales_quota from customer where customer.salesman_id = (select salesman_id where lname = 'SMITH');

FALSE

The natural join is very rarely used.

FALSE

There is a special operation in SQL to join a table to itself.

FALSE

) Correlated subqueries are less efficient than queries that do not use nesting.

TRUE

) Figuring out what attributes you want in your query before you write the query will help with query writing.

TRUE

) Joining tables or using a subquery may produce the same result.

TRUE

A procedure is run by calling it by its name.

TRUE

The following queries produce the same results. select customer_name, customer_city from customer, salesman where customer.salesman_id = salesman.salesman_id and salesman.lname = 'SMITH'; select customer_name, customer_city from customer where customer.salesman_id = (select salesman_id from salesman where lname = 'SMITH');

TRUE

The joining condition of an equi-join is based upon an equality.

TRUE

In order for two queries to be UNION-compatible, they must:

both output compatible data types for each column and return the same number of rows.

In SQL, a(n) ________ subquery is a type of subquery in which processing the inner query depends on data from the outer query

correlated

) A ________ is a temporary table used in the FROM clause of an SQL query

derived table

) Embedded SQL consists of:

hard-coded SQL statements included in a program written in another language.

One major advantage of the outer join is that:

information is not lost.

) Explicit commands to manage transactions are needed when

multiple SQL commands must be run as part of a transaction.

A join that is based upon equality between values in two common columns with the same name and where one duplicate column has been removed is called a(n):

natural join.

A join in which rows that do not have matching values in common columns are still included in the result table is called a(n):

outer join.

) User-defined transactions can improve system performance because:

transactions are processed as sets, reducing system overhead.

A named set of SQL statements that are considered when a data modification occurs are called:

triggers

A function has only input parameters but can return multiple values.

FALSE

EXISTS takes a value of false if the subquery returns an intermediate result set.

FALSE

IF-THEN-ELSE logical processing cannot be accomplished within an SQL statement.

FALSE

) RDBMSs store database definition information in system-created tables which can be considered a data dictionary.

TRUE

) The UNION clause is used to combine the output from multiple queries into a single result table.

TRUE

User-defined data types:

can have all of the above.

A join operation:

causes two tables with a common domain to be combined into a single table or view.

If the DBA wishes to describe all tables in the database, which data dictionary view should be accessed in Oracle?

dba_tables

) All of the following are advantages of SQL-invoked routines EXCEPT:

security.

An operation to join a table to itself is called a:

self-join

Persistent Sorted Modules are extensions defined in SQL-99 that include the capability to create and drop modules of code stored in the database schema across user sessions

FALSE

What can be done with Persistent Stored Modules?

Persistent Stored Modules allow one to create procedures and functions within SQL, making it possible to input and output parameters and return a value. Additionally, error handling can be built into SQL statements. The DECLARE command creates variables which will stay in scope throughout the procedure or function. Groups of SQL statements can be passed, which improves performance. Despite all of this, Persistent Stored Modules have not been widely implemented. At this time, developers seem to prefer embedding SQL within high-level languages.

What are some tips for developing queries?

Some suggestions to help the query writing process include: gaining familiarity with the data model, entity and attributes that you are querying. It is also very important to think about the results that you wish to obtain from the query. Related to this, figure out what attributes you want the query to return. Once this is done, figure out which tables contain the attributes and include these in the FROM clause. By reviewing the ERD, you can determine which columns in each table will be used to establish relationships and establish a link in the WHERE clause. Once everything works fine, then you can look at the use of GROUP BY and HAVING.

A join in which the joining condition is based on equality between values in the common column is called a(n) equi-join.

TRUE

A natural join is the same as an equi-join, except that it is performed over matching columns that have been defined with the same name, and one of the duplicate columns is eliminated.

TRUE

Constraints are a special case of triggers.

TRUE

EXISTS will take a value of ________ if the subquery returns an intermediate results table which contains one or more rows.

TRUE

Establishing IF-THEN-ELSE logical processing within an SQL statement can now be accomplished by using the CASE keyword in a statement.

TRUE

In order to find out what customers have not placed an order for a particular item, one might use the NOT qualifier along with the IN qualifier. Answer: TRUE

TRUE

Persistent Stored Modules are extensions defined in SQL:1999 that include the capability to add and drop modules of code.

TRUE

SQL statements can be included in another language, such as C or Java.

TRUE

The following SQL statement is an example of a correlated subquery. select first_name, last_name, total_sales from salesman s1 where total_sales > all (select total_sales from salesman s2 where s1.salesman_id != s2.salesman_id);

TRUE

Triggers have three parts: the event, the condition, and the action.

TRUE

When EXISTS or NOT EXISTS is used in a subquery, the select list of the subquery will usually just select all columns as a placeholder because it doesn't matter which columns are returned.

TRUE

What is a derived table? When is it used? Can you describe any situations where you would have to use it over a subquery in the WHERE clause?

What is a derived table? When is it used? Can you describe any situations where you would have to use it over a subquery in the WHERE clause?A derived table can be created by placing a subquery within the FROM clause. The derived table is simply a temporary table in memory which can be accessed just like a table or view. Sometimes, these are referred to as inline views. A derived table is useful for situations where you need to create aggregate values (such as a sum) and then use these in another query. A derived table would be used instead of a subquery in cases where you need to display results from multiple tables. If the results need to come from a subselect, this is not possible, so we would have to use a derived table.

The outer join syntax does not apply easily to a join condition of more than ________ tables.

two


Conjuntos de estudio relacionados

Chapter 5 Business and Labor Test (Sole Proprietorship)

View Set

Ch. 2 Instruction Set Architecture

View Set

PNU 133 PassPoint PrepU Intrapartum

View Set

Chapter 21: Family-Centered Care of the Child During Illness and Hospitalization

View Set

Cervix & Vagina normal anatomy & histology 2-25

View Set