Vocabulary Identify the vocabulary word for each definition below. An entry in a table, consisting of values for each appropriate col-umn. [Row] The set of mandatory columns within a table that is used to en-force uniqueness of rows, and that is normally the most frequent means by which rows are accessed. [Premary Key] An arrangement of data in rows and columns. [Table] A column or set of columns that refers to a primary key in the same table or another table. [Foreign Key] Collections of objects or relations, set of operators to act on those relations, and data integrity for accuracy and consistency. [Relational dB] Intersection of a row and column. [Field] Used to modify the table data by entering, changing, or removing Rows. [Data Manipulation Language] Creates, changes, and removes data structures from the data-base. [Data Manipulation Language] Used to manage the changes made by DML statements. [Transaction Control Language] Used to give or remove access rights to the database and the structures within it. [Data Control Language] 1. The Global Fast Foods database consists of how many tables? ____ tables SELECT DISTINCT owner, count(table_name) FROM all_tables GROUP BY owner; OWNER MDSYS CTXSYS OLAPSYS SYSTEM COUNT(TABLE_NAME) 48 5 2 7 XDB HKUMAR SYS But this contains tables from all the ERD’s in: 2 35 37 And I need for: Specific to Global Fast Foods ERD [9] are: F_ORDER_LINES F_FOOD_ITEMS F_PROMOTIONAL_MENUS F_REGULAR_MENUS F_SHIFTS F_SHIFT_ASSIGNMENTS F_STAFFS F_CUSTOMERS F_ORDERS 2. How is the F_SHIFTS table related to the F_STAFFS table? SELECT DISTINCT table_name from user_constraints WHERE r_constraint_name in ( SELECT constraint_name FROM user_constraints WHERE table_name in (upper('f_shifts'), upper('F_STAFFS')) ); Above query gives an idea that, go look study tables F_ORDERS, F_SHIFT_ASSIGNMENTS Now finally I found that, F_SHIFTS table related to the F_STAFFS – both having foreign key reference in F_SHIFT_ASSIGNMENTS. 3. What are the names of the columns in the F_CUSTOMERS table? SELECT column_name FROM all_tab_cols WHERE table_name = 'F_CUSTOMERS' COLUMN_NAME: ID FIRST_NAME LAST_NAME ADDRESS CITY STATE ZIP PHONE_NUMBER 4. How many rows of data have been entered in the F_PROMOTIONAL_MENUS table? select count(*) from F_PROMOTIONAL_MENUS Result is 2. 5. In the F_FOOD_ITEMS table, column _________ is a foreign-key column. What table and column is this key referencing? select * from user_constraints where table_name = 'F_FOOD_ITEMS' and CONSTRAINT_TYPE = 'R'; select table_name from user_constraints where constraint_name in ( select r_constraint_name from user_constraints where table_name = 'F_FOOD_ITEMS' and CONSTRAINT_TYPE = 'R' ); "REGULAR_CODE" to "CODE" in "F_REGULAR_MENUS" "PROMO_CODE" to "CODE" in "F_PROMOTIONAL_MENUS" 6. List the primary key to foreign key relationships required to go from the F_SHIFTS table to the F_REGULAR_MENUS table. This must be there to identify hours served. Now, ideally it should have been like this: But seems to be, our fellow restaurant owner have separate regular menu for each shift. So ignore suggestion above. Now again, values of hours served in regular menu table ['6-11am', '11-9pm'] don’t match any shift timings [8am to 12pm, 6pm to 10pm], seems to be these values on menu side are meant to be lost while this exercise --remove HOURS_SERVED alter table "F_REGULAR_MENUS" drop column "HOURS_SERVED" ; --add SHIFT_CODE alter table "F_REGULAR_MENUS" add "SHIFT_CODE" NUMBER(5, 0) ; --give some value so that it may be set to not null later UPDATE "F_REGULAR_MENUS" SET "SHIFT_CODE" = 1; --set SHIFT_CODE to not null ALTER TABLE "F_REGULAR_MENUS" MODIFY ("SHIFT_CODE" NUMBER(5,0) CONSTRAINT "F_RMU_SHIFT_CODE_NN" NOT NULL ENABLE); --now create the foreign key constraint ALTER TABLE "F_REGULAR_MENUS" ADD CONSTRAINT "F_RMU_SHIFT_CODE_FK" FOREIGN KEY ("SHIFT_CODE") REFERENCES "F_SHIFTS" ("CODE") ENABLE; 7. Which table(s) contains null values? As per definition available at https://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_2094.htm, below mentioned query would have been sufficient to give this result: SELECT distinct "TABLE_NAME" FROM "USER_TAB_COLUMNS" WHERE "NULLABLE" = 'Y' and "NUM_NULLS" > 0 Or SELECT count(distinct "TABLE_NAME") FROM "USER_TAB_COLUMNS" WHERE "NULLABLE" = 'Y' and "NUM_NULLS" > 0 But, It didn’t work as per design, due to some index issues. So I removed the last condition in above query and manually verified each table: [10] Table EMPLOYEES LOCATIONS EMP_DETAILS_VIEW JOBS JOB_GRADES REGIONS COUNTRIES D_CLIENTS D_JOB_ASSIGNMENTS D_SONGS D_VENUES F_ORDERS F_STAFFS Has some field null yes no n/a no no no no no no no no no yes it's a view JOB_HISTORY WF_COUNTRIES D_EVENTS HTMLDB_PLAN_TABLE WF_CURRENCIES WF_SPOKEN_LANGUAGES D_PLAY_LIST_ITEMS F_PROMOTIONAL_MENUS DEPARTMENTS F_FOOD_ITEMS D_PARTNERS no yes no yes yes yes yes no yes yes yes But to verify my manual observation above, I needed something, for which I created below mentioned query: SELECT 'SELECT count(*) from "' || "TABLE_NAME" || '" where "' || "COLUMN_NAME" ||'" is null;' as query FROM "USER_TAB_COLUMNS" WHERE "NULLABLE" = 'Y'; This gives output like: SELECT count(*) from "D_PARTNERS" where "EXPERTISE" is null; (112 count) I executed each query generated above to verify above results. Sample queries to verify above results (off the 112 generated): SELECT count(*) from "DEPARTMENTS" where "MANAGER_ID" is null; SELECT count(*) from "D_PARTNERS" where "EXPERTISE" is null; SELECT count(*) from "D_PLAY_LIST_ITEMS" where "COMMENTS" is null; SELECT count(*) from "EMPLOYEES" where "COMMISSION_PCT" is null; SELECT count(*) from "F_FOOD_ITEMS" where "REGULAR_CODE" is null; SELECT count(*) from "F_STAFFS" where "OVERTIME_RATE" is null; SELECT count(*) from "HTMLDB_PLAN_TABLE" where "REMARKS" is null; SELECT count(*) from "WF_COUNTRIES" where "COUNTRY_TRANSLATED_NAME" is null; SELECT count(*) from "WF_CURRENCIES" where "COMMENTS" is null; SELECT count(*) from "WF_SPOKEN_LANGUAGES" where "COMMENTS" is null; Vocabulary Identify the vocabulary word for each definition below. Display data from two or more related tables. [Join] A symbol used to perform an operation on some values. [Arithmetic Operator] An implementation of an attribute or relationship in a table. [Column] The capability in SQL to choose the columns in a table that you want returned from a query. [Projection] A value that is unavailable, unassigned, unknown, or inapplica-ble. [NULL] Renames a column heading. [Column Alias] A mathematical equation. [Arithmetic expression] The capability in SQL to choose the rows in a table returned from a query. [Selection] Retrieves information from the database. [Select statement] Specifies the columns to be displayed. [Select clause] Specifies the table containing the column listed in the select clause. [From clause] An individual SQL statement.[Keyword] Part of a SQL statement. [Clause] A combination of the two clauses. [Statement] Try It / Solve It Now you know the basics of a SELECT statement, It's time to practice what you've learned. 1. Write a SQL statement that demonstrates projection and selection. SELECT constraint_name FROM user_constraints WHERE table_name in (upper('f_shifts'), upper('F_STAFFS')); 2. Write a query that displays the last_name and email addresses for all the people in the DJs on Demand d_client table. The column headings should appear as “Client” and “Email Address.” SELECT last_name AS "Client", email AS "Email Address" FROM d_clients; 3. The manager of Global Fast Foods decided to give all employees at 5%/hour raise + a $.50 bonus/hour. However, when he looked at the results, he couldn't figure out why the new raises were not as he predicted. Ms. Doe should have a new salary of $7.59, Mr. Miller's salary should be $11.00, and Monique Tuttle should be $63.50. He used the following query. What should he have done? SELECT last_name, salary *.05 +.50 FROM f_staffs; He assumed wrong that if he has to give 5% raise, he should multiply by ‘.05’. It should be multiplied by ‘1.05’ and rounded to two digits after decimal. Precedence he knows about correctly. (*/+- grouped, */ being higher precedence than +- and then left to right in statement for the two in same group) SELECT last_name, ROUND(salary*1.05 +.50, 2) as "Salary" FROM f_staffs; 4. Which of the following would be the easiest way to see all rows in the d_songs table? a. SELECT id, title, duration, artist, type_code b. SELECT columns c. SELECT * d. SELECT all 5. If tax = 8.5% * car_cost and license = car_cost * .01%, which value will produce the largest car payment? a. Payment = (car_cost * 1.25) + 5.00 - (tax) - (license) b. Payment = car_cost * 1.25 + 5.00 - (tax - license)
© Copyright 2025 Paperzz