Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Question 1 --
- SELECT Rental.rentalID, Make.carMakeName, Model.carModelName
- FROM Rental
- INNER JOIN Car ON Car.carID = Rental.carID
- INNER JOIN Car_Model AS Model ON Car.carModelID = Model.carModelID
- INNER JOIN Car_Make AS Make ON Model.carMakeID = Make.carMakeID;
- -- This join could be used to check what the most common cars rented in order to make future
- -- purchase decisions
- -- Question 2 --
- CREATE PROC FordReturnDates
- AS
- SELECT Rental.rentalID, Make.carMakeName, Rental.dueDate
- FROM Rental
- INNER JOIN Car ON Car.carID = Rental.carID
- INNER JOIN Car_Model AS Model ON Car.carModelID = Model.carModelID
- INNER JOIN Car_Make AS Make ON Model.carMakeID = Make.carMakeID
- WHERE Make.carMakeName LIKE 'Ford';
- EXEC dbo.FordReturnDates;
- -- This Stored Procedure can be used to return the due dates of all Fords currently rented.
- -- This is useful if a customer is requesting a Ford Vehicle for an upcoming trip
- -- Question 3 --
- DECLARE @CustomerBirthday as DATE;
- DECLARE @BirthdayCursor as CURSOR;
- SET @BirthdayCursor = CURSOR FOR
- SELECT birthDate
- FROM Customer
- WHERE birthDate IS NULL;
- OPEN @BirthdayCursor;
- FETCH NEXT FROM @BirthdayCursor INTO @CustomerBirthday;
- WHILE @@FETCH_STATUS = 0
- BEGIN
- PRINT @CustomerBirthday;
- FETCH FROM @BirthdayCursor INTO @CustomerBirthday
- END
- CLOSE @BirthdayCursor;
- DEALLOCATE @BirthdayCursor;
- -- This cursor can be used to check that all customers have the birthdate field filled in.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement