Upload
brentbybee
View
454
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
SetFocus SQL Portfolio
SetFocus has designed The Masters Program: SQL Server training track to help bring database administrators to the next level in their careers, utilizing Microsoft SQL Server 2005 integrated closely with Visual Studio 2005.
ER Diagram
Customer
PK CustomerID
FirstName MiddleInitial LastName Address City State ZipCode SSNumber
Contact
PK ContactID
FK1 CustomerID HomePhone WorkPhone CellPhone Email
Transaction
PK TransactionID
FK1 AccountIDFK2 TransactionTypeID TransactionAmt TransactionDate
TransactionType
PK TransactionTypeID
TransactionType TransactionTypeName
FailedTransaction
PK FailedTransID
FK1 TransactionID FailedTransXML
Accounts
PK AccountID
FK1 CustomerIDFK2 EmployeeID SavingsAcctNumber CheckingAcctNumber DateOpened OpeningBalance CurrentBalance AcctStatus SavingsIntRate
FailedTransError
PK FailedTransErrorID
FK1 FailedTransID FailedTransErrorTime
ErrorLog
PK ErrorLogID
FK1 FailedTransErrorID ErrorTime
Employee
PK EmployeeID
EmployeeFirstName EmployeeMiddleInitial EmployeeLastName EmployeeIsManager
OverdraftAcct
PK OverdraftAcctID
FK1 TransactionID
UserLogin
PK UserLogin
FK1 CustomerID UserName UserPassword UserSecurityQuestion UserSecurityAnswer
AcctReactivationLog
PK AcctReactLogID
FK1 EmployeeID ReactivationDate
UserErrorLog
PK UserErrorLogID
FK1 UserLogin
3
/*
Author: Team B (Brent Bybee)
Date: 3/3/2009
Description: Create the "Checked In Movie" proc and delete row from RentalTransaction table, insert into History table, and update copy table
*/
--Create Stored Proc
CREATE PROC [dbo].[CheckInMovie]
@MembershipID smallint = NULL,
@MovieID smallint = NULL,
@CopyNumberID smallint = NULL,
@MediaTypeID smallint = NULL
AS
--Validation
IF @MembershipID IS NULL
BEGIN
PRINT 'MembershipID cannot be null'
RETURN -1
END
IF @MovieID IS NULL
BEGIN
PRINT 'MovieID cannot be null'
RETURN -2
END
IF @CopyNumberID IS NULL
BEGIN
PRINT 'CopyNumberID cannot be null'
RETURN -3
END
IF @MediaTypeID IS NULL
BEGIN
PRINT 'MediaTypeID cannot be null'
RETURN -4
END
--Verify Movie exists
SELECT @MediaTypeID = MediaTypeID
FROM Copy
WHERE MovieID = @MovieID AND CopyNumberID = @CopyNumberID
IF @MediaTypeID IS NULL
BEGIN
PRINT 'Movie is Invalid'
RETURN -5
END
--Verify correct copy is being checked in
IF NOT EXISTS (SELECT * FROM Copy WHERE MovieID = @MovieID AND CopyNumberID = @CopyNumberID)
BEGIN
PRINT 'Wrong Copy'
RETURN -6
END
--Declare Variables
DECLARE @TransactionID smallint
DECLARE @TransactionTypeID smallint
SET @TransactionTypeID = '2'
DECLARE @StoreID smallint
SET @StoreID = '2'
DECLARE @CheckOutDate datetime
SET @CheckOutDate = (SELECT CheckOutDate FROM RentalTransaction WHERE CopyNumberID = @CopyNumberID AND StoreID = @StoreID)
DECLARE @CheckInDate datetime
SET @CheckInDate = GETDATE()
--Begin Transaction
BEGIN TRAN
--Insert row into RentalTransactionHistory table
INSERT INTO RentalTransactionHistory ( MovieID, CopyNumberID, TransactionTypeID, MembershipID, StoreID, CheckOutDate, CheckInDate)
VALUES (
@MovieID,
@CopyNumberID,
@TransactionTypeID,
@MembershipID,
@StoreID,
@CheckOutDate,
@CheckInDate
)
--Test Error Value
IF @@ERROR <> 0
BEGIN
PRINT 'Error occured inserting into RentalTransactionHistory table'
ROLLBACK TRAN --Rollback if error occured
RETURN -8
END
--Delete row from RentalTransaction table
DELETE FROM RentalTransaction
WHERE TransactionID = @TransactionID
--Test Error Value
IF @@ERROR <> 0
BEGIN
PRINT 'Error occured deleting row from Rental Transaction table'
ROLLBACK TRAN --Rollback if error occured
RETURN -7
END
--Update CopyStatusID to Rentable in Copy table
UPDATE Copy
SET CopyStatusID = '1'
WHERE MovieID = @MovieID AND CopyNumberID = @CopyNumberID
--Test Error Value
IF @@ERROR <> 0
BEGIN
PRINT 'Error occured updating Copy table'
ROLLBACK TRAN --Rollback if error occured
RETURN -9
END
--Commit Transaction
COMMIT TRAN
PRINT 'Movie successfully Checked In'
RETURN 0
Stored Procedures
DML Triggers
4
-- ===============================================-- Author: Brent Bybee-- Create date: 01-08-2009-- Description: Trigger to prevent deletes and -- updates on the transactions table-- ===============================================CREATE TRIGGER [dbo].[NoChangesToTransactions] ON [dbo].[Transactions]INSTEAD OF DELETE, UPDATE NOT FOR REPLICATIONAS BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;
RAISERROR (N'Transactions cannot be deleted, or updated.', -- Message 10, -- Severity 1); -- Status -- Rollback any active or uncommittable transactions IF @@TRANCOUNT > 0 BEGIN ROLLBACK TRANSACTION; ENDEND;
5
SELECT dbo.Employees.EmployeeID, dbo.Customers.CompanyName, dbo.Products.ProductName, dbo.Orders.OrderDate,
dbo.[Order Details].UnitPrice
FROM dbo.Employees INNER JOIN
dbo.Orders ON dbo.Employees.EmployeeID = dbo.Orders.EmployeeID INNER JOIN
dbo.Customers ON dbo.Orders.CustomerID = dbo.Customers.CustomerID INNER JOIN
dbo.[Order Details] ON dbo.Orders.OrderID = dbo.[Order Details].OrderID INNER JOIN
dbo.Products ON dbo.[Order Details].ProductID = dbo.Products.ProductID
WHERE (dbo.Employees.EmployeeID = 1)
ORDER BY dbo.Products.ProductName, dbo.Orders.OrderDate
Joins
6
Database Backup
Database Backup (cont.)
Database Backup Completion
Database Restore
Database Restore (cont.)
Database Restore Completion
Database Reports
Database Reports (cont.)
SSIS using Visual Studio
SSIS using Visual Studio (cont.)
SSIS Package in Excel Format