Murach\'s racle SQL and PL/SQL CH.10 pg.346-347 Add constraints and an index to
ID: 3535471 • Letter: M
Question
Murach's racle SQL and PL/SQL CH.10 pg.346-347
Add constraints and an index to the AP schema
1. Write an ALTER TABLE statement that adds two new check constraints to the Invoices table of the AP schema. The first should allow (1) payment_date to be null only if payment_total is zero and (2) payment_date to be not null only if payment_total is greater than zero. The second constraint should prevent the sum of payment_total and credit_total from being greater than invoice_total.
2.Add an index to the AP schema for the zip code field in the Vendors table
Implement a database design
3.Write the CREATE TABLE statements needed to implement the following design in the EX schema:
These tables provide for members of an association, and each member can be registered in one or more groups within the association. There should be one row for each member in the Members table and one row for each group in the Groups table. The member ID and group ID columns are the primary keys for the Members and Groups tables. And the Members_Groups table relates each member to one or more groups.
When you create the tables, be sure to include the key constraints. Also, include any null or default constraints that you think are necessary.
4. Write INSERT statements that add two rows to the Members table for member IDs 1 and 2, two rows to the Groups table for group IDs 1 and 2, and three rows to the Group_Membership table: one row for member 1 and group 2; one for member 2 and group 1; and one for member 2 and group 2. Then, write a SELECT statement that joins the three tables and retrieves the group name, member last name, and member first name.
5.Create sequences that can be used to number the member ID and group ID values starting with 3 (since you already added members and groups for IDs 1 and 2).
6. Write an INSERT statement that adds another row to the Groups table. This statement should use the NEXTVAL pseudo column to get the value for the next group ID from the sequence that you created in exercise 5. Then, write a SELECT statement that gets all of the data for all of the rows in the Groups table to make sure your sequence worked correctly.
7. Write an ALTER TABLE statement that adds two new columns to the Members table: one column for annual dues that provides for three digits to the left of the decimal point and two to the right; and one column for the payment date. The annual dues column should have a default value of 52.50.
8. Write an ALTER TABLE statement that modifies the Groups table so the group name in each row has to be unique. Then, re-run the INSERT statement that you used in exercise 6 to make sure this works.
it must be work.. please help
Explanation / Answer
1)1)ALTER TABLE Invoices WITH CHECK
ADD check (
(PaymentTotal = 0 AND PaymentDate is NULL)
OR
(PaymentTotal > 0 AND PaymentDate is NOT NULL)
)
ADD CHECK (
(PaymentTotal < InvoiceTotal = SUM)
OR
(CreditTotal < InvoiceTotal = SUM)
)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.