Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the SQL code to create *at least* two tables; however, you might need more tables to accomplish the specific task. Your tables will keep

Write the SQL code to create *at least* two tables; however, you might need more tables to accomplish the specific task. Your tables will keep track of:

Owners; the properties of an owner are:

Owner IDFirst NameLast NameAddressPhone

Note: If you have already created the tables with the same names as the assignment, you will need to drop them before you can recreate them. This is a *very* commonly-used schema!

Vehicles; the properties of a vehicle are:

Vehicle ID Make Model Year Color

Cause the following relationship to exist: An owner has many cars; a car may have at most one owner (no common-property here). (This is a one to many)

Write the code to insert at least three records into each table.

Use proper SQL programming style for table creation (e.g.: name all of your constraints and use semicolons.) Choose meaningful identifiers and reasonable data types. For example: a last name might allow 16 characters... perhaps; 50 is too many and two characters is too few. Constrain all last names against NULL.

************************************************************

Part 2 (For part two, use your default database and the existing Vendors-Invoices-Terms schema.) Part two is weighted as indicated.

Write SQL code to accomplish the following tasks:

.

1) Insert the following record into the Terms table:

6 Existing Credit -1

2) Change the CreditTotal to 50.00 for all of the invoices for VendorID 122.

3) Update the Vendors table to to show (999) 999-9999 for the phones that are currently NULL.

4) Write an SQL SELECT query to show the name and city for Vendors in zip 53707 whose city begins with 'Ma'; sort the output by city.

5) Write the SQL code to delete VendorID = 113 from the Vendor's table; also delete any associated invoices. This will probably require two SQL statements in the correct order.

6) Write an SQL SELECT query that shows the invoiceNumber and invoiceDueDate for Vendors in California ("CA").

7) Write an SQL join that will find any unused "Terms" in the table; i.e., no invoice has these terms.

8) Write an SQL query that will return the vendorCity, invoiceNumber, and invoiceTotal for all rows with an invoice less than 100 and a termsDueDays less than or equal to 20.

9) You may have noticed that the defaultTermsID field of the vendors table is not constrained as a foreign key. If we tried to add a foreign key constraint, it would fail because there are invalid data in the table... because I placed them there. Write an SQL query that will find all invalid data in that field.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions