SQL

All questions 1-19

2

Don't use plagiarized sources. Get Your Custom Essay on
SQL
Just from $13/Page
Order Essay

>Assignment

3

SQL

Problem

1

through 19

Note:

· Please be loyal to the data model provided; in the meantime make necessary decisions (e.g., on appropriate data types etc.). Document and justify your decisions, whenever necessary.

· Please submit a single file that includes answers to all questions.

· When you answer question, you can save your SQL code in a document in case you need to repeat

· After you create database, please save one copy the database in case you make mistakes

RentalAVideo is a movie rental store. It needs a database system to track the rental of movies to its members. RentalAVideo can own several copies (VIDEO) of each movie (MOVIE). For example, the store may have 1

0

copies of the movie “Gone with the Wind”. “Gone with the Wind” would be one MOVIE and each copy would be a VIDEO. A rental transaction (RENTAL) involves one or more videos being rented to a member (MEMBERSHIP). A video can be rented many times over its lifetime, therefore, there is a M:N relationship between RENTAL and VIDEO. DETAILRENTAL is the bridge table to resolve this relationship. The complete RDM is provided below.

RentalAVideo ERD (Figure 1)

1. Write the SQL code to create the table structures for the entities shown in Figure 1. The structures should contain the specified attributes. Use data types that would be appropriate for the data that will need to be stored in each attribute. Enforce primary key and foreign key constraints as indicated by the ERD.

2. The following tables provide a very small portion of the data that will be kept in the database. This data needs to be inserted into the database for testing purposes. Write the INSERT commands necessary to place the following data in the tables that were created in problem 1.

Note: For each table, you can write insert statements for 2 rows. If it works, you can copy these data to Excel file. Then, you can import the Excel file to MS Access using the method provided in Access tutorial slide #

10

. But please make sure to create primary key for each table and relationships between tables shown in Figure 1 after you import data

TN

MEMBERSHIP

Mem_ Num

Mem_ Fname

Mem_ Lname

Mem_Street

Mem_City

Mem_ State

Mem_Zip

Mem_ Balance

102

Tami

Dawson

2

6

32 Takli Circle

Norene

TN

37136

11

103

Curt

Knight

4

02

5

Cornell Court

Flatgap

KY

41219

6

104

Jamal

Melendez

7

8

8 East 145th Avenue

Quebeck

38579

0

KY

TN

0

TN

KY

0

TN

TN

0

TN

TN

TN

0

105

Iva

Mcclain

6045 Musket Ball Circle

Summit

42783

15

106

Miranda

Parks

4469 Maxwell Place

Germantown

38183

107

Rosario

Elliott

7578 Danner Avenue

Columbia

38402

5

108

Mattie

Guy

4390 Evergreen Street

Lily

40740

109

Clint

Ochoa

1711 Elm Street

Greeneville

37745

10

110

Lewis

Rosales

4524 Southwind Circle

Counce

38326

111

Stacy

Mann

2789 East Cook Avenue

Murfreesboro

37132

8

112

Luis

Trujillo

7267 Melvin Avenue

Heiskell

37754

3

113

Minnie

Gonzales

6430 Vasili Drive

Williston

38076

103

01-MAR-09

105

102

02-MAR-09

110

02-MAR-09

111

02-MAR-09

107

02-MAR-09

104

105

03-MAR-09

111

RENTAL

Rent_Num

Rent_Date

Mem_Num

1001

01-MAR-09

1002

1003

02-MAR-09

1004

1005

1006

1007

1008

03-MAR-09

1009

Rent_Num

1001

02-MAR-09

1001

2

04-MAR-09

03-MAR-09

1

1002

04-MAR-09

04-MAR-09

3

1003

3.5

04-MAR-09

3

1003

2

09-MAR-09

1

1003

0

06-MAR-09

09-MAR-09

1

1004

3.5

3

1004

3.5

05-MAR-09

07-MAR-09

3

1004

2

07-MAR-09

07-MAR-09

1

1005

34342

2

07-MAR-09

05-MAR-09

1

1005

3.5

05-MAR-09

05-MAR-09

3

1006

3.5

05-MAR-09

04-MAR-09

3

1006

2

07-MAR-09

1

1007

3.5

05-MAR-09

3

1008

