Your SlideShare is downloading. ×
SQL Server 2008 Portfolio
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

SQL Server 2008 Portfolio

749

Published on

SQL Server 2008 Portfolio

SQL Server 2008 Portfolio

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

  • Be the first to like this

No Downloads
Views
Total Views
749
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1.
    • SQL Portfolio
    • Anthony Feliciano
    • [email_address]
    • (831) 295-4440
  • 2. Table of Contents
    • What is SetFocus ?
    • Transact-SQL samples: Pivot and CTE
    • SSMS Project “Piggy Bank”
      • Diagram and Withdrawal Stored Procedure
    • SSIS /SSRS Project “MiniAdventureWorks”
      • Data and Control Flows, Matrix Report
      • SSRS Report with Gauge
    • Final Project “BlockFlix”
      • Database Diagram, Control and Data Flows, Stored Procedures and Streaming Video Proposal
  • 3. What is SetFocus?
    • The SetFocus SQL Master’s Program is an intensive, hands–on, project-oriented program that combines knowledge and valuable experience in putting the SQL skill set to use in a simulated work environment.
    • I received almost 320 hours of in-depth hands on experience which focused on T-SQL Development, SSIS and SSRS Packages.
    • SetFocus projects are real world projects that are just like those I would receive in a position. I received project specifications and was expected to identify best courses of action within very tight deadlines for completion.
  • 4. Transact-SQL: A Pivot Sample
    • use AdventureWorks2008
    • GO
    • -- We want to take the orders in 2003, group them by Vendor and by Month
    • -- We can use the PIVOT statement to convert rows to analytic columns
    • -- First we'll retrieve Orders from 2003 and place into a CTE
    • WITH OrdCTE AS (
    • SELECT VendorID, Name As VendorName, DatePart(m,OrderDate) AS OrderMonth, POHdr.TotalDue
    • FROM Purchasing.PurchaseOrderHeader POHdr
    • join Purchasing.Vendor ON Vendor.BusinessEntityID = POHdr.VendorID
    • where YEAR(OrderDate) = 2003 )
    • -- Now we'll query the CTE, and use a PIVOT statement
    • SELECT VendorID, VendorName, [1] AS Jan, [2] AS Feb, [3] AS Mar, [4] AS Apr, [5] AS May, [6] AS June, [7] AS July, [8] AS Aug, [9] AS Sep, [10] AS Oct, [11] AS Nov, [12] AS Dec FROM OrdCTE
    • -- we take each of the 12 possible values and associate them with 12 buckets
    • PIVOT (SUM(TotalDue) FOR OrderMonth IN ( [1],[2],[3],[4],
    • [5], [6], [7], [8], -- Note, these 12 values are static
    • [9], [10], [11], [12] ) ) as TempList -- We'd need to use dynamic SQL if they weren't
  • 5. Transact-SQL: CTE example
    • A Common Table Expression is a temporary named result set which is later used in a query
    • Once it’s used, it’s gone
    • USE AdventureWorks2008
    • GO
    • -- Put all vendors with a Credit Rating of 2 into one CTE
    • -- Put all orders with a line item unit price > 25 in another CTE
    • ;WITH VendorCTE AS
    • (SELECT Vendor.AccountNumber, Vendor.BusinessEntityID, Vendor.Name
    • FROM Purchasing.Vendor WHERE CreditRating = 2) ,
    • OrderCTE AS
    • (SELECT VendorID, SUM(TotalDue) AS SumTotalDue
    • FROM Purchasing.PurchaseOrderHeader POH
    • JOIN Purchasing.PurchaseOrderDetail POD ON POH.PurchaseOrderID = POD.PurchaseOrderID
    • WHERE UnitPrice > 25.00
    • GROUP BY VendorID)
    • -- And then query against them
    • SELECT VendorCTE.AccountNumber, VendorCTE.Name, SumTotalDue
    • FROM VendorCTE
    • JOIN OrderCTE ON VendorCTE.BusinessEntityID = OrderCTE.VendorID
    • ORDER BY SumTotalDue DESC
  • 6. Bookstore Database Diagram
  • 7. User Defined Function sample using Cross Apply
    • -- Create a User Defined Function that gets the top N books for a customer for a year (2007)
    • -- First, create a Table-Valued Function GetTopNBooksByCustomer that would perform the RANKING on the inside...just for the one customer
    • -- We could do a TOP N and A RANK in the TVF...just for one customer
    • -- Run that TVF and apply it to every customer by using a CROSS APPLY against DimCustomers BookSales;
    • use BookSales
    • GO
    • ALTER FUNCTION dbo.TopNSalesbyCustomer
    • (@CustomerPk int,@N int)
    • RETURNS TABLE
    • AS
    • RETURN
    • SELECT TOP (@N) C.CustomerName as Customer, B.BookName as BookName, SUM(FSB.SalesDollars) TotalDollars
    • from DimCustomers C, FactBookSales FSB, DimDates D, DimBooks B, DimBookPrice P
    • where D.DatePK = FSB.DatePK and
    • FSB.CustomerPK = C.CustomerPK and
    • FSB.BookPricePK = P.BookPricePK and
    • P.BookTitlePK = B.BookTitlePK
    • and DATEPART(YEAR, ActualDate) = 2007
    • and C.CustomerPk = @CustomerPK
    • group by C.CustomerName, B.BookName
    • GO
    • SELECT CustomerName, X.Bookname, X.TotalDollars
    • from DimCustomers
    • cross apply dbo.TopNSalesbyCustomer(DimCustomers.CustomerPK,5) as X
    • ORDER BY CustomerName, TotalDollars desc;
  • 8. “ PiggyBank” Project
    • Introduction: A real world, transaction-based application where T-SQL and SSMS are used extensively to carry out a retail bank’s mission-critical operations, among others
    • Project Goal: Build a retail banking application
    • using the tools available in SQL Server 2008
    • Audience: Bank President, Vice-Presidents, Managers and Tellers, Security Administrators
  • 9. Database Diagram for PiggyBank
  • 10. Stored Procedure: Withdrawal transaction
    • -- Author: <Anthony Feliciano>
    • -- Create date: <26-July.2010>
    • -- Description: <Withdrawal Procedure>
    • --Applicable for:
    • -- Cash Withdrawals <Transaction 3>
    • -- Transfer Withdrawals <Transaction 4>
    • -- Debit Purchases <Transaction 6>
    • -- Checks <Transaction 7>
    • -- =============================================
    • -- ================================================
    • -- =============================================
    • -- Withdrawal business rules Procedure for PIGGY BANK, N. A. application
    • -- 1. Upon presentation of a valid ATM card the procedure will validate the amount requested for withdrawal.
    • -- 2. When prompted, the customer will indicate whether the WITHDRAWAL is meant for checking or savings.
    • -- 3. The procedure will check if the customer has an active account.
    • -- 4. If the requested target account is active, the transaction amount will be compared against the available balance.
    • -- 5. If deducting the requested withdrawal amt results in a negative balance the procedure will check see if there is enough money
    • -- in the linked account to accommodate the withdrawal.
    • -- 6. If there are available funds in the linked account, and the resulting balance does not go below 0.00 in the linked account,
    • -- the withdrawal will go through and a fee of $10.00 will be assessed to the originating account.
    • -- 7. If there are no linked accounts, the procedure will verify if the account has a general overdraft &quot;credit line&quot;.
    • -- If this General Overdraft account is present, and the resulting balance in the General Overdraft does not go below -400.00, the withdrawal will ----- be allowed. For this type of coverage, a $30 fee will be assessed.
    • -- 8. In either type of overdraft coverage, the fee will appear as a separate transaction.
    • -- 9. NOTE: For this project, all transactions that withdraw money from an account (i.e.,
    • --- Cash at an ATM, Debit Purchase or Check - will be treated the same.
    • -- =============================================
  • 11. Withdrawal transaction: p.2
    • CREATE PROCEDURE dbo.Withdrawal
    • -- All these parameters can be supplied in just one data entry screen --
    • @CustomerId int = NULL,
    • @AccountID int = NULL,
    • @AccountTypeId tinyint = NULL,
    • @TransactionType tinyint = NULL,
    • @TransactionAmount money = NULL
    • AS
    • SET NOCOUNT ON
    • BEGIN TRY
    • -- Validate the CustomerAccountId first
    • if NOT EXISTS (SELECT * FROM dbo.CustomerAccount
    • WHERE CustomerID = @CustomerId
    • and AccountID = @AccountID)
    • BEGIN
    • raiserror('CustomerId and Account Invalid',11,1)
    • END
    • -- Check to see if AccountTypeId exists in the Account Table
    • if NOT EXISTS (SELECT * FROM dbo.Account
    • WHERE AccountID = @AccountID
    • AND AccountTypeId = @AccountTypeId)
    • BEGIN
    • raiserror ('Invalid Account Type',11,2)
    • END
  • 12. Transaction Withdrawal: p.3
    • -- Check to see if Account is Active and allows withdrawals --
    • if (SELECT AccountStatusId FROM dbo.Account
    • WHERE AccountID = @AccountID) = 2
    • BEGIN
    • raiserror ('Withdrawal not allowed for this account',11,3)
    • END
    • -- Check to see if there are available funds in the Primary Account --
    • declare @resulting_bal money
    • declare @current_bal money
    • set @current_bal = (SELECT CurrentBalance from dbo.Account
    • WHERE AccountID = @AccountID)
    • set @resulting_bal = @current_bal - @TransactionAmount
    • if @resulting_bal < 0.00
    • BEGIN
    • declare @OD_Account int
    • set @OD_Account = (SELECT OverdraftAccountID from dbo.Account
    • where AccountID = @AccountID)
    • if @OD_Account IS NULL
    • BEGIN --do this
    • if (SELECT GeneralOverdraft from dbo.Account
    • where AccountID = @AccountID) = 0 /* 0 = no General Overdraft
    • 1 there is $400 credit */
    • BEGIN
    • raiserror ('No Linked Account NOR General Overdraft Account',11,4)
    • raiserror ('Withdrawal Refused',11,5)
    • END
    • else
  • 13. Transaction withdrawal: p.4
    • BEGIN
    • set @resulting_bal = 400.00 - @TransactionAmount
    • if @resulting_bal < 0.00
    • BEGIN
    • raiserror ('Not enough money to cover withdrawal',11,5)
    • END
    • else
    • BEGIN
    • INSERT INTO dbo.Transactions
    • (AccountId,
    • TransactionTypeID,
    • CustomerId,
    • TransactionDate,
    • TransactionAmount,
    • NewBalance)
    • VALUES
    • (@AccountID,
    • @TransactionType,
    • @CustomerId,
    • GETDATE(),
    • @TransactionAmount,
    • @resulting_bal)
    • declare @NewBalance money
    • declare @GeneralOverdraftFee money = 30.00
    • set @NewBalance = @current_bal - @GeneralOverdraftFee
  • 14. Withdrawal Transaction: p.5
    • INSERT into dbo.Transactions
    • (AccountId,
    • TransactionTypeID,
    • CustomerId,
    • TransactionDate,
    • TransactionAmount,
    • NewBalance)
    • VALUES
    • (@AccountID,
    • @TransactionType,
    • @CustomerId,
    • GETDATE(),
    • @GeneralOverdraftFee,
    • @NewBalance)
    • UPDATE dbo.Account
    • set CurrentBalance = CurrentBalance - @GeneralOverdraftFee
    • where AccountID = @AccountID
    • END
    • END
    • END
    • else
  • 15. Withdrawal Transaction: p.6
    • BEGIN
    • declare @OverdraftAccountBalance money
    • declare @OverdraftAccountResultingBal money
    • declare @OverdraftAccountId int
    • set @OverdraftAccountId = (SELECT OverdraftAccountID from dbo.Account
    • WHERE AccountID = @AccountID)
    • set @OverdraftAccountBalance = (SELECT CurrentBalance from dbo.Account
    • WHERE AccountID = @OverdraftAccountId)
    • set @OverdraftAccountResultingBal = @OverdraftAccountBalance - @TransactionAmount
    • if @OverdraftAccountResultingBal < 0.00
    • BEGIN
    • raiserror ('Amount Insufficient for Withdrawal,',11,6)
    • raiserror ('Debit Purchases or Checks',11,7)
    • END
    • else
    • BEGIN
    • UPDATE dbo.Account
    • set CurrentBalance = CurrentBalance - @TransactionAmount
    • where AccountID=@OverdraftAccountId
    • INSERT INTO dbo.Transactions
    • (AccountId,
    • TransactionTypeID,
    • CustomerId,
    • TransactionDate,
    • TransactionAmount,
    • NewBalance)
  • 16. Withdrawal Transaction: p.7
    • VALUES
    • (@OverdraftAccountId, /* NOT the Primary Account! */
    • @TransactionType,
    • @CustomerId,
    • GETDATE(),
    • @TransactionAmount,
    • @OverdraftAccountResultingBal)
    • declare @OverdraftFee money = 10.00
    • set @NewBalance = @current_bal - @OverdraftFee
    • INSERT into dbo.Transactions
    • (AccountId,
    • TransactionTypeID,
    • CustomerId,
    • TransactionDate,
    • TransactionAmount,
    • NewBalance)
    • VALUES
    • (@AccountID,
    • @TransactionType,
    • @CustomerId,
    • GETDATE(),
    • @OverdraftFee,
    • @NewBalance)
    • UPDATE dbo.Account
    • set CurrentBalance = CurrentBalance - @OverdraftFee where AccountID = @AccountID
    • END
    • END
    • END
  • 17. Withdrawal Transaction: p.8
    • else
    • BEGIN
    • INSERT INTO dbo.Transactions
    • (AccountId,
    • TransactionTypeID,
    • CustomerId,
    • TransactionDate,
    • TransactionAmount,
    • NewBalance)
    • VALUES
    • (@AccountID,
    • @TransactionType,
    • @CustomerId,
    • GETDATE(),
    • @TransactionAmount,
    • @resulting_bal)
    • UPDATE dbo.Account
    • set CurrentBalance = CurrentBalance - @TransactionAmount
    • where AccountID = @AccountID
    • END
    • END TRY
    • BEGIN CATCH
    • DECLARE @ErrorMessage NVARCHAR(4000);
    • DECLARE @ErrorSeverity INT;
    • DECLARE @ErrorState INT;
    • SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(),
    • @ErrorState = ERROR_STATE();
    • -- rethrow goes to front end c#
    • RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState);
    • END CATCH
  • 18. SSIS/SSRS Project: MiniAdventureWorks
    • Specifications: Import .csv data into tables for Purchase Header Orders and Purchase Details
    • Aggregate the PO Details by PO Header No.
    • Build SSIS Packages with Control and Data Flows showing the importation/aggregation processes
    • Build Matrix and Table reports using SSRS
    • Deploy packages and create data subscriptions
  • 19. Control Flow: Import Purchase Header Order Package
  • 20. Data Flow: Purchase Header Order Package
  • 21. SSRS Matrix Report
  • 22. SSRS Matrix Report with Gauge
  • 23. SSRS Table Report
  • 24.  
  • 25. Final Project Blockflix: Specifications in a nutshell
    • Design a business model patterned after Netflix and Blockbuster
    • Members can rent a movie online, or through a retail store in their neighborhood
    • Use XML to introduce movies into the catalog
    • Create procedures to handle all transactions
    • Create packages in SSIS for nightly batch runs
    • Create reports in SSRS for management use
  • 26. AddMovieMaster Package Control Flow
  • 27. AddMovieMaster Package Data Flow
  • 28. XML to add a movie to the catalog
    • <?xml version=&quot;1.0&quot;?>
    • <xs:schema attributeFormDefault=&quot;unqualified&quot; elementFormDefault=&quot;qualified&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;>
    • <xs:element name=&quot;List&quot;>
    • <xs:complexType>
    • <xs:sequence>
    • <xs:element minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot; name=&quot;row&quot;>
    • <xs:complexType>
    • <xs:attribute name=&quot;Movie_ID&quot; type=&quot;xs:unsignedInt&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;Disk_ID&quot; type=&quot;xs:unsignedByte&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;Title&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;Genre&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;Rating&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;Year&quot; type=&quot;xs:unsignedShort&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;MediaType&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;D1FirstName&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;D1LastName&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;A1FirstName&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;A1LastName&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;D2FirstName&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;D2LastName&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;P1FirstName&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • <xs:attribute name=&quot;P1LastName&quot; type=&quot;xs:string&quot; use=&quot;optional&quot; />
    • </xs:complexType>
    • </xs:element>
    • </xs:sequence>
    • </xs:complexType>
    • </xs:element>
    • </xs:schema>
  • 29. Add a member Transaction
    • USE [BlockFlix]
    • GO
    • DECLARE @return_value int,
    • @member_id int
    • EXEC @return_value = [dbo].[CreateMember]
    • @membership_type_id = 2,
    • @first_name = N'David',
    • @middle_initial = NULL,
    • @last_name = N'Jaciow',
    • @street_address = N‘1600 Pennsylvania Avenue',
    • @city = N‘Washington',
    • @state = N‘DC',
    • @zip_code = N'02001',
    • @phone_number = N'555-123-1234',
    • @email = N'djaciow@aol.com',
    • @payment_type_id = 1,
    • @payment_amt = 8.99,
    • @credit_card_number = N'0000-0000-0000-0000',
    • @member_id = @member_id OUTPUT
    • SELECT @member_id as N'@member_id'
    • SELECT 'Return Value' = @return_value
    • GO
  • 30. SSRS Report rendered in PDF
  • 31. SSRS Report rendered in Excel
  • 32. Streaming Video (VOD) Proposal
    • BlockFlix Entertainment, Inc.
    • Streaming Video Proposal
    • September 3, 2010
    • What’s needed from BlockFlix : A cluster of 24 x 7 high-availability media player servers is absolutely necessary. An upload speed of 100 megabits/second will assure the best video quality. At any time during the day, as many as 1,000 members can be logged on. Ideally, BlockFlix should be ready to “deliver” a movie online to each and every one of those members. A video streaming licensing agreement should have to be written up between the movie studio and BlockFlix, much like a DVD/Blu-Ray licensing agreement. The movie studio will charge a royalty fee to BlockFlix for every viewing of a movie title. BlockFlix gets billed every time a member requests to view the movie online. Details are described below.
    • What’s needed from the Member : A high-speed internet connection capable of at least T1 speed, or 1.5 Megabytes (not megabits) per second is required for best video quality. The faster the download speed, the better. The member can view the movie straight through a PC with a processor speed of at least 1.5 GHz with an Nvidia Video Card issued in 2004 or later, or a video box that can be purchased directly from BlockFlix for $199. (A similar box can be purchased at Best Buy for about $249). For true stereophonic quality, the PC or box will need a special sound card.
    • How it works : A member, whose account is up to date, decides to watch a movie online instead of waiting one more day (maybe even two) for a DVD in the mail. He goes into his Blockflix account online, and chooses one of the 200+ selections available. A request emanates from the BlockFlix website that sends a request to the movie studio’s server. The movie studio’s server issues an invoice to Blockflix and sends a copy of an .asx file with that invoice. (.ASX is a streaming video file extension). BlockFlix then bills the member $4.99 for the movie, the member accepts the charges in a pop-up window, and a “movie viewer” opens up in the member’s PC or video box. The movie viewer has rewind/fast forward and pause capabilities, however it cannot stop at the end of a chapter, or resume playing (after a full stop) at the beginning of a chapter the way a DVD can. Just like in a movie theater, the member has to pretty much view the whole movie in one sitting. The movie studios that are offering streaming videos have gone to great lengths in preventing members from copying their movies. This is of course is piracy, and is a federal offense in addition to carrying huge penalties. A warning to this effect is displayed at the beginning of the movie.
    • Initial Rollout and future expansion : At the outset, only 200 of the most popular titles in BlockFlix’s DVD inventory will be made available in the streaming catalog. Depending on the popularity of this delivery method, the streaming catalog will expand to 500 titles in six months and about 1,000 titles in twelve months. In the future, platinum members with excellent payment records can view up to 10 streaming videos a month without paying a fee. Basic members can view up to 2 streaming videos a month without paying a fee.

×