<ul><li>.SQL Portfolio </li></ul><ul><li>Name: Chris McGlothen </li></ul><ul><li>Email:  </li></ul><ul><li>[email_address]...
Table of Contents <ul><li>Bank Project </li></ul><ul><ul><li>ER Diagram </li></ul></ul><ul><ul><li>Stored Procedures </li>...
Table of Contents (cont.) <ul><li>Online Movie Project </li></ul><ul><ul><li>ER Diagram </li></ul></ul><ul><ul><li>XML Sch...
Bank Project <ul><li>Introduction:  </li></ul><ul><ul><li>Develop custom stored procedures to manage transactions for a cl...
ER Diagram
TRY/CATCH Blocks <ul><li>BEGIN TRY </li></ul><ul><ul><li>--Body of Stored Procedure, including validation and BEGIN TRANSA...
Debit Account Procedure
Transfer Funds Procedure
Interest with Avg. Daily Balance
Get Customer Data w/ Dynamic WHERE Clause <ul><li>CREATE PROCEDURE uspGetCustomer </li></ul><ul><li>@AccountID int = NULL ...
Calculate Monthly Interest Function <ul><li>CREATE FUNCTION [dbo].[ufnCalcMonthlyInterest] ( @Balance money, @ID int, @Acc...
DDL Trigger <ul><li>CREATE TRIGGER tgrSafety </li></ul><ul><li>ON DATABASE  </li></ul><ul><li>FOR DROP_TABLE, ALTER_TABLE,...
DML Trigger <ul><li>CREATE TRIGGER tgrGuardTransactions </li></ul><ul><li>ON Transactions INSTEAD OF DELETE, UPDATE </li><...
Library Project <ul><li>Introduction:  </li></ul><ul><ul><li>Develop custom SSRS reports for an existing database manageme...
ER Diagram
Most Active Members by Month and Year
Active Member Report Procedure <ul><li>CREATE PROCEDURE [dbo].[uspGetActiveMembers] </li></ul><ul><li>@Month int </li></ul...
Current Fines Report
Current Fine Report Procedure <ul><li>CREATE PROCEDURE [dbo].[uspCurrentOverDue] </li></ul><ul><li>AS </li></ul><ul><li>SE...
Kids Club Report
Kids Club Report Procedure <ul><li>CREATE PROCEDURE [dbo].[uspGetKids] </li></ul><ul><li>AS </li></ul><ul><li>DECLARE @Kid...
Online Movie Project <ul><li>Introduction:  </li></ul><ul><ul><li>Design and implement DBMS for a movie rental chain </li>...
ER Diagram
ER Diagram (cont.)
ER Diagram (cont.)
XML Schema Collection
XML File
Shredding the data
Backup and Recovery <ul><li>Implementation of Log Shipping between headquarters server and secondary server located off si...
Backup and Recovery (cont.)
Security Considerations <ul><li>Implement Principle of Least Privilege </li></ul><ul><li>Role based security </li></ul><ul...
Upcoming SlideShare
Loading in...5
×

Chris Mc Glothen Sql Portfolio

620

Published on

My portfolio showing examples of use, creation, and maintenance of SQL Server 2005 database objects.

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

  • Be the first to like this

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

No notes for slide

Chris Mc Glothen Sql Portfolio

  1. 1. <ul><li>.SQL Portfolio </li></ul><ul><li>Name: Chris McGlothen </li></ul><ul><li>Email: </li></ul><ul><li>[email_address] </li></ul><ul><li>Phone: (702) 839-9568 </li></ul>
  2. 2. Table of Contents <ul><li>Bank Project </li></ul><ul><ul><li>ER Diagram </li></ul></ul><ul><ul><li>Stored Procedures </li></ul></ul><ul><ul><li>User Defined Functions </li></ul></ul><ul><ul><li>Triggers </li></ul></ul><ul><li>Library Project </li></ul><ul><ul><li>ER Diagram </li></ul></ul><ul><ul><li>SSRS Reports </li></ul></ul>
  3. 3. Table of Contents (cont.) <ul><li>Online Movie Project </li></ul><ul><ul><li>ER Diagram </li></ul></ul><ul><ul><li>XML Schema Collection </li></ul></ul><ul><ul><li>Shred XML file </li></ul></ul><ul><ul><li>Backup and Recovery Plan </li></ul></ul><ul><ul><li>Security Considerations </li></ul></ul><ul><ul><ul><li>Users/Roles </li></ul></ul></ul><ul><ul><ul><li>Application </li></ul></ul></ul>
  4. 4. Bank Project <ul><li>Introduction: </li></ul><ul><ul><li>Develop custom stored procedures to manage transactions for a client bank operation. </li></ul></ul><ul><ul><li>Shred initial data from XML file into database </li></ul></ul>
  5. 5. ER Diagram
  6. 6. TRY/CATCH Blocks <ul><li>BEGIN TRY </li></ul><ul><ul><li>--Body of Stored Procedure, including validation and BEGIN TRANSACTION statement </li></ul></ul><ul><li>END TRY </li></ul><ul><li>BEGIN CATCH </li></ul><ul><li>--Rollback the transaction </li></ul><ul><li>--Perform while loop to close all uncommitted transactions </li></ul><ul><li>DECLARE @tmpCount int </li></ul><ul><li>SELECT @tmpCount = CONVERT(int, @@TRANCOUNT) </li></ul><ul><li>IF @tmpCount >= 0 </li></ul><ul><li>BEGIN </li></ul><ul><li>WHILE @tmpCount > 0 </li></ul><ul><li>BEGIN </li></ul><ul><li>ROLLBACK TRAN </li></ul><ul><li>SET @tmpCount = @tmpCount - 1 </li></ul><ul><li>END </li></ul><ul><li>END </li></ul><ul><li>--Declare local variables to hold the error information passes back to the caller </li></ul><ul><li>DECLARE @Message nvarchar(4000); </li></ul><ul><li>DECLARE @Severity int; </li></ul><ul><li>DECLARE @State int; </li></ul><ul><li>--Set the variables to the error values </li></ul><ul><li>SELECT </li></ul><ul><li>@Message = ERROR_MESSAGE(), </li></ul><ul><li>@Severity = ERROR_SEVERITY(), </li></ul><ul><li>@State = ERROR_STATE(); </li></ul><ul><li>--Raise the error to the caller with the error variables </li></ul><ul><li>RAISERROR(@Message, @Severity, @State) </li></ul><ul><li>RETURN -1 </li></ul><ul><li>END CATCH </li></ul>
  7. 7. Debit Account Procedure
  8. 8. Transfer Funds Procedure
  9. 9. Interest with Avg. Daily Balance
  10. 10. Get Customer Data w/ Dynamic WHERE Clause <ul><li>CREATE PROCEDURE uspGetCustomer </li></ul><ul><li>@AccountID int = NULL -- NULL </li></ul><ul><li>, @CustomerID int = NULL -- NULL </li></ul><ul><li>, @Name varchar(50) = NULL -- NULL </li></ul><ul><li>, @Phone varchar(12) = NULL -- NULL </li></ul><ul><li>AS </li></ul><ul><li>BEGIN TRY </li></ul><ul><li>--Use the ISNULL function to create a dynamic WHERE clause </li></ul><ul><li>SELECT * </li></ul><ul><li>FROM vwCustomers </li></ul><ul><li>WHERE AccountID = ISNULL(@AccountID, AccountID) </li></ul><ul><li>AND CustomerID = ISNULL(@CustomerID, CustomerID) </li></ul><ul><li>AND [Name] LIKE ISNULL('%' + @Name + '%', '%') </li></ul><ul><li>AND (HomePhone LIKE ISNULL('%' + @Phone + '%', '%') </li></ul><ul><li>OR WorkPhone LIKE ISNULL('%' + @Phone + '%', '%') </li></ul><ul><li>OR CellPhone LIKE ISNULL('%' + @Phone + '%', '%')) </li></ul><ul><li>ORDER BY TransactionDate DESC </li></ul><ul><li>END TRY </li></ul>
  11. 11. Calculate Monthly Interest Function <ul><li>CREATE FUNCTION [dbo].[ufnCalcMonthlyInterest] ( @Balance money, @ID int, @AcctType tinyint ) </li></ul><ul><li>RETURNS money </li></ul><ul><li>AS </li></ul><ul><li>BEGIN </li></ul><ul><li>DECLARE @InterestToBeAdded money </li></ul><ul><li>DECLARE @MonthlyRate decimal(6,6) </li></ul><ul><li>SET @MonthlyRate = ((SELECT InterestRate FROM AccountType WHERE AccountTypeID = @AcctType) / 12) </li></ul><ul><li>SET @InterestToBeAdded = (SELECT (@Balance * @MonthlyRate) FROM Account WHERE AccountID = @ID) </li></ul><ul><li>RETURN @InterestToBeAdded </li></ul><ul><li>END </li></ul>
  12. 12. DDL Trigger <ul><li>CREATE TRIGGER tgrSafety </li></ul><ul><li>ON DATABASE </li></ul><ul><li>FOR DROP_TABLE, ALTER_TABLE, DROP_VIEW, ALTER_VIEW </li></ul><ul><li>AS </li></ul><ul><li>BEGIN </li></ul><ul><li>SET NOCOUNT ON; </li></ul><ul><li>--Throw an error </li></ul><ul><li>RAISERROR ('You may not drop or alter objects from this database.', 11,1) </li></ul><ul><li>IF @@TRANCOUNT > 0 </li></ul><ul><li>BEGIN </li></ul><ul><li>--Rollback the transaction </li></ul><ul><li>ROLLBACK TRANSACTION </li></ul><ul><li>END </li></ul><ul><li>END </li></ul>
  13. 13. DML Trigger <ul><li>CREATE TRIGGER tgrGuardTransactions </li></ul><ul><li>ON Transactions INSTEAD OF DELETE, UPDATE </li></ul><ul><li>AS </li></ul><ul><li>BEGIN </li></ul><ul><li>--Throw an error </li></ul><ul><li>RAISERROR ('Deletions and Updates not allowed from this table (source = instead of)', 11, 1) </li></ul><ul><li>IF @@TRANCOUNT > 0 </li></ul><ul><li>BEGIN </li></ul><ul><li>--Rollback the transaction </li></ul><ul><li>ROLLBACK TRANSACTION </li></ul><ul><li>END </li></ul><ul><li>END </li></ul>
  14. 14. Library Project <ul><li>Introduction: </li></ul><ul><ul><li>Develop custom SSRS reports for an existing database management system </li></ul></ul>
  15. 15. ER Diagram
  16. 16. Most Active Members by Month and Year
  17. 17. Active Member Report Procedure <ul><li>CREATE PROCEDURE [dbo].[uspGetActiveMembers] </li></ul><ul><li>@Month int </li></ul><ul><li>, @Year int </li></ul><ul><li>AS </li></ul><ul><li>DECLARE @LoanTable TABLE </li></ul><ul><li>( </li></ul><ul><li>MemberNo int </li></ul><ul><li>, FullName varchar(100) </li></ul><ul><li>, OutDate datetime </li></ul><ul><li>, CurrentLoan bit </li></ul><ul><li>) </li></ul><ul><li>INSERT INTO @LoanTable </li></ul><ul><li>SELECT m.Member_No </li></ul><ul><li>, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName) </li></ul><ul><li>, lh.Out_Date </li></ul><ul><li>, 0 </li></ul><ul><li>FROM Member m </li></ul><ul><li>INNER JOIN LoanHist lh </li></ul><ul><li>ON m.Member_No = lh.Member_No </li></ul><ul><li>UNION </li></ul><ul><li>SELECT m.Member_No </li></ul><ul><li>, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName) </li></ul><ul><li>, l.Out_Date </li></ul><ul><li>, 1 </li></ul><ul><li>FROM Member m </li></ul><ul><li>INNER JOIN Loan l </li></ul><ul><li>ON m.Member_No = l.Member_No </li></ul><ul><li>SELECT MemberNo, FullName, COUNT(*) AS TotalLoans </li></ul><ul><li>FROM @LoanTable lt </li></ul><ul><li>WHERE MONTH(OutDate) = @Month AND YEAR(OutDate) = @Year </li></ul><ul><li>GROUP BY MemberNo, FullName </li></ul><ul><li>ORDER BY TotalLoans DESC </li></ul>
  18. 18. Current Fines Report
  19. 19. Current Fine Report Procedure <ul><li>CREATE PROCEDURE [dbo].[uspCurrentOverDue] </li></ul><ul><li>AS </li></ul><ul><li>SELECT CONVERT(varchar, l.Due_Date, 110) AS Due_Date </li></ul><ul><li>, DATEDIFF(dd, l.Due_Date, GETDATE()) AS DaysOverDue </li></ul><ul><li>, CAST((DATEDIFF(dd, l.Due_Date, GETDATE()) * .25) AS money) AS FineDue </li></ul><ul><li>, l.ISBN </li></ul><ul><li>, t.Title </li></ul><ul><li>, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName) AS FullName </li></ul><ul><li>FROM Loan l </li></ul><ul><li>INNER JOIN Title t </li></ul><ul><li>ON l.Title_No = t.Title_No </li></ul><ul><li>INNER JOIN Member m </li></ul><ul><li>ON l.Member_No = m.Member_No </li></ul><ul><li>WHERE DATEDIFF(dd, l.Due_Date, GETDATE()) >0 </li></ul><ul><li>ORDER BY FullName </li></ul>
  20. 20. Kids Club Report
  21. 21. Kids Club Report Procedure <ul><li>CREATE PROCEDURE [dbo].[uspGetKids] </li></ul><ul><li>AS </li></ul><ul><li>DECLARE @KidsTable TABLE </li></ul><ul><li>( </li></ul><ul><li>MemberNo int </li></ul><ul><li>, FullName varchar(100) </li></ul><ul><li>, Age int </li></ul><ul><li>) </li></ul><ul><li>INSERT INTO @KidsTable </li></ul><ul><li>( </li></ul><ul><li>MemberNo </li></ul><ul><li>, FullName </li></ul><ul><li>, Age </li></ul><ul><li>) </li></ul><ul><li>SELECT j.Member_No, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName) AS FullName, 7 AS Age </li></ul><ul><li>FROM Juvenile j </li></ul><ul><li>INNER JOIN Member m ON j.Member_No = m.Member_No </li></ul><ul><li>WHERE j.Birth_Date BETWEEN (CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE() + 1)AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -8, GETDATE()))) AS varchar)) </li></ul><ul><li>AND CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE())AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -7, GETDATE()))) AS varchar) </li></ul><ul><li>UNION </li></ul><ul><li>SELECT j.Member_No, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName) AS FullName, 8 AS Age </li></ul><ul><li>FROM Juvenile j </li></ul><ul><li>INNER JOIN Member m ON j.Member_No = m.Member_No </li></ul><ul><li>WHERE j.Birth_Date BETWEEN (CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE() + 1)AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -9, GETDATE()))) AS varchar)) </li></ul><ul><li>AND CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE())AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -8, GETDATE()))) AS varchar) </li></ul><ul><li>UNION </li></ul><ul><li>SELECT j.Member_No, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName) AS FullName, 9 AS Age </li></ul><ul><li>FROM Juvenile j </li></ul><ul><li>INNER JOIN Member m ON j.Member_No = m.Member_No </li></ul><ul><li>WHERE j.Birth_Date BETWEEN (CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE() + 1)AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -10, GETDATE()))) AS varchar)) </li></ul><ul><li>AND CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE())AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -9, GETDATE()))) AS varchar) </li></ul><ul><li>SELECT * </li></ul><ul><li>FROM @KidsTable </li></ul><ul><li>ORDER BY Age </li></ul>
  22. 22. Online Movie Project <ul><li>Introduction: </li></ul><ul><ul><li>Design and implement DBMS for a movie rental chain </li></ul></ul><ul><ul><ul><li>Database Design and Implementation </li></ul></ul></ul><ul><ul><ul><li>Stored Procedures </li></ul></ul></ul><ul><ul><ul><li>SSRS Reports </li></ul></ul></ul><ul><ul><ul><li>Backup and Recovery Plan </li></ul></ul></ul><ul><ul><ul><li>Database Security Strategy </li></ul></ul></ul>
  23. 23. ER Diagram
  24. 24. ER Diagram (cont.)
  25. 25. ER Diagram (cont.)
  26. 26. XML Schema Collection
  27. 27. XML File
  28. 28. Shredding the data
  29. 29. Backup and Recovery <ul><li>Implementation of Log Shipping between headquarters server and secondary server located off site </li></ul><ul><li>Off site location for archive server to hold legacy data and static information and also acts as the monitor for the Log Shipping solution </li></ul><ul><li>Implementation of RAID 5 on production servers </li></ul><ul><li>High aggregation transfer rates </li></ul><ul><li>Backup strategies implemented both locally and at corporate levels </li></ul>
  30. 30. Backup and Recovery (cont.)
  31. 31. Security Considerations <ul><li>Implement Principle of Least Privilege </li></ul><ul><li>Role based security </li></ul><ul><li>User management via groups and integrated windows security </li></ul><ul><li>Stored Procedures for all interactions with data </li></ul><ul><li>Exclusion of all dynamic SQL statements </li></ul><ul><li>Use of Certificates and Symmetric Encryption </li></ul><ul><li>Additional security considerations will be included in the front end applications that interface with the data </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×