SlideShare uma empresa Scribd logo
1 de 34
Name: Doug McGlasson Email:  [email_address] Phone: (281) 853-4217
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Table of Contents
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Table of Contents - cont.
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Introduction
RDBMS Project This project provided a list of columns and business rules that are to be used as a guide for development of the proposed PiggyBank database.  The goal is a database in the third normal form but the developer is allowed to denormalize for a valid business reason.  The column list that is provided has redundancies and new columns may be necessary.  The developer is to make the best choices for primary and foreign key constraints.  The expected deliverable is an ER diagram with crows-foot notation.
RDBMS - ER Diagram
Bank Project We are given a modified version of the ER diagram we developed earlier and tasked with developing stored procedures for the following: Create new customer and update customer Create new account (savings or checking), update account status and add user Change account status, close account, reactivate account Deposit, Withdrawal and Transfer Overdraft setup (general and specific accounts) ATM procedures Show balance for last five transactions Show transaction history for the last 30 days Additionally create a trigger to prevent drop and alteration of tables plus a trigger to prevent deletes and updates to the transaction table (and any others deemed necessary)
Bank Project - ER Diagram
Bank Project – Try/Catch Block BEGIN TRY  -validate parameters - -state codes are used to send outcome to the caller  BEGIN TRANSACTION  -set Nocount on to prevent extra results from interfering with select statements  BEGIN  -body of procedure  END COMMIT TRANSACTION  END TRY  BEGIN CATCH  .  IF @@TRANCOUNT>0 ROLLBACK TRANSACTION  --Declare local variables to hold the error passed back to the caller  DECLARE @ERRORMESSAGE NVARCHAR(4000); DECLARE @ERRORSEVERITY INT; DECLARE @ERRORSTATE INT; -- Set the variables to the error values SELECT @ERRORMESSAGE = ERROR_MESSAGE(), @ERRORSEVERITY = ERROR_SEVERITY(), @ERRORSTATE = ERROR_STATE(); --Raise the error to the caller with the error  variables RAISERROR   (@ERRORMESSAGE,  @ ERRORSEVERITY,@ERRORSTATE) END CATCH
Bank Project – New Account Procedure BEGIN TRANSACTION   -- INSERT INTO ACCOUNT TABLE B EGIN BEGIN INSERT account (AccountTypeID,   AccountStatusID,CurrentBalance,   O verDraftAccountID,   GeneralOverDraft) VALUES (@AccountTypeID,   1,   @InitialAmount,   @OverDraftAccountID, @GeneralOverDraft) END --Declare local variable to hold the new AccountID -to be used to add new records to the  Transactions   and CustomerAccount tables declare @newAccountNo int --Set the value to the new AccountID set @newAccountNo=scope_identity()   BEGIN   -- INSERT INTO TRANSACTIONS TABLE INSERT TRANSACTIONS (AccountID,   TransactionTypeID,   CustomerID,   TransactionDate,   TransactionAmount,   NewBalance) Values (@NewAccountNo,   1,   @CustomerID,   getdate(),   @InitialAmount,   @InitialAmount) END BEGIN   --INSERT INTO CUSTOMERACCOUNT TABLE INSERT CustomerAccount (AccountID,   CustomerID) VALUES (@newAccountNo,   @CustomerID) END END COMMIT TRANSACTION
Bank Project – Transfer Funds Procedure BEGIN TRANSACTION SET NOCOUNT ON; declare @BeginOutBalance money set @BeginOutBalance=( SELECT  CurrentBalance  FROM  Account  WHERE  Accountid=@FromAccountID) BEGIN INSERT Transactions   (AccountID,   TransactionTypeId,   CustomerID,   TransactionDate,   TransactionAmount,   NewBalance) VALUES   (@FromAccountId,   4,   @CustomerID,   Getdate(),   @TransferAmount,   @BeginOutBalance-@TransferAmount) END DECLARE @NewOutbalance INT SET  @NewOutBalance=(@BeginOutBalance-@TransferAmount) BEGIN Update Account SET  CurrentBalance=@NewOutBalance  WHERE  AccountID=@FromAccountID END DECLARE  @BeginInBalance money SET  @BeginInBalance=( SELECT  CurrentBalance  FROM  Account  WHERE  Accountid=@ToAccountID) BEGIN INSERT Transactions   (AccountID,   TransactionTypeId,   CustomerID,   TransactionDate,   TransactionAmount,   NewBalance) VALUES     (@ToAccountId,   5,   @CustomerID,   Getdate(),   @TransferAmount,     @BeginInBalance+@TransferAmount) END DECLARE @NewInBalance INT SET  @NewInBalance=(@BeginInBalance+@TransferAmount) BEGIN Update Account SET  CurrentBalance=@NewInBalance  WHERE  AccountID=@ToAccountID END COMMIT TRANSACTION
Bank Project – DDL Trigger CREATE TRIGGER tgr_ddl_safe ON DATABASE FOR ALTER_VIEW, DROP_VIEW, ALTER_TABLE, DROP_TABLE AS BEGIN SET NOCOUNT ON --Throw an error RAISERROR('You may not drop or alter database objects.',11,1) IF @@TRANCOUNT>0 BEGIN ROLLBACK TRANSACTION END END
Bank Project – DML Trigger CREATE TRIGGER [dbo].[delTransactions] on [dbo].[Transactions] INSTEAD OF DELETE, UPDATE  AS BEGIN SET NOCOUNT ON; DECLARE @DeleteCount int; SELECT  @DeleteCount=Count(*) from Deleted;   if @DeleteCount>0 BEGIN   RAISERROR   (N'Transactions cannot be deleted or updated.', 10,1); IF @@TRANCOUNT >0 BEGIN ROLLBACK TRANSACTION; END END; END;
Library Project A database has been created to support the principal functions of a lending library’s day-to-day operations: adding new members (adult and juvenile), checking books out and in, adding new books, renewing memberships, changing a juvenile record to an adult record once the juvenile reaches 18 and updating adult record information.  Books are identified by International Standard Book Number (ISBN).  Books with the same title will have different ISBN based upon language and cover type.  The library also holds multiple copies of each ISBN.  Loan history is considered critical information and must be kept indefinitely. Library memberships are good for one year from issue date.  Adults are issued memberships and juveniles are associated with an adult sponsor until they reach 18.  Books are checked out for 14 days and members may have only 4 books out at any one time.  The deliverable is to create stored procedures to support system functionality and any necessary views and a variety of reports that can be viewed online.
Library Project  - ER Diagram
Library Project – Add New Member Proc  BEGIN TRANSACTION BEGIN  INSERT MEMBER  (LastName,   FirstName,   MiddleInitial,   Photograph)   Values   (@LastName,   @FirstName,   @MiddleInitial,   @Photograph) END if @@error<> 0 Begin print'Member name information failed' ROLLBACK TRANSACTION Return -8 End Set @newidentity=scope_identity() --STATE HAS DEFAULT CONSTRAINT If @state is null BEGIN INSERT ADULT   (Member_no,   Street,   City,   Zip,   Phone_no,   Expr_date)   VALUES     (@newidentity,   @Street,   @City,   @Zip,   @Phone_no,   getdate()+365) END   ELSE BEGIN INSERT ADULT   (Member_no,   Street,   City,   State,   Zip,   Phone_no,   Expr_date)   VALUES (@newidentity,   @Street,   @City,   @State,   @Zip,   @Phone_no,getdate()+ 365) END if @@error<>0 BEGIN PRINT 'Address insert failed' ROLLBACK TRANSACTION RETURN -9 END Set @member_no=@NEWIDENTITY -- To populate the output parameter COMMIT TRANSACTION RETURN 0 -- SUCCESS
Library Project – Check in Item Proc BEGIN TRANSACTION BEGIN UPDATE copy SET on_loan='N'where isbn=@isbn and copy_no=@copy_no END BEGIN INSERT LOANHIST SELECT @isbn,@copy_no,out_date,title_no,member_no, due_date,getdate(),NULL, NULL,NULL,NULL from loan where isbn=@isbn and copy_no=@copy_no END BEGIN delete loan where @isbn=isbn and  @copy_no=copy_no  END COMMIT TRANSACTION
Library Project – Kids Club Report    Beginning Reader June 28 Barr, Angela S Beginning Reader June 28 Barr, Angela K Junior Reader June 28 Anderson, Karl B Junior Reader June 28 Anderson, Jose H Reading Ace August 17 Anderson, Jose A Junior Reader June 28 Anderson, Frank Y Notes Birthday Member Name                                                             7 years old   8 years old   9 years old   Legend:                                      The Kids Club                                    
Library Project – Kids Club Procedure  SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROC [dbo].[uspKidsClub] AS SELECT (Lastname+', '+firstname+' '+middleinitial) AS membername,  cast(datediff(day,(birth_date+.5),Getdate())/(365.25)AS int) AS age, datename(month,Birth_date) AS birthMonth, day(Birth_date) AS DayOfBirth, juvenile.member_no FROM juvenile inner Join member  ON member.member_no=juvenile.member_no WHERE datediff(day,(birth_date+.5),Getdate())/(365.25) between 7 and 10 ORDER BY memberName GO
Library Project – Most Active Report   4 2009 January 66 Anderson, Linda B   4 2009 January 16 Anderson, Michael A Active Reader 6 2009 January 860 Barr, Angela G Active Reader 9 2009 January 2029 Chen, Amy A Active Reader 9 2009 January 516 Anderson, Shelly R Avid Reader 10 2009 January 2609 Chen, Gary T Avid Reader 11 2009 January 5547 Harui, Gary E Avid Reader 12 2009 January 4955 Graff, Mary Anne H Avid Reader 12 2009 January 302 Anderson, Michael K Reader Status No of checkouts Year Month Member Number Member Name                         For Member Activity January 2009                               Most Active Members Report                               The Library Project                            
Library Project – Most Active Procedure  CREATE proc [dbo].[uspCheckoutHist] (@Year varchar(4),   @Month varchar(15)) AS SELECT (member.lastname+', '+ member.firstname+' '+member.middleInitial) as Fullname, count(out_date)as No_of_checkouts, dateNAME(mm,out_date) as Month, datepart(month,out_date) as mo_int, datepart(year,out_date) as [Year], loanhist.member_no  FROM  loanhist inner join member  ON  member.member_no=loanhist.member_no WHERE  datepart(year,out_date)=@Year and dateNAME(mm,out_date)=@Month GROUP BY   l oanhist.member_no,datename(mm,out_date),datepart(year,out_date), datepart( month,out_date), (member.lastname+', '+ member.firstname+' '+member.middleInitial) ORDER BY  count(out_date) DESC,member_no,year desc, mo_int asc
Online Movie Project The online movie rental company, BlockFlix, has stores nationwide and is creating a centralized database  for tracking inventory, sales, customers and memberships.  The stores rent VHS movies, DVD’s and video games as well as selling new and used movies, movie memorabilia, games, game consoles, snack foods and drinks. A new website will be created that uses the database to rent movies online. Database access must be through stored procedures. All inventory is received at one location and distributed to stores.  Stores have ancillary kiosk locations in supermarkets and other retail locations that allow member or non-member rentals at $ 1.00 per day per movie. Online and store customers purchase a yearly membership at one of six levels with right to a certain number of movies out at any one time based upon their membership level.  Additionally each member will have a queue of movies they would like to be mailed to them as they return movies as specified by their membership level.  Management is expecting a high-availability database solution and mandate that all transactions are to be stored indefinitely within the database.
 
 
 
 
 
 
 
 
 
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
 
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Mais conteúdo relacionado

