I am having an error and cannot figure out how to solve this question. Could someone please assist? Please be advised, I am using PostgreSQL as that is what was used in class. Thus, I must use PLPGSQL

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Hello,

I am having an error and cannot figure out how to solve this question. Could someone please assist?

Please be advised, I am using PostgreSQL as that is what was used in class. Thus, I must use PLPGSQL

Application: PostgreSQL 12 or 13
PLPGSQL

CREATE OR REPLACE FUNCTION Moreno_03_bankTriggerFunction()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS
$BODY$

CREATE TRIGGER Moreno_03_bankTrigger
AFTER DELETE ON account
FOR EACH ROW
EXECUTE PROCEDURE Moreno_15_bankTriggerFunction();

TABLES (if needed)

CREATE TABLE branch (
branch_name varchar(35),
branch_city varchar(15),
assets numeric(15,2) CHECK (assets > 0.00),
CONSTRAINT branch_pkey PRIMARY KEY (branch_name)
);

CREATE TABLE customer (
ID varchar(15),
customer_name varchar(25) NOT NULL,
customer_street varchar(35),
customer_city varchar(15),
CONSTRAINT customer_pkey PRIMARY KEY (ID)
);

CREATE TABLE loan (
loan_number varchar(15),
branch_name varchar(35),
amount numeric(15,2),
CONSTRAINT loan_pkey PRIMARY KEY (loan_number),
CONSTRAINT loan_fkey FOREIGN KEY (branch_name) REFERENCES branch (branch_name)
ON DELETE SET NULL
);

CREATE TABLE borrower (
ID varchar(15),
loan_number varchar(15),
CONSTRAINT borrower_pkey PRIMARY KEY (ID, loan_number),
CONSTRAINT borrower_fkey_1 FOREIGN KEY (ID) REFERENCES customer (ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT borrower_fkey_2 FOREIGN KEY (loan_number) REFERENCES loan (loan_number)
ON DELETE CASCADE
ON UPDATE CASCADE
);

CREATE TABLE account (
account_number varchar(25),
branch_name varchar(35) NOT NULL,
balance numeric(15,2) DEFAULT 0.00,
CONSTRAINT account_pkey PRIMARY KEY (account_number),
CONSTRAINT account_fkey FOREIGN KEY (branch_name) REFERENCES branch (branch_name)
ON DELETE SET NULL
);

CREATE TABLE depositor (
ID varchar(15),
account_number varchar(15),
CONSTRAINT depositor_pkey PRIMARY KEY (ID, account_number),
CONSTRAINT depositor_fkey FOREIGN KEY (ID) REFERENCES customer (ID)
ON DELETE CASCADE
ON UPDATE CASCADE
-- No fkey constrains on account number as it is managed via trigger.
);

 

stu
tak
10
CREATE OR REPLACE FUNCTION Moreno_03_bankTriggerFunction ()
11
RETURNS TRIGGER
tea
12
LANGUAGE PLPGSQL
13
AS
14
$BODY$
15
16
CREATE TRIGGER Moreno_03_bankTrigger
17
AFTER DELETE ON account
18
FOR EACH ROW
19
EXECUTE PROCEDURE Moreno_15_bankTrigger Function ();
20
Data Output Explain
Messages
Notifications
>
ERROR:
syntax error at or near
II ||
LINE 6:
SQL state: 42601
Character: 131
>
A tim
> Trigger
> O Types
田
HI >
>
Transcribed Image Text:stu tak 10 CREATE OR REPLACE FUNCTION Moreno_03_bankTriggerFunction () 11 RETURNS TRIGGER tea 12 LANGUAGE PLPGSQL 13 AS 14 $BODY$ 15 16 CREATE TRIGGER Moreno_03_bankTrigger 17 AFTER DELETE ON account 18 FOR EACH ROW 19 EXECUTE PROCEDURE Moreno_15_bankTrigger Function (); 20 Data Output Explain Messages Notifications > ERROR: syntax error at or near II || LINE 6: SQL state: 42601 Character: 131 > A tim > Trigger > O Types 田 HI > >
3. Consider the bank database schema given in question (2). Write a SQL trigger to carry
out the following action: If an account is deleted, then write a trigger to delete the
dependent tuple(s) from the depositor table for every owner of the deleted account. Note
that there may be jointly-owned bank accounts. In other words, you are to write a trigger
that performs the exact action of an ON DELETE CASCADE clause of a FOREIGN
KEY CONSTRAINT. You must submit both your trigger function definition, and your
trigger definition. You must name your trigger function:
<LastName>_<DOB_DayOfMonth>_bankTriggerFunction
You must name your trigger:
<LastName> <DOB DayOfMonth>_bankTrigger
Where <LastName> is your last name and <DOB DayofMonth> is the day of the month
you were born. Below is an example of how I named my trigger function and trigger,
respectively:
Morabito_05_bankTriggerFunction ()
Morabito 05 bankTrigger
Transcribed Image Text:3. Consider the bank database schema given in question (2). Write a SQL trigger to carry out the following action: If an account is deleted, then write a trigger to delete the dependent tuple(s) from the depositor table for every owner of the deleted account. Note that there may be jointly-owned bank accounts. In other words, you are to write a trigger that performs the exact action of an ON DELETE CASCADE clause of a FOREIGN KEY CONSTRAINT. You must submit both your trigger function definition, and your trigger definition. You must name your trigger function: <LastName>_<DOB_DayOfMonth>_bankTriggerFunction You must name your trigger: <LastName> <DOB DayOfMonth>_bankTrigger Where <LastName> is your last name and <DOB DayofMonth> is the day of the month you were born. Below is an example of how I named my trigger function and trigger, respectively: Morabito_05_bankTriggerFunction () Morabito 05 bankTrigger
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY