Marcus Matthews

873 views
810 views

Published on

Snapshots of my work while attending the Set Focus Master\'s Program

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
873
On SlideShare
0
From Embeds
0
Number of Embeds
24
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Marcus Matthews

  1. 1. SQL Portfolio<br />Marcus Matthews<br />marcusmatthews@setfocus.com<br />http://www.linkedin.com/in/marcuswmatthews<br />
  2. 2. Table of Contents<br />Introduction 2<br />Jungle Books 3<br />Library 7<br />Piggy Bank 11<br />Block Flix 19<br />
  3. 3. Introduction<br />This portfolio contains examples of my development skills in MS SQL Server. It is a result of my work during an 8-week hands-on experience with The SetFocus Master's Program.<br />SetFocus utilizes Microsoft Official Curriculum in conjunction with its own materials to produce some of the following coursework:<br />RDBMS and XML<br />Querying using Transact SQL<br />Implementing and maintaining a MS SQL Server 2008 Database<br />Designing an MS SQL Server 2008 Infrastructure<br />Designing security for MS SQL Server 2008<br />Designing High Availability Database Solutions using MS SQL Server 2008<br />Troubleshooting and Optimizing Database Solutions using MS SQL Server 2008<br />SQL Server Integration Services <br />SQL Server reporting Services<br />In addition to the coursework and programming labs, the program included challenging real-world projects where I have applied the skills experienced in class. <br />
  4. 4. Jungle Books<br />Jungle Books is company which uses a database to store data for books, authors, customers that purchase these items and order records.<br />This database diagram was used to create the database and show the relationship between entities within it. <br />The application developer that we are working with fictitiously will use this design for a client application using .NET.<br />
  5. 5. Jungle Books<br />SELECT [o].[OrderID] AS 'Order ID'<br />,[o].[CustomerID] AS 'Cust ID'<br />,c.Name<br />,(SELECT SUM([oi].[QuantityOrdered])) AS '# of items'<br />FROM [Orders] o <br />JOIN [OrderItems] oi<br />ON oi.OrderID = o.OrderID<br />JOIN Customers AS c<br />ON c.CustomerID = o.CustomerID<br />GROUP BY o.OrderID, o.CustomerID, c.Name<br />Order BY (SELECT SUM([oi].[QuantityOrdered])) desc;<br /> The select statement for the Large Orders report is used to return orders from the Jungle Books' database that contain the highest number of items sold per order, OrderID, CustomerID, Customer Name and the items within their order. The result set is displayed in descending order listing the order with the largest quantity first. <br />
  6. 6. Jungle Books<br /> The report named Expired Cards is a select statement used to generate a list of customers whose credit cards have expired and those that will expire within 30 days. <br />SELECT CustomerID AS 'ID', [Name], expiryDate AS 'Expires'<br />FROM customers WHERE expirydate < (getDate() +30)<br />
  7. 7. Library<br />The Library Database is designed to maintain records of the day-to-day lending operations such: items available or on loan, overdue books, fees, member information, and reservations. <br /> This database has been used for number of projects:<br />Create queries against the Library Database to return results using UNION and several join types.<br />Search for book titles, by name, ISBN, and author. <br />Create new member accounts for juveniles and adults. Set up a reservation for an item that is currently unavailable to loan once it has been returned.<br />
  8. 8. Library<br />ER Diagram<br />
  9. 9. Library<br />SELECT lh.member_no, m.lastname, m.firstname, SUM(lh.fine_paid) AS "Fines Paid" <br />from loanhistlh<br />INNER JOIN member m ON lh.member_no = m.member_no<br />GROUP BY lh.member_no, m.lastname, m.firstname<br />HAVING SUM(lh.fine_paid) IS NOT NULL<br />ORDER BY SUM(lh.fine_paid) DESC, lh.member_no<br />
  10. 10. Library<br />SELECT r.isbn, t.title, m.member_no, m.lastname, 'adult' AS [member_type]<br />FROM member m <br />INNER JOIN reservation r ON r.member_no = m.member_no<br />INNER JOIN item i ON i.isbn = r.isbn<br />INNER JOIN title t ON t.title_no = i.title_no<br />INNER JOIN adult a ON a.member_no = m.member_no<br />WHERE r.isbn = 288<br />UNION<br />SELECT r.isbn, t.title, m.member_no, m.lastname, 'juvenile' AS [member_type]<br />FROM member m <br />INNER JOIN reservation r ON r.member_no = m.member_no<br />INNER JOIN item i ON i.isbn = r.isbn<br />INNER JOIN title t ON t.title_no = i.title_no<br />INNER JOIN juvenile j ON j.member_no = m.member_no<br />WHERE r.isbn = 288<br />GROUP BY r.isbn, t.title, m.member_no, m.lastname<br />ORDER BY [member_type]<br />
  11. 11. Piggy Bank<br />The Piggy Bank Database is used to simulate the daily operations of a financial institution, providing its user access to their personal information and manage accounts.<br />This database has been used for a number of projects:<br />Using stored procedures this database is capable of accounting for typical banking transactions, such as deposits, funds withdrawal, account transfers or if you are a new customer, create a new account. <br />Update account information capabilities to change an address, add another account or member to an existing account transaction history.<br />
  12. 12. Piggy Bank<br />ER Diagram<br />
  13. 13. Piggy BankCreate new customer Stored procedure <br />SET ANSI_NULLS ON<br />GO<br />SET QUOTED_IDENTIFIER ON<br />GO<br />/*<br />written by: Marcus Matthews<br />Date: 05/10/2010<br />Errors<br />'Last name cannot be null', 11, 1<br />'First name cannot be null', 11, 2<br />'Street cannot be null', 11, 3<br />'City cannot be null', 11, 4<br />'State cannot be null', 11, 5<br />'Zip code cannot be null', 11, 6<br />'Home Phone number cannot be null', 11, 7<br />*/<br />CREATE PROCEDURE [dbo].[usp_CreateNewCustomer]<br />@CustomerLastName nvarchar(20)=null,<br />@CustomerFirstName nvarchar(20)=null,<br />@CustomerMiddleName nvarchar(20)=null,<br />@Street nvarchar(50) =null,<br />@City nvarchar(20) =null, <br />@State nchar(2) =null,<br />@ZipCode nvarchar(10) =null,<br />@Email nvarchar(50) =null,<br />@HomePhone nvarchar(15) =null,<br />@WorkPhone nvarchar(15) =null,<br />@CellPhone nvarchar(15) =null<br />AS<br />BEGIN TRY<br />
  14. 14. Piggy BankCreate new customer Stored procedure (cont.) <br />-- Test parameters. All required fields must have a value, only test those that do not allow nulls<br />If @CustomerLastName is null<br /> BEGIN<br /> RAISERROR ('Last name cannot be null', 11, 1)<br /> END<br />If @CustomerFirstName is null<br /> BEGIN<br /> RAISERROR ('First name cannot be null', 11, 2)<br /> END<br />If @Street is null<br /> BEGIN<br /> RAISERROR ('Street cannot be null', 11, 3)<br />END<br />If @City is null<br /> BEGIN<br /> RAISERROR ('City cannot be null', 11, 4)<br /> END<br />If @State is null<br /> BEGIN<br /> RAISERROR ('State cannot be null', 11, 5)<br /> END<br />If @ZipCode is null<br /> BEGIN<br /> RAISERROR ('Zip code cannot be null', 11, 6)<br /> END<br />
  15. 15. Piggy Bank Create new customer Stored procedure (cont.) <br />If @HomePhone is null<br /> BEGIN<br /> RAISERROR ('Home Phone number cannot be null', 11, 7)<br /> END<br />--Create customer and insert data <br />BEGIN<br /> INSERT INTO dbo.Customer (<br /> CustomerFirstName,<br /> CustomerLastName,<br /> CustomerMiddleName,<br /> Street,<br /> City,<br /> [State],<br /> ZipCode,<br /> Email, <br />HomePhone,<br /> WorkPhone, <br /> CellPhone <br /> )<br /> VALUES (<br /> @CustomerFirstName,<br /> @CustomerLastName,<br /> @CustomerMiddleName,<br /> @Street,<br /> @City,<br /> @State,<br /> @ZipCode,<br /> @Email, <br /> @HomePhone,<br /> @WorkPhone, <br /> @CellPhone <br /> )<br />
  16. 16. Piggy Bank Create new customer Stored procedure (cont.) <br />END<br />RETURN<br />END TRY<br />BEGIN CATCH<br /> -- IF @@TRANCOUNT > 0<br /> -- ROLLBACK TRAN<br /> DECLARE @ErrorMessage NVARCHAR(4000);<br /> DECLARE @ErrorSeverity INT;<br /> DECLARE @ErrorState INT;<br /> SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(), <br /> @ErrorState = ERROR_STATE();<br /> RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState);<br />END CATCH<br />GO <br />
  17. 17. Piggy BankAccount Balance Stored procedure <br />GO<br />SET ANSI_NULLS ON<br />GO<br />SET QUOTED_IDENTIFIER ON<br />GO<br />/*This stored procedure is used to return the current account balance and last 5 transactions. Error messages for omitted data in required fields. <br />written by: Marcus Matthews<br />Date: 05/15/2010<br />Errors<br />'Customer ID cannot be null', 11, 1<br />'Account ID cannot be null', 11, 2<br />'Account numbers provided do not match', 11, 3<br />*/<br />CREATE PROCEDURE [dbo].[GetBalance] <br />@CustomerID int =null,<br />@AccountIDint =null<br />AS<br />BEGIN TRY<br />If @CustomerID is null<br /> BEGIN<br /> RAISERROR ('Customer ID cannot be null', 11, 1)<br /> END<br />If @AccountID is null<br /> BEGIN<br /> RAISERROR ('Account ID cannot be null', 11, 2)<br /> END<br />
  18. 18. Piggy BankAccount Balance Stored procedure (cont.) <br />-- Make sure accounts match<br />IF EXISTS(SELECT a.AccountID FROM Account a<br /> JOIN CustomerAccount ca<br /> ON ca.AccountID = a.AccountID<br /> JOIN Customer c<br /> ON c.CustomerID = ca.CustomerID<br /> WHERE a.AccountID = @AccountID<br /> )<br />-- Make sure accounts match<br />IF EXISTS(SELECT a.AccountID FROM Account a<br /> JOIN CustomerAccount ca<br /> ON ca.AccountID = a.AccountID<br /> JOIN Customer c<br /> ON c.CustomerID = ca.CustomerID<br /> WHERE a.AccountID = @AccountID<br /> )<br />-- shows current balance with last 5 transactions.<br />BEGIN<br /> SELECT DISTINCT TOP(5) c.CustomerID,<br />a.CurrentBalance, t.transactionID, t.transactionDate, t.TransactionAmount<br /> FROM Account a<br /> JOIN [Transaction] t<br /> ON t.AccountID = a.AccountID<br /> JOIN Customer c<br /> ON c.customerID= t.CustomerID<br /> WHERE a.accountID = @AccountID<br /> AND c.CustomerID = @CustomerID<br />END<br />
  19. 19. Piggy BankAccount Balance Stored procedure (cont.)<br />ELSE <br /> BEGIN<br /> RAISERROR ('Account numbers provided do not match', 11, 3)<br /> END<br />RETURN<br />END TRY<br />BEGIN CATCH<br /> DECLARE @ErrorMessage NVARCHAR(4000);<br /> DECLARE @ErrorSeverity INT;<br /> DECLARE @ErrorState INT;<br /> SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(), <br /> @ErrorState = ERROR_STATE();<br /> RAISERROR (@ErrorMessage, <br />@ErrorSeverity, @ErrorState);<br />END CATCH<br />GO<br />
  20. 20. Brian Henry<br />Marcus Matthews<br />Robert Parkin<br />BlockFlix Project<br />
  21. 21. Database Design<br />
  22. 22. XML Data<br />Original XML<br />Modified XML<br />There were a couple issues we had to overcome to process the XML.<br />One of the challenges of processing the XML was formatting it properly and creating a schema.<br />Another problem we had to overcome was entering the quantity of the movie into our Inventory Table. This was done by using a OLE DB Command Transformation and calling a proc (LoadMovieInventory) to insert records in a While Loop until it looped the appropriate amount of times.<br />
  23. 23. Loading Genre Data (SSIS)<br />Raw Data<br />Data in the Genre Table<br />
  24. 24. Load Inventory/Talent SSISAlso used SSIS to load all Base Tables<br />
  25. 25. Checking Out an Online Movie<br />Member David Smith checks out movie Dark Knight<br />(MemberID 2, MovieID 5, InventoryID 50)<br />Rental Transaction Tables:<br />
  26. 26. Checking Out a Movie (Cont.)<br />Current Member Queue (GetMemberQueView)<br />When Member returns Dark Night they will receive Saving Private Ryan. <br />
  27. 27. Returning a Movie<br />David Smith (2) returns (2) the movie Dark Knight (50)<br />Rental Transactions<br />Showing return of Dark Knight (50) and Shipment (1) of Saving Private Ryan (20)<br />
  28. 28. Returning a Movie (Cont.)<br />Member Transaction<br />Showing return of Dark Knight and Shipment of Saving Private Ryan<br />
  29. 29. Returning a Movie (Cont.)<br />Movie Inventory for Dark Knight<br />Showing Available (1)<br />
  30. 30. Returning a Movie (Cont.)<br />Member Queue<br />Remains the same… when Saving Private Ryan is returned Gold Finger will be shipped. <br />
  31. 31. Returning a Movie Continued<br />When Saving Private Ryan was returned, it was deleted from the queue.<br />
  32. 32. Movies Checked Out By Store<br />exec uspGetCheckedOutByStore 1<br />
  33. 33. Available Inventory By Store<br />exec uspGetInvByStore 1<br />
  34. 34. Update Member StatususpMembershipUpgrade<br />Pre-Update<br />Post Update<br />
  35. 35. Update Movie Queue uspUpdateMemberQue<br />Pre-Update<br />Judith Hayward<br />Only has Goldfinger<br />Post-Update<br />Judith Hayward<br />added FrankensteinWill not allow movie <br /> to be in the queue more than once<br />
  36. 36. Monthly Member Debit/Credit<br />uspMonthlyMemberDebit<br />uspMonthlyMemberCredit<br />uspGetMemberTransactions (Lookup)<br />TransTypeID 4 is Debit<br />TransTypeID 3 is Credit<br />
  37. 37. Lost/Damage FunctionalityuspCreateLostDamagedTransaction<br />Pre-Damage – Movie is checked out<br />Movie Rental Transaction<br />Damage Report – Movie is Lost/Damaged<br />
  38. 38. Lost/Damage Functionality (Cont.)<br />Member Transactions showing fine of $4.99<br />LostDamaged Table<br />
  39. 39. Inactivate Member if Balance Over Due<br />uspInactivateMemberIfOverdue<br />Member’s account is over due<br />Now the Member’s account is inactive.<br />
  40. 40. Membership Report<br />
  41. 41. Most Rented Movies<br />
  42. 42. Lost or Damaged Movies<br />
  43. 43. Most Active Customers<br />
  44. 44. Most Rented Movies<br />
  45. 45. Reports on the Report Server<br />
  46. 46. Database Backup (Cont.)<br />
  47. 47. Database Backup<br />
  48. 48. Online Streaming Proposal<br /><ul><li>Security is a high priority due to access over the internet (for both ourselves and our customers)
  49. 49. Create Database to track usage
  50. 50. Master List of Movies as only one movie is needed for download
  51. 51. Possibly offer unlimited usage per month for mailing members and one time usage fees for non-members
  52. 52. Possibly offer an Online Only Member Status with its own fees
  53. 53. Genre/Talent preference list for customer</li></li></ul><li>Phase II<br /><ul><li>Due to time constraints and team size only the Online portion was completed.
  54. 54. We have already designed and created the databases for the In-Store Retail Sales and Kiosks.
  55. 55. Stored Procedures, Report Packages, SSIS Packages, Test Data are currently in the development phase.</li>

×