I have created the DDL below: I am getting an error about an existing constraint with the borrower_fkey for the borrower relation. At the same time, I feel like I have not satisfied all the...


I have created the DDL below:


I am getting an error about an existing constraint with the borrower_fkey for the borrower relation. At the same time, I feel like I have not satisfied all the requirements. Could someone show me what I did wrong?


The class is being taught using PostgreSQL so the changes have to be applicable to postgreSQL.


Thank you!



CREATE TABLE branch (
branch_name varchar(25) NOT NULL,
branch_city varchar(15),
assets numeric(15,2),
CONSTRAINT branch_pkey PRIMARY KEY (branch_name)
);


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


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


CREATE TABLE borrower (
ID varchar(25),
loan_number varchar(25) NOT NULL,
CONSTRAINT borrower_pkey PRIMARY KEY (ID, loan_number),
CONSTRAINT borrower_fkey FOREIGN KEY (ID) REFERENCES customer (ID) ON DELETE CASCADE,
CONSTRAINT borrower_fkey FOREIGN KEY (loan_number) REFERENCES loan (loan_number) ON UPDATE CASCADE

);


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


CREATE TABLE depositor (
ID varchar(25),
account_number varchar(25) NOT NULL,
CONSTRAINT depositor_pkey PRIMARY KEY (ID, account_number),
CONSTRAINT depositor_fkey FOREIGN KEY (ID) REFERENCES customer (ID) ON DELETE CASCADE
);


Query Editor Query History<br>23<br>24<br>CREATE TABLE borrower (<br>25<br>ID varchar (25),<br>26<br>loan_number varchar (25) NOT NULL,<br>27<br>CONSTRAINT borrower_pkey PRIMARY KEY (ID, loan_number),<br>28<br>CONSTRAINT borrower_fkey FOREIGN KEY (ID) REFERENCES customer (ID) ON DELETE CASCADE,<br>29<br>CONSTRAINT borrower_fkey FOREIGN KEY (loan_number) REFERENCES loan (loan_number) ON UPDATE CASCADE<br>30<br>) ;<br>31<br>32<br>CREATE TABLE account (<br>33<br>account_number<br>varchar(25),<br>34<br>branch_name varchar (25) NOT NULL,<br>35<br>balance numeric(25,2),<br>36<br>CONSTRAINT account_pkey PRIMARY KEY (account_number),<br>37<br>CONSTRAINT account_fkey FOREIGN KEY (branch_name) REFERENCES branch (branch_name) ON DELETE CASCADE<br>38<br>) ;<br>39<br>40<br>CREATE TABLE depositor (<br>41<br>ID<br>varchar(25),<br>42<br>account_number<br>varchar(25) NÓ<br>NULL,<br>43<br>CONSTRAINT depositor_pkey PRIMARY KEY (ID, account_number),<br>44<br>CONSTRAINT depositor_fkey FOREIGN KEY (ID) REFERENCES customer (ID) ON DELETE CASCADE<br>45<br>) ;<br>Data Output Explain<br>Messages<br>Notifications<br>ERROR:<br>constraint