Semelhante a My Portfolio

Sql Portfolio(March 31)
Sql Portfolio(March 31)Sql Portfolio(March 31)
Sql Portfolio(March 31)
iceolated
 
Kevin Bengtson Portfolio
Kevin Bengtson PortfolioKevin Bengtson Portfolio
Kevin Bengtson Portfolio
Kbengt521
 
Nitin\'s Business Intelligence Portfolio
Nitin\'s Business Intelligence PortfolioNitin\'s Business Intelligence Portfolio
Nitin\'s Business Intelligence Portfolio
npatel2362
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
Chris Seebacher
 
Jazmine Kane Portfolio
Jazmine Kane PortfolioJazmine Kane Portfolio
Jazmine Kane Portfolio
Jazmine Kane
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
eileensauer
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
eileensauer
 
SetFocus SQL Portfolio
SetFocus SQL PortfolioSetFocus SQL Portfolio
SetFocus SQL Portfolio
geometro17
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
skymusic
 

Semelhante a My Portfolio (20)

Marcus Matthews
Marcus MatthewsMarcus Matthews
Marcus Matthews
 
Chris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql PortfolioChris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql Portfolio
 
SQL Server 2008 Portfolio
SQL Server 2008 PortfolioSQL Server 2008 Portfolio
SQL Server 2008 Portfolio
 
