Preview only show first 10 pages with watermark. For full document please download

Quizzuri | Relational Model | Sql

Any column in the EMPLOYEES table, any expression in the SELECT list or any ALIAS in the SELECT list. (*) All the columns in the database. 3. A column alias can be specified in an ORDER BY Clause. True or False? True (*) False. 4. What clause must you place in a SQL statement to have your results sorted from highest ...

   EMBED

  • Rating

  • Date

    December 2017
  • Size

    592.9KB
  • Views

    6,112
  • Categories

    SQL

Share

Transcript

Test: Quiz: Second Normal Form 1. What is the rule of Second Normal Form? All non-UID attributes must be dependent upon the entire UID (*) Some non-UID attributes can be dependent on the entire UID No non-UID attributes can be dependent on any part of the UID None of the Above 2. Examine the following entity and decide which attribute breaks the 2nd Normal Form rule: ENTITY: CLASS ATTRIBUTES: CLASS ID DURATION SUBJECT TEACHER NAME AND ADDRESS CLASS ID DURATION SUBJECT TEACHER NAME AND ADDRESS (*) 3. All instances of the subtypes must be an instance of the supertype. True (*) False 4. Not all instances of the supertype are instances of one of the subtypes. True False (*) 5. A supertype should have at least two subtypes. True (*) False 6. An entity can be on 2nd Normal Form even if it has repeated values. True or False? True False (*) Test: Quiz: Third Normal Form 1. No databases in the world is ever truly on 3rd Normal Form. Everyone always stops after 2nd Normal Form. True or False? True False (*) 2. Examine the following Entity and decide which sets of attributes breaks the 3rd Normal Form rule: (Choose Two) ENTITY: TRAIN (SYNONYM: ROLLING STOCK) ATTRIBUTES: TRAIN ID MAKE MODEL DRIVER NAME DEPARTURE STATION NUMBER OF CARRIAGES NUMBER OF SEATS DATE OF MANUFACTURE (Choose all answers) TRAIN ID, MAKE DEPARTURE STATION, DRIVER NAME (*) NUMBER OF CARRIAGES, NUMBER OF SEATS (*) MODEL, DATE OF MANUFACTURE 3. As a database designer it is your job to store data in only one place and the best place. True or False? True (*) False Section 7 Test: Quiz: Arcs 1. To visually represent exclusivity between two or more relationships in an ERD you would most likely use an ________. Arc (*) UID Subtype Supertype 2. Which of the following would best be represented by an arc? STUDENT (senior, junior) STUDENT (graduating, non-graduating) STUDENT (will-attend-university, will-not-attend-university) STUDENT ( University, Trade School) (*) 3. This diagram could also be expressed as a supertype/subtype construction. True or False? True False (*) 4. All parts of a UID are mandatory. True or False? True (*) False 5. Which of the following can be added to a relationship? an attribute an arc can be assigned (*) a composite attribute an optional attribute can be created 6. Secondary UID's are not permitted in data modeling mandatory in data modeling useful as an alternative means identifying instances of an entity (*) always comprised of numbers 7. If the entity CD has the attributes: #number, *title, *producer, *year, o store name, o store address, this entity is in 3rd Normal Form ("no non-UID attribute can be dependent on another non-UID attribute). True or False? True False (*) 8. Which of the following is the definition for Third Normal Form? All attributes are single valued An attribute must be dependent upon entity's entire unique identifier No non-UID attribute can be dependent on another non-UID attribute (*) All attributes are uniquely doubled and independent Test: Quiz: Hierarchies and Recursive Relationships 1. A relationship can be both recursive and hierachal at the same time. True or False? True False (*) 2. A recursive rationship should not be part of a UID. True or False? True (*) False 3. Which of the following would be a good Unique Identifier for its Entity? (Choose Two) (Choose all answers) Identification Number for Person (*) Birthdate for Baby Which Includes Hour, Minute, and Seconds (*) Order date for Order Vehicle Type Number for Car 4. In this simple diagram, what comprises the unique identifier for the student class entity? student id and class id student id, class id and course id course id student id and course id (*) Test: Quiz: Modeling Historical Data 1. Historical data should always be kept. True or False? True False (*) 2. Modeling historical data can produce a unique identifier that includes a date. True or False? True (*) False 3. Audit trail attributes cannot be placed in the entities they are auditing, they must be placed in separate, new entities, created just for that purpose. True or False? True False (*) 4. Which of the following scenarios should be modeled so that historical data is kept? (Choose two) (Choose all answers) LIBRARY and BOOK (*) STUDENT and AGE STUDENT and GRADE (*) LIBRARY and NUMBER OF STAFF Section 8 Test: Quiz: What is a Consultant 1. How does the dictionary define "consultant"? A person who knows everything One responsible for knowing everything One who gives expert or professional advice (*) None of the Above 2. Two) Which of the following skills are required for Consultants. (Choose (Choose all answers) Communication skills (*) Excellent drawing skills Must be able to speak at least two languages fluently, preferably four or more Team-working skills (*) 3. Only Consultants can develop new data models for a company, they are mandatory, so companies must find them and hire them. True or False? True False (*) Test: Quiz: Overcoming the Fear Factor 1. Which of the following is a valid technique for effective public speaking? Making eye contact Using familiar words when communicating technical information Being enthusiastic All of the Above (*) 2. Your apperance at a presentation is not important, you should just show up and give the presentation in whatever clothes makes you comfortable. So feel free to wear Jeans and old T-Shirts etc. Being comfortable is more important than anything else. True or False? True False (*) 3. When you are involved in a group presentation, your group should practice before hand and agree on who presents the various parts. You should all be involved somehow. True or False? True (*) False Test: Quiz: Modeling Change: Time 1. How do you know when to use the different types of time in your design? The rules are fixed and should be followed It depends on the functional needs of the system (*) You would first determine the existence of the concept of time and map it against the Greenwich Mean Time Always model time, you can take it out later if it is not needed 2. It is desirable to have an entity called DAY with a holiday attribute when you want to track special holidays in a payroll system. True or False? True (*) False 3. When you add the concept of time to your data model, you are: Simplifying your model. Adding complexity to your model. (*) Just changing the model, but this does not change the complexity of it. None of the above. 4. What is the benefit to the users of a system that includes "time," e.g. Start Date and End Date for Employees? Increased usability and flexibility of a system; we can the trace e.g. the different managers an employee had over time. (*) System becomes 100% unstable; allows users to log on and log off at will. Users are able to create complex programs in support of this component. Reporting becomes nearly impossible, users enjoy this. 5. If you are tracking employment dates for an employee, do you need to have an "End Date" attribute? Yes, because you always need an end date when you have a start date No, because an end date is usually redundant Yes, if the company wants to track employee information, like multiple start and end dates (*) No, not if the company likes the employee 6. Which of the following would be a logical constraint when modeling time for a country entity? People have births and deaths in their countries that must be tracked by the system. If you are doing a system for France or Germany, you would need security clearance. Countries may need an end date in your system, because they can change fundamentally over time, e.g. Yugoslavia. (*) You need a constant record of countries, because they are still countries, even if leadership changes over time, e.g. France, USA and most other countries. 7. Modeling historical data produces efficient ways for a business to operate such as: Modeling historical data does not help a business. Providing valuable information via reports to management . (*) Keeping track of holiday dates. Employees can work in two time zones. Test: Quiz: Modeling Change: Price 1. Why would you want to model a time component when designing a system that lets people buy bars of gold? The price of gold fluctuates and for determining price, you need to know the time of purchase (*) To allow the sales people to determine where the gold is coming from You would not want to model this, it is not important The Government of your country might want to be notified of this transaction. 2. What is the function of logging or journaling in conceptual data models? Allows you to track the history of attribute values, relationships and/or entire entities (*) Gives a timestamp to all entities Represents entities as time in the data model Creates a fixed time for all events in a data model 3. Which of the following is a logical constraint that could result from considering how time impacts an example of data storage? End Date must be before the Start Date. ASSIGNMENT periods can overlap causing the database to crash. An ASSIGNMENT may only refer to a COUNTRY that is valid at the Start Date of the ASSIGNMENT. (*) Dates can be valued only with Time. 4. You are doing a data model for a computer sales company, where the price goes down on a regular basis. If you want to allow them to modify the price and keep track of the changes, what is the best way to model this? A. Create a product entity and a related price entity with start and end dates, and then let the users enter the new price whenever required. B. Create a new item and a new price every day. C. Use a price entity with a start and end date D. Allow them to delete the item and enter a new one. E. Both A and C (*) Test: Quiz: Drawing Conventions for Readability 1. There are no formal rules for how to draw ERD's. The most important thing is to make sure all entities, attributes and relationships are documented on diagram. The layout is not significant. True or False? True False (*) 2. It is a good idea to group your entities in a diagram according to the expected volumes. By grouping high volume entities together, the diagrams could become easier to read. True or False? True (*) False 3. Which of the following statements are true for ERD's to enhance their readability. (Choose Two) (Choose all answers) There should be no crossing lines. (*) All crows feet (Many-ends) of relationships should point the same way. (*) There should be many crossing lines. It does not matter which way the crows feet (many ends) point. 4. You must make sure all entities of a proposed system can fit onto one diagram. It is not allowed to break up a data model into more than one diagram. True or False? True False (*) Test: Quiz: Generic Modeling 1. Generic models are generally less complex than a specific model. True or False? True False (*) 2. All data models MUST have some portions of the model modeled as a generic component. True or False? True False (*) 3. When you transform a specific model to be generic, which of the following statements are true? (Choose Two) (Choose all answers) You tend to end up with fewer entities in the generic model than you had in the specific model. (*) Either all or none of the original attributes make it into the generic model. (*) You will always have more entities in a generic model than in the corresponding specific model. None of the original specific model attributes are allowed in a generic model. Test: Quiz: Introduction to Relational Database Concepts 1. Identify all of the primary key is: (Choose Three) (Choose all statements that complete this sentence: A answers) A single column that uniquely identifies each row in a table. (*) A set of columns that uniquely identifies each row in a table. (*) A set of columns and keys in a single table that uniquely identifies each row in a single table. (*) Only one column that cannot be null. 2. A table does not have to have a primary key. True or False? True (*) False 3. One or more columns in a primary key can be null. True or False? True False (*) 4. A foreign key always refers to a primary key in the same table. True or False? True False (*) 5. Foreign keys cannot be null when: It is part of a primary key. (*) It refers to another table. It contains three or more columns. 6. Column integrity refers to: Columns always having values. Columns always containing positive numbers. Columns always containing values consistent with the defined data format. (*) Columns always containing text data less than 255 characters. 7. The explanation below defines which constraint type: A primary key must be unique, and no part of the primary key can be null. Entity integrity. (*) Referential integrity. Column integrity. User-defined integrity. 8. The explanation below defines which constraint type: A column must contain only values consistent with the defined data format of the column. Entity integrity. Referential integrity. Column integrity. (*) User-defined integrity. 9. The explanation below is an example of what constraint type: The value in the dept_no column of the EMPLOYEES table must match a value in the dept_no column in the DEPARTMENTS table. Entity integrity. Referential integrity. (*) Column integrity. User-defined integrity. 10. The explanation below is an example of what constraint type: If the value in the balance column of the ACCOUNTS table is below 100, we must send a letter to the account owner which will require extra programming to enforce. Entity integrity. Referential integrity. Column integrity. User-defined integrity. (*) Test: Quiz: Basic Mapping: The Transformation Process 1. In a physical data model, an entity becomes a _____________. Attribute Table (*) Constraint Column 2. In a physical data model, a relationship is represented as a: Column Primary Key Unique Identifier Foreign Key (*) 3. Attributes become columns in a database table. True or False? True (*) False 4. Why would this table name NOT work in an Oracle database? 2007_EMPLOYEES Numbers cannot be incorporated into table names Table names must start with an alphabetic character (*) Underscores "_" are not allowed in table names None of the above 5. In an Oracle database, why would the following table name not be allowed 'EMPLOYEE JOBS'? The database does not understand all capital letters EMPLOYEE is a reserved word JOBS is a reserved word You cannot have spaces between words in a table name (*) 6. The transformation from an ER diagram to a physical design involves changing terminology. Entities in the ER diagram become __________ , and attributes become ____________. Columns, Tables Tables, Columns (*) Foreign Keys, Columns Tables, Foreign Keys 7. The transformation from an ER diagram to a physical design involves changing terminology. Relationships in the ER diagram become __________ , and primary unique identifiers become ____________. Foreign keys, primary keys (*) Primary keys, foreign keys Foreign keys, mandatory business rules Foreign keys, optional business rules Test: Quiz: Relationship Mapping 1. What do you create when you transform a many to many relationship from your ER diagram into a physical design? Foreign key constraints Intersection entity Intersection table (*) Primary key constraints 2. Relationships on an ERD can only be transformed into UIDs in the physical model? True or False? True False (*) 3. One-to-One relationships are transformed into Foreign Keys in the tables created at either end of that relationship? True or False? True False (*) 4. One-to-Many Optional to Mandatory becomes a _______________ on the Master table. Mandatory Foreign Key Nothing (There are no new columns created on the Master table) (*) Optional Foreign Key Primary Key 5. Two entities A and B have an optional (A) to Mandatory (B) One-toOne relationship. When they are transformed, the Foreign Key(s) is placed on: The table BS (*) The Table AS Nowhere, One-to-One are not transformed Both tables As and Bs get a new column and a Foreign Key. 6. A barrred Relationship will result in a Foreign Key column that also is part of: The Table Name The Column Name The Check Constraint The Primary Key (*) Test: Quiz: Subtype Mapping 1. The "Arc Implementation" is a synonym for what type of implementation? Supertype Implementation Subtype Implementation Cascade Implementation Supertype and Subtype Implementation (*) 2. When translating an arc relationship to a physical design, you must turn the arc relationships into foreign keys. What additional step must you take with the created foreign keys to ensure the exclusivity principle of arc relationships? (Assume that you are implementing an Exclusive Design) (Choose Two) (Choose all answers) Make all relationships mandatory Make all relationships optional (*) Create an additional check constraint to verify that one foreign key is populated and the others are not (*) All the above 3. When mapping supertypes, relationships at the supertype level transform as usual. Relationships at subtype level are implemented as foreign keys, but the foreign key columns all become optional. True or False? True (*) False 4. Which of the following are reasons you should consider when using a Subtype Implementation? (Choose Two) (Choose all answers) When the common access paths for the subtypes are similar. When the common access paths for the subtypes are different. (*) Business functionality and business rules are similar between subtypes. Most of the relationships are at the subtype level (*) Test: Quiz: SQL Introduction: Querying the Database 1. What command retrieves data from the database? ALTER SELECT (*) DESCRIBE INSERT 2. What command can be used to show information about the structure of a table? ALTER SELECT DESCRIBE (*) INSERT 3. What command can be added to a select statement to return a subset of the data? WHERE (*) WHEN ALL EVERYONE 4. What command do you use to add rows to a table INSERT (*) ADD ADD_ROW NEW_ROW 5. Examine the follolowing SELECT statement. SELECT * FROM employees; This statement will retrieve all the rows in the employees table. True or False? True (*) False Test: Quiz: Basic Table Modifications 1. The SQL statement ALTER TABLE EMPLOYEES DROP COLUMN SALARY will delete all of the rows in the employees table. True or False? True False (*) 2. The f_customers table contains the following data: ID Name Address City State Zip 1 Cole Bee 123 Main Street Orlando FL 32838 2 Zoe Twee 1009 Oliver Avenue Boston MA 02116 3 Sandra Lee 22 Main Street Tampa FL 32444 If you run the following statement, DELETE FROM F_CUSTOMERS WHERE STATE='FL'; how many rows will be left in the table? 0 1 (*) 2 3 3. What will the following statement do to the employee table? ALTER TABLE employees ADD (gender VARCHAR2(1)) Add a new row to the EMPLOYEES table Rename a column in the EMPLOYEES table Change the datatype of the GENDER column Add a new column called GENDER to the EMPLOYEES table (*) Test: Quiz: System Development Life Cycle 1. During which phases of the System Development Life Cycle would you roll out the system to the users? Build and Transition Strategy and Analysis Design and Production Transition and Production (*) 2. In which phases of the System Development Life Cycle will we need to use SQL as a language? (Choose Two) (Choose all answers) Analysis Transition (*) Strategy Build and Document (*) 3. The data model can be used to... Communicate and group Describe and specify Analyze and copy All of the Above (*) Test: Quiz: Anatomy of a SQL Statement 1. The SQL SELECT statement is capable of: Selection and protection Selection and projection (*) Projection and updating None of the above 2. SELECT * FROM departments; is a: Keyword Statement (*) Declaration Strategy 3. The order of operator precedence is / + - * * - + / * / + - (*) None of the above 4. If you want to see all columns of data in a table, you use what symbol? & % $ * (*) 5. If you want to see just a subset of the columns in a table, you use what symbol? & % * None of the above, instead of using a symbol you name the columns you want to see the data for. (*) 6. What is a NULL value? A perfect zero A known value less than zero A blank space An unknown value (*) Test: Quiz: Relational Database Technology 1. RDBMS stands for Relational database manipulation system. Relational database management system. (*) Relational database mutilation system. Relational database management style. 2. The following statements are true regarding tables in a RDBMS: (Choose Two) (Choose all answers) A table is a logical object only. They cannot be created in a RDBMS. A table holds all the data necessary about something in the real world, such as employees, invoices or customers. (*) Tables contain fields, which can be found at the intersection of a row and a column. (*) It is not possible to relate multiple tables within an RDBMS. 3. The following table creation statement is valid. True or False? CREATE TABLE country ( ID NUMBER(6) NOT NULL, NAME VARCHAR2(30) NOT NULL, LOC VARCHAR2(40), REG_ID NUMBER, NAME VARCHAR2(25)) True False (*) 4. Once data has been created in a RDBMS, the ony way of getting it out again is by writing a Java or C program. No other languages can be used to access that data. True or False? True False (*) Test: Quiz: Working with Columns, Characters, and Rows 1. The structure of the table can be displayed with the _________ command: Desc Describe Dis A and B (*) 2. The concatenation operator ... Brings together columns or character strings into other columns Creates a resultant column that is a character expression Is represented by two vertical bars ( || ) All of the above (*) 3. In order to eliminate duplicate rows use the ________ keyword FIRST_ONLY DISTINCT (*) SINGLES_ONLY EXCLUSIVE 4. Which of the following is NOT BEING DONE in this SQL statement? SELECT first_name || ' ' || last_name "Name" FROM employees; Concatenating first name, middle name and last name (*) Putting a space between first name and last name Selecting columns from the employees table Using a column alias 5. The following is a valid SQL SELECT statement. True or False? SELECT first_name || ' ' || last_name alias AS Employee_Name FROM employees: True False (*) Test: Quiz: Limit Rows Selected 1. To restrict the rows returned from an SQL Query, you should use the _____ clause: SELECT WHERE (*) GROUP BY CONDITION All of the above 2. Which example would limit the number of rows returned? SELECT title FROM d_songs WHEN type_code = 88; SELECT title FROM d_songs WHERE type_code = = 88; SELECT title FROM d_songs WHERE type_code = 88; (*) SELECT title FROM d_songs WHEN type_code = = 88; 3. Which query would give the following result? LAST_NAME FIRST_NAME DEPARTMENT_ID King Steven 90 SELECT last_name, first_name, department_id FROM employees C WHERE last_name = 'KING'; SELECT last_name, first_name, department_id FROM employees WHERE last_name = 'King'; (*) SELECT last_name, first_name, department_id FROM employees WHERE last_name LIKE 'k%'; SELECT last_name, first_name, department_id FROM employees WHERE last_name LIKE 'KING'; 4. Which of the following statements will work? SELECT first_name ||' '||last_name NAME, department_id DEPARTMENT, salary*12 "ANNUAL SALARY" FROM employees WHERE name = 'King'; SELECT first_name ||' '||last_name NAME, department_id DEPARTMENT, salary*12 "ANNUAL SALARY" FROM employees WHERE last_name = 'King'; (*) SELECT first_name ||' '||last_name NAME, department_id DEPARTMENT, salary*12 'ANNUAL SALARY' FROM employees WHERE last_name = 'King'; SELECT first_name ||' '||last_name NAME, department_id DEPARTMENT, salary*12 'ANNUAL SALARY' FROM employees WHERE name = 'King'; 5. Which of the following would be returned by this SELECT statement: SELECT last_name, salary FROM employees WHERE salary < 3500; LAST_NAME SALARY King 5000 LAST_NAME SALARY Rajas 3500 LAST_NAME SALARY Davies 3100 (*) All of the above 6. Which of the following are true? (Choose Two) (Choose all answers) Character strings are enclosed in double quotation marks Date values are enclosed in single quotation marks (*) Character values are not case-sensitive Date values are format-sensitive (*) 7. How can you write not equal to in the WHERE-clause != ^= <> All of the above (*) EXCLUSIVE 4. Which of the following is NOT BEING DONE in this SQL statement? SELECT first_name || ' ' || last_name "Name" FROM employees; Concatenating first name, middle name and last name (*) Putting a space between first name and last name Selecting columns from the employees table Using a column alias 5. The following is a valid SQL SELECT statement. True or False? SELECT first_name || ' ' || last_name alias AS Employee_Name FROM employees: True False (*) Test: Quiz: Comparison Operators 1. Which of the following are examples of comparison operators used in the WHERE clause? =, >, <, <=, >=, <> between ___ and ___ in (..,..,.. ) like is null All of the above (*) 2. When using the "LIKE" operator, the % and _ symbols can be used to do a pattern-matching, wild card search. True or False? True (*) False 3. Which statement would select salaries that are greater than or equal to 2500 and less than or equal to 3500? Choose two answers. (Choose all answers) WHERE salary >= 2500 AND salary <= 3500 (*) WHERE salary <=2500 AND salary >= 3500 WHERE salary BETWEEN 2500 AND 3500 (*) WHERE salary BETWEEN 3500 AND 2500 4. 10? Which of the following WHERE clauses would not select the number WHERE hours BETWEEN 10 AND 20 WHERE hours <= 10 WHERE hours <>10 (*) WHERE hours IN (8,9,10) Test: Quiz: Logical Comparisons and Precedence Rules 1. Which of the following statements best describes the rules of precedence when using SQL? The order in which the columns are displayed The order in which the expressions are sorted The order in which the operators are returned The order in which the expressions are evaluated and calculated (*) All of the above 2. Which of the following is earliest in the rules of precedence? Concatenation operator Logical condition Comparison condition Arithmetic operator (*) 3. Which symbol in the WHERE clause means "Not Equal To"? (Choose Two) (Choose all NOT IN (...) (*) =+ <> (*) answers) >< 4. Which of the following are examples of logical operators that might be used in a WHERE clause. (Choose Two) (Choose all answers) AND, OR (*) < >, =, <=, >=, <> NOT (*) LIKES All of the above 5. What will be the results of the following selection? SELECT * FROM employees WHERE last_name NOT LIKE 'A%' AND last_name NOT LIKE 'B%' All last names that begin with A or B All last names that do not begin with A or B (*) No rows will be returned. There is a syntax error All rows will be returned 6. Find the clause that will give the same results as: SELECT * FROM d_cds WHERE cd_number NOT IN(90, 91, 92); WHERE cd_id <=90 and cd_id >=92; WHERE cd_id NOT LIKE (90, 91, 92); WHERE cd_id != 90 and cd_id != 91 and cd_id != 92; (*) WHERE cd_id != 90 or cd_id != 91 or cd_id!= 92; 7. Which of the following would be returned by this SQL statement: SELECT First_name, last_name, department_id FROM employees WHERE department_id IN(50,80) AND first_name LIKE 'C%' OR last_name LIKE '%s%' FIRST_NAME LAST_NAME DEPARTMENT_ID Shelly Higgins 110 FIRST_NAME LAST_NAME DEPARTMENT_ID Curtis Davies 50 FIRST_NAME LAST_NAME DEPARTMENT_ID Randall Matos 50 FIRST_NAME LAST_NAME DEPARTMENT_ID Michael Hartstein 20 All of the above (*) In . Refer to Test: Quiz: Sorting Rows 8 1. Which of the following is true of the ORDER BY clause: (Choose Two) (Choose all answers) Must be the last clause of the SQL statement (*) Displays the fetched rows in no particular order Defaults to a descending order (DESC) Defaults to an ascending order (ASC) (*) 2. What columns can be added to the following SELECT statement in its ORDER BY clause? (Choose Three) SELECT first_name, last_name, salary, hire_date FROM employees WHERE department_id = 50 ORDER BY ?????; (Choose all answers) last_name, first_name. (*) All columns in the EMPLOYEES table. (*) The table name, EMPLOYEES, which would then automatically sort by all columns in the table. Any column in the EMPLOYEES table, any expression in the SELECT list or any ALIAS in the SELECT list. (*) All the columns in the database. 3. A column alias can be specified in an ORDER BY Clause. True or False? True (*) False 4. What clause must you place in a SQL statement to have your results sorted from highest to lowest salary? ORDER BY salary ASC ORDER BY salary DESC (*) ORDER salary BY DESC None, the database always sorts from highest to lowest on the salary column. Test: Quiz: Introduction to Functions 1. The conversion function TO_CHAR is a single row function. True or False? True (*) False 2. The function COUNT is a single row function. True or False? True False (*) 3. The following statement represents a multi-row function. True or False? SELECT UPPER(last_name) FROM employees; True False (*) 4. The following statement represents a multi-row function. True or False? SELECT MAX(salary) FROM employees True (*) False 5. Will the following statement return one row? SELECT MAX(salary), MIN(Salary), AVG(SALARY) FROM employees; No, it is illegal. You cannot use more than one multi-row function in a SELECT statement Yes, it will return the highest salary, the lowest salary and the average salary from all employees (*) Yes, it will return the highest salary from each employee Yes, it will return the average salary from the employees table. Oracle Academy Database Programming with SQL - Teacher Character, Number and Date Functions 1. What does the following SQL SELECT statement return? SELECT UPPER( SUBSTR('Database Programming', INSTR('Database Programming','P'),20)) FROM dual; Programming PROGRAMMING (*) Database DATABASE 2. Single row functions may be used in ______, _______ and _______ clauses. (Choose two answers.) (Choose all answers) SELECT, FROM, ALWAYS FROM, SELECT, ORDERS WHERE, DECODE, ORDER BY (*) SELECT, WHERE, ORDER BY (*) 3. Which query selects the first names of the DJ On Demand clients who have a first name beginning with "A"? SELECT UPPER(first_name) FROM d_clients WHERE first_name LIKE %a% SELECT UPPER(first_name) FROM d_clients v WHERE first_name LIKE '%a%' SELECT UPPER(first_name) FROM d_clients WHERE first_name LIKE 'a%' SELECT UPPER(first_name) FROM d_clients WHERE LOWER(first_name) LIKE 'a%' (*) 4. Which character manipulation function always returns a numerical value? TRIM LPAD LENGTH (*) SUBSTR 5. Which query would return a user password combining the ID of an employee and the first 4 digits of the last name? SELECT CONCAT (employee_id, SUBSTR(last_name,4,1)) AS "User Passwords" FROM employees SELECT CONCAT (employee_id, INSTR(last_name,4,1)) AS "User Passwords" FROM employees SELECT CONCAT (employee_id, INSTR(last_name,1,4)) AS "User Passwords" FROM employees SELECT CONCAT (employee_id, SUBSTR(last_name,1,4)) AS "User Passwords" FROM employees (*) 6. Character functions accept character arguments and only return character values. True or False? True False (*) 7. Which of the following are types of SQL functions? (Choose two answers.) (Choose all answers) Multi-Row Functions (*) Column-Row Functions Single-Row Functions (*) Many-to-Many Functions 8. Which of the following SQL statements would ly return a song title identified in the database as "All These Years"? WHERE title CONTAINS 'Years'; WHERE title LIKE LOWER('all these years'); WHERE title IN('All','These','Years'); WHERE title LIKE INITCAP('%all these years'); (*) 9. Identify the output from the following SQL statement: SELECT RPAD('SQL',6, '*') FROM DUAL; ******SQL ***SQL SQL*** (*) SQL****** Test: Quiz: Number Functions 1. The answer to the following script is 456. True or False? SELECT TRUNC(ROUND(456.98)) FROM dual True False (*) 2. ROUND and TRUNC functions can be used with which of the following Datatypes? Dates and numbers (*) Dates and characters Numbers and characters None of the above 3. Which number function may be used to determine if a value is odd or even? MOD (*) TRUNC ROUND BINARY 4. What is the result of the following SQL Statement: SELECT ROUND(45.923,-1) FROM DUAL; 46 45.9 50 (*) None of the above Test: Quiz: Date Functions Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. Which query would return a whole number if the sysdate is 26-MAY04? Mark for Review SELECT TRUNC(MONTHS_BETWEEN(SYSDATE,'19-MAR-79') /12) AS YEARS FROM DUAL; (*) SELECT TRUNC(YEARS_BETWEEN(SYSDATE,'19-MAR-79') /12) AS YEARS FROM DUAL; SELECT MONTHS_BETWEEN(SYSDATE,'19-MAR-79') /12 AS YEARS FROM DUAL; None of the above 2. Round and Trunc can be used on Date datatypes. True or False? for Review True (*) Mark False 3. What is the result of the following query? SELECT ADD_MONTHS ('11-JAN-94',6) FROM dual; Mark for Review 1/17/2004 1/11/1995 7/11/1994 (*) 7/17/1994 4. What is the result of the following query? SELECT ADD_YEARS ('11-JAN-94',6) FROM dual; Mark for Review This in not a valid SQL statement. (*) 7/11/1995 1/11/2000 7/11/2000 5. What function would you use to return the highest date in a month? Mark for Review FINAL_DAY END_DAY HIGHEST_DAY LAST_DAY (*) 6. If hire_date has a value of '03-July-03', then what is the output from this code? SELECT ROUND(hire_date, 'Year') FROM employees; Mark for Review 01-JAN-04 (*) 01-JAN-03 01-JUL-03 01-AUG-03 Section 2 Single Row Functions Test: Quiz: Conversion Functions Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. The following script will run successfully. True or False? SELECT TO_CHAR(TO_DATE("25-DEC-04",'dd-MON-yy')) FROM dual Mark for Review True False (*) 2. You need to display the HIRE_DATE values in this format: 25th of July 2002. Which SELECT statement would you use? Mark for Review SELECT enroll_date(hire_date, 'DDspth "of" Month YYYY') FROM employees; SELECT TO_CHAR(hire_date, 'ddth "of" Month YYYY') FROM employees; (*) SELECT TO_CHAR(hire_date, 'DDTH "of" Month YYYY') FROM employees; SELECT TO_CHAR(hire_date, 'DDspth 'of' Month RRRR') FROM employees; 3. Sysdate is 12-MAY-2004. You need to store the following date: 7-DEC-89 Which statement about the date format for this value is true? Mark for Review Both the YY and RR date formats will interpret the year as 1989. Both the YY and RR date formats will interpret the year as 2089. The RR date format will interpret the year as 1989, and the YY date format will interpret the year as 2089. (*) The RR date format will interpret the year as 2089, and the YY date format will interpret the year as 1989. 4. Which statement is true about SQL functions? Mark for Review Functions can convert values or text to another data type. Functions can round a number to a specified decimal place. Functions can convert upper case characters to lower case characters. a, b and c are true. (*) None of the above statements are true. 5. A table has the following definition: EMPLOYEES( EMPLOYEE_ID NUMBER(6) NOT NULL, LAST_NAME VARCHAR2(10) NOT NULL, MANAGER_ID VARCHAR2(6)) and contains the following rows: (1001, 'Bob Bevan', '200') (200,'Natacha Hansen', null) Will the following query work? SELECT * FROM employees WHERE employee_id = manager_id; Mark for Review No, because the WHERE-clause will not find any matching data. No, because the datatypes of ID and MANAGER are different. Yes, Oracle will perform implicit datatype conversion. (*) No. You will have to re-write the statement and perform explicit datatype conversion. 6. Which statement will return the salary of e.g. 6000 from the Employees table in the following format $6000.00? Mark for Review SELECT TO_CHAR(salary, '$99999.00') SALARY FROM employees (*) SELECT TO_CHAR(salary, '99999.00') SALARY FROM employees SELECT TO_CHAR(salary, '$99999') SALARY FROM employees SELECT TO_CHAR(sal, '$99999.00') SALARY FROM employees Test: Quiz: Null Functions Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. The following statement returns 0 (zero). True or False? SELECT 121/NULL FROM dual; Mark for Review True False (*) 2. If quantity is a number datatype, what is the result of this statement? SELECT NVL(200/quantity, 'zero') FROM inventory; Mark for Review zero ZERO The statement fails (*) Null 3. Which function compares two expressions? Mark for Review NVL NULLIF (*) NVL2 NULL 4. Consider the following data in the Employees table: (last_name, commission_pct, manager_id) DATA: King,null,null Kochhar, null,100 Vargas, null, 124 Zlotkey,.2, 100 What is the result of the following statement: SELECT last_name, COALESCE(commission_pct, manager_id, -1) comm FROM employees ; Mark for Review Statement will fail King, -1 Kochhar, 100 Vargas, 124 Zlotkey, .2 (*) King, -1 Kochhar, 100 Vargas, 124 Zlotkey, 100 King, null Kochhar, 100 Vargas, 124 Zlotkey, .2 5. With the following data in Employees (last_name, commission_pct, manager_id) what is the result of the following statement? DATA: King,null,null Kochhar, null,100 Vargas, null, 124 Zlotkey,.2, 100 SELECT last_name, NVL2(commission_pct, manager_id, -1) comm FROM employees ; Mark for Review King, -1 Kochhar, -1 Vargas, -1 Zlotkey, .2 Statement will fail. King, -1 Kochhar, 100 Vargas, 124 Zlotkey, .2 King, -1 Kochhar, -1 Vargas, -1 Zlotkey, 100 (*) Test: Quiz: Conditional Expressions Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. CASE and DECODE evaluate expressions in a similar way to IF-THENELSE logic. However, DECODE is specific to Oracle syntax. True or False? Mark for Review True (*) False 2. Which of the following is a conditional expression used in SQL? for Review Mark CASE (*) DESCRIBE WHERE NULLIF 3. Which statement will return a listing of last names, salaries and a rating of 'Low', 'Medium', 'Good' or 'Excellent' depending on the salary value? Mark for Review SELECT last_name,salary, (CASE WHEN salary < 5000 THEN 'Low' WHEN salary < 10000 THEN 'Medium' WHEN salary < 20000 THEN 'Good' ELSE 'Excellent' END) qualified_salary FROM employees; (*) SELECT last_name,salary, (CASE WHEN sal < 5000 THEN 'Low' WHEN sal < 10000 THEN 'Medium' WHEN sal < 20000 THEN 'Good' ELSE 'Excellent' END) qualified_salary FROM employees; SELECT last_name,sal, (CASE WHEN sal < 5000 THEN 'Low' WHEN sal < 10000 THEN 'Medium' WHEN sal < 20000 THEN 'Good' ELSE 'Excellent' END) qualified_salary FROM employees; SELECT last_name,salary, (RATING WHEN salary < 5000 THEN 'Low' WHEN salary < 10000 THEN 'Medium' WHEN salary < 20000 THEN 'Good' ELSE 'Excellent' END) qualified_salary FROM employees; 4. For the given data from Employees (last_name, manager_id) what is the result of the following statement: DATA: ( King, null Kochhar, 100 De Haan, 100 Hunold, 102 Ernst, 103) SELECT last_name, DECODE(manager_id, 100, 'King', 'A N Other') "Works For?" FROM employees Mark for Review King, Null Kochhar, King De Haan, King Hunold, A N Other Ernst, A N Other King, A N Other Kochhar, King De Haan, King Hunold, A N Other Ernst, A N Other (*) Invalid statement. King, A N Other Kochhar, King De Haan, King Hunold, Kochhar Ernst, De Haan Test: Quiz: Cartesian Product and the Join Operations Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. What is the result of a query that selects from two tables but includes no join condition? Mark for Review A Cartesian product. (*) A selection of matched rows from both tables. A Syntax error. A selection of rows from the first table only. 2. When must column names be prefixed by table names in JOIN syntax? Mark for Review When more than two tables participate in the join. Only when query speed and database performance is a concern. When the same column name appears in more than one table of the query. (*) Never. 3. If table A have 10 rows and table B have 5 rows, how many rows will be returned if you perform a cartesian join on those two tables? Mark for Review 5 50 (*) 10 15 4. If table A have 10 rows and table B have 5 rows, how many rows will be returned if you perform a equi-join on those two tables? Mark for Review 50 10 5 It depends on the data found in the two tables. (*) 5. Will the following statement work? SELECT department_name, last_name FROM employees, departments WHERE department_id = department_id; Mark for Review Yes, there are no syntax errors in the statement. No, Oracle will return a column ambiguously defined error. (*) Yes, Oracle will resolve which department_id colum comes from which table. No, Oracle will not allow joins in the WHERE clause. 6. Oracle proprietary JOINS can use the WHERE clause for conditions other than the join-condition. True or False? Mark for Review True (*) False Test: Quiz: Nonequijoins Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. Which of the following operators is/are typically used in a nonequijoin? Mark for Review NOT OR IN >=, <=, BETWEEN ...AND (*) * 2. Which statement about joining tables with a non-equijoin is false? Mark for Review A WHERE clause must specify a column in one table that is compared to a column in the second table (*) The number of join conditions required is always one less than the number of tables being joined The columns being joined must have compatible data types None of the above 3. The following statement is an example of a nonequi-join? SELECT e.last_name, e.salary, j.grade_level FROM employees e, job_grades j WHERE e.salary BETWEEN j.lowest_sal AND j.highest_sal; True or False? Mark for Review True (*) False Test: Quiz: Outer Joins Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. Which symbol is used to perform an outer join? Mark for Review * || (+) (*) # 2. The ID column in the CLIENT table that corresponds to the CLIENT_ID column of the ORDER table contains null values for rows that need to be displayed. Which type of join should you use to display the data? Mark for Review Equijoin Self join Outer join (*) Nonequi-Join 3. To perform a valid outer join between DEPARMENTS and EMPLOYEES to list departments without employees select the correct WHERE clause for the following select statement: SELECT d.department_name, e.last_name FROM employees e, departments d WHERE Mark for Review e.department_id(+) = d.department_id (*) e.department_id(+) = d.department_id(+) e.department_id = d.department_id(+) e.department_id = d.department_id 4. The following is a valid outer join statement: SELECT c.country_name, d.department_name FROM countries c, departments d WHERE c.country_id (+) = d.country_id (+) True or False? Mark for Review True False (*) Test: Quiz: Self Joins and Hierarchical Queries Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. Which of the following database design concepts is implemented with a self join? Mark for Review Non-Transferability Recursive Relationship (*) Supertype Arc 2. Which SELECT statement implements a self join? Mark for Review SELECT e.employee_id, m.manager_id FROM employees e NATURAL JOIN employees m; SELECT e.employee_id, m.manager_id FROM employees e, employees m WHERE m.employee_id = e.manager_id; (*) SELECT e.employee_id, m.manager_id FROM employees e, manager m WHERE e.employee_id = m.manager_id; SELECT e.employee_id, m.manager_id FROM employees e, departments m WHERE e.employee_id = m.manager_id; 3. Which select statement will return the last name and hire data of an employee and his/ her manager for employees that started in the company before their managers? Mark for Review SELECT w.last_name, w.hire_date, m.last_name, m.hire_date FROM employees w , employees m WHERE w.manager_id = m.employee_id AND w.hire_date < m.hire_date (*) SELECT w.last_name, w.hire_date, m.last_name, m.hire_date FROM employees w , employees m WHERE w.manager_id != m.employee_id AND w.hire_date < m.hire_date SELECT w.last_name, w.hire_date, m.last_name, m.hire_date FROM employees w , employees w WHERE w.manager_id = w.employee_id AND w.hire_date < w.hire_date SELECT w.last_name, w.hire_date, m.last_name, m.hire_date FROM employees w , employees m WHERE w.manager_id = m.employee_id AND w.hire_date > m.hire_date 4. Which of the following database design concepts do you need in your tables to write Hierarchical queries? Mark for Review Non-Transferability Recursive Relationship (*) Supertype Arc 5. Hierarchical queries MUST use the LEVEL pseudo column. True or False? Mark for Review True False (*) 6. Hierarchical queries can walk both Top-Down and Bottom-Up. True or False? Mark for Review True (*) False Test: Quiz: Cross joins and Natural Joins Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. A NATURAL JOIN is based on: Mark for Review Columns with the same name and datatype (*) Columns with the same name Columns with the same datatype and width Tables with the same structure 2. The ___________ join is the ANSI-standard syntax used to generate a Cartesian product. Mark for Review NATURAL ALL FULL CROSS (*) 3. What happens when you create a Cartesian product? Mark for Review All rows from one table are joined to all rows of another table (*) No rows are returned as you entered wrong join-criteria The table is joined to itself, one column to the next column, exhausting all possibilities All rows that do not match in the WHERE clause are displayed 4. The join column must be included in the select statement when you use the NATURAL JOIN clause. True or False? Mark for Review True False (*) Test: Quiz: Join Clauses Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. The keywords JOIN _____________ should be used to join tables with the same column names but different datatypes. Mark for Review NATURAL ON ON WHEN USING (*) 2. Table aliases MUST be used with columns referenced in the JOIN USING clause. True or False? Mark for Review True False (*) 3. The primary advantage of using JOIN ON is: Mark for Review The join happens automatically based on matching column names and data types It will display rows that do not meet the join condition It easily produces a Cartesian product between the tables in the statement It permits columns that don?t have matching data types to be joined It permits columns with different names to be joined (*) 4. You can do nonequi-joins with ANSI-Syntax. True or False? Review Mark for True (*) False 5. The following is a valid SQL statement. SELECT e.employee_id, e.last_name, d.location_id, department_id FROM employees e JOIN departments d USING (department_id) ; True or False? Mark for Review True (*) False Test: Quiz: Inner versus Outer Joins Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. Which syntax would be used to retrieve all rows in both the EMPLOYEES and DEPARTMENTS tables, even when there is no match? Mark for Review FULL OUTER JOIN (*) LEFT OUTER JOIN AND RIGHT OUTER JOIN FULL INNER JOIN Use any equijoin syntax 2. What is another name for a simple join or an inner join? Review Mark for Nonequijoin Equijoin (*) Self Join Outer Join 3. The following statement is an example of what kind of join? SELECT car.vehicle_id, driver.name FROM car LEFT OUTER JOIN driver ON (driver_id) ; Mark for Review Inner Join Outer Join (*) Equijoin Optimal Join 4. EMPLOYEES Table: Name Null? Type EMPLOYEE_ID NOT NULL NUMBER(6) FIRST_NAME VARCHAR2(20) LAST_NAME NOT NULL VARCHAR2(25) DEPARTMENT_ID NUMBER (4) DEPARTMENTS Table: Name Null? Type DEPARTMENT_ID NOT NULL NUMBER 4 DEPARTMENT_NAME NOT NULL VARCHAR2(30) MANAGER_ID NUMBER (6) A query is needed to display each department and its manager name from the above tables. However, not all departments have a manager but we want departments returned in all cases. Which of the following SQL: 1999 syntax scripts will accomplish the task? Mark for Review SELECT d.department_id, e.first_name, e.last_name FROM employees e LEFT OUTER JOIN departments d WHERE (e.department_id = d.department_id); SELECT d.department_id, e.first_name, e.last_name FROM employees e RIGHT OUTER JOIN departments d ON (e.employee_id = d.manager_id); (*) SELECT d.department_id, e.first_name, e.last_name FROM employees e FULL OUTER JOIN departments d ON (e.employee_id = d.manager_id); SELECT d.department_id, e.first_name, e.last_name FROM employees e, departments d WHERE e.employee_id RIGHT OUTER JOIN d.manager_id; 5. For which of the following tables will all the values be retrieved even if there is no match in the other? SELECT e.last_name, e.department_id, d.department_name FROM employees e LEFT OUTER JOIN departments d ON (e.department_id = d.department_id); Mark for Review employees (*) department both Neither. the LEFT OUTER JOIN limits the value to the matching department id's. 6. If you select rows from two tables (employees and departments) using an outer join, what will you get? Use the code below to arrive at your answer: SELECT e.last_name, e.department_id, d.department_name FROM employees e LEFT OUTER JOIN departments d ON (e.department_id = d.department_id); Mark for Review All employees that do not have a department_id assigned to them All employees including those that do not have a department_id assigned to them (*) No employees as the statement will fail None of the above 7. Given the following descriptions of the employees and jobs tables, which of the following scripts will display each employee?s possible minimum and maximum salaries based on their job title? EMPLOYEES Table: Name Null? Type EMPLOYEE_ID NOT NULL NUMBER (6) FIRST_NAME VARCHAR2 (20) LAST_NAME NOT NULL VARCHAR2 (25) EMAIL NOT NULL VARCHAR2 (25) PHONE_NUMBER VARCHAR2 (20) HIRE_DATE NOT NULL DATE JOB_ID NOT NULL VARCHAR2 (10) SALARY NUMBER (8,2) COMMISSION_PCT NUMBER (2,2) MANAGER_ID NUMBER (6) DEPARTMENT_ID NUMBER (4) JOBS Table: Name Null? Type JOB_ID NOT NULL VARCHAR2 (10) JOB_TITLE NOT NULL VARCHAR2 (35) MIN_SALARY NUMBER (6) MAX_SALARY NUMBER (6) Mark for Review SELECT e.first_name, e.last_name, e.job_id, j.min_salary, j.max_salary FROM employees e NATURAL JOIN jobs j USING (job_id); SELECT first_name, last_name, job_id, min_salary, max_salary FROM employees NATURAL JOIN jobs; (*) SELECT e.first_name, e.last_name, e.job_id, j.min_salary, j.max_salary FROM employees e NATURAL JOIN jobs j; SELECT first_name, last_name, job_id, min_salary, max_salary FROM employees e FULL JOIN jobs j (job_id); SELECT e.first_name, e.last_name, e.job_id, j.min_salary, j.max_salary FROM employees e NATURAL JOIN jobs j ON (e.job_title = j.job_title); Test: Quiz: Group Functions Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. What two group functions can be used with any datatype? Review STDDEV, VARIANCE SUM, AVG Mark for COUNT, SUM MIN, MAX (*) 2. What would the following SQL statement return? SELECT MAX(hire_date) FROM employees; Mark for Review The hire date of the longest serving employee The hire date of the newest employee (*) The hire dates of all employees in ascending order The hire dates of all employees 3. You can use GROUP functions in all clauses of a SELECT statement. True or False? Mark for Review True False (*) 4. The following statement will work even though it uses the same column with different GROUP functions: SELECT AVG(salary), MAX(salary), MIN(salary), SUM(salary) FROM employees; True or False? Mark for Review True (*) False 5. Given the following data in the employees table (employee_id, salary, commission_pct) DATA: (143, 2600, null 144, 2500, null 149, 10500, .2 174, 11000, .3 176, 8600, .2 178, 7000, .15) What is the result of the following statement: SELECT AVG(commission_pct) FROM employees WHERE employee_id IN( 143,144,149,174,176,178) Mark for Review 1.2125 This statement is invalid 0.2125 (*) 0.0425 6. Given the following data in the employees table (employee_id, salary, commission_pct) DATA: (143, 2600, null 144, 2500, null 149, 10500, .2 174, 11000, .3 176, 8600, .2 178, 7000, .15) What is the result of the following statement: SELECT SUM(commission_pct), COUNT(commission_pct) FROM employees WHERE employee_id IN( 143,144,149,174,176,178) Mark for Review SUM = .85 and COUNT = 6 SUM = 1.85 and COUNT = 6 SUM = .85 and COUNT = 4 (*) SUM = 1.85 and COUNT = 4 Test: Quiz: Count, Distinct, NVL Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. To include null values in the calculations of a group function, you must: Mark for Review Precede the group function name with NULL Count the number of null values in that column using COUNT Convert the null to a value using the NVL( ) function (*) Group functions can never use null values 2. What would the following SQL statement return? SELECT COUNT(first_name) FROM employees; Mark for Review A listing of all non-null first names in the employees table The total number of non-null first names in the employees table (*) The total number of rows in the employees table A listing of all unique first names in the employees table 3. What would the following SQL statement return? SELECT COUNT(DISTINCT salary) FROM employees; Mark for Review A listing of all unique salaries in the employees table The total number of rows in the employees table The total amount of salaries in the employees table The number of unique salaries in the employees table (*) 4. Using your existing knowledge of the employees table, would the following two statements produce the same result? SELECT COUNT(*) FROM employees; SELECT COUNT(commission_pct) FROM employees; Mark for Review The first statement is invalid Yes No (*) The second statement is invalid Test: Quiz: Group By and Having Clauses, ROLLUP and CUBE Operations, and Grouping Sets 1. Read the following SELECT statement. Choose the column or columns that must be included in the GROUP BY clause. SELECT COUNT(last_name), grade, gender FROM STUDENTS GROUP_BY ?????; last_name last_name, grade grade, gender (*) last_name, gender 2. Is the following statement SELECT department_id, AVG(salary) FROM employees; ? No, because a GROUP BY department_id clause is needed (*) No, because the SELECT clause cannot contain both individual columns and group functions No, because the AVG function cannot be used on the salary column Yes 3. Which of the following SQL statements could display the number of people with the same last name: SELECT first_name, last_name, COUNT(employee_id) FROM EMPLOYEES GROUP BY last_name; SELECT employee_id, COUNT(last_name) FROM EMPLOYEES GROUP BY last_name; SELECT last_name, COUNT(last_name) FROM EMPLOYEES GROUP BY last_name; (*) SELECT employee_id, DISTINCT(last_name) FROM EMPLOYEES GROUP BY last_name; 4. How would you alter the following query to list only employees where more than one employee exists with the same last_name: SELECT last_name, COUNT(employee_id) FROM EMPLOYEES GROUP BY last_name; SELECT last_name, COUNT(employee_id) FROM EMPLOYEES WHERE COUNT(*) > 1 GROUP BY last_name SELECT last_name, COUNT(last_name) FROM EMPLOYEES GROUP BY last_name HAVING COUNT(last_name) > 1; (*) SELECT last_name, COUNT(last_name) FROM EMPLOYEES GROUP BY last_name EXISTS COUNT(last_name) > 1; SELECT employee_id, DISTINCT(last_name) FROM EMPLOYEES GROUP BY last_name HAVING last_name > 1; 5. Is the following statement : SELECT first_name, last_name, salary, department_id, COUNT(employee_id) FROM employees WHERE department_id = 50 GROUP BY last_name, first_name, department_id; Yes No, beause you cannot have a WHERE-clause when you use group functions. No, because the statement is missing salary in the GROUP BY clause (*) Yes, because Oracle will any mistakes in the statement itself 6. The following is a valid statement: SELECT MAX(AVG(salary)) FROM employees GROUP BY department_id; True or False? True (*) False 7. The use of GROUP BY GROUPING SETS(....) can speed up the execution of complex report statements? (True or False) True (*) False 8. Examine the following statement: SELECT department_id, manager_id, job_id, SUM(salary) FROM employees GROUP BY GROUPING SETS(.......); Select the GROUP BY GROUPING SETS clause from the following list: GROUP BY GROUPING SETS (department_id, AVG(salary)), (department_id, job_id), (department_id, manager_id) GROUP BY GROUPING SETS (department_id, salary), (department_id, job_id), (department_id, manager_id) GROUP BY GROUPING SETS ((department_id, manager_id), (department_id, job_id), (manager_id, job_id)) (*) GROUP BY GROUPING SETS ((department_id, manager_id), (department_id, SUM(salary), (manager_id, job_id)) 9. If you want to include subtotals and grant totals for all columns mentioned in a GROUP BY clause you should use which of the following extensions to the GROUP BY clause? ROLLUP CUBE (*) GROUP BY ALL COLUMNS HAVING 10. Examine the following statement: SELECT department_id, manager_id, job_id, SUM(salary) FROM employees GROUP BY ROLLUP(department_id, manager_id) What extra data will this query generate? Subtotals for department_id, and grand totals for salary. Subtotals for department_id, job_id and grand totals for salary. Subtotals for department_id, job_id, manager_id and grand totals for salary. The statement will fail. (*) 11. Examine the following statement: SELECT department_id, manager_id, job_id, SUM(salary) FROM employees GROUP BY GROUPING SETS((department_id, manager_id), (department_id, job_id)) What data will this query generate? Total salaries for (department_id, job_id) and (department_id, manager_id) (*) Total salaries for (department_id, job_id, manager_id) Total for (job_id, manager_id) The statement will fail. Test: Quiz: Subqueries 1. Which of the following statements is a true guideline for using subqueries? Do not enclose the subquery in parentheses. Place the subquery on the left side of the comparison condition. The outer and inner queries can reference more than one table. They can get data from different tables. (*) Only one WHERE clause can be used for a SELECT statement, and if specified, it must be the outer query. 2. Subqueries can only be placed in the WHERE clause. True or False? True False (*) 3. What will the following statement return: SELECT last_name, salary FROM employees WHERE salary < (SELECT salary FROM employees WHERE employee_id = 103) A list of last_names and salaries of employees that makes more than employee 103 A list of last_names and salaries of employees that makes less than employee 103 (*) A list of first_names and salaries of employees making less than employee 103 Nothing. It is an invalid statement. 4. What will the following statement return: SELECT employee_id, last_name FROM employees WHERE salary = (SELECT MIN(salary) FROM employees GROUP BY department_id); Nothing. It is an invalid statement. (*) A list of last_names and salaries of employees A list of first_names and salaries of employees in Department 50 A list of last_names and salaries of employees grouped by department_id. 5. What will the following statement return: SELECT last_name, salary FROM employees WHERE (department_id, job_id) IN (SELECT (department_id, job_id) FROM employees WHERE employee_id = 103) A list of last_names and salaries of employees that works in the same department and has the same job_id as that of employee 103. (*) A list of last_names or salaries of employees that works in the same department and has the same job_id as that of employee 103. A list of last_names and salaries of employees that works in the same department or has the same job_id as that of employee 103. Nothing. It is an invalid statement. 6. Examine the following statement: SELECT last_name, salary FROM employees WHERE department_id = (SELECT department_id FROM employees WHERE employee_id = 103) AND job_id = (SELECT job_id FROM employees WHERE employee_id = 103) Is this a pair-wise or non-pair-wise Subquery? This is an example of a non-pair-wise subquery. (*) This is an example of a pair-wise subquery. Neither. This statement is illegal, and will not run. Test: Quiz: Single-Row Subqueries 1. In a non-correlated subquery, the outer query always executes prior to the inner query's execution. True or False? True False (*) 2. The result of this statement will be: SELECT last_name, job_id, salary, department_id FROM employees WHERE job_id = (SELECT job_id FROM employees WHERE employee_id = 141) AND department_id = (SELECT department_id FROM departments WHERE location_id =1500) All employees from Location 1500 will be displayed An error since you can?t get data from two tables in the same subquery All employees with the department id of 141 Only the employees whose job id matches employee 141 and who work in location 1500 (*) 3. Subqueries are limited to four per SQL transaction. True or False? True False (*) 4. Single row subqueries may not include this operator: ALL (*) = <> > 5. If the subquery returns no rows will the outer query return any values? No, because you are not allowed to not return any rows from a subquery Yes. It will just run and ignore the subquery No, because the subquery will be treated like a null value. (*) Yes, Oracle will find the nearest value and rewrite your statement implicitly when you run it Test: Quiz: Multiple-Row Subqueries 1. There can be more than one subquery returning information to the outer query. True or False? True (*) False 2. Group functions can be used in subqueries even though they may return many rows. True or False? True (*) False 3. Multiple-row subqueries must have NOT, IN or ANY in the WHERE clause of the inner query. True or False? True False (*) 4. Group functions, such as HAVING and GROUP BY can be used in multiplerow subqueries. True or False? True (*) False 5. The salary column of the f_staffs table contains the following values: 4000 5050 6000 11000 23000 Which of the following statements will return the last_name and first_name of those employees who earn more than 5000. SELECT last_name, first_name FROM f_staffs WHERE salary = (SELECT salary FROM f_staffs WHERE salary > 5000); SELECT last_name, first_name FROM f_staffs WHERE salary = (SELECT salary FROM f_staffs WHERE salary < 5000);

SELECT last_name, first_name FROM f_staffs WHERE salary IN (SELECT salary FROM f_staffs WHERE salary > 5000); (*) SELECT last_name, first_name FROM f_staffs WHERE salary IN (SELECT last_name, first_name FROM f_staffs WHERE salary < 5000); 6. When a multiple-row subquery uses the NOT IN (<>ALL) operator, if one of the values returned by the inner query is a null value, the entire query returns: A list of Nulls All rows that were selected by the inner query including the null value(s) All rows, minus the null value(s), that were selected by the inner query No rows returned (*) 7. The SQL multiple-row subquery extends the capability of the singlerow syntax through the use of what three comparison operators? IN, ANY and EQUAL IN, ANY and ALL (*) IN, ANY and EVERY IN, ALL and EVERY 8. In a subquery the ALL operator compares a value to every value returned by the inner query. True or False? True (*) False Test: Quiz: Correlated Subqueries 1. In a correlated subquery the outer and inner query are joined on one or more columns? (True or False) True (*) False 2. The WITH-clause is a way of creating extra tables in the database? (True or False) True False (*) 3. Correlated Subqueries must work on the same tables in both the inner and outer query? (True or False) True False (*) 4. Table aliases must be used when you are writing correlated subqueries? (True or false) True (*) False Test: Quiz: Using SET Operators 1. Which ones of the following are (Choose all SET operators? (choose two) answers) UNION, MINUS (*) UNION ALL, PLUS ALL UNION ALL, INTERSECT (*) MINUS, PLUS 2. The difference between UNION and UNION ALL is There is no difference between, you get exactly the same result. UNION will remove duplicates, UNION ALL returns all rows from all queries (*) UNION ALL is like a NATURAL JOIN UNION is a synomym for UNION ALL 3. MINUS will give you rows from the first query not present in the second query? (True or False) True (*) False 4. INTERSECT will give you rows found in both queries? (True or False) True (*) False Test: Quiz: Insert Statement 1. DML is an acronym that stands for: Debit Markup Language Don't Manipulate Language Data Markup Language Data Manipulation Language (*) . Which of the following statements will add a new customer to the customers table in the Global Fast Foods database? INSERT IN customers (id, first_name, last_name, address, city, state, zip, phone_number); INSERT INTO customers (id, first_name, last_name, address, city, state, zip, phone_number) VALUES ("145", 'Katie', 'Hernandez', '92 Chico Way', 'Los Angeles', 'CA', "98008", "8586667641"); INSERT INTO customers (id, first_name, last_name, address, city, state, zip, phone_number) VALUES (145, 'Katie', 'Hernandez', '92 Chico Way', 'Los Angeles', 'CA', 98008, 8586667641); (*) INSERT INTO customers (id 145, first_name 'Katie', last_name 'Hernandez', address '92 Chico Way', city 'Los Angeles', state 'CA', zip 98008, phone_number 8586667641); . To return a table summary on the customers table, which of the following is ? SHOW customers, or SEE customers DISTINCT customers, or DIST customers DESCRIBE customers, or DESC customers (*) DEFINE customers, or DEF customers 4. When inserting a new row the null keyword can be included in the values list for any null column. True or False? True (*) False 5. When inserting rows into a table all columns must be given values. True or False? True False (*) 6. Is it possible to insert more than one row at a time using an INSERT statement with a VALUES clause? No, you can only create one row at a time when using the VALUES clause. (*) Yes, you can just list as many rows as you want, just remember to separate the rows with commas. No, there is no such thing as INSERT ... VALUES. 7. Insert statements can be combined with subqueries to create more than one row per statement. True or False? True (*) False 8. If the employees table have 7 rows how many rows are inserted into the copy_emps table with the following statement: INSERT INTO copy_emps (employee_id, first_name, last_name, salary, department_id) SELECT employee_id, first_name, last_name, salary, department_id FROM employees No rows, as you cannot use subqueries in an insert statement. 7 rows, as there is no WHERE-clause on the subquery. (*) No rows, as the SELECT statement is invalid. 10 rows will be created. 9. What is the quickest way to use today's date when you are creating a new row? Simply write today's date in the format of 'dd-mon-rr'. Simply use the keyword DATE in the insert statement. Use the SYSDATE function. (*) Use the TODAYS_DATE function. Test: Quiz: Updating Column Values and Deleting Rows 1. To change an existing row in a table, you can use the UPDATE or INSERT statements. True or False? True False (*) 2. Which of the following statements best describes what will happen to the student table in this SQL statement? UPDATE students SET lunch_number = (SELECT lunch_number FROM student WHERE student_id = 17) WHERE student_id = 19; The statement updates the student_table by replacing student id 19's lunch number with student id 17's lunch number. (*) Inserts a new row into the students table. Does nothing, the as you cannot use subqueries in update statements. Deletes student 17's lunch_number and inserts a new value from student 19. 3. Using your knowledge of the employees table, what would be the result of the following statement: DELETE FROM employees; Nothing, no data will be changed. All rows in the employees table will be deleted if there are no constraints on the table. (*) The first row in the employees table will be deleted. Deletes employee number 100. 4. Is the following statement valid, i.e. is it allowed to update rows in one table, based on a subquery from another table? UPDATE copy_emp SET department_id = (SELECT department_id FROM employees WHERE employee_id = 100) WHERE job_id = (SELECT job_id FROM employees WHERE employee_id = 200); Yes, this is a perfectly valid statement. (*) The statement will fail, because the subqueries are returning data from different rows No, this will not work No, this statement will return an error. 5. Assuming there are no Foreign Keys on the EMPLOYEES table, if the following subquery returns one row, how many rows will be deleted from the EMPLOYEES table? DELETE FROM employees WHERE department_id = (SELECT department_id FROM departments WHERE department_name LIKE '%Public%'); No rows will be deleted. One row will be deleted, as the subquery only returns one row. All the rows in the EMPLOYEES table with department_ids matching the department_id returned by the subquery. (*) All rows in the EMPLOYEES table will be deleted, regardless of their department_id. 6. How many rows will be deleted from the employees table with the following statement? DELETE FROM employees WHERE last_name = 'king'; All the rows in the employees table will be deleted. No rows will be deleted, as no employees match the WHERE-clause. (*) One will be deleted, as there exists one employee called King. All rows with last_name = 'King' will be deleted. 7. If the subquery returns one row, how many rows will be deleted from the employees table? DELETE FROM employees WHERE department_id = (SELECT department_id FROM departments WHERE department_name LIKE '%Public%'); No rows will be deleted. One row will be deleted, as the subquery only returns one row. All rows in the employees table which work in the given department will be deleted. (*) All rows in the employees table will be deleted, no matter their department_id. 8. If you are performing an UPDATE statement with a subquery, it MUST be a correlated subquery? (True or False) True False (*) 9. DELETE statements can use correlated subqueries? (True or False) True (*) False Test: Quiz: Default Values, Merge, and Multi-Table Inserts 1. Which statement below will not insert a row of data onto a table? INSERT INTO student_table (id, lname, fname, lunch_num) VALUES (143354, 'Roberts', 'Cameron', 6543); INSERT INTO student_table VALUES (143354, 'Roberts', 'Cameron', 6543); INSERT INTO student_table (id, lname, fname, lunch_num) VALUES (143352, 'Roberts', 'Cameron', DEFAULT); INSERT INTO (id, lname, fname, lunch_num) VALUES (143354, 'Roberts', 'Cameron', 6543); (*) 2. The MERGE function combines the: CREATE and UPDATE commands INSERT and UPDATE commands (*) ALTER and UPDATE commands all of the above 3. In developing the Employees table, you create a column called hire_date. You assign the hire_date column a DATE datatype with a DEFAULT value of 0 (zero). A user can come back later and enter the hire_date. This is __________. A great idea. When a new employee record is entered, if no hire_date is specified, the 0 (zero) will be automatically specified. A great idea. When new employee records are entered, they can be added faster by allowing the 0's (zeroes) to be automatically specified. Both a and b are . A bad idea. The default value must match the DATE datatype of the column. (*) 4. If a default value was set for a null column, Oracle sets the column to the default value. However, if no default value was set when the column was created, Oracle inserts an empty space. True or False? True False (*) 5. The MERGE statement can be used to update rows in one table based on values in another table and if the update fails, then the rows will automatically be inserted instead. True or False? True (*) False 6. The DEFAULT keyword can be used in the following statements: INSERT and UPDATE (*) INSERT and DELETE DELETE and UPDATE All of the above 7. A multi-table insert statement must have a subquery at the end of the statement? (True or False) True (*) False 8. A multi-table insert statement can insert into more than one table? (True or False) True (*) False Test: Quiz: Creating Tables Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. I have a table named School_Friends in my schema. You want to build a table in your schema named School_Friends. This is ______________, because ____________________________________. Mark for Review possible; my schema is separate from yours, and it is okay for us to have like-named tables in our separate schemas. (*) possible; our data will merge into one table, and we can more easily access our mutual friends information. impossible; no matter what, there can never be two tables with the same name, even if they are in separate schemas. impossible; School_Friends is a reserved term in SQL. 2. DCL, which is the acronym for Data Control Language, allows: for Review Mark the ALTER command to be used. a Database Administrator the ability to grant privileges to users. (*) the TRUNCATE command to be used. the CONTROL TRANSACTION statement can be used. 3. It is possible to create a table by using the CREATE TABLE command in conjunction with a subquery. True or False? Mark for Review True (*) False 4. CREATE TABLE bioclass (hire_date DATE DEFAULT SYSDATE, first_name varchar2(15), last_name varchar2(15)); The above CREATE TABLE statement is acceptable, and will create a Table named bioclass that contains a hire_date, first_name and last_name column. True or False? Mark for Review True (*) False 5. When creating a new table, which of the following naming rules apply: (Choose three) Mark for Review (Choose all correct answers) Must begin with a letter (*) Can have the same name as another object owned by the same user Must contain ONLY A - Z, a - z, 0 - 9, _ (underscore), $, and # (*) Must be an Oracle reserved word Must be between 1 and 30 characters long (*) 6. CREATE TABLE student_table (id NUMBER(6), lname VARCHAR(20), fname VARCHAR(20), lunch_num NUMBER(4)); Which of the following statements best describes the above SQL statement: Mark for Review creates a table named student_table with four columns: lname, fname, lunch, num creates a table named student with four columns: id, lname, fname, lunch_num creates a table named student_table with four columns: id, lname, fname, lunch_num (*) creates a table named student_table with four columns: lname, fname, lunch, num 7. Given this employee table: (employee_id NUMBER(10) NOT NULL, first_name VARCHAR2(25) NOT NULL, last_name VARCHAR2(30) NOT NULL, hire_date DATE DEFAULT sysdate) What will be the result in the hire_date column following this insert statement: INSERT INTO employees VALUES (10, 'Natacha', 'Hansen', DEFAULT); Mark for Review Statement will fail, as you must list the columns into which you are inserting. Statement will work and the hire_date column will have the value of the date when the statement was run. (*) The character string SYSDATE. The column for hire_date will be null. 8. Examine this CREATE TABLE statement: CREATE TABLE emp_load (employee_number CHAR(5), employee_dob CHAR(20), employee_last_name CHAR(20), employee_first_name CHAR(15), employee_middle_name CHAR(15), employee_hire_date DATE) ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY def_dir1 ACCESS PARAMETERS (RECORDS DELIMITED BY NEWLINE FIELDS (employee_number CHAR(2), employee_dob CHAR(20), employee_last_name CHAR(18), employee_first_name CHAR(11), employee_middle_name CHAR(11), employee_hire_date CHAR(10) date_format DATE mask "mm/dd/yyyy“)) LOCATION ('info.dat')); What kind of table is created here? Mark for Review An external table with the data stored in a file outside the database. (*) A View. An external table with the data stored in a file inside the database. None. This is in invalid statement. 9. Once they are created, external tables are accessed with normal SQL statements? (True or False) Mark for Review True (*) False Test: Quiz: Using Data Types Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. INTERVAL DAY TO SECOND stores a period of time in terms of days, hours, minutes, and seconds. True or False? Mark for Review True (*) False 2. To store large amounts of text you should simply create a series of VARCHAR2 columns in a table. True or False? Mark for Review True False (*) 3. The BLOB datatype can hold a maximum of 128 Terabytes of data. True or False? Mark for Review True (*) False 4. Which of the following are valid Oracle datatypes? Review DATE, BLOB, LOB, VARCHAR2 DATE, TIMESTAMP WITH LOCAL TIMEZONE, BLOB (*) TIMESTAMP, LOB, VARCHAR2, NUMBER Mark for SYSDATE, TIMESTAMP, DATE, LOCAL TIMEZONE Test: Quiz: Modifying a Table Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct column: 1. When you use ALTER TABLE to add a column, the new Mark for Review Becomes the first column in the table Becomes the last column in the table (*) Can be placed by adding a GROUP BY clause Will not be created because you cannot add a column after the table is created 2. To completely get rid of a table, its contents, its structure, AND release the storage space the keyword is: Mark for Review DROP (*) DELETE TRUNCATE KILL 3. Comments can be added to a table by using the COMMENT ON TABLE statement. The comments being added are enclosed in: Mark for Review Double quotes " " Single quotes ' ' (*) Parentheses ( ) Brackets { } 4. A column?s data type can always be changed from NUMBER to VARCHAR2 but not from VARCHAR2 to NUMBER, provided the table is empty. True or False? Mark for Review True False (*) 5. You can use DROP COLUMN to drop all columns in a table, leaving a table structure with no columns. True or False? Mark for Review True False (*) 6. After issuing a SET UNUSED command on a column, another column with the same name can be added using an ALTER TABLE statement. True or False? Mark for Review True (*) 7. False When should you use the SET UNUSED command? Mark for Review Never, there is no SET UNUSED command You should use it if you think the column may be needed again later You should use it when the system is being heavily used (*) You should only use this command if you want the column to still be visible when you DESCRIBE the table 8. The following code creates a table named student_table with four columns: id, lname, fname, lunch_num CREATE TABLE student_table (id NUMBER(6), lname VARCHAR(20), fname VARCHAR(20), lunch_num NUMBER(4)); The lunch_num column in the above table has been marked as UNUSED. Which of the following is the best statement you can use if you wish to remove the UNUSED column from the student_table? Mark for Review DROP column ALTER TABLE DELETE UNUSED COLUMNS ALTER TABLE DROP UNUSED COLUMNS (*) ALTER TABLE DELETE ALL COLUMNS 9. You can use the ALTER TABLE statement to: Mark for Review Add a new column Modify an existing column Drop a column All of the above (*) 10. Which of the following will correctly change the name of the LOCATIONS table to NEW_LOCATIONS? Mark for Review ALTER TABLE LOCATIONS RENAME NEW_LOCATIONS MODIFY TABLE LOCATIONS RENAME NEW_LOCATIONS RENAME LOCATIONS TO NEW_LOCATIONS (*) None of the above; you cannot rename a table, you can only CREATE, ALTER and DROP a table. 11. The data type of a column can never be changed once it has been created. True or False? Mark for Review True False (*) 12. ALTER TABLE table_name RENAME can be used to: Mark for Review Rename a row. Rename a column. Rename a table. (*) All of the above. 13. The FLASHBACK QUERY statement can restore data back to a point in time before the last COMMIT. True or False? Mark for Review True False (*) 14. The FLASHBACK TABLE to BEFORE DROP can restore only the table structure, but not its data back to before the table was dropped. True or False? Mark for Review True False (*) Test: Quiz: Defining Not Null and Unique Constraints Answer the question(s) on this page, and click Next to go to the next test page. Click Summary to see which questions you need to answer before submitting the test. Click Finish Test if you are ready to submit your test. 1. A unique key constraint can only be defined on a not null column. True or False? Mark for Review True False (*) 2. A table can have more than one UNIQUE key constraint. True or False? Mark for Review True (*) False 3. A column defined as NOT NULL can have a DEFAULT value of NULL. True or False? Mark for Review True False (*) 4. If the employees table has a UNIQUE constraint on the DEPARTMENT_ID column, we can only have one employee per department. True or False? Mark for Review True (*) False 5. A table must have at least one not null constraint and one unique constraint. True or False? Mark for Review True False (*) 6. Which of the following is not a valid Oracle constraint type? Mark for Review UNIQUE KEY NOT NULL EXTERNAL KEY (*) PRIMARY KEY Test: Quiz: Creating Views Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. Views contain no data of their own. True or False? Mark for Review True (*) 2. False What is one advantage of using views? Mark for Review To provide data dependence To be able to store the same data in more than one place To provide restricted data access (*) 3. Any select statement can be stored in the database as a view. True or False Mark for Review True (*) False 4. Given the following CREATE VIEW statement, what data will be returned? CREATE OR REPLACE VIEW emp_dept AS SELECT SUBSTR(e.first_name,1,1) ||' '||e.last_name emp_name, e.salary, e.hire_date, d.department_name FROM employees e, departments d WHERE e.department_id = d.department_id AND d.department_id >=50; Mark for Review First character from employee first_name concatenated to the last_name, the salary, the hire_date and department_id of all employees working in department number 50 or higher. First character from employee first_name concatenated to the last_name, the salary, the hire_date and department_id of all employees working in department number 50. First character from employee first_name concatenated to the last_name, the salary, the hire_date and department_name of all employees working in department number 50. First character from employee first_name concatenated to the last_name, the salary, the hire_date and department_name of all employees working in department number 50 or higher. (*) 5. A view can contain group functions. True or False? Review Mark for True (*) False 6. A view can contain a select statement with a subquery. True or False? Mark for Review True (*) False Test: Quiz: Primary Key, Foreign Key, and Check Constraints Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct is: 1. The main reason that constraints are added to a table Mark for Review Constraints add a level of complexity Constraints ensure data integrity (*) Constraints gives programmers job security None of the Above 2. A Primary Key that is made up of more than one column is called a: Mark for Review Multiple Primary Key Composite Primary Key (*) Double Key Primary Multi-Key None of the Above 3. Foreign Key Constraints are also known as: Mark for Review Parental Key Constraints Child Key Constraints Referential Integrity Constraints (*) Multi-Table Constraints 4. The table that contains the Primary Key in a Foreign Key Constraint is known as: Mark for Review Child Table Parent Table (*) Detail Table Mother and Father Table 5. To automatically delete rows in a child table when a parent record is deleted use: Mark for Review ON DELETE SET NULL ON DELETE ORPHAN ON DELETE CASCADE (*) None of the Above 6. The number of check constraints that can be defined on a column is: Mark for Review 10 5 100 There is no limit (*) 7. An example of adding a check constraint to limit the salary that an employee can earn is: Mark for Review ALTER TABLE employees ADD CONSTRAINT emp_salary_ck SALARY < 100000 ALTER TABLE employees CONSTRAINT emp_salary_ck CHECK(salary < 100000) MODIFY TABLE employees ADD CONSTRAINT emp_salary_ck CHECK(salary < 100000 ALTER TABLE employees ADD CONSTRAINT emp_salary_ck CHECK (salary < 100000) (*) 8. If a Primary Key is made up of more than one column, one of the columns can be null. True or False? Mark for Review True False (*) 9. The employees table contains a foreign key column department_id that references the id column in the departments table. Which of the following constraint modifiers will NOT allow the deletion of id values in the department table? Mark for Review ON DELETE CASCADE ON DELETE SET NULL Neither A nor B (*) Both A and B 10. Which of the following pieces of code will NOT successfully create a foreign key in the CDS table that references the SONGS table Mark for Review CONSTRAINT d_cd_ song_id_fk FOREIGN KEY (song_id)REFERENCES d_songs(id) CONSTRAINT k_cd_songid_fk FOREIGN KEY (song_id)REFERENCES d_songs(id) song_id NUMBER(5) CONSTRAINT d_cd_ song_id_fk REFERENCES d_songs(id) None of the above (*) 11. A composite primary key may only be defined at the table level. True or False? Mark for Review True (*) False Test: Quiz: Managing Constraints Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. Once constraints have been created on a table you will have to live with them as they are unless you drop and re-create the table. True or False? Mark for Review True False (*) 2. The command to 'switch off' a constraint is: Mark for Review ALTER TABLE STOP CHECKING ALTER TABLE STOP CONSTRAINTS ALTER TABLE DISABLE CONSTRAINT (*) ALTER TABLE PAUSE CONSTRAINT 3. All of a user's constraints can be viewed in the Oracle Data Dictionary view called: Mark for Review USER_TABLES USER_CONSTRAINTS (*) CONSTRAINTS TABLE_CONSTRAINTS 4. You can drop a column in a table with a simple ALTER TABLE DROP COLUMN statement, even if the column is referenced in a constraint. True or False? Mark for Review True False (*) 5. What mechamisn does Oracle use in the background to enforce uniqueness in Primary and Unique key constraints? Mark for Review Ordered Lists Internal Pointers Nothing extra is created when Primary Keys and Unique Keys are created Unique indexes are created in the background by Oracle when Primary and Unique constraints are created or enabled (*) Test: Quiz: Creating Views Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. Views contain no data of their own. True or False? Mark for Review True (*) False 2. What is one advantage of using views? Mark for Review To provide data dependence To be able to store the same data in more than one place To provide restricted data access (*) 3. Any select statement can be stored in the database as a view. True or False Mark for Review True (*) False 4. Given the following CREATE VIEW statement, what data will be returned? CREATE OR REPLACE VIEW emp_dept AS SELECT SUBSTR(e.first_name,1,1) ||' '||e.last_name emp_name, e.salary, e.hire_date, d.department_name FROM employees e, departments d WHERE e.department_id = d.department_id AND d.department_id >=50; Mark for Review First character from employee first_name concatenated to the last_name, the salary, the hire_date and department_id of all employees working in department number 50 or higher. First character from employee first_name concatenated to the last_name, the salary, the hire_date and department_id of all employees working in department number 50. First character from employee first_name concatenated to the last_name, the salary, the hire_date and department_name of all employees working in department number 50. First character from employee first_name concatenated to the last_name, the salary, the hire_date and department_name of all employees working in department number 50 or higher. (*) 5. A view can contain group functions. True or False? Review Mark for True (*) False 6. A view can contain a select statement with a subquery. True or False? Mark for Review True (*) False Test: Quiz: DML Operations and Views Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. Which of the following DML operations is not allowed when using a Simple View created with read only? Mark for Review INSERT UPDATE DELETE All of the above (*) 2. Examine the view below and choose the operation that CANNOT be performed on it. CREATE VIEW dj_view (last_name, number_events) AS SELECT c.last_name, COUNT(e.name) FROM d_clients c, d_events e WHERE c.client_number = e.client_number GROUP BY c.last_name Mark for Review CREATE OR REPLACE dj_view (last_name, number_events) AS SELECT c.last_name, COUNT(e.name) FROM d_clients c, d_events e WHERE c.client_number = e.client_number GROUP BY c.last_name; INSERT INTO dj_view VALUES ('Turner', 8); (*) SELECT last_name, number_events FROM dj_view; DROP VIEW dj_view; 3. If a database administrator wants to ensure that changes performed through a view do not violate existing constraints, which clause should he/she include when creating the view? Mark for Review WITH READ ONLY FORCE WITH CONSTRAINT CHECK WITH CHECK OPTION (*) 4. Given the following view what operations would be allowed on the emp_dept view: CREATE OR REPLACE VIEW emp_dept AS SELECT SUBSTR(e.first_name,1,1) ||' '||e.last_name emp_name, e.salary, e.hire_date, d.department_name FROM employees e, departments d WHERE e.department_id = d.department_id AND d.department_id >=50; Mark for Review SELECT, DELETE SELECT, UPDATE of all columns SELECT, UPDATE of some columns, DELETE (*) SELECT, INSERT 5. Using the pseudocolumn ROWNUM in a view has no implications on the ability to do DML's through the view. True or False? Mark for Review True 6. False (*) There is only one kind view? True or False? Mark for Review True False Test: Quiz: Review your indicates a (*) Managing Views answers, feedback, and question scores below. An asterisk (*) correct 1. A Top-N Analysis is capable of ranking a top or bottom set of results. True or False? Mark for Review True (*) False 2. Which of these is not a valid type of View? INLINE Mark for Review ONLINE (*) SIMPLE 3. COMPLEX Which of these Keywords is typically used with a Top-N Analysis? Mark for Review Rowid Rownum (*) Sequence Number 4. Which of the following is true about ROWNUM? Mark for Review It is the number assigned to each row returned from a query after they are ordered. It is the number assigned to each row returned from a query as they are read from disk. (*) It is the number of rows in a table. 5. None of the above How do you remove a view? Mark for Review DELETE VIEW view_name REMOVE VIEW view_name DROP VIEW view_name (*) You cannot remove a view 6. When you drop a table referenced by a view, the view is automatically dropped as well. True or False? Mark for Review True False (*) 7. When you drop a view, the data it contains is also deleted. True or False? Mark for Review True False (*) Sectiunea 11 Test: Quiz: In Class Interview Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. When you know you are good at answering questions in interviews, there is no need to worry about your appearance or "first impressions." True or False? Mark for Review True False (*) 2. Which answer would be the best in response to an interviewer's question: "Do you have any children"? Mark for Review Yes, I have 5 children and I am a single parent. I am not required to answer that question. I know your concern about my abilities to be able to be on the job everyday, but I assure you, I took this into account when I applied for the job. (*) It's none of your business. 3. Since you are not planning to get a job until after completing college/university, you don't need to learn interview skills at this point? True or False? Mark for Review True False (*) 4. When applying for a job at a discount department store, wearing casual clothing would demonstrate an applicant's appropriateness for a position as a check out clerk. True or False? Mark for Review True False (*) 5. In a behavioral interview, candidates are asked about: Review Mark for Accomplishments, college, etc. Past Performance. (*) Personality traits. How much money they would like to earn. 6. In a traditional interview, candidates are asked about: Mark for Review Accomplishments, college, etc. (*) Job history. Personality traits. How much money they would like to earn. Test: Quiz: Sequences Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. for Review True (*) False A sequence is a database object. True or False? Mark 2. NEXTVAL and CURRVAL are known as column aliases. True or False? Mark for Review True False (*) 3. Which keyword is used to modify a sequence? Mark for Review Change. Update. Alter. (*) Create. 4. Which keyword is used to remove a sequence? Mark for Review Drop. (*) Delete. Remove. Revoke. 5. Which is the correct syntax for specifying a maximum value in a sequence? Mark for Review Maxval. Max_value. Maximumvalue. Maxvalue. (*) 6. CURRVAL is a pseudocolumn used to extract successive sequence numbers from a specified sequence. True or False? Mark for Review True False (*) 7. CURRVAL is a pseudocolumn used to refer to a sequence number that the current user has just generated by referencing NEXTVAL. True or False? Mark for Review True (*) False 8. When you alter a sequence, a new increased MAXVALUE can be entered without changing the existing number order. True or False? Mark for Review True (*) False 9. A sequence is a window through which data can be queried or changed. True or False? Mark for Review True False (*) 10. Why do gaps in sequences occur? Mark for Review A rollback is executed. The system crashes. The sequence is used in another table. All of the above. (*) 11. Examine the code for creating this sequence: CREATE SEQUENCE track_id_seq INCREMENT BY 10 START WITH 1000 MAXVALUE 10000 What are the first three values that would be generated by the sequence? Mark for Review 100010011002. 1000, 1010, 1020. (*) 1100, 1200, 1300. 0, 1, 2. 12. In order to be able to generate primary key values that are not likely to contain gaps, which phrase should be included in the sequence creation statement? Mark for Review NOCACHE. (*) CACHE. MAXVALUE. Test: Quiz: Indexes and Synonyms Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. In SQL what is a synonym? Mark for Review A table with the same number of columns as another table. A table with the same name as another view. A different name for a table, view or other database object. (*) A table with that must be qualified with a username. 2. You must use a synonym to access another users table. True or False? Mark for Review True False (*) 3. Which of the following SQL statments shows a correct syntax example of creating a synonym accessible to all users of a database? Mark for Review CREATE SYNONYM emp FOR EMPLOYEES CREATE PUBLIC SYNONYM emp FOR EMPLOYEES (*) CREATE UNRESTRICTED SYNONYM emp FOR EMPLOYEES CREATE SHARED SYNONYM emp FOR EMPLOYEES 4. All tables must have indexes on them otherwise they cannot be queried. True or False? Mark for Review True False (*) 5. key? What kind of INDEX is created by Oracle when you create a primary Mark for Review UNIQUE INDEX. (*) NONUNIQUE INDEX. INDEX. Oracle cannot create indexes automatically. 6. It is possible to have an indexed column in a table where a value in the table column does not exist in the index. True or False? Mark for Review True False (*) 7. use? Which of the following statements best describes indexes and their Mark for Review They are just random copies of data in no particular order. They contain the column value and pointers to the data in the table, but the data is sorted. (*) They contain all the rows and columns from the table. None of the above. 8. Indexes can be used to speed up queries. True or False? Mark for Review True (*) False Sectiunea 12 Test: Quiz: Controlling User Access Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. Which of the following is not a database object? Mark for Review View Subquery (*) Table Sequence 2. Which of these is not a System Privilege granted by the DBA? for Review Mark Create Sequence Create Index (*) Create Procedure Create Session 3. Sequence? Which Object Privilege apart from Alter can be granted to a Mark for Review SELECT (*) UPDATE INSERT DELETE 4. A Schema is a collection of Objects such as Tables, Views and Sequences. True or False? Mark for Review True (*) False 5. By Controlling User Access with Oracle Database Security you can give access to specific Objects in the Database. True or False? Mark for Review True (*) False 6. The following table shows some of the output from one of the data dictionary views. Which view is being queried? USERNAME PRIVILEGE USCA_ORACLE_SQL01_S08 USCA_ORACLE_SQL01_S08 USCA_ORACLE_SQL01_S08 USCA_ORACLE_SQL01_S08 USCA_ORACLE_SQL01_S08 USCA_ORACLE_SQL01_S08 ADMIN_OPTION CREATE VIEW NO CREATE TABLE NO CREATE SYNONYM NO CREATE TRIGGER NO CREATE SEQUENCE NO CREATE DATABASE NO Mark for Review user_sys_privs (lists system privileges granted to the user) (*) user_tab_privs_recd (lists object privileges granted to the user) role_tab_privs (lists table privileges granted to roles) role_sys_privs (lists system privileges granted to roles) 7. Object privileges are: Mark for Review Required to gain access to the database. Required to manipulate the content of objects in the database. (*) Named groups of related privileges given to a user. A collection of objects, such as tables, views, and sequences. 8. A schema is: Mark for Review Required to gain access to the database. Required to manipulate the content of objects in the database. A named group of related privileges given to a user. A collection of objects, such as tables, views, and sequences. (*) 9. System privileges are: Mark for Review Required to gain access to the database. (*) Required to manipulate the content of objects in the database. Named groups of related privileges given to a user. A collection of objects, such as tables, views, and sequences. 10. What system privilege must be held in order to login to an Oracle database? Mark for Review CREATE LOGIN CREATE SESSION (*) CREATE LOGON No special privilege is needed, if your username exists in the database, you can login. 11. Which of the following Object Privileges can be granted on an individual column on a table? (Choose two) Mark for Review (Choose all correct answers) Update (*) References (*) Insert Delete Test: Quiz: Creating and Revoking Object Privileges Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. What Oracle feature simplifies the process of granting and revoking privileges? Mark for Review Role (*) Object Data dictionary Schema 2. Scott King owns a table called employees. He issues the following statement: GRANT select ON employees TO PUBLIC; Allison Plumb has been granted CREATE SESSION by the DBA. She logs into the database and issues the following statement: GRANT select ON scott_king.employees TO jennifer_cho; True or False: Allison's statement will fail. Mark for Review True (*) False 3. User1 owns a table and grants select on it WITH GRANT OPTION to User2. User2 then grants select on the same table to User3. If User1 revokes select privileges from User2, will User3 be able to access the table? Mark for Review Yes No (*) 4. Which of the following statements about granting object privileges is false? Mark for Review To grant privileges on an object, the object must be in your own schema, or you must have been granted the object privileges WITH GRANT OPTION. An object owner can grant any object privilege on the object to any other user or role of the database. The owner of an object automatically acquires all object privileges on that object. Object privileges can only be granted through roles. (*) 5. If you are granted privileges to your friend's object, by default you may also grant access to this same object to other users. True or False? Mark for Review True False (*) 6. Roles are: Mark for Review Required to gain access to the database. Required to manipulate the content of objects in the database. Named groups of related privileges given to a user or another role. (*) A collection of objects, such as tables, views, and sequences. 7. A role can be granted to another role. True or False? Review Mark for True (*) False 8. To take away a privilege from a user you use which command? for Review Mark DELETE REMOVE REVOKE (*) ALTER 9. When a user is logged into one database, they are restricted to working with objects found in that database. True or False? Mark for Review True False (*) 10. Database Links are always accessible to all users of a database? True or False? Mark for Review True False (*) 11. Which of the following statements is true? Mark for Review Database Links allow users to work on remote database objects without having to log into the other database. (*) Database Links are pointers to another schema in the same database. Database Links are never used in the real world. Database Links can be created by any user of a database. You do not need any special privileges to create them. Test: Quiz: Regular Expressions Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct 1. REGULAR EXPRESSIONS does exactly the same as LIKE. No more and no less? (True or False) Mark for Review True False (*) 2. REGULAR EXPRESSIONS can be used on CHAR, CLOB and VARCHAR2 datatypes? (True or False) Mark for Review True (*) False 3. Select the correct REGULAR EXPRESSION functions: (Choose two) Mark for Review (Choose all correct answers) REGEXP_LIKE, REGEXP_NEAR REGEXP_LIKE, REGEXP_REPLACE (*) REGEXP_REPLACE, REGEXP_REFORM REGEXP_INSTR, REGEXP_SUBSTR (*) 4. REGULAR EXPRESSIONS can be used as a part of contraint definitions? (True or False) Mark for Review True (*) False Sectiunea 14 Test: Quiz: Database Transactions Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 1. You need not worry about controlling your transactions. Oracle does it all for you. True or False? Mark for Review (1) Points True False (*) 2. As soon as UserA has entered data into a table UserB has privileges to see, UserB can see that data. True or False? Mark for Review (1) Points True False (*) 3. When you log out of Oracle, your data changes are automatically rolled back. True or False? Mark for Review (1) Points True False (*) 4. If Oracle crashes your changes are automatically rolled back. True or False? Mark for Review (1) Points True (*) False 5. Examine the following statements: INSERT INTO emps SELECT * FROM employees; -- 107 rows inserted. SAVEPOINT Ins_Done; DELETE employees; -- 107 rows deleted SAVEPOINT Del_Done; UPDATE emps SET last_name = 'Smith'; How would you undo the last Update only? Mark for Review (1) Points Rollback update; Rollback to savepoint Del_Done; (*) There is nothing you can do. Commit until Del_Done; 6. Examine the following Statement: INSERT INTO emps SELECT * FROM employees; -- 107 rows inserted. SAVEPOINT Ins_Done; CREATE INDEX emp_lname_idx ON employees(last_name); UPDATE emps SET last_name = 'Smith'; What happens if you issue a Rollback statement? Mark for Review (1) Points The update of last_name is undone, but the insert was committed by the CREATE INDEX statement. (*) Both the UPDATE and the INSERT will be rolled back. The INSERT is undone but the UPDATE is committed Nothing happens. 7. COMMIT saves all outstanding data changes? True or False? for Review (1) Points True (*) False Mark