SQL

  Home  Databases Programming  SQL


“SQL Interview Questions and Answers will guide us now that SQL (Structured Query Language) is a database computer language designed for managing data in relational database management systems (RDBMS), and originally based upon Relational Algebra. So learn SQL or get preparation for the job of SQL (Structured Query Language) with the help of this SQL Interview Questions with Answers guide”



172 SQL Questions And Answers

123⟩ Read the following code and explain

Read the following code:

22. CREATE OR REPLACE TRIGGER update_show_gross

23. {trigger information}

24. BEGIN

25. {additional code}

26. END;

The trigger code should only execute when the column, COST_PER_TICKET, is greater than $3. Which trigger information will you add?

1. WHEN (new.cost_per_ticket > 3.75)

2. WHEN (:new.cost_per_ticket > 3.75

3. WHERE (new.cost_per_ticket > 3.75)

4. WHERE (:new.cost_per_ticket > 3.75)

 201 views

124⟩ Examine this below sql code

71. BEGIN

72. theater_pck.v_total_seats_sold_overall := theater_pck.get_total_for_year;

73. END;

For this code to be successful, what must be true?

1. Both the V_TOTAL_SEATS_SOLD_OVERALL variable and the GET_TOTAL_FOR_YEAR function must exist only in the body of the THEATER_PCK package.

2. Only the GET_TOTAL_FOR_YEAR variable must exist in the specification of the THEATER_PCK package.

3. Only the V_TOTAL_SEATS_SOLD_OVERALL variable must exist in the specification of the THEATER_PCK package.

4. Both the V_TOTAL_SEATS_SOLD_OVERALL variable and the GET_TOTAL_FOR_YEAR function must exist in the specification of the THEATER_PCK package.

 200 views

125⟩ Read the following code 2

CREATE OR REPLACE FUNCTION get_budget(v_studio_id IN NUMBER)

RETURN number IS

v_yearly_budget NUMBER;

BEGIN

SELECT yearly_budget

INTO v_yearly_budget

FROM studio

WHERE id = v_studio_id;

RETURN v_yearly_budget;

END;

Which set of statements will successfully invoke this function within SQL*Plus?

1. VARIABLE g_yearly_budget NUMBER

EXECUTE g_yearly_budget := GET_BUDGET(11);

2. VARIABLE g_yearly_budget NUMBER

EXECUTE :g_yearly_budget := GET_BUDGET(11);

3. VARIABLE :g_yearly_budget NUMBER

EXECUTE :g_yearly_budget := GET_BUDGET(11);

4. VARIABLE g_yearly_budget NUMBER

31. CREATE OR REPLACE PROCEDURE update_theater

32. (v_name IN VARCHAR v_theater_id IN NUMBER) IS

33. BEGIN

34. UPDATE theater

35. SET name = v_name

36. WHERE id = v_theater_id;

37. END update_theater;

 195 views

126⟩ How to Select last N records from a Table?

select * from (select rownum a, CLASS_CODE,CLASS_DESC from clm)

where a > ( select (max(rownum)-10) from clm)

Here N = 10

The following query has a Problem of performance in the execution of the following query where the table ter.ter_master have 22231 records. So the results are obtained after hours.

Cursor rem_master(brepno VARCHAR2) IS

select a.* from ter.ter_master a

where NOT a.repno in (select repno from ermast) and

(brepno = 'ALL' or a.repno > brepno)

Order by a.repno

What are steps required tuning this query to improve its performance?

-Have an index on TER_MASTER.REPNO and one on ERMAST.REPNO

-Be sure to get familiar with EXPLAIN PLAN. This can help you determine the execution path that Oracle takes. If you are using Cost Based Optimizer mode, then be sure that your statistics on TER_MASTER are up-to-date. -Also, you can change your SQL to:

SELECT a.*

FROM ter.ter_master a

WHERE NOT EXISTS (SELECT b.repno FROM ermast b

WHERE a.repno=b.repno) AND

(a.brepno = 'ALL' or a.repno > a.brepno)

ORDER BY a.repno;

 183 views

128⟩ Examine this database trigger?

52. CREATE OR REPLACE TRIGGER prevent_gross_modification

53. {additional trigger information}

54. BEGIN

55. IF TO_CHAR(sysdate, DY) = MON

56. THEN

57. RAISE_APPLICATION_ERROR(-20000,Gross receipts cannot be deleted on Monday);

58. END IF;

59. END;

This trigger must fire before each DELETE of the GROSS_RECEIPT table. It should fire only once for the entire DELETE statement. What additional information must you add?

1. BEFORE DELETE ON gross_receipt

2. AFTER DELETE ON gross_receipt

3. BEFORE (gross_receipt DELETE)

4. FOR EACH ROW DELETED FROM gross_receipt

 183 views

130⟩ What occurs if a procedure or function terminates with failure without being handled?

1. Any DML statements issued by the construct are still pending and can be committed or rolled back.

2. Any DML statements issued by the construct are committed

3. Unless a GOTO statement is used to continue processing within the BEGIN section, the construct terminates.

4. The construct rolls back any DML statements issued and returns the unhandled exception to the calling environment.

 271 views

131⟩ Read the following code 3?

Read the following code

40. CREATE OR REPLACE PROCEDURE calculate_budget IS

41. v_budget studio.yearly_budget%TYPE;

42. BEGIN

43. v_budget := get_budget(11);

44. IF v_budget < 30000

45. THEN

46. set_budget(11,30000000);

47. END IF;

48. END;

You are about to add an argument to CALCULATE_BUDGET. What effect will this have?

1. The GET_BUDGET function will be marked invalid and must be recompiled before the next execution.

2. The SET_BUDGET function will be marked invalid and must be recompiled before the next execution.

3. Only the CALCULATE_BUDGET procedure needs to be recompiled.

4. All three procedures are marked invalid and must be recompiled.

 175 views