You are on page 1of 25

PETS PET_NAM E Spike Mia Patches Cosmo Spooky SELECT * from PETS What do you add in order to limit

the above query's results to only cats? WHERE PET_TYPE = 'Cat' WHERE PET_TYPE NOT = 'Dog' WHERE PET_TYPE LIKE 'Ca*' WHERE VARIETY = 'Calico' WHERE WEIGHT < 13 OWNER_NAM E CT Simpson Arnold Robbins Ronnie Ames Timmy Turner Arnie Marx PET_TYP E Dog Dog Cat Fish Cat VARIETY Yorkie BIRTH_DAT E 2004-12-10 WEIGH T 8 15 12 .3 10

Chihuahu 2006-09-15 a Calico Beta Mixed Breed 1998-04-12 null 2003-10-31

restaurants rest_id name 001 002 003 004 Bert's Beans Java Shakes Cattle Baron phone 817-555-1212 202-555-2188 817-555-9989

menu_items rest_id item_id menu_item 001 001 002 002 002 003 004 004 004 100 200 300 310 120 500 700 710 720 Bean Soup Three Bean Salad Ham Dinner Pork Chop Coffee Cake Ribeye KC Strip Steak Sandwich price 2.00 2.50 7.00 5.00 4.00 21.00 24.00 11.00

Herb's Ham Heaven 202-555-1779

Ham and Bean Soup 2.00

SELECT menu_item, price FROM menu_items WHERE rest_id IN (SELECT rest_id FROM restaurants WHERE SUBSTR(phone,1,3) = '817') How many rows does the above query return? 1 2 3 4

Considering the above PETS table definition, what database object do you use to enforce a rule that the only types of pets allowed are cats and dogs? A trigger to check values being inserted A User Defined Function defined on TYPE An index on the TYPE field A column constraint defined on TYPE A column constraint defined on OWNER_NAME

The above diagram describes three related tables. Which statement do you use to list all of the employees who are now or have been assigned to JOB_ID 1234? SELECT EMP_LAST_NAME FROM Employee E INNER JOIN (Job_Assignment A LEFT JOIN Job_Assignment P ON A.JOB_ID = P.JOB_ID HAVING A.JOB_ID = '1234' or P.JOB_ID = '1234') ON E.EMP_ID = A.EMP_ID SELECT EMP_LAST_NAME FROM Employee E LEFT JOIN (Job_Assignment A LEFT JOIN Job_Assignment P on A.JOB_ID = P.JOB_ID) on E.EMP_ID = A.EMP_ID

WHERE A.JOB_ID = '1234' or P.JOB_ID = '1234' SELECT EMP_LAST_NAME FROM Employee E LEFT OUTER JOIN Job_Assignments A ON E.EMP_ID = A.EMP_ID WHERE A.JOB_ID = '1234' or PRIOR_JOB_ID = '1234' SELECT EMP_LAST_NAME FROM Employee E INNER JOIN Job_Assignment A ON E.EMP_ID = A.EMP_ID WHERE A.JOB_ID = '1234' or PRIOR_JOB_ID = '1234' SELECT EMP_LAST_NAME FROM Employee E INNER JOIN (Job_Assignment A LEFT JOIN Jobs J on A.JOB_ID = J.JOB_ID) on E.EMP_ID = A.EMP_ID WHERE A.JOB_ID = '1234' or J.JOB_ID = '1234'

After the above cursor is opened and a row fetched, how do you update the selected employee's salary by 5 percent? UPDATE EMPLOYEE SET EMP_SALARY = EMP_SALARY * 1.05 WHERE EMP_ID = :emp-id SET EMP_SALARY = EMP_SALARY * 1.05 WHERE CURRENT OF EMP_CURSOR UPDATE EMP_CURSOR SET EMP_SALARY = EMP_SALARY * 1.05 No additional code is needed. UPDATE EMPLOYEE SET EMP_SALARY = EMP_SALARY * 1.05 WHERE CURRENT OF EMP_CURSOR

Referring to the above definition of the EMPLOYEE table, which WHERE clause do you use to return all records from EMPLOYEE with last names starting with the letters "AR"? WHERE EMP_LAST_NAME = "AR*" WHERE EMP_LAST_NAME LIKE 'AR' WHERE LEFT(EMP_LAST_NAME) = 'AR' WHERE EMP_LAST_NAME LIKE 'AR%' WHERE EMP_LAST_NAME LIKE 'A%'

