Chris Mc Glothen Sql Portfolio
-
Upload
clmcglothen -
Category
Documents
-
view
614 -
download
1
description
Transcript of Chris Mc Glothen Sql Portfolio
Table of Contents
• Bank Project• ER Diagram• Stored Procedures• User Defined Functions• Triggers
• Library Project• ER Diagram• SSRS Reports
Table of Contents (cont.)
• Online Movie Project• ER Diagram• XML Schema Collection• Shred XML file • Backup and Recovery Plan• Security Considerations• Users/Roles• Application
Bank Project
• Introduction: • Develop custom stored procedures to
manage transactions for a client bank operation.• Shred initial data from XML file into
database
ER Diagram
TRY/CATCH BlocksBEGIN TRY
--Body of Stored Procedure, including validation and BEGIN TRANSACTION statementEND TRYBEGIN CATCH
--Rollback the transaction--Perform while loop to close all uncommitted transactionsDECLARE @tmpCount intSELECT @tmpCount = CONVERT(int, @@TRANCOUNT)IF @tmpCount >= 0
BEGINWHILE @tmpCount > 0
BEGINROLLBACK TRANSET @tmpCount = @tmpCount - 1
ENDEND
--Declare local variables to hold the error information passes back to the callerDECLARE @Message nvarchar(4000);DECLARE @Severity int;DECLARE @State int;--Set the variables to the error valuesSELECT
@Message = ERROR_MESSAGE(),@Severity = ERROR_SEVERITY(),@State = ERROR_STATE();
--Raise the error to the caller with the error variablesRAISERROR(@Message, @Severity, @State)RETURN -1
END CATCH
Debit Account Procedure
Transfer Funds Procedure
Interest with Avg. Daily Balance
Get Customer Data w/ Dynamic WHERE Clause
CREATE PROCEDURE uspGetCustomer@AccountIDint = NULL -- NULL, @CustomerID int = NULL -- NULL, @Name varchar(50) = NULL -- NULL, @Phone varchar(12) = NULL -- NULL
ASBEGIN TRY
--Use the ISNULL function to create a dynamic WHERE clauseSELECT *FROM vwCustomersWHERE AccountID = ISNULL(@AccountID, AccountID)
AND CustomerID = ISNULL(@CustomerID, CustomerID)AND [Name] LIKE ISNULL('%' + @Name + '%', '%')AND (HomePhone LIKE ISNULL('%' + @Phone + '%', '%')
OR WorkPhone LIKE ISNULL('%' + @Phone + '%', '%')OR CellPhone LIKE ISNULL('%' + @Phone + '%', '%'))
ORDER BY TransactionDate DESCEND TRY
Calculate Monthly Interest FunctionCREATE FUNCTION [dbo].[ufnCalcMonthlyInterest] ( @Balance money, @ID int, @AcctType
tinyint )RETURNS moneyASBEGIN
DECLARE @InterestToBeAdded moneyDECLARE @MonthlyRate decimal(6,6)
SET @MonthlyRate = ((SELECT InterestRate FROM AccountType WHERE AccountTypeID = @AcctType) / 12)SET @InterestToBeAdded = (SELECT (@Balance * @MonthlyRate) FROM Account WHERE AccountID = @ID)
RETURN @InterestToBeAdded
END
DDL TriggerCREATE TRIGGER tgrSafetyON DATABASE FOR DROP_TABLE, ALTER_TABLE, DROP_VIEW, ALTER_VIEWASBEGIN
SET NOCOUNT ON;--Throw an errorRAISERROR ('You may not drop or alter objects from this database.', 11,1)
IF @@TRANCOUNT > 0BEGIN
--Rollback the transactionROLLBACK TRANSACTION
ENDEND
DML TriggerCREATE TRIGGER tgrGuardTransactionsON Transactions INSTEAD OF DELETE, UPDATEASBEGIN
--Throw an error RAISERROR ('Deletions and Updates not allowed from this table (source = instead of)', 11, 1)
IF @@TRANCOUNT > 0BEGIN
--Rollback the transactionROLLBACK TRANSACTION
ENDEND
Library Project
• Introduction: • Develop custom SSRS reports for an existing
database management system
ER Diagram
Most Active Members by Month and Year
Active Member Report ProcedureCREATE PROCEDURE [dbo].[uspGetActiveMembers]
@Month int, @Year int
ASDECLARE @LoanTable TABLE
(MemberNo int, FullName varchar(100), OutDate datetime, CurrentLoan bit
)INSERT INTO @LoanTable
SELECT m.Member_No, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName), lh.Out_Date, 0
FROM Member mINNER JOIN LoanHist lh
ON m.Member_No = lh.Member_NoUNION
SELECT m.Member_No, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName), l.Out_Date, 1
FROM Member mINNER JOIN Loan l
ON m.Member_No = l.Member_NoSELECT MemberNo, FullName, COUNT(*) AS TotalLoansFROM @LoanTable ltWHERE MONTH(OutDate) = @Month AND YEAR(OutDate) = @Year GROUP BY MemberNo, FullNameORDER BY TotalLoans DESC
Current Fines Report
Current Fine Report ProcedureCREATE PROCEDURE [dbo].[uspCurrentOverDue]
AS
SELECT CONVERT(varchar, l.Due_Date, 110) AS Due_Date, DATEDIFF(dd, l.Due_Date, GETDATE()) AS DaysOverDue, CAST((DATEDIFF(dd, l.Due_Date, GETDATE()) * .25) AS money) AS FineDue, l.ISBN, t.Title, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName) AS FullName
FROM Loan lINNER JOIN Title t
ON l.Title_No = t.Title_NoINNER JOIN Member m
ON l.Member_No = m.Member_NoWHERE DATEDIFF(dd, l.Due_Date, GETDATE()) >0ORDER BY FullName
Kids Club Report
Kids Club Report Procedure• CREATE PROCEDURE [dbo].[uspGetKids]• AS• DECLARE @KidsTable TABLE• (• MemberNo int• , FullName varchar(100)• , Age int• )• INSERT INTO @KidsTable• (• MemberNo• , FullName• , Age• )• SELECT j.Member_No, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName) AS FullName, 7 AS Age• FROM Juvenile j• INNER JOIN Member m ON j.Member_No = m.Member_No• WHERE j.Birth_Date BETWEEN (CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE() + 1)AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -8, GETDATE()))) AS varchar)) • AND CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE())AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -7, GETDATE()))) AS varchar)• UNION• SELECT j.Member_No, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName) AS FullName, 8 AS Age• FROM Juvenile j• INNER JOIN Member m ON j.Member_No = m.Member_No• WHERE j.Birth_Date BETWEEN (CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE() + 1)AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -9, GETDATE()))) AS varchar)) • AND CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE())AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -8, GETDATE()))) AS varchar)• UNION• SELECT j.Member_No, (m.FirstName + ' ' + ISNULL(m.MiddleInitial + ' ', '') + m.LastName) AS FullName, 9 AS Age• FROM Juvenile j• INNER JOIN Member m ON j.Member_No = m.Member_No• WHERE j.Birth_Date BETWEEN (CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE() + 1)AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -10, GETDATE()))) AS varchar)) • AND CAST(MONTH(GETDATE()) AS varchar) + '/' + CAST(DAY(GETDATE())AS varchar) + '/' + CAST((YEAR(DATEADD(yy, -9, GETDATE()))) AS varchar)• SELECT *• FROM @KidsTable• ORDER BY Age
Online Movie Project
• Introduction: • Design and implement DBMS for a movie
rental chain• Database Design and Implementation• Stored Procedures• SSRS Reports• Backup and Recovery Plan• Database Security Strategy
ER Diagram
ER Diagram (cont.)
ER Diagram (cont.)
XML Schema Collection
XML File
Shredding the data
Backup and Recovery
• Implementation of Log Shipping between headquarters server and secondary server located off site
• Off site location for archive server to hold legacy data and static information and also acts as the monitor for the Log Shipping solution
• Implementation of RAID 5 on production servers• High aggregation transfer rates• Backup strategies implemented both locally and at
corporate levels
Backup and Recovery (cont.)
Security Considerations
• Implement Principle of Least Privilege• Role based security• User management via groups and integrated
windows security• Stored Procedures for all interactions with data• Exclusion of all dynamic SQL statements• Use of Certificates and Symmetric Encryption• Additional security considerations will be included in
the front end applications that interface with the data