Extracted text: Query Editor Query History 23 24 CREATE TABLE borrower ( 25 ID varchar (25), 26 loan_number varchar (25) NOT NULL, 27 CONSTRAINT borrower_pkey PRIMARY KEY (ID, loan_number), 28 CONSTRAINT borrower_fkey FOREIGN KEY (ID) REFERENCES customer (ID) ON DELETE CASCADE, 29 CONSTRAINT borrower_fkey FOREIGN KEY (loan_number) REFERENCES loan (loan_number) ON UPDATE CASCADE 30 ) ; 31 32 CREATE TABLE account ( 33 account_number varchar(25), 34 branch_name varchar (25) NOT NULL, 35 balance numeric(25,2), 36 CONSTRAINT account_pkey PRIMARY KEY (account_number), 37 CONSTRAINT account_fkey FOREIGN KEY (branch_name) REFERENCES branch (branch_name) ON DELETE CASCADE 38 ) ; 39 40 CREATE TABLE depositor ( 41 ID varchar(25), 42 account_number varchar(25) NÓ NULL, 43 CONSTRAINT depositor_pkey PRIMARY KEY (ID, account_number), 44 CONSTRAINT depositor_fkey FOREIGN KEY (ID) REFERENCES customer (ID) ON DELETE CASCADE 45 ) ; Data Output Explain Messages Notifications ERROR: constraint "borrower_fkey" for relation "borrower" already exists SQL state: 42710 LO
2. Consider the bank database schema given below, where the primary keys are underlined.<br>Write the SQL DDL corresponding to this schema (i.e. the CREATE TABLE statements).<br>Make any reasonable assumptions about the data types. Be sure to declare primary and<br>foreign keys; both types of constraints should be given appropriate names. Correctly and<br>appropriately implement at least one instance for each of the following: check constraint,<br>not null constraint, on delete cascade clause, on update cascade clause, and a default<br>value statement. Lastly, construct the following SQL queries for this relational database.<br>NOTE THE FOLLOWING: You are free to define the DDL for this banking database as<br>you wish, provided that the above requirements are satisfied. However, there is one<br>prohibition: You must not include a foreign key constraint on the account number<br>attribute of the depositor relation that references the account relation. To be perfectly<br>clear, this means you must not include the following foreign key constraint in your DDL:<br>CREATE TABLE depositor<br>CONSTRAINT depositor_fkey FOREIGN KEY (account_number)<br>REFERENCES account (account number)<br>ON DELETE CASCADE<br>ON UPDATE CASCADE<br>);<br>The reason for this specific foreign key prohibition concerns question (3) of this<br>assignment. The spirit behind question (3) is to write a trigger that performs the same<br>action that is accomplished by the ON DELETE CASCADE clause of the above foreign<br>So, if you were to include this foreign key constraint with the ON<br>key constraint.<br>DELETE CASCADE clause in your DDL, then the trigger you must define in question (3)<br>would be useless since the action would be performed not by the trigger - but, rather by<br>the ON DELETE<br>CASCADE clause instead. If you were to include this foreign key<br>constraint without the ON DELETE CASCADE clause in your DDL, then the DBMS<br>would disallow you from deleting any tuples from the account relation. If you include the<br>specified foreign key constraint in your DDL, you will receive a grade of zero for<br>question (3).<br>Database Schema:<br>branch ( branch_name, branch_city, assets )<br>customer ( ID, customer_name, customer_street, customer_city )<br>loan (loan mиmber, branch пате, атоиnt)<br>borrower ( ID, loan number )<br>ассоunt (аccount mumber, branch_name, balance)<br>depositor ( ID. account_number )<br>Note that in the following problem, there is only one bank, and the individual branches<br>listed in the data are all owned by the one bank.<br>Data for this bank database can be found on Brightspace. You may, of course, add more<br>data if it aids you in testing queries.<br>

Extracted text: 2. Consider the bank database schema given below, where the primary keys are underlined. Write the SQL DDL corresponding to this schema (i.e. the CREATE TABLE statements). Make any reasonable assumptions about the data types. Be sure to declare primary and foreign keys; both types of constraints should be given appropriate names. Correctly and appropriately implement at least one instance for each of the following: check constraint, not null constraint, on delete cascade clause, on update cascade clause, and a default value statement. Lastly, construct the following SQL queries for this relational database. NOTE THE FOLLOWING: You are free to define the DDL for this banking database as you wish, provided that the above requirements are satisfied. However, there is one prohibition: You must not include a foreign key constraint on the account number attribute of the depositor relation that references the account relation. To be perfectly clear, this means you must not include the following foreign key constraint in your DDL: CREATE TABLE depositor CONSTRAINT depositor_fkey FOREIGN KEY (account_number) REFERENCES account (account number) ON DELETE CASCADE ON UPDATE CASCADE ); The reason for this specific foreign key prohibition concerns question (3) of this assignment. The spirit behind question (3) is to write a trigger that performs the same action that is accomplished by the ON DELETE CASCADE clause of the above foreign So, if you were to include this foreign key constraint with the ON key constraint. DELETE CASCADE clause in your DDL, then the trigger you must define in question (3) would be useless since the action would be performed not by the trigger - but, rather by the ON DELETE CASCADE clause instead. If you were to include this foreign key constraint without the ON DELETE CASCADE clause in your DDL, then the DBMS would disallow you from deleting any tuples from the account relation. If you include the specified foreign key constraint in your DDL, you will receive a grade of zero for question (3). Database Schema: branch ( branch_name, branch_city, assets ) customer ( ID, customer_name, customer_street, customer_city ) loan (loan mиmber, branch пате, атоиnt) borrower ( ID, loan number ) ассоunt (аccount mumber, branch_name, balance) depositor ( ID. account_number ) Note that in the following problem, there is only one bank, and the individual branches listed in the data are all owned by the one bank. Data for this bank database can be found on Brightspace. You may, of course, add more data if it aids you in testing queries.
Jun 02, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here