UJIAN SQL MODEL SOAL D.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

BACS 485—Database Management Advanced SQL Overview Advanced DDL, DML, and DCL Commands.
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Virtual training week 4 structured query language (SQL)
Database Programming Sections 13. Marge Hohly  1. Which statements are True about the following sequence? The sequence was used to generate numbers.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
1 Lecture 3: Subqueries DCO11310 Database Systems and Design By Rose Chang.
10 Copyright © 2004, Oracle. All rights reserved. Creating Other Schema Objects.
Introduction to Structured Query Language (SQL)
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
Database Systems More SQL Database Design -- More SQL1.
Introduction to Structured Query Language (SQL)
SQL Joins.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Oracle Database Administration Lecture 2 SQL language.
11 Copyright © 2007, Oracle. All rights reserved. Creating Other Schema Objects.
Quick review of SQL And conversion to Oracle SQL.
11 Copyright © Oracle Corporation, All rights reserved. Creating Views.
Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows.
Nitin Singh/AAO RTI ALLAHABAD 1 SQL Nitin Singh/AAO RTI ALLAHABAD 2 OBJECTIVES §What is SQL? §Types of SQL commands and their function §Query §Index.
Database Programming Sections 11 & 12 – Creating, and Managing Views, Sequences, Indexes, and Synonymns.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
INTRODUCTION TO SQL Chapter SELECT * FROM teacher WHERE INSTR (subject_id, ‘&1’)= 4 AND LOWER (subject_id) LIKE ‘HST%’ ; When prompted for the.
Transactions, Roles & Privileges Oracle and ANSI Standard SQL Lecture 11.
Soal Minggu 1 Pengenalan Basis Data Perintah Dasar SQL.
Aggregating Data Using Group Functions. What Are Group Functions? Group functions operate on sets of rows to give one result per group.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
6 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using Subqueries.
Insert, update, delete TCL. Data Manipulation Language – A DML statement is executed when you: Add new rows to a table Modify existing rows in a table.
Pengenalan Basis Data Perintah Dasar SQL
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Using Subqueries to Solve Queries
SQL Query Getting to the data ……..
More SQL: Complex Queries,
Relational Database Design
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
Introduction to SQL Karolina muszyńska
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
Manipulating Data.
Oracle Certified 1z0-047 Exam Questions
Introduction to Oracle9i: SQL
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Using Subqueries to Solve Queries
Chapter 4 Indexes.
CH 4 Indexes.
Chapter 2 Views.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Database systems Lecture 3 – SQL + CRUD
SQL Fundamentals in Three Hours
CH 4 Indexes.
Manipulating Data.
Using Subqueries to Solve Queries
Chapter 2 Views.
1 Manipulating Data. 2 Objectives After completing this lesson, you should be able to do the following:  Describe each data manipulation language (DML)
Reporting Aggregated Data Using the Group Functions
Index Note: A bolded number or letter refers to an entire lesson or appendix. A Adding Data Through a View ADD_MONTHS Function 03-22, 03-23,
Contents Preface I Introduction Lesson Objectives I-2
CSC 453 Database Systems Lecture
Using Subqueries to Solve Queries
IST 318 Database Administration
Reporting Aggregated Data Using the Group Functions
Using Subqueries to Solve Queries
Reporting Aggregated Data Using the Group Functions
Subqueries Schedule: Timing Topic 25 minutes Lecture
Presentation transcript:

UJIAN SQL MODEL SOAL D

1. Evaluate this SQL statement : SELECT c.customer_id, o.order_id, o.order_date, p.product_name FROM customer c, curr_order o, product p WHERE customer.customer_id = curr_order. customer_id AND o.product_id = p.product_id ORDER BY o.order_amount; This statement fails when executed. Which change will correct the problem? Use the table name in the ORDER BY clause. Remove the table aliases from the WHERE clause. Include the ORDER_AMOUNT column in the SELECT list. Use the table aliases instead of the table names in the WHERE clause. Remove the table alias from the ORDER BY clauses and use only the column name.

use to achieve these result? 2. You need to create user Susan and allow this user to create and drop tables in any schema. She should be able to create procedures and sequences only in her schema. Which script should you use to achieve these result? CREATE USER susan IDENTIFIED BY sue123; GRANT CREATE SESSION, CREATE ANY TABLE, DROP ANY TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO susan/ CREATE USER susan IDENTIFIED BY sue123; GRANT CREATE SESSION, DROP ANY TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO susan/ CREATE USER susan IDENTIFIED BY sue123; GRANT CREATE TABLE, DROP TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO susan/ CREATE USER susan IDENTIFIED BY sue123; GRANT DROP ANY TABLE, CREATE SEQUENCE, CREATE PROCEDURE TO susan/