3.5

05-MAR-09

05-MAR-09

3

1009

3.5

05-MAR-09

3

1001

34366

3.5

04-MAR-09

02-MAR-09

3

DETAILRENTAL

Vid_Num

Detail_Fee

Detail_Duedate

Detail_Returndate

Detail_Dailylatefee

34342

2

04-MAR-09

1

61353

59237

3

.5

54325

09-MAR-09

61369

06-MAR-09

61388

44392

05-MAR-09

07-MAR-09

34367

34341

44397

34366

61367

34368

34369

54324

Vid_Num

54324

18-JUN-08

1234

54325

18-JUN-08

1234

34341

34342

22-JAN-07

1235

34366

02-MAR-09

34367

02-MAR-09

1236

34368

02-MAR-09

1236

34369

02-MAR-09

1236

44392

44397

21-OCT-08

1237

59237

1237

61388

61353

28-JAN-06

1245

61367

61369

30-JUL-08

1246

VIDEO

Vid_Indate

Movie_Num

54321

18-JUN-08

1234

22-JAN-07

1235

1236

21-OCT-08

1237

14-FEB-09

25-JAN-07

1239

28-JAN-06

1245

61354

30-JUL-08

1246

Movie_Num

1234

2

1235

1

1236

59.95

2

1237

2007

2

2008

DRAMA

2

1239

DRAMA

3

1245

ACTION

1

1246

COMEDY

1

MOVIE

Movie_Name

Movie_Year

Movie_Cost

Movie_Genre

Price_Code

The Cesar Family

Christmas

2007

39.95

FAMILY

Smokey Mountain Wildlife

2004

59.95

ACTION

Richard Goodhope

2008

DRAMA

Beatnik Fever

29.95

COMEDY

1238

Constant Companion

89.95

Where Hope Dies

1998

25.49

Time to Burn

2005

45.49

What He Doesn’t Know

2006

58.29

Price_Code

1

2

1

2

3.5

3

3

1

1

PRICE

Price_Description

Price_Rentfee

Price_Dailylatefee

Standard

New Release

Discount

1.5

4

Weekly Special

.5

For questions 3– 19, use the tables that were created in Problem 1 and the data that was loaded into those tables in Problem 2.

3. Write the SQL command to change the movie year for movie number 1245 to 2006.

4. Write the SQL command to change the price code for all Action movies to price code 3.

5. Write a single SQL command to increase all price rental fee values by $0.50.

6. Write a query to display the movie title, movie year, and movie genre for all movies sorted by movie genre in ascending order, then sorted by movie year in descending order within genre (result shown in Figure 2).

Figure 2 Movies with multicolumn sort

7. Write a query to display the movie number, movie title, and price code for all movies with a title that starts with the letter “R” (result shown in Figure 3).

Figure 3 Movies starting with R

8. Write a query to display the movie title, movie year, and movie cost for all movies that contain the word “hope” anywhere in the title. Sort the results in ascending order by title (result shown in figure 4).

Figure 4 Movies with “Hope” in the title

9. Write a query to display the movie title, movie year, and movie genre for all action movies (result shown in Figure 5).

Figure 5 Action movies

10. Write a query to display the movie number, movie title, movie cost, and movie genre for movies that are either action or comedy movies and movies that have a cost that is less than $50. Sort the results in ascending order by genre. (Result shown in Figure 6.)

Figure 6 Action or comedy movies costing less than $50

11. Write a query to display the movie genre and the number of movies in each genre (result shown in Figure 7).

Figure 7 Number of movies in genre

12. Write a query to display the movie genre and average cost of movies in each genre (result shown in Figure 8).

Figure 8 Average movie cost by genre

13. Write a query to display the movie title, movie genre, price description, and price rental fee for all movies with a price code (result shown in Figure 9).

Figure 9 Rental fees for movies

Movie_Genre

Price_Rentfee

What He Doesn’t Know

COMEDY

Standard

The Cesar Family Christmas

FAMILY

New Release

4

Richard Goodhope

DRAMA

New Release

4

Beatnik Fever

COMEDY

New Release

4

Constant Companion

DRAMA

New Release

4

Smokey Mountain Wildlife

ACTION

Discount

2

Where Hope Dies

DRAMA

Discount

2

Time to Burn

ACTION

Discount

2

Movie_Title

Price_Descriptioin

2.5

14. Write a query to display the movie title, movie year, and movie cost for all movies that have a cost between $44.99 and $49.99 (result shown in Figure 10).

Figure 10 Movies costs within a range

15. Write a query to display the movie title, movie year, price description, and price rental fee for all movies that are in the genres Family, Comedy, or Drama (result shown in Figure 11).

Figure 11 Movies with specific genres

Movie_Title

Movie_Year

Price_Rentfee

Movie_Genre

2007

New Release

4

FAMILY

Richard Goodhope

2008

New Release

4

DRAMA

Beatnik Fever

2007

New Release

4

COMEDY

Constant Companion

2008

New Release

4

DRAMA

Where Hope Dies

1998

Discount

2

DRAMA

What He Doesn’t Know

2006

Standard

2.5

COMEDY

Price_Desciption

The Cesar Family

16. Write a query to display the minimum balance, maximum balance, and average balance for memberships that have a rental (result shown in Figure 12).

Figure 12 Minimum, maximum, and average balances

0

15

MINIMUM_BALANCE

MAXIMUM_BALANCE

AVERAGE_BALANCE

6.43

17. Write a query to display the rental number, rental date, video number, movie title, due date, and return date for all videos that were returned after the due date. Sort the results by rental number and movie title (result shown in Figure 13).

Figure 13 Late video returns

18. Write a query to display the rental number, rental date, movie title, and detail fee for each movie that was returned on or before the due date (result shown in Figure 14).

Figure 14 Actual rental fees charged

19. Write a query to display the membership number, last name, and total rental fees earned from that membership (result shown in Figure 15). The total rental fee is the sum of all of the detail fees (without the late fees) from all movies that the membership has rented.

Figure 15 Total rental fees paid by membership

What Will You Get?

We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.

Premium Quality

Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.

Experienced Writers

Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.

On-Time Delivery

Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.

24/7 Customer Support

Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.

Complete Confidentiality

Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.

Authentic Sources

We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.

Moneyback Guarantee

Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.

Order Tracking

You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.

image

Areas of Expertise

Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.

Areas of Expertise

Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.

image

Trusted Partner of 9650+ Students for Writing

From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.

Preferred Writer

Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.

Grammar Check Report

Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.

One Page Summary

You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.

Plagiarism Report

You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.

Free Features $66FREE

  • Most Qualified Writer $10FREE
  • Plagiarism Scan Report $10FREE
  • Unlimited Revisions $08FREE
  • Paper Formatting $05FREE
  • Cover Page $05FREE
  • Referencing & Bibliography $10FREE
  • Dedicated User Area $08FREE
  • 24/7 Order Tracking $05FREE
  • Periodic Email Alerts $05FREE
image

Our Services

Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.

  • On-time Delivery
  • 24/7 Order Tracking
  • Access to Authentic Sources
Academic Writing

We create perfect papers according to the guidelines.

Professional Editing

We seamlessly edit out errors from your papers.

Thorough Proofreading

We thoroughly read your final draft to identify errors.

image

Delegate Your Challenging Writing Tasks to Experienced Professionals

Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!

Check Out Our Sample Work

Dedication. Quality. Commitment. Punctuality

Categories
All samples
Essay (any type)
Essay (any type)
The Value of a Nursing Degree
Undergrad. (yrs 3-4)
Nursing
2
View this sample

It May Not Be Much, but It’s Honest Work!

Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.

0+

Happy Clients

0+

Words Written This Week

0+

Ongoing Orders

0%

Customer Satisfaction Rate
image

Process as Fine as Brewed Coffee

We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.

See How We Helped 9000+ Students Achieve Success

image

We Analyze Your Problem and Offer Customized Writing

We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.

  • Clear elicitation of your requirements.
  • Customized writing as per your needs.

We Mirror Your Guidelines to Deliver Quality Services

We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.

  • Proactive analysis of your writing.
  • Active communication to understand requirements.
image
image

We Handle Your Writing Tasks to Ensure Excellent Grades

We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.

  • Thorough research and analysis for every order.
  • Deliverance of reliable writing service to improve your grades.
Place an Order Start Chat Now
image

Order your essay today and save 30% with the discount code Happy