Which WHERE clause do you need to add to the above query so that only employees with NULL term dates are returned? WHERE ISNULL(TERM_DT) = "TRUE" WHERE TERM_DT = "" WHERE TERM_DT IS NULL WHERE NULL(TERM_DT) WHERE TERM_DT = NULL

In the above scenario, what locking change occurs when the UPDATE statement executes? The lock type changes from S (share) to X (exclusive). The lock type changes from X (exclusive) to U (intent update). The lock type changes from U (intent update) to X (exclusive). The lock type changes from I (intent share) to U (intent update). The lock type changes from S (share) to U (intent update).

In the above database, when an Owner's name needs to be changed, what process do you follow? Delete the OWNER record with the old name, insert a new OWNER record with the new name, and update the PETS records with

the new name. Update the PETS records with the new name, then update the OWNERS table with the new name. Insert a new OWNER record with the new name, update the PETS records with the new name, and delete the original OWNER record. Insert a new OWNER record with the new name, delete the original OWNER record, and update the PETS records with the new name. Issue an UPDATE command on OWNERS setting HUMAN_NAME = 'newname' WHERE HUMAN_NAME = 'oldname'.

EVENTS event_name Boston Symphony Carrie Underwood Fall Festival Valentine Dance New Years Eve Ball Dog Show event_date event_type ticket_price 2008-07-04 Concert 2008-09-02 Concert 2008-10-29 Family 2008-02-14 Dance 2008-12-31 Dance 2009-01-12 Family 32.00 2.00 26.00 2.00 17.00 45.00 8.00

Back To School Party 2008-08-25 Church

DECLARE event_list SENSITIVE STATIC SCROLL CURSOR for SELECT event_name FROM events ORDER BY event_date; OPEN event_list; FETCH ABSOLUTE 2 into :hv_event; FETCH ABSOLUTE 3 into :hv_event; What is the value of hv_event when you execute the above sequence of DECLARE, OPEN, and both FETCH statements? NULL Back To School Party Carrie Underwood Dog Show Valentine Dance

Which one of the following nested table expressions do you add to the FROM clause in the above query to supply the average boat length for each owner's fleet?

(SELECT VESSEL_NAME, AVG(VESSEL_LENGTH) as VESSEL_AVG FROM BOATS GROUP BY VESSEL_NAME) as M (SELECT OWNER_NAME, AVG(VESSEL_LENGTH) as VESSEL_AVG FROM BOATS GROUP BY VESSEL_LENGTH) as M

(SELECT OWNER_NAME, AVG(VESSEL_LENGTH) as VESSEL_AVG FROM BOATS GROUP BY OWNER_NAME) as M (SELECT OWNER_NAME, MAX(VESSEL_LENGTH) as VESSEL_MAX FROM BOATS GROUP BY OWNER_NAME) as M (SELECT OWNER_NAME, MAX(VESSEL_LENGTH) as VESSEL_AVG FROM BOATS GROUP BY OWNER_NAME) as M

PETS PET_NAME OWNER_NAME PET_TYPE VARIETY Spike Mia Patches CT Simpson Ronnie Ames Dog Cat Yorkie Chihuahua Calico Arnold Robbins Dog BIRTH_DATE WEIGHT 2004-12-10 2006-09-15 1998-04-12 8 15 12

Cosmo Spooky

Timmy Turner Arnie Marx

Fish Cat

Beta

null

.3 10

Mixed Breed 2003-10-31

In the above PETS table, how do you return the total weight for each type of pet? SELECT PET_TYPE, COUNT(WEIGHT) FROM PETS GROUP BY PET_TYPE SELECT PET_TYPE, WEIGHT FROM PETS GROUP BY PET_TYPE SUM BY WEIGHT SELECT PET_TYPE, SUM(WEIGHT) FROM PETS GROUP BY PET_TYPE SELECT PET_TYPE, SUM(WEIGHT) FROM PETS ORDER BY PET_TYPE SELECT PET_TYPE, WEIGHT FROM PETS SUM WEIGHT BY PET_TYPE

