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.
SQL
SQL stands for Structured Query Language, is a form of communication that uses queries structured in a specific format to store, manage & retrieve data from a relational database.
Queries
A query is a type of computer programming language that is used to retrieve data from a database. Databases are useful in a variety of ways. They enable the retrieval of records or parts of records, as well as the performance of various calculations prior to displaying the results. A search query is one type of query that many people perform several times per day. A search query is executed every time you use a search engine to find something. When you press the Enter key, the keywords are sent to the search engine, where they are processed by an algorithm that retrieves related results from the search index. Your query's results are displayed on a search engine results page, or SER.
create table branch(branch_name varchar(30) primary key, branch_city varchar(30), assets varchar(60) );
create table customer(ID_number integer primary key, customer_name varchar(30), customer_street varchar(40), customer_city varchar(40) );
create table loan(loan_number integer primary key, branch_name varchar(30),amount integer, foreign key(branch_name) references branch(branch_name) );
create table borrower(ID_number integer primary key, loan_number integer , foreign key(loan_number) references loan(loan_number) );
create table account(account_number integer primary key, branch_name varchar(30), balance integer , foreign key(branch_name)
references branch(branch_name) );
create table depositor(ID_number integer primary key, account_number int , foreign key(account_number) references account(account_number) );
Consider the bank
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:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps