Tag: databases

Questions Related to databases

  1. ALTER TABLE emp ADD CONSTRAINT ck_sal CHECK (sal BETWEEN sal AND sal*1.1);

  2. CREATE OR REPLACE TRIGGER check_sal BEFORE UPDATE OF sal ON emp - 6 - FOR EACH ROW WHEN (new.sal < old.sal OR new.sal > old.sal * 1.1) BEGIN RAISE_APPLICATION_ERROR ( - 20508, ‘Do not decrease salary not increase by more than 10%’); END;

  3. CREATE OR REPLACE TRIGGER check_sal BEFORE UPDATE OF sal ON emp WHEN (new.sal < old.sal OR new.sal > old.sal * 1.1) BEGIN RAISE_APPLICATION_ERROR ( - 20508, ‘Do not decrease salary not increase by more than 10%’); END;

  4. CREATE OR REPLACE TRIGGER check_sal AFTER UPDATE OR sal ON emp WHEN (new.sal < old.sal OR -new.sal > old.sal * 1.1) BEGIN RAISE_APPLICATION_ERROR ( - 20508, ‘Do not decrease salary not increase by more than 10%’); END;


Correct Option: B
Explanation:

To answer this question, the user needs to know about SQL triggers and how they can be used to enforce constraints on database operations. Option B is the correct answer because it creates a trigger that runs before each update of the sal (salary) column in the emp table. The trigger checks if the new salary is less than the old salary or greater than the old salary multiplied by 1.1 (i.e., increased by more than 10%). If either of these conditions is true, the trigger raises an error to prevent the update from occurring.

Option A is incorrect because it uses a check constraint to limit the salary increase, but it does not prevent salary decreases.

Option C is almost correct, but it has a syntax error. The FOR EACH ROW clause is not needed in this case, and the semicolon at the end of the RAISE_APPLICATION_ERROR function call is missing.

Option D is also incorrect because it creates a trigger that runs after each update of the sal column, which means the constraint is not enforced until after the update has already occurred.

Therefore, the correct answer is:

The Answer is: B. CREATE OR REPLACE TRIGGER check_sal BEFORE UPDATE OF sal ON emp

  • FOR EACH ROW WHEN (new.sal < old.sal OR new.sal > old.sal * 1.1)
  • BEGIN
  • RAISE_APPLICATION_ERROR ( - 20508, ‘Do not decrease salary not increase by more than 10%’);
  • END;
  1. Use a drop procedure statement to drop a standalone procedure.

  2. Use a drop procedure statement to drop a procedure that is part of a package. Then recompile the package specification.

  3. Use a drop procedure statement to drop a procedure that is part of a package. Then recompile the package body.

  4. For faster removal and re-creation, do not use a drop procedure statement. Instead, recompile the procedure using the alter procedure statement with the REUSE SETTINGS clause.


Correct Option: A
  1. FOR EACH ROW trigger on the EMP table.

  2. Statement-level trigger on the EMP table.

  3. FOR EACH ROW trigger on the AUDIT_TABLE table

  4. Statement-level trigger on the AUDIT_TABLE table


Correct Option: A
Explanation:

To solve this question, the user needs to know the concept of triggers in database management systems. The user must also understand the difference between statement-level triggers and row-level triggers.

In this scenario, we need to create a trigger that monitors every row that is changed in the EMP table and inserts that information into the AUDIT_TABLE. Therefore, we need to create a row-level trigger.

Now, let's go through each option and explain why it is right or wrong:

A. FOR EACH ROW trigger on the EMP table. This option is correct. A FOR EACH ROW trigger on the EMP table will monitor every row that is changed in the EMP table and execute the trigger code for each affected row. This is the type of trigger that we need to create to accomplish the task.

B. Statement-level trigger on the EMP table. This option is incorrect. A statement-level trigger on the EMP table triggers once for each SQL statement that is executed, regardless of the number of rows that are affected. This type of trigger would not be suitable for the task at hand.

C. FOR EACH ROW trigger on the AUDIT_TABLE table. This option is incorrect. A FOR EACH ROW trigger on the AUDIT_TABLE table would monitor every row that is changed in the AUDIT_TABLE table, but this is not what we need. We need to monitor changes in the EMP table.

D. Statement-level trigger on the AUDIT_TABLE table. This option is incorrect. A statement-level trigger on the AUDIT_TABLE table would only trigger once for each SQL statement that is executed, regardless of the number of rows that are affected. This type of trigger would not be suitable for the task at hand.

The Answer is: A. FOR EACH ROW trigger on the EMP table.

  1. Oracle Advanced Queuing

  2. DBMS_JOB

  3. DBMS_SQL

  4. Pipelined Functions


Correct Option: C