Professional Documents
Culture Documents
SQL Portfolio
Table of Contents
My Projects
Piggy Bank Project (A dummy back end bank application)
ER Diagram - Stored Procedures - Triggers
County Library Project
ER Diagram - Reports Backup Plan
Movie Rental Company (BlockFlix)
Table Design 2 Stored Procedures SSIS - SSRS
Deposit Procedure
/****** Object: StoredProcedure [dbo].[Deposit] Script Date: 10/15/2009 19:06:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Proc [dbo].[Deposit]
@CustID int, @AcctID int, @TransAmt money, @TransID int output
As
--Validation of Customer ID and Account ID
if
@CustID NOT IN
(Select CustomerID from Customer)
Begin
Raiserror ('Customer does not Exist in the Database',14,1)
Return -1
End
if
@AcctID NOT IN
(Select AccountID from CustomerAccount where CustomerID=@CustID)
Begin
Raiserror ('Account does not belong to the Customer',14,1)
Return -1
End
Declare @NewBal money,@Currntbalance money, @AcctStatus tinyint, @Genroverdrft bit
-- Validation of Account Status
Select @AcctStatus = AccountStatusID from Account where AccountID=@AcctID
if @AcctStatus = 2
Begin
Raiserror ('ACCOUNT IS INACTIVE, FIRST CHANGE THE ACCOUNT TO ACTIVE STATUS',14,1)
Return -1
End
Set @NewBal=(Select CurrentBalance from Account
where AccountID=@AcctID)+ @TransAmt
Deposit (Cont)
Begin Try
Begin Tran
insert into dbo.Transactions(AccountID,TransactionTypeID,
CustomerID,TransactionDate,TransactionAmount,NewBalance)
values (@AcctID,2,@CustID,GetDate(),@TransAmt,@NewBal)
Update Account
Set CurrentBalance = @NewBal where AccountID = @AcctID
Commit Tran
End Try
Begin Catch
Rollback Tran
Select Error_number(), Error_Message()
End Catch
Transfer Money
/****** Object: StoredProcedure [dbo].[Transfer] Script Date: 10/15/2009 20:12:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[Transfer]
@FromAccount int, @ToAccount int, @Amount money,
@TransID int output
AS
Declare @CustID1 int, @CustID2 int, @balance money, @ToBalance money,
@AcctStatus tinyint
Return -1
End
END
Begin Try
Begin Tran
Insert into Transactions (AccountID, TransactionTypeID, CustomerID, TransactionDate, TransactionAmount, NewBalance)
Values (@FromAccount,4, @CustID1, getdate(), @Amount, @balance-@Amount)
Insert into Transactions (AccountID, TransactionTypeID, CustomerID, TransactionDate, TransactionAmount, NewBalance)
Values (@ToAccount,5, @CustID1, getdate(), @Amount, @ToBalance+@Amount)
Update Account Set CurrentBalance = CurrentBalance - @Amount
where AccountID = @FromAccount
Update Account Set CurrentBalance = CurrentBalance + @Amount
where AccountID = @ToAccount
Commit Tran
End Try
Begin Catch
Rollback Tran
Select Error_number(), Error_Message()
End Catch
Triggers
USE [PiggyBank]
GO
/****** Object: DdlTrigger [Security] Script Date: 06/20/2009 17:34:37 ******/
IF EXISTS (SELECT * FROM sys.triggers WHERE name = N'Security' AND parent_class=0)
DROP TRIGGER [Security] ON DATABASE
USE [PiggyBank]
GO
/****** Object: DdlTrigger [Security] Script Date: 06/20/2009 17:35:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create TRIGGER [Security]
ON DATABASE
FOR DROP_TABLE, ALTER_TABLE
AS
PRINT 'You are not allowed to Drop or Alter table in the database!'
ROLLBACK ;
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ENABLE TRIGGER [Security] ON DATABASE
Library Project
Objectives
To create Several Reports to accommodate
business practices of a lending library.
To create a backup schedule for the library
database.
ER Diagram
title
title_no
title
author
synopsis
loan
isbn
copy_no
member
loanhist
title_no
member_no
member_no
lastname
out_date
firstname
due_date
isbn
copy_no
copy
out_date
middleinitial
isbn
title_no
photograph
copy_no
member_no
title_no
due_date
on_loan
in_date
fine_assessed
fine_paid
reservation
isbn
member_no
log_date
remarks
adult
member_no
juvenile
street
member_no
city
adult_member_no
state
birth_date
zip
phone_no
expr_date
item
isbn
title_no
translation
cover
loanable
fine_waived
remarks
List of checked out Books order by ISBN, Copy Number (include member name)
Adult Member detail report. Details about adult members: name, address, total number of active
checkouts (loan table), with a drill down option for total fines assessed, total fines paid, total fines
waived, and total due. Also a second report displays each juveniles checkout/fine information
Total Fines by Member: Design a report, ordered by member name that will accommodate the fine
information from Current Fines for Overdue Books and combine this with the historical fine
information in the Loan History table.
Expired Memberships. A complete list of expired memberships, organized by adult members with a drill
down to all dependant juvenile memberships.
BlockFlix: Objective
A fully functional movie database
Track:
Inventory of Movies
Customer Information
Sales / Checkout
Payment & Fees
Service Outlets:
Online Stores
Local Branches
Kiosk
Table Design:
Customers (7)
Media/Rentable Items (8)
Products/Stores (4)
Transactions/History (8)
(27 tables)
ER Diagram
This is the Sales Table from BlockFlix with no data before the
package is executed.
Here is the SSIS Package that has been Executed and the Rows being
added to the BlockFlix Database to the corresponding tables.
After the InStore package ran successfully, BlockFlix database Sales table is
populated with data that was in Store1 database Sales Table.
A Report that shows the most Rented Movies in the past month.
A Report that shows the most active customers in the past month.