Which predicate clause in the above query is NOT a stage 1 predicate? CUSTOMER_ID = :hv_cust_id EST_SHIP_DT < current date - 30 days ACT_SHIP_DT BETWEEN ORDER_DT and EST_SHIP_DT

CUST_PD_DT is NULL ORDER_TYPE = 'B'

PETS PET_NAME OWNER_NAME PET_TYPE VARIETY Spike Mia Patches Cosmo Spooky CT Simpson Ronnie Ames Timmy Turner Arnie Marx Dog Cat Fish Cat Yorkie Chihuahua Calico Beta Arnold Robbins Dog BIRTH_DATE WEIGHT 2004-12-10 2006-09-15 1998-04-12 null 8 15 12 .3 10

Mixed Breed 2003-10-31

SELECT COUNT(*), COUNT(DISTINCT PET_TYPE) FROM PETS What values does the above query return? 5, 5 3, 5 5, null 5, 3 3, 3

The above diagram shows the definition of three related tables. If the delete rule for these tables is ON DELETE CASCADE, what happens when you delete a record from the Jobs table? The Jobs record, all Job Assignment records for that JOB_ID, and all Employee records associated with those jobs are deleted. All records are deleted from the Jobs table. The Jobs record and all Job Assignment records for that JOB_ID are deleted. An error is returned; you are required to delete the related Job Assignment records before deleting the Jobs record. The Jobs record is deleted; no other records are affected.

employees first_name last_name salary Carl Ron Art Amy Ken Martin Spellman 60000.00 Rinkle Todd Walters Reyes Johnson 50000.00 40000.00 45500.00 60400.00 50600.00

markets location avg_salary N S NE NW SE 40000.00 30000.00 40000.00 30000.00 40000.00

SELECT last_name, first_name, salary FROM employees WHERE salary IN (SELECT avg_salary FROM markets WHERE location IN ('N', 'S')) How many rows does the above SQL statement return? 0 1 2 3 4

PETS PET_NAME OWNER_NAME PET_TYPE VARIETY Spike Mia Patches CT Simpson Ronnie Ames Dog Cat Yorkie Calico Arnold Robbins Dog BIRTH_DATE WEIGHT 2004-12-10 1998-04-12 8 15 12

Chihuahua 2006-09-15

Referring to the above table, how do you change Mia's record to show that she now weighs 18 pounds? UPDATE Mia SET WEIGHT = 18 FROM PETS UPDATE PETS.WEIGHT(Mia) = 18 SET PETS.WEIGHT = 18 WHERE PET_NAME = 'Mia' MODIFY PETS SET WEIGHT = 18 WHERE PET_NAME = 'Mia' UPDATE PETS SET WEIGHT = 18 WHERE PET_NAME = 'Mia'

In the above Job Assignment and Employee tables, what is the effect of the Foreign Key relationship between the EMP_ID columns? Every Employee record must have an EMP_ID that exists in Job Assignment. When adding records to Job Assignment, records are automatically created in Employee. Every Job Assignment record must have an EMP_ID that exists in Employee. When adding records to Employee, records are automatically created in Job Assignment. Matching records must be inserted to the two tables within the same INSERT statement.

Considering the PETS table definition listed above, what causes the provided INSERT statement to fail? The value '18' should not be in quotes. NULL is not allowed in an INSERT statement. Double quotes are required for CHAR data. The value list does not include an entry for 'BIRTH_DATE'. Spaces are only allowed in VARCHAR fields. Table Name: vtable Column Name Null/Not Null Data Type a b c d not null null null not null integer char(50) integer char(100)

Referring to the table above, which one of the following SQL statements is valid? SELECT FROM vtable WHERE a = 5 SELECT a, b, AND c FROM vtable SELECT * WHERE vtable.b = "bvalue" SELECT a TO d FROM vtable WHERE c IS NULL SELECT a * c FROM vtable

After the above cursor is opened and a row is fetched, how do you delete the row? OLD_EMP.DELETE DELETE WHERE CURRENT OF OLD_EMP DELETE FROM EMPLOYEE WHERE CURRENT OF OLD_EMP DELETE FROM CURRENT OF OLD_EMP DELETE OLD_EMP

animals name family dog lion eagle mammal mammal bird