Presentation Paul
Presentation PaulPresentation Paul
Presentation Paul
 
Sql Portfolio(March 31)
Sql Portfolio(March 31)Sql Portfolio(March 31)
Sql Portfolio(March 31)
 
James Colby Maddox Business Intellignece and Computer Science Portfolio
James Colby Maddox Business Intellignece and Computer Science PortfolioJames Colby Maddox Business Intellignece and Computer Science Portfolio
James Colby Maddox Business Intellignece and Computer Science Portfolio
 
My Business Intelligence Portfolio
My Business Intelligence PortfolioMy Business Intelligence Portfolio
My Business Intelligence Portfolio
 
Kevin Bengtson Portfolio
Kevin Bengtson PortfolioKevin Bengtson Portfolio
Kevin Bengtson Portfolio
 
Nitin\'s Business Intelligence Portfolio
Nitin\'s Business Intelligence PortfolioNitin\'s Business Intelligence Portfolio
Nitin\'s Business Intelligence Portfolio
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Jazmine Kane Portfolio
Jazmine Kane PortfolioJazmine Kane Portfolio
Jazmine Kane Portfolio
 
SQL Server 2008 Portfolio
SQL Server 2008 PortfolioSQL Server 2008 Portfolio
SQL Server 2008 Portfolio
 
Uncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony DavisUncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony Davis
 
Shangz R Brown Presentation
Shangz R Brown PresentationShangz R Brown Presentation
Shangz R Brown Presentation
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Tufte Sample Bi Portfolio
Tufte Sample Bi PortfolioTufte Sample Bi Portfolio
Tufte Sample Bi Portfolio
 
SetFocus SQL Portfolio
SetFocus SQL PortfolioSetFocus SQL Portfolio
SetFocus SQL Portfolio
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineering
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

My Portfolio

  • 1. Name: Doug McGlasson Email: [email_address] Phone: (281) 853-4217
  • 2.
  • 3.
  • 4.
  • 5. RDBMS Project This project provided a list of columns and business rules that are to be used as a guide for development of the proposed PiggyBank database. The goal is a database in the third normal form but the developer is allowed to denormalize for a valid business reason. The column list that is provided has redundancies and new columns may be necessary. The developer is to make the best choices for primary and foreign key constraints. The expected deliverable is an ER diagram with crows-foot notation.
  • 6. RDBMS - ER Diagram
  • 7. Bank Project We are given a modified version of the ER diagram we developed earlier and tasked with developing stored procedures for the following: Create new customer and update customer Create new account (savings or checking), update account status and add user Change account status, close account, reactivate account Deposit, Withdrawal and Transfer Overdraft setup (general and specific accounts) ATM procedures Show balance for last five transactions Show transaction history for the last 30 days Additionally create a trigger to prevent drop and alteration of tables plus a trigger to prevent deletes and updates to the transaction table (and any others deemed necessary)
  • 8. Bank Project - ER Diagram
  • 9. Bank Project – Try/Catch Block BEGIN TRY -validate parameters - -state codes are used to send outcome to the caller BEGIN TRANSACTION -set Nocount on to prevent extra results from interfering with select statements BEGIN -body of procedure END COMMIT TRANSACTION END TRY BEGIN CATCH . IF @@TRANCOUNT>0 ROLLBACK TRANSACTION --Declare local variables to hold the error passed back to the caller DECLARE @ERRORMESSAGE NVARCHAR(4000); DECLARE @ERRORSEVERITY INT; DECLARE @ERRORSTATE INT; -- Set the variables to the error values SELECT @ERRORMESSAGE = ERROR_MESSAGE(), @ERRORSEVERITY = ERROR_SEVERITY(), @ERRORSTATE = ERROR_STATE(); --Raise the error to the caller with the error variables RAISERROR (@ERRORMESSAGE, @ ERRORSEVERITY,@ERRORSTATE) END CATCH
  • 10. Bank Project – New Account Procedure BEGIN TRANSACTION -- INSERT INTO ACCOUNT TABLE B EGIN BEGIN INSERT account (AccountTypeID, AccountStatusID,CurrentBalance, O verDraftAccountID, GeneralOverDraft) VALUES (@AccountTypeID, 1, @InitialAmount, @OverDraftAccountID, @GeneralOverDraft) END --Declare local variable to hold the new AccountID -to be used to add new records to the Transactions and CustomerAccount tables declare @newAccountNo int --Set the value to the new AccountID set @newAccountNo=scope_identity() BEGIN -- INSERT INTO TRANSACTIONS TABLE INSERT TRANSACTIONS (AccountID, TransactionTypeID, CustomerID, TransactionDate, TransactionAmount, NewBalance) Values (@NewAccountNo, 1, @CustomerID, getdate(), @InitialAmount, @InitialAmount) END BEGIN --INSERT INTO CUSTOMERACCOUNT TABLE INSERT CustomerAccount (AccountID, CustomerID) VALUES (@newAccountNo, @CustomerID) END END COMMIT TRANSACTION
  • 11. Bank Project – Transfer Funds Procedure BEGIN TRANSACTION SET NOCOUNT ON; declare @BeginOutBalance money set @BeginOutBalance=( SELECT CurrentBalance FROM Account WHERE Accountid=@FromAccountID) BEGIN INSERT Transactions (AccountID, TransactionTypeId, CustomerID, TransactionDate, TransactionAmount, NewBalance) VALUES (@FromAccountId, 4, @CustomerID, Getdate(), @TransferAmount, @BeginOutBalance-@TransferAmount) END DECLARE @NewOutbalance INT SET @NewOutBalance=(@BeginOutBalance-@TransferAmount) BEGIN Update Account SET CurrentBalance=@NewOutBalance WHERE AccountID=@FromAccountID END DECLARE @BeginInBalance money SET @BeginInBalance=( SELECT CurrentBalance FROM Account WHERE Accountid=@ToAccountID) BEGIN INSERT Transactions (AccountID, TransactionTypeId, CustomerID, TransactionDate, TransactionAmount, NewBalance) VALUES (@ToAccountId, 5, @CustomerID, Getdate(), @TransferAmount, @BeginInBalance+@TransferAmount) END DECLARE @NewInBalance INT SET @NewInBalance=(@BeginInBalance+@TransferAmount) BEGIN Update Account SET CurrentBalance=@NewInBalance WHERE AccountID=@ToAccountID END COMMIT TRANSACTION
  • 12. Bank Project – DDL Trigger CREATE TRIGGER tgr_ddl_safe ON DATABASE FOR ALTER_VIEW, DROP_VIEW, ALTER_TABLE, DROP_TABLE AS BEGIN SET NOCOUNT ON --Throw an error RAISERROR('You may not drop or alter database objects.',11,1) IF @@TRANCOUNT>0 BEGIN ROLLBACK TRANSACTION END END
  • 13. Bank Project – DML Trigger CREATE TRIGGER [dbo].[delTransactions] on [dbo].[Transactions] INSTEAD OF DELETE, UPDATE AS BEGIN SET NOCOUNT ON; DECLARE @DeleteCount int; SELECT @DeleteCount=Count(*) from Deleted; if @DeleteCount>0 BEGIN RAISERROR (N'Transactions cannot be deleted or updated.', 10,1); IF @@TRANCOUNT >0 BEGIN ROLLBACK TRANSACTION; END END; END;
  • 14. Library Project A database has been created to support the principal functions of a lending library’s day-to-day operations: adding new members (adult and juvenile), checking books out and in, adding new books, renewing memberships, changing a juvenile record to an adult record once the juvenile reaches 18 and updating adult record information. Books are identified by International Standard Book Number (ISBN). Books with the same title will have different ISBN based upon language and cover type. The library also holds multiple copies of each ISBN. Loan history is considered critical information and must be kept indefinitely. Library memberships are good for one year from issue date. Adults are issued memberships and juveniles are associated with an adult sponsor until they reach 18. Books are checked out for 14 days and members may have only 4 books out at any one time. The deliverable is to create stored procedures to support system functionality and any necessary views and a variety of reports that can be viewed online.
  • 15. Library Project - ER Diagram
  • 16. Library Project – Add New Member Proc BEGIN TRANSACTION BEGIN INSERT MEMBER (LastName, FirstName, MiddleInitial, Photograph) Values (@LastName, @FirstName, @MiddleInitial, @Photograph) END if @@error<> 0 Begin print'Member name information failed' ROLLBACK TRANSACTION Return -8 End Set @newidentity=scope_identity() --STATE HAS DEFAULT CONSTRAINT If @state is null BEGIN INSERT ADULT (Member_no, Street, City, Zip, Phone_no, Expr_date) VALUES (@newidentity, @Street, @City, @Zip, @Phone_no, getdate()+365) END ELSE BEGIN INSERT ADULT (Member_no, Street, City, State, Zip, Phone_no, Expr_date) VALUES (@newidentity, @Street, @City, @State, @Zip, @Phone_no,getdate()+ 365) END if @@error<>0 BEGIN PRINT 'Address insert failed' ROLLBACK TRANSACTION RETURN -9 END Set @member_no=@NEWIDENTITY -- To populate the output parameter COMMIT TRANSACTION RETURN 0 -- SUCCESS
  • 17. Library Project – Check in Item Proc BEGIN TRANSACTION BEGIN UPDATE copy SET on_loan='N'where isbn=@isbn and copy_no=@copy_no END BEGIN INSERT LOANHIST SELECT @isbn,@copy_no,out_date,title_no,member_no, due_date,getdate(),NULL, NULL,NULL,NULL from loan where isbn=@isbn and copy_no=@copy_no END BEGIN delete loan where @isbn=isbn and @copy_no=copy_no END COMMIT TRANSACTION
  • 18. Library Project – Kids Club Report   Beginning Reader June 28 Barr, Angela S Beginning Reader June 28 Barr, Angela K Junior Reader June 28 Anderson, Karl B Junior Reader June 28 Anderson, Jose H Reading Ace August 17 Anderson, Jose A Junior Reader June 28 Anderson, Frank Y Notes Birthday Member Name                                                             7 years old   8 years old   9 years old   Legend:                                     The Kids Club                                    
  • 19. Library Project – Kids Club Procedure SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROC [dbo].[uspKidsClub] AS SELECT (Lastname+', '+firstname+' '+middleinitial) AS membername, cast(datediff(day,(birth_date+.5),Getdate())/(365.25)AS int) AS age, datename(month,Birth_date) AS birthMonth, day(Birth_date) AS DayOfBirth, juvenile.member_no FROM juvenile inner Join member ON member.member_no=juvenile.member_no WHERE datediff(day,(birth_date+.5),Getdate())/(365.25) between 7 and 10 ORDER BY memberName GO
  • 20. Library Project – Most Active Report   4 2009 January 66 Anderson, Linda B   4 2009 January 16 Anderson, Michael A Active Reader 6 2009 January 860 Barr, Angela G Active Reader 9 2009 January 2029 Chen, Amy A Active Reader 9 2009 January 516 Anderson, Shelly R Avid Reader 10 2009 January 2609 Chen, Gary T Avid Reader 11 2009 January 5547 Harui, Gary E Avid Reader 12 2009 January 4955 Graff, Mary Anne H Avid Reader 12 2009 January 302 Anderson, Michael K Reader Status No of checkouts Year Month Member Number Member Name                         For Member Activity January 2009                               Most Active Members Report                               The Library Project                            
  • 21. Library Project – Most Active Procedure CREATE proc [dbo].[uspCheckoutHist] (@Year varchar(4), @Month varchar(15)) AS SELECT (member.lastname+', '+ member.firstname+' '+member.middleInitial) as Fullname, count(out_date)as No_of_checkouts, dateNAME(mm,out_date) as Month, datepart(month,out_date) as mo_int, datepart(year,out_date) as [Year], loanhist.member_no FROM loanhist inner join member ON member.member_no=loanhist.member_no WHERE datepart(year,out_date)=@Year and dateNAME(mm,out_date)=@Month GROUP BY l oanhist.member_no,datename(mm,out_date),datepart(year,out_date), datepart( month,out_date), (member.lastname+', '+ member.firstname+' '+member.middleInitial) ORDER BY count(out_date) DESC,member_no,year desc, mo_int asc
  • 22. Online Movie Project The online movie rental company, BlockFlix, has stores nationwide and is creating a centralized database for tracking inventory, sales, customers and memberships. The stores rent VHS movies, DVD’s and video games as well as selling new and used movies, movie memorabilia, games, game consoles, snack foods and drinks. A new website will be created that uses the database to rent movies online. Database access must be through stored procedures. All inventory is received at one location and distributed to stores. Stores have ancillary kiosk locations in supermarkets and other retail locations that allow member or non-member rentals at $ 1.00 per day per movie. Online and store customers purchase a yearly membership at one of six levels with right to a certain number of movies out at any one time based upon their membership level. Additionally each member will have a queue of movies they would like to be mailed to them as they return movies as specified by their membership level. Management is expecting a high-availability database solution and mandate that all transactions are to be stored indefinitely within the database.
  • 23.  
  • 24.  
  • 25.  
  • 26.  
  • 27.  
  • 28.  
  • 29.  
  • 30.  
  • 31.  
  • 32.
  • 33.  
  • 34.