Ch7_2

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

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.

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.

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

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.

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

True

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

True

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

True

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

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

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.

Dynamic SQL: A) is used to generate appropriate SQL code on the fly as an application is processing. B) is quite volatile. C) is not used widely on the Internet. D) creates a less flexible application

A

Embedded SQL consists of: A) hard-coded SQL statements included in a program written in another language. B) SQL encapsulated inside of other SQL statements. C) SQL written into a front-end application. D) SQL translated to a lower-level language.

A

The ________ DBA view shows information about all users of the database in Oracle. A) DBA_USERS B) USERS C) DBA_VIEWS D) DBA_INDEXES

A

The outer join syntax does not apply easily to a join condition of more than ________ tables. A) two B) three C) four D) any number of

A

User-defined transactions can improve system performance because: A) transactions are processed as sets, reducing system overhead. B) transactions are mapped to SQL statements. C) speed is improved due to query optimization. D) all of the above.

A

All of the following are new data types added in SQL:200n EXCEPT: A) BIGINT. B) BIT. C) MULTISET. D) XML.

B

One major advantage of the outer join is that: A) information is easily accessible. B) information is not lost. C) the query is easier to write. D) all of the above.

B

What results would the following SQL statement produce? select owner, table_name from dba_tables where table_name = 'CUSTOMER'; A) A listing of all customers in the customer table B) A listing of the owner of the customer table C) A listing of the owner of the customer table as well as customers D) An error message

B

While triggers run automatically, ________ do not and have to be called. A) trapdoors B) routines C) selects D) updates

B

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.

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): A) natural join. B) equi-join. C) outer join. D) union join.

C

All of the following are part of the coding structure for triggers EXCEPT: A) event. B) condition. C) selection. D) action.

C

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

False

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

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

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

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

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

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

False

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

Constraints are a special case of triggers.

True

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

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.

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

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

True

________ use the result of the outer query to determine the processing of the inner query. A) Correlated subqueries B) Outer subqueries C) Inner subqueries D) Subqueries

A

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

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

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

True

The UNION clause is used to: A) combine the output from multiple queries into a single result table. B) join two tables together to form one table. C) find all rows that do not match in two tables. D) none of the above.

A

A join operation: A) brings together data from two different fields. B) causes two tables with a common domain to be combined into a single table or view. C) causes two disparate tables to be combined into a single table or view. D) is used to combine indexing operations.

B

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): A) equi-join. B) natural join. C) multivariate join. D) inner join

B

A type of join where a table is joined to itself is called a(n): A) unary join. B) self-join. C) unnatural join. D) pinned join.

B

A type of query that is placed within a WHERE or HAVING clause of another query is called a: A) master query. B) subquery. C) superquery. D) multi-query

B

All of the following are guidelines for better query design EXCEPT: A) understand how indexes are used in query processing. B) use a lot of self-joins. C) write simple queries. D) retrieve on the data that you need.

B

A join in which the joining condition is based on equality between values in the common columns is called a(n): A) equi-join. B) unilateral join. C) natural join. D) both A and C.

D

A procedure is: A) stored within the database. B) given a unique name. C) called by name. D) all of the above.

D

All of the following are advantages of SQL-invoked routines EXCEPT: A) flexibility. B) efficiency. C) sharability. D) security.

D

An operation to join a table to itself is called a: A) sufficient-join. B) inner join. C) outer join. D) self-join.

D

If the DBA wishes to describe all tables in the database, which data dictionary view should be accessed in Oracle? A) dba_tab_privs B) dba_tab_comments C) dba_table_label D) dba_tables

D

The ________ clause is used to combine the output from multiple queries into a single result table. A) INTERSECT B) DIVIDE C) COLLATE D) UNION

D

The most commonly used form of join operation is the: A) outer join. B) union join. C) equi-join. D) natural join.

D

User-defined data types: A) can be a subclass of a standard type. B) can behave as an object. C) can have defined functions and methods. D) can have all of the above.

D

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

False

DBA_USERS contains comments on all tables in an Oracle database.

False

MULTISET is similar to the table datatype.

False

One major disadvantage of the outer join is that information is easily lost.

False

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

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 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.

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.

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

A procedure is run by calling it by its name.

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

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

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

A ________ is a temporary table used in the FROM clause of an SQL query. A) correlated subquery B) derived table C) view table D) none of the above

B

A new set of analytical functions added in SQL:2008 is referred to as: A) OLAF functions. B) MOLAP functions. C) average functions. D) OLAP functions.

D

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

False

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

False

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.

In SQL, a(n) ________ subquery is a type of subquery in which processing the inner query depends on data from the outer query. A) correlated B) paired C) natural D) inner

A

The MERGE command: A) allows one to combine the INSERT and UPDATE operations. B) allows one to combine the INSERT and DELETE operations. C) joins 2 tables together. D) none of the above.

A

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.

Explicit commands to manage transactions are needed when: A) a transaction consists of just one SQL command. B) multiple SQL commands must be run as part of a transaction. C) autocommit is set to off. D) none of the above

B

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. B) Persistent Stored Modules. C) flow control modules. D) none of the above.

B

In order for two queries to be UNION-compatible, they must: A) both have the same number of lines in their SQL statements. B) both output compatible data types for each column and return the same number of rows. C) both return at least one row. D) all of the above.

B

In order to embed SQL inside of another language, the ________ statement must be placed before the SQL in the host language. A) GET SQL B) EXEC SQL C) RUN SQL D) SQL SQL

B

) In which of the following situations would one have to use an outer join in order to obtain the desired results? A) A report is desired that lists all customers who placed an order. B) A report is desired that lists all customers and the total of their orders. C) 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). D) There is never a situation that requires only an outer join.

C

A named set of SQL statements that are considered when a data modification occurs are called: A) stored procedures. B) treatments. C) triggers. D) trapdoors.

C

An interactive command that can be used to dynamically control a user session for appropriate integrity measures is: A) rollback. B) rollforward. C) set autocommit. D) expunge.

C

EXISTS will take a value of ________ if the subquery returns an intermediate results table which contains one or more rows. A) FALSE B) 1 C) TRUE D) undefined

C

Establishing IF-THEN-ELSE logical processing within an SQL statement can be accomplished by: A) using the if-then-else construct. B) using the immediate if statement. C) using the CASE keyword in a statement. D) using a subquery.

C

RANK and DENSE-RANK are examples of: A) ceilings. B) door functions. C) window functions. D) moving functions.

C

SQL provides the ________ technique, which involves placing an inner query within the WHERE or HAVING clause of an outer query. A) grouping B) joining C) subquery D) union

C

SQL-invoked routines can be: A) procedures. B) functions. C) all of the above. D) none of the above.

C

________ differs from array because it can contain duplicates. A) BIGINT B) XML C) MULTISET D) TABLE

C

________ takes a value of true if a subquery returns an intermediate results table which contains one or more rows. A) IN B) HAVING C) EXISTS D) EXTENTS

C


Conjuntos de estudio relacionados

Erik Erikson's 8 Stages of Psychosocial Development

View Set

troubleshooting methodology/resolving core HW Prob

View Set

Statistics - Ch5 z Scores and standardized distributions

View Set