types family fish bird reptile blood_temp cold warm cold mammal warm

guppy fish guppy fish pelican bird bass SELECT name FROM animals a WHERE EXISTS (SELECT 1 FROM types t WHERE t.family = a.family AND t.family LIKE 'b%') How many rows does the above query return? 1 2 4 5 7 fish

Considering the above table, what special register value do you use in your insert or update statement to set the acct_chg_tmstp? CURRENT TIMESTAMP CURRENT DATE NOW() TIMESTAMP(now) TIMESTAMP(current date, '00.00.00')

Which one of the following FROM clauses do you add to the above query to show the percentage of each owner's fleet that is above his fleet's average gross tonnage? FROM (SELECT OWNER_NAME, AVG(VESSEL_GROSS_TONS) AS AVG_TONS FROM BOATS GROUP BY OWNER_NAME) AS A, BOATS B FROM (SELECT OWNER_NAME, COUNT(*) AS FLEET_COUNT FROM BOATS GROUP BY OWNER_NAME AS A, BOATS B FROM (SELECT OWNER_NAME, COUNT(*) AS FLEET_COUNT, AVG(VESSEL_GROSS_TONS) AS AVG_TONS FROM BOATS GROUP BY VESSEL_NAME) AS A, BOATS B FROM (SELECT VESSEL_NAME, COUNT(*) AS FLEET_COUNT, AVG(VESSEL_GROSS_TONS) AS AVG_TONS FROM BOATS GROUP BY VESSEL_NAME) AS A, BOATS B FROM (SELECT OWNER_NAME, COUNT(*) AS FLEET_COUNT, AVG(VESSEL_GROSS_TONS) AS AVG_TONS FROM BOATS GROUP BY OWNER_NAME) AS A, BOATS B

EVENTS event_name event_date event_type ticket_price

Fall Festival

2008-10-29 Family

2.00 32.00 26.00 17.00 15.00 8.00

Boston Symphony 2008-07-04 Concert Carrie Underwood 2008-09-02 Concert Valentine Dance New Year's Ball Dog Show 2008-02-14 Dance 2008-12-31 Dance 2009-01-12 Family

SELECT * FROM EVENTS WHERE event_date between '2008-09-01' and '2008-12-31' AND ticket_price <= 15.00 How many rows does the above query return? 1 2 3 4 5

Which ORDER BY do you add to the above query to sort the result by most recent hire date, then sort by last name in alphabetical order within each date? ORDER BY 1, 4 ORDER BY EMP_LAST_NAME, HIRE_DATE DESC ORDER BY HIRE_DATE, EMP_LAST_NAME ORDER BY 4, 1 ORDER BY HIRE_DATE DESC, EMP_LAST_NAME

In the above query, what WHERE clause do you add to select all the orders in the ORDERS table for customers that have orders in the ORDER_ARCHIVE table? WHERE CUSTOMER_ID IN (SELECT 1 FROM ORDER_ARCHIVE A WHERE O.CUSTOMER_ID = A.CUSTOMER_ID) WHERE EXISTS (SELECT 1 FROM ORDER_ARCHIVE A WHERE O.CUSTOMER_ID = A.CUSTOMER_ID) WHERE EXISTS CUSTOMER_ID IN (SELECT 1 FROM ORDER_ARCHIVE A WHERE O.CUSTOMER_ID = A.CUSTOMER_ID) WHERE CHECK (SELECT 1 FROM ORDER_ARCHIVE A WHERE O.CUSTOMER_ID = A.CUSTOMER_ID) WHERE ANY CUSTOMER_ID IN (SELECT 1 FROM ORDER_ARCHIVE A WHERE O.CUSTOMER_ID = A.CUSTOMER_ID)

If acct_no in the above table is defined as GENERATED ALWAYS AS IDENTITY, which one of the following statements do you use to insert a new ACCOUNTS record? INSERT INTO ACCOUNTS (acct_no, acct_type, acct_chg_tmstp) VALUES (NEXT(acct_no), 'Checking', current timestamp) INSERT INTO ACCOUNTS (acct_no, acct_type, acct_chg_tmstp) VALUES (NEXTVAL for acct_no, 'Checking', current timestamp) INSERT INTO ACCOUNTS (acct_no, acct_type, acct_chg_tmstp) VALUES (NEXT acct_no, 'Checking', current timestamp) INSERT INTO ACCOUNTS (acct_type, acct_chg_tmstp) VALUES

('Checking', current timestamp)

INSERT INTO ACCOUNTS (acct_no, acct_type, acct_chg_tmstp) VALUES (NEXT IDENTITY, 'Checking', current timestamp What type of database object do you create if you want to reduce network traffic? Trigger User-defined function Constraint View Stored procedure An update program is locking enough data to cause lock escalation, but adding COMMIT statements is not an acceptable option. How do you prevent the overhead of lock escalation in this situation? Change the order in which your program accesses the data. Add the LOCK TABLE instruction to the program. Ensure that the program uses Repeatable Read (RR) isolation. Add the SET MAXLOCKS instruction to your program. Add the SET LOCKESC= -1 instruction to your program.

Table A fname lname idnumber

Table B idnumber salary startdate Referring to the tables above, which one of the following phrases do you use to return all of the rows from table A and any corresponding rows from table B? INNER JOIN LEFT JOIN IF EXISTS CROSSREF JOIN NULL

What query do you use to determine information about the indexes defined on the table named

"your_table"? SELECT * FROM SYSIBM.TABLEINDEXES WHERE TABLENAME = 'your_table' SELECT INDEXNAME, INDEXDEF FROM SYSIBM.SYSTABLES WHERE TBNAME = 'your_table' SELECT * FROM SYSIBM.SYSINDEXES WHERE TBNAME = 'your_table' SELECT INDEX_DEF FROM your_table SELECT * FROM SYSIBM.SYSINDEXDEF WHERE TBNAME = 'your_table' CREATE PROCEDURE add_three (IN a1 INTEGER ,IN a2 INTEGER ,IN a3 INTEGER ,OUT s1 INTEGER) LANGUAGE SQL SPECIFIC add_three BEGIN SET s1 = a2+a2+a3; END Referring to the above procedure definition, which one of the following calls is valid? CALL add_three(1, 2, 3, 4) CALL add_three(1, 2, 4) CALL add_three(1, 2, 3, ?) CALL add_three(a, b, current date, ?) CALL add_three(1.2, 3, 4, ?)

Referring the the above ACCOUNTS table, which WHERE clause do you use if you want to select only the records that were changed yesterday? WHERE acct_chg_tmstp >= current timestamp - 1 day WHERE acct_chg_tmstp = current date - 1 day WHERE acct_chg_tmstp = current timestamp - 1 day WHERE DATE(acct_chg_tmstp) = current date - 1 day WHERE DATE(acct_chg_tmstp) > current date - 1 day When handling error conditions, programs may implement "retry" logic to attempt the operation again before failing. Which one of the following error conditions justifies retry logic as described above? Deadlock or timeout Row not found Duplicate key violation Value incompatible with column's data type Insufficient authorization

The above Pet Club data tables are related through the HUMAN_NAME fields. What result do you get from the above SELECT query? Each pet owner and his/her address A single record is returned for each pet owner; whichever pet was listed first in the PETS table is shown. You get no result; the statement is not valid. (CHECK) Each pet and its owner Every pet and it's address

Which one of the following do you use to place the value of today's date into the variable "program_date"? set program_date = run_date

set program_date = current date set program_date = now() set program_date = current timestamp set program_date = date(today)

Which fields do you include in an index if you want to optimize performance of the above query? CUSTOMER_ID, ORDER_DT, CUST_PD_DT CUSTOMER_ID, ORDER_DT, ACT_SHIP_DT, BILL_AMT CUSTOMER_ID, CUST_PD_DT ORDER_ID, ORDER_DT CUSTOMER_ID, ORDER_DT

PETS PET_NAME OWNER_NAME PET_TYPE VARIETY Spike Mia Patches Cosmo Spooky Pepper CT Simpson Ronnie Ames Timmy Turner Arnie Marx Arnie Marx Dog Cat Fish Cat Dog Yorkie Chihuahua Calico Beta Arnold Robbins Dog BIRTH_DATE WEIGHT 2004-12-10 null 1998-04-12 null 8 15 12 .3 10 56

Mixed Breed 2003-10-31 Great Dane 2001-01-29

SELECT PET_NAME, COALESCE(BIRTH_DATE, '9999-12-31') FROM PETS

WHERE PET_TYPE = 'DOG' What is the result of the above query? Spike 2004-12-10 Mia 9999-12-31 Spooky 2003-10-31 Pepper 2001-01-29 Spike 2004-12-10 Mia 2004-12-10 Pepper 2001-01-29 Spike 9999-12-31 Mia 9999-12-31 Pepper 9999-12-31 Spike 2004-12-10 Mia 9999-12-31 Pepper 2001-01-29 Spike 2004-12-10 Mia null Pepper 2001-01-29

What do you need to add to the above query if you want to produce a sorted list, with newest first, of how many employees were hired on each date? SUM BY EMP_HIRE_DT ORDER BY EMP_HIRE_DT DESC ORDER BY EMPLOYEE COUNT BY EMP_HIRE_DT GROUP BY EMP_HIRE_DT ORDER BY EMP_HIRE_DT DESC

COUNT BY EMPLOYEE ORDER BY EMP_HIRE_DT GROUP BY EMP_HIRE_DT

A dynamic SQL statement is executed many times with different valued variables each time. Referring to the above scenario, how do you prepare the statement to use the same access path at each execution? PREPARE using the maximum values of each variable. PREPARE using ? as a parameter marking. PREPARE using % as a parameter marking. BIND using the DYNAMIC(REUSE) option. Add the WITH UR clause to the statement.

products name price type soap 2.00 C floss 2.00 D brush 3.00 A SELECT name, COUNT(price) FROM products WHERE type BETWEEN 'A' AND 'D' Which one of the following do you use to complete the above query? GROUP BY type GROUP BY name (CHECK) GROUP BY price GROUP BY COUNT(price) GROUP BY 1 ACCOUNT acc_no acc_type amount --------- ---------- --------10 c 356.12 31 m 1387.64 25 c 12500.00 22 m 40356.15 61 c 12500.00 SELECT acc_type, amount, 'small' as category1 FROM ACCOUNT WHERE amount <= 10000 ORDER BY acc_type, amount

UNION SELECT acc_type, amount, 'big' as category2 FROM ACCOUNT WHERE amount >= 10000 ORDER BY amount,acc_type Referring to the above table, how many rows does the query return? None, the columns in the SELECTs do not match, which causes an error. None, WHERE cannot intersect. None, ORDER BY in the first SELECT causes an error. Three rows Five rows (CHECK)

Table Definition Referring to the above ACCOUNTS table, how do you convert the acct_chg_dt and acct_chg_tm fields into a single timestamp value? Choice 1 TIMESTAMP(acct_chg_dt, acct_chg_tm, '000000') Choice 2 TIMESTAMP(acct_chg_dt + acct_chg_tm) Choice 3 TIMESTAMP(acct_chg_dt, acct_chg_tm) Choice 4 CAST(acct_chg_dt, acct_chg_tm) as TIMESTAMP Choice 5 CAST(acct_chg_dt || acct_chg_tm) as TIMESTAMP Scenario Clients cno fname lname city state tax ----------- ---------- ---------- ---------- ----- -------10 Rachel Wise Fair Lawn NJ 7.00 20 Michael Strong FLINT MI 8.00 30 Mario Subrutini <NULL> NC 6.00 40 Mark Shine Two Oaks <NULL> 5.00 50 David D'Ark Chicago IL <NULL> SELECT fname || lname || ' from ' || city || ', ' || state From clients WHERE tax > 0

Referring to the Clients table above, what is the result of the query?

Choice 1 Rachel Wise from Fair Lawn, NJ Michael Strong from FLINT, MI NULL NULL Choice 2 Rachel Wise from Fair Lawn, NJ Michael, Strong from FLINT, MI Choice 3 Rachel Wise from Fair Lawn, NJ Michael Strong from FLINT, MI NULL NULL

David D'Ark from Chicago, IL Choice 4 Rachel Wise from Fair Lawn, NJ Michael Strong from FLINT, MI David D'Ark from Chicago, IL Choice 5 Rachel Wise from Fair Lawn, NJ Michael Strong from FLINT, MI NULL NULL NULL For Not Found Condition : SQLCODE : +100 SQLSTATE : 02000

You might also like