Set Focus SQL Portfolio

612 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
612
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Set Focus SQL Portfolio

  1. 1. 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.
  2. 2. ER Diagram
  3. 3. <ul><li>/* </li></ul><ul><li>Author: Team B (Brent Bybee) </li></ul><ul><li>Date: 3/3/2009 </li></ul><ul><li>Description: Create the &quot;Checked In Movie&quot; proc and delete row from RentalTransaction table, insert into History table, and update copy table </li></ul><ul><li>*/ </li></ul><ul><li>--Create Stored Proc </li></ul><ul><li>CREATE PROC [dbo].[CheckInMovie] </li></ul><ul><li>@MembershipID smallint = NULL, </li></ul><ul><li>@MovieID smallint = NULL, </li></ul><ul><li>@CopyNumberID smallint = NULL, </li></ul><ul><li>@MediaTypeID smallint = NULL </li></ul><ul><li>AS </li></ul><ul><li>--Validation </li></ul><ul><li>IF @MembershipID IS NULL </li></ul><ul><li>BEGIN </li></ul><ul><li>PRINT 'MembershipID cannot be null' </li></ul><ul><li>RETURN -1 </li></ul><ul><li>END </li></ul><ul><li>IF @MovieID IS NULL </li></ul><ul><li>BEGIN </li></ul><ul><li>PRINT 'MovieID cannot be null' </li></ul><ul><li>RETURN -2 </li></ul><ul><li>END </li></ul><ul><li>IF @CopyNumberID IS NULL </li></ul><ul><li>BEGIN </li></ul><ul><li>PRINT 'CopyNumberID cannot be null' </li></ul><ul><li>RETURN -3 </li></ul><ul><li>END </li></ul><ul><li>IF @MediaTypeID IS NULL </li></ul><ul><li>BEGIN </li></ul><ul><li>PRINT 'MediaTypeID cannot be null' </li></ul><ul><li>RETURN -4 </li></ul><ul><li>END </li></ul><ul><li>--Verify Movie exists </li></ul><ul><li>SELECT @MediaTypeID = MediaTypeID </li></ul><ul><li>FROM Copy </li></ul><ul><li>WHERE MovieID = @MovieID AND CopyNumberID = @CopyNumberID </li></ul><ul><li>IF @MediaTypeID IS NULL </li></ul><ul><li>BEGIN </li></ul><ul><li>PRINT 'Movie is Invalid' </li></ul><ul><li>RETURN -5 </li></ul><ul><li>END </li></ul><ul><li>--Verify correct copy is being checked in </li></ul><ul><li>IF NOT EXISTS (SELECT * FROM Copy WHERE MovieID = @MovieID AND CopyNumberID = @CopyNumberID) </li></ul><ul><li>BEGIN </li></ul><ul><li>PRINT 'Wrong Copy' </li></ul><ul><li>RETURN -6 </li></ul><ul><li>END </li></ul><ul><li>--Declare Variables </li></ul><ul><li>DECLARE @TransactionID smallint </li></ul><ul><li>DECLARE @TransactionTypeID smallint </li></ul><ul><li>SET @TransactionTypeID = '2' </li></ul><ul><li>DECLARE @StoreID smallint </li></ul><ul><li>SET @StoreID = '2' </li></ul><ul><li>DECLARE @CheckOutDate datetime </li></ul><ul><li>SET @CheckOutDate = (SELECT CheckOutDate FROM RentalTransaction WHERE CopyNumberID = @CopyNumberID AND StoreID = @StoreID) </li></ul><ul><li>DECLARE @CheckInDate datetime </li></ul><ul><li>SET @CheckInDate = GETDATE() </li></ul><ul><li>--Begin Transaction </li></ul><ul><li>BEGIN TRAN </li></ul><ul><li>--Insert row into RentalTransactionHistory table </li></ul><ul><li>INSERT INTO RentalTransactionHistory ( MovieID, CopyNumberID, TransactionTypeID, MembershipID, StoreID, CheckOutDate, CheckInDate) </li></ul><ul><li>VALUES ( </li></ul><ul><li>@MovieID, </li></ul><ul><li>@CopyNumberID, </li></ul><ul><li>@TransactionTypeID, </li></ul><ul><li>@MembershipID, </li></ul><ul><li>@StoreID, </li></ul><ul><li>@CheckOutDate, </li></ul><ul><li>@CheckInDate </li></ul><ul><li>) </li></ul><ul><li>--Test Error Value </li></ul><ul><li>IF @@ERROR <> 0 </li></ul><ul><li>BEGIN </li></ul><ul><li>PRINT 'Error occured inserting into RentalTransactionHistory table' </li></ul><ul><li>ROLLBACK TRAN --Rollback if error occured </li></ul><ul><li>RETURN -8 </li></ul><ul><li>END </li></ul><ul><li>--Delete row from RentalTransaction table </li></ul><ul><li>DELETE FROM RentalTransaction </li></ul><ul><li>WHERE TransactionID = @TransactionID </li></ul><ul><li>--Test Error Value </li></ul><ul><li>IF @@ERROR <> 0 </li></ul><ul><li>BEGIN </li></ul><ul><li>PRINT 'Error occured deleting row from Rental Transaction table' </li></ul><ul><li>ROLLBACK TRAN --Rollback if error occured </li></ul><ul><li>RETURN -7 </li></ul><ul><li>END </li></ul><ul><li>--Update CopyStatusID to Rentable in Copy table </li></ul><ul><li>UPDATE Copy </li></ul><ul><li>SET CopyStatusID = '1' </li></ul><ul><li>WHERE MovieID = @MovieID AND CopyNumberID = @CopyNumberID </li></ul><ul><li>--Test Error Value </li></ul><ul><li>IF @@ERROR <> 0 </li></ul><ul><li>BEGIN </li></ul><ul><li>PRINT 'Error occured updating Copy table' </li></ul><ul><li>ROLLBACK TRAN --Rollback if error occured </li></ul><ul><li>RETURN -9 </li></ul><ul><li>END </li></ul><ul><li>--Commit Transaction </li></ul><ul><li>COMMIT TRAN </li></ul><ul><li>PRINT 'Movie successfully Checked In' </li></ul><ul><li>RETURN 0 </li></ul>Stored Procedures
  4. 4. DML Triggers -- =============================================== -- 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 REPLICATION AS 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); -- Statua -- Rollback any active or uncommittable transactions IF @@TRANCOUNT > 0 BEGIN ROLLBACK TRANSACTION; END END; -- =============================================== -- 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 REPLICATION AS 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); -- Statu s -- Rollback any active or uncommittable transactions IF @@TRANCOUNT > 0 BEGIN ROLLBACK TRANSACTION; END END;
  5. 5. <ul><li>SELECT dbo.Employees.EmployeeID, dbo.Customers.CompanyName, dbo.Products.ProductName, dbo.Orders.OrderDate, </li></ul><ul><li>dbo.[Order Details].UnitPrice </li></ul><ul><li>FROM dbo.Employees INNER JOIN </li></ul><ul><li>dbo.Orders ON dbo.Employees.EmployeeID = dbo.Orders.EmployeeID INNER JOIN </li></ul><ul><li>dbo.Customers ON dbo.Orders.CustomerID = dbo.Customers.CustomerID INNER JOIN </li></ul><ul><li>dbo.[Order Details] ON dbo.Orders.OrderID = dbo.[Order Details].OrderID INNER JOIN </li></ul><ul><li>dbo.Products ON dbo.[Order Details].ProductID = dbo.Products.ProductID </li></ul><ul><li>WHERE (dbo.Employees.EmployeeID = 1) </li></ul><ul><li>ORDER BY dbo.Products.ProductName, dbo.Orders.OrderDate </li></ul>Joins
  6. 6. Database Backup
  7. 7. Database Backup (cont.)
  8. 8. Database Backup Completion
  9. 9. Database Restore
  10. 10. Database Restore (cont.)
  11. 11. Database Restore Completion
  12. 12. Database Reports
  13. 13. Database Reports (cont.)
  14. 14. SSIS using Visual Studio
  15. 15. SSIS using Visual Studio (cont.)
  16. 16. SSIS Package in Excel Format

×