which statements produces the required result ? 3. Seniority is based on the number of years a student has been enrolled at the university. You must create a report that displays each student’s name, id number, and the number of years enrolled. The years enrolled must be rounded to a whole number, based on the number of months from the date enrolled until today. which statements produces the required result ? SELECT first_name||’,’||last_name “Student Name, id ”id”, enroll_date, TRUNC(SYSDATE,’YY’) – TRUNC(enroll_date,’YY’) “Seniority” FROM student; c. SELECT first_name||’,’||last_name “Student Name, id ”id”, enroll_date, ROUND(MONTHS_BETWEEN(SYSDATE,enroll_date)/12) “Seniority” FROM student d. SELECT first_name||’,’||last_name “Student Name”, id ”id”, enroll_date, ROUND(SYSDATE) – ROUND(enroll_date) “Seniority” e. SELECT first_name||’,’||last_name “Student Name, id ”id”, enroll_date, (ROUND((SYSDATE) – ROUND(enroll_date)) /12 “Seniority” FROM student

4. The EVENT table contains these columns: EVENT_ID NUMBER EVENT_NAME VARCHAR2(30) EVENT_DESC VARCHAR2(100) EVENT_TYPE NUMBER LOCATION_ID NUMBER You have been asked to provide a report of the number of different event types at each location. Which SELECT statement will produce the desired result? SELECT UNIQUE(location_id), COUNT(event_type) FROM event GROUP BY location_id; SELECT location_id, COUNT(DISTINCT event_type) FROM event GROUP BY location_id; SELECT location_id, MAX(DISTINCT event_type) FROM event GROUP BY location_id SELECT DISTINCT(event_type) FROM event GROUP BY location_id; SELECT COUNT(*), DISTINCT(location_id) FROM event;

5. Evaluate this SQL statement: SELECT supplier_id, AVG(cost) FROM product WHERE AVG(list_price) > 60.00 GROUP BY supplier_id ORDER BY AVG(cost) DESC; Which clause will cause an error? SELECT ORDER BY WHERE GROUP BY

The precision of the sequence is changed The sequence is dropped 6. The ACCOUNT table contains these colums: ACCOUNT_ID NUMBER(12), NEW_PURCHASES NUMBER PREV_BALANCE NUMBER(72), FINANCE_CHARGE NUMBER(7,2) PAYMENTS NUMBER(7,2) You created the ACCOUNT_ID_SEQ sequence to generate sequential values for the ACCOUNT_ID column. You issue this statement: ALTER TABLE account MODIFY (finace_charge NUMBER(8,2)); Which statement about the ACCOUNT_ID_SEQ sequence is true? The precision of the sequence is changed The sequence is dropped The sequence is reverted to its minimum value The sequence is unchanged

7. Which statement will permanently remove all the data in, the indexes on, and the structure of the PO_DETAIL table ? DROP TABLE po_detail; DELETE TABLE po_detail; ALTER TABLE po_detail TRUNCATE TABLE po_detail; SET UNUSED (po_num, po_line_id, product_id, quantity, unit_price);

8. Which statement type would be used to remove transactions more than one year old from the TRX table ? DCL DDL DML DRL TCL

9. Which statements would cause an implicit COMMIT to occur ? GRANT SELECT COMMIT UPDATE ROLLBACK

10. Which CREATE TABLE statement will true ? CREATE TABLE date (time_id NUMBER(9)); CREATE TABLE time (time_id NUMBER(9)); CREATE TABLE $time (time_id NUMBER(9)); CREATE TABLE datetime (time_id NUMBER(9)); CREATE TABLE number (time_id NUMBER(9));

11. Evaluate this statement: TRUNCATE TABLE inventory; Which three users could succesfully issue this statement> (choose three) The owner of the INVENTORY table Any user with access to the PUBLIC schema Any member of the CONNECT and RESOURCE roles Any user with the DROP ANY TABLE system privilege Any user with the DELETE object privilege on the INVENTORY table

12. Which Database Objects not incluided in a Oracle Database Table Sequence Constraint Synonym Index

13. Evaluate this SQL statement : SELECT c.customer_id, o.order_id, o.order_date, p.product_name FROM customers c, curr_order o, product p WHERE customer.customer_id = curr_order. customer_id AND o.product_id = p.product_id ORDER BY o.order_amount; This statement fails when executed. Which changne will corect the problem? Use the table name in the ORDER BY clause Remove the table aliases from the WHERE clause Include the ORDER_AMOUNT column in the SELECT list. Use the table aliases instead of the table names in the WHERE clause Remove the table alias from the ORDER BY clauses and use only the column name

14. The WORKORDER table contains these columns : WO_ID NUMBER PK CUST_ID NUMBER REQUIRED_DT DATE COMPL_DT DATE AMOUNT NUMBER (7,2) Which statement regarding the use of aggregate functions on the WORKORDER table is true ? Using the AVG aggregate function with any column in the table is allowed Using the AVG aggregate function on the AMOUNT column ignores null values. Using the MIN aggregate function on the COMPL_DT column will return a null values. Using the SUM aggregate function with AMOUNT column is allowed in any portion of a SELECT statement. Using the SUM aggregate function on the AMOUNT column will result in erroneous result because the column contains null Grouping on the REQUIRED_DT and COMPL_DT column is NOT allowed.

15. Which two operators can be used in an outer join condition? ALL OR IN AND

16. You want to produce a report containing the total number of orders placed for a particular time periode. Which aggregate functions should you use in your SQL statement? STOT TSUM VALUE COUNT STDDEV

17. The EVENT table contains these columns: EVENT_ID NUMBER EVENT_NAME VARCHAR2(30) EVENT_DESC VARCHAR2(100) EVENT_TYPE NUMBER LOCATION_ID NUMBER You have been asked to provide a report of the number of different event types at each location. Which SELECT statement will produce the desired result? SELECT UNIQUE(location_id), COUNT(event_type) FROM event GROUP BY location_id; SELECT COUNT(*), DISTINCT(location_id) FROM event; SELECT DISTINCT(event_type) FROM event GROUP BY location_id; SELECT location_id, COUNT(DISTINCT event_type) FROM event GROUP BY location_id; SELECT location_id, MAX(DISTINCT event_type) FROM event GROUP BY location_id;

18. How many levels can subqueries be nested in a FROM caluse? 2 4 8 16 unlimited

19. Evaluate this SQL statement SELECT supplier_id, AVG(cost) FROM product WHERE AVG(list_price) > 60.00 GROUP BY supplier_id ORDER BY AVG(cost) DESC; Which clause will cause an error? SELECT WHERE GROUP BY ORDER BY

20. Which SELECT statement implements a self join? SELECT i.id_number, m.manufacturer_id FROM inventory i NATURAL JOIN inventory m; SELECT i.id_number, m.manufacturer_id FROM inventory i, inventory m WHERE i.manufacturer_id = m.id_number; SELECT i.id_number, m.manufacturer_id FROM inventory i, manufacturer m WHERE i.manufacturer_id = m.id_number; SELECT i.id_number, m.manufacturer_id FROM inventory i, manufacturer m WHERE i.manufacturer_id <> m.id_number;

21. How many values could a subquery used with the <> operator return? Only 1 Up to 2 Up to 10 unlimited

21. Evaluate this SELECT statement: SELECT employee_id, name FROM employee WHERE employee_id NOT IN (SELECT employee_id FROM employee WHERE department_id = 30 AND job = ‘CLERK’); What would happen if the inner query returned a NULL values? A syntax error would be returned No rows would beselected from the employee tables All the EMPLOYEE_ID and NAME values in the EMPLOYEE table would be displayed Only the rows with EMPLOYEE_ID values equal to NULL would be included in the results

22. You query the database with the SELECT statement: SELECT COUNT(instructor_id) FROM class; Which value is displayed? 2 3 4 5 The statement will NOT execute succesfully CLASS_ID CLASS_NAME HOURS_CREDIT INSTRUCTOR_ID 1 Intro. To Acc. 3 4 2 Computer Basic Tax Accounting American History 5 Basic Engineering

23. The ID column in the CUSTOMER table that corresponds to the CUSTOMER_ID column of the CURR_ORDER table contains null values for rows that need to be diaplayed. Which type of join should you use to display the data? equijoin self join outer join natural join

The statement creates a composite unique index. 24. The TEACHER table in your schema contains these columns : ID NUMBER(9) NOT NULL PERIMARY KEY LAST_NAME VARCHAR2(25) FIRST_NAME VARCHAR2(25) SUBJECT_ID NUMBER(9) You execute this statement: CREATE INDEX teacher_name_idx ON teacher(first_name, last_name); Which statements is true ? The statement creates a composite unique index. The statement will fail because It contains a syntax error. You must have the CREATE ANY INDEX privilege for the statemen to succed. The statement creates a composite non-unique index.

The statement failed to execute because an inline view was NOT used. 25. The ACCOUNT table contains these colums: ACCOUNT_ID NUMBER(12) NEW_BALANCE NUMBER(7,2) PREV_BALANCE NUMBER(7,2) PAYMENTS NUMBER(7,2) FINANCE_CHARGE NUMBER(7,2) CREDIT_LIMIT NUMBER(7) You execute this statement: SELECT ROWNUM “Rank”, account_id, finance_charge FROM (SELECT account_id, finance_charge FROM account ORDER BY finance_charge ) WHERE ROWNUM <= 50; What statement regarding the execution of this statement is true? The statement failed to execute because an inline view was NOT used. The ORDER BY clause was ignored because it was NOT placed in the outer query. The 50 greatest finance charge values were displayed from the highest to the lowest . The statement failed to execute because the ORDER BY does NOT use the Top-n column. The 50 greatest finance charge values were displayed from the lowest to the highest.