Question: CREATE TABLE People ( PID SERIAL, pName VARCHAR(50), pGender CHAR(1), pHeight FLOAT, PRIMARY KEY (PID) ); CREATE TABLE Accounts ( AID SERIAL, PID INT, aDate

CREATE TABLE People ( PID SERIAL, pName VARCHAR(50), pGender CHAR(1), pHeight FLOAT, PRIMARY KEY (PID) );

CREATE TABLE Accounts ( AID SERIAL, PID INT, aDate DATE, aBalance INT, aOver INT, PRIMARY KEY (AID), FOREIGN KEY (PID) REFERENCES People(PID) );

CREATE TABLE AccountRecords ( RID SERIAL, AID INT, rDate DATE, rType CHAR(1), rAmount INT, rBalance INT, PRIMARY KEY (RID), FOREIGN KEY (AID) REFERENCES Accounts(AID) );

CREATE TABLE Bills ( BID SERIAL, PID INT, bDueDate DATE NOT NULL, bAmount INT, bIsPaid BOOLEAN NOT NULL, PRIMARY KEY (BID), FOREIGN KEY (PID) REFERENCES People(PID) );

a.) Create a view AllAccountRecords that joins the Accounts and AccountRecords and shows one entry for each record for each account. The view should show all columns from both tables, first Accounts and then AccountRecords, except the AccountRecords.AID column. Accounts with no entry in AccountRecords should be shown with NULLs in the columns for AccountRecords.

b.) Create a view DebtorStatus that shows, for each person whose total balance is less than 0, the PID and pName of the person, the total balance of all their accounts, and the total overdraft of all their accounts.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!