A Guide to SQL
A Guide to SQL
9th Edition
ISBN: 9781111527273
Author: Philip J. Pratt
Publisher: Course Technology Ptr
Question
Book Icon
Chapter 8, Problem 9TD
Program Plan Intro

a.

Trigger:

The trigger is a named set of SQL statement that is executed at the time of data modification or meets some data description.

  • If the stated trigger condition meets up, then the mentioned action in the trigger has been performed.

There are three parts of trigger; they are:

Event:

  • It specifies the change to be made, such as an UPDATE or DELETE of a record.

Condition:

  • It specifies the condition to examine the records about to be affected. For each record, that meets the condition given in the trigger.

Action:

  • The action performed after the start of the trigger.

The syntax to create a trigger is as given below:

  CREATE TRIGGER trigger_name

  {BEFORE| AFTER|INSTEAD OF} {INSERT|DELETE|UPDATE} ON

  table_name

  [FOR EACH{ROW|STATEMENT}] [WHEN(condition)]

  <triggered SQL statement here>;

Explanation of Solution

b.

Query to create trigger:

CREATE OR REPLACE TRIGGER UPD_CUSTOMER

AFTER UPDATE ON CUSTOMER FOR EACH ROW

BEGIN

UPDATE REP

SET COMMISSION = COMMISSION + ((:NEW.BALANCE - :OLD.BALANCE)*RATE);

END;

Explanation:

  • The above query is used to create a trigger named “UPD_CUSTOMER” to update the “COMMISSION” contents in the “REP” table whenever a record is inserted in the “CUSTOMER” table...

Explanation of Solution

c.

Query to create trigger:

CREATE OR REPLACE TRIGGER DEL_CUSTOMER

AFTER DELETE ON CUSTOMER FOR EACH ROW

BEGIN

UPDATE REP

SET COMMISSION = COMMISSION - (:OLD.BALANCE * RATE);

END;

Explanation:

  • The above query is used to create a trigger named “DEL_CUSTOMER” to update the “COMMISSION” contents in the “REP” table whenever a record is delete in the “CUSTOMER” table...

Blurred answer
Students have asked these similar questions
Write the code for the following triggers in MySQL, PL/SQL, or T-SQL following the style shown in the text. a. When adding a customer, add the customer’s balance multiplied by the sales rep’s commission rate to the commission for the corresponding sales rep. b.   When updating a customer, add the difference between the new balance and the old balance multiplied by the sales rep’s commission rate to the commission for the corresponding sales rep. c.   When deleting a customer, subtract the balance multiplied by the sales rep’s commission rate from the commission for the corresponding sales rep.
THIS MODULE IS ABOUT SUBQUERIES, SO YOU MUST USE SUBQUERIES INSTEAD OF TABLE JOINS  (a) From which two fields in which table can you calculate the enrollment of a section?(b) From which table can you get both course and section numbers?(c) Which field in table SECTION uniquely identifies a section, section id or section no?(d) Write a SQL statement to show sections and their enrollment.(e) Write a SQL statement to show sections with enrollment greater than five. Display both course andsection numbers
T-SQL procedure A: obtain the name and credit limit of the customer whose number currently is stored in I_CUSTOMER_NUM. Place these valuse in the variables I_CUSTOMER_NAME and I_CREDIT_LIMIT, respectively. Output the content of I_CUSTOMER_NAME and I_CREDIT_LIMIT. B: obtain the order date, customer number and name for the order whose number currently is stored in I_ORDER_NUM. place these values in the variables I_ORDER_DATE, I_CUSTOMER_NUM and I_CUSTOMER_NAME , respectively. output the contents of I_ORDER_DATE, I_CUSTOMER_NUM , and I_CUSTOMER_NAME. C: add a row to the ORDERS table. D: change the date of the whole number is stored in I_ORDER_DATE to the date currently found in I_ORDER_DATE. E: delete the order whose number is stored in I_ORDER_NUM.
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
A Guide to SQL
Computer Science
ISBN:9781111527273
Author:Philip J. Pratt
Publisher:Course Technology Ptr
Text book image
Oracle 12c: SQL
Computer Science
ISBN:9781305251038
Author:Joan Casteel
Publisher:Cengage Learning
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781305627482
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781285196145
Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos Coronel
Publisher:Cengage Learning
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning