SlideShare uma empresa Scribd logo
1 de 20
/2005

    Portfolio

         Greg Lewis
greg.lewis@ymail.com
     (310) 985 - 3324
Table of Contents
What is SetFocus                              3
RDBMS Concepts                                4
Writing Queries using SQL Server 2008 T SQL   7
Implementing a SQL Server Database            13
SSIS – SQL Server Integration Services        17
SSRS – SQL Server Reporting Services          19
What is SetFocus?

• The SetFocus SQL Master’s Program is an intensive, hands–on,
project oriented program allowing knowledge and valuable
experience putting the SQL skill set to use in a simulated work
environment.

• Over 300 hours of in-depth hands on experience focused on SQL.

• SetFocus projects are real world projects that are distributed just
as I would receive in a position. I received project specifications and
was expected to identify best courses of action with deadlines set
for completion.
RDBMS Concepts
 Normalization and Database Objects
• Displaying data to a user in a familiar form alleviates
confusion when describing how the system will perform

• In order to get the best performance from a database
data needs to be organized. This helps it to function at its
optimal efficiency.

• Keys/constraints are needed to keep the Data Integrity
and assist in the separation of duties amongst database
programmers and administrators.




  Normalization - What and Why
  We normalize data into a computerized and logical model by
   converting the data from its real world or physical model.
• Views – is a highly utilized tool in a SQL database and can
combine data from two or more tables. It also can utilize tables,
functions, and even other views to produce results.

• Functions – performs specific tasks by taking one or more
arguments and return a result as a SQL object.

•Stored Procedures – are complete T SQL programs that may
consist of SQL statements and functions.

• Triggers – is a special form of a stored procedure and is
automatically run when an event such as INSERT, UPDATE,
DELETE occurs in a table. Similar to Schemabinding.




         Database Objects - Why
Data retrieval needs to be as efficient as possible. Databases needs
           more tools to meet demands placed on them.
Writing Queries using MS
 SQL Server 2008 T-SQL
Single Table Queries, Views and Stored Procedures, Joins,
                          Unions, and Advanced Queries
• The Cheap Books form displays available books below a certain price. The user enters 15 in the txtUnitPrice form field. Return
ISBN, title and publisher in order by title.

Use JungleBooks
DECLARE @txtUnitPrice int
SET @txtUnitPrice = 15
SELECT B.ISBN as ISBN, B.Title as Title, B.Publisher as Publisher
FROM dbo.Books as B
WHERE B.UnitPrice < @txtUnitPrice
ORDER BY b.Title

• The Range of Customers form allows the user to view orders placed within a given range of customer IDs. The user enters 6 in
the txtIDStart form field and 15 in txtIDEnd form field. Display all columns of data in order by Customer ID. Alias the columns
in the result set as: ‘Order #’, ‘Cust ID’, ‘Order Date’.

Use JungleBooks
Declare @txtlDStart as int , @txtlDEnd as int
Set @txtlDStart = 6
Set @txtlDEnd = 15
Select OrderDate as [Order Date], CustomerID as [Cust ID], OrderID as [Order #]
From dbo.Orders
Where OrderID BETWEEN @txtlDStart AND @txtlDEnd
Order by [Cust ID]




                           Single Table Queries
•The Expired Cards page is a report on credit cards that have expired and
             credit cards that will expire soon. Output the customer ID, customer name and
             expiry date of the card for records with an expiry date prior to 30 days after the
             current date (today). Display the records by expiry date in descending order.
             Alias as: ‘ID’, ‘Name’, ‘Expires’.


              Use JungleBooks

              Declare @Expiration datetime
              Set @Expiration = DATEADD(day, 30, Getdate())
              Select CustomerID as [ID], Name as [Name], Day(ExpiryDate)as [Expires]
              From dbo.Customers
              Where Day(ExpiryDate) < @Expiration
              Order by Expires DESC




Advanced Single Table Query with
            Results
• Write and execute a query on the Title, Item and Copy tables that returns the ISBN, copy_no, on_loan, title, translation, cover for rows in
the copy table with an ISBN of 500 or 1000. Only available books should be displayed and hardback copies should be listed first.
Use library

Declare @onloan char(10) = 'N'
Select Distinct I.isbn, C.copy_no, C.on_loan, T.title, I.translation,I.cover
   From dbo.title as T
   Join dbo.item as I
   on T.title_no = I.title_no
   Join dbo.copy as C
   on C.title_no = I.title_no
Where I.isbn IN(500, 1000) and C.on_loan = @onloan
Order by I.cover, C.on_loan

• Retrieve the member’s full name and member_no from the Member table and the ISBN and log_date values fromthe Reservation table for
member numbers 250, 341, and 1675. Order the results by member_no and log_date. You should show information for these members, even
if they have no books on reserve.
Use library

Select M.firstname + N' ' + COALESCE(M.middleinitial, + N'') + N' ' + M.lastname as [Full Name], M.member_no, R.isbn, R.log_date
   From dbo.reservation as R
   Right Join dbo.member as M
   on R.member_no = M.member_no
Where M.member_no IN(250, 341, 1675)
Order by M.member_no, R.log_date




         Advanced Queries Using Joins
Using joins and a UNION clause, write a query to retrieve a single list of members both adult and juvenile, who have
        reserved ISBN number 288. The list must include the ISBN, title, member_no and name (i.e.: Smith, John) of each
        member who has the reservation. Additionally, the list should indicate whether the member is an adult or a juvenile.
        Output the records by name.
Use library
Declare @reserved# int = 288,
@txtAdult As Char(10) = 'Adult‘, @txtJuvenile As Char(10) = 'Juvenile'
Select R.isbn as ISBN, T.title as Title, R.member_no as [Member No.],
@txtAdult as 'Member Type' , M.lastname + N', ' + (M.middleinitial, + N'') + N' ' +
M.firstname as FullName
From dbo.item as I
Join dbo.reservation as R
On I.isbn = R.isbn
Join dbo.member as M
On R.member_no = M.member_no
Join dbo.adult as A
On M.member_no = A.member_no
Join dbo.title as T
On I.title_no = T.title_no
Where R.isbn = @reserved#
Union All
Select R.isbn, T.title, M.member_no, @txtJuvenile, M.lastname + N', ' +
M.middleinitial, + N'') + N' ' + M.firstname as FullName
From dbo.item as I
Join dbo.reservation as R
On I.isbn = R.isbn
Join dbo.member as M
On R.member_no = M.member_no
Join juvenile as J
On M.member_no = J.member_no
Join dbo.title as T
On I.title_no = T.title_no
Where R.isbn = @reserved#
Order by FullName



Join/Union Query with Results
Create a view in the TSQLFundamentals2008 database that returns the orderid, day of the week
 (Spelled Out), the name of the month (spelled Out), the day of the month, and the year based on the
                                 order date in the sales.orders table

USE TSQLFundamentals2008
Create VIEW [dbo].[MyDateView]
AS
SELECT orderid, DATENAME(dw, orderdate) AS [Day Name], DATENAME(MM, orderdate) AS [Month
Name], DAY(orderdate) AS [Day Of Month], YEAR(orderdate) AS [Order Year]
FROM Sales.Orders;

Create a stored procedure in the TSQLFundamentals2008 database that returns the order ID, the order
date, the ship country. The employee full name, and the company name. The ship country should be a
        parameter and the result set should be sorted by order date from most recent to oldest.
                                                     pagef
                                                format o
                                      ed to fit
USE [TSQLFundamentals2008]
GO SET ANSI_NULLS ON GO           Edit
SET QUOTED_IDENTIFIER ON GO
CREATE PROCEDURE [dbo].[usp_OrdersByCountry]
       @ShipCountry as VarChar(25)= 'USA'
AS
BEGIN
SET NOCOUNT ON;
Select O.orderid, O.orderdate, O.shipcountry, E.firstname + N' ' + E.lastname As Employee, C.companyname
From Sales.Orders As O
Inner Join Sales.Customers As C
       On C.custid = O.custid
Inner Join HR.Employees As E
       On E.empid = O.empid
Where O.shipcountry = @ShipCountry
Order By O.orderdate Desc
END


      View and Stored Procedure
Implementing a Microsoft
         SQL Server Database
                   Piggy Bank
 Piggy Bank is a database produced by SetFocus students
   ranging from the CREATE DATABASE script to all stored
    procedures, Functions, Views, and Triggers required so
that banking transactions may be done in a clean efficient
manner. Deposits, withdrawals, bank statements, etc. are
just a few of the requirements considered in this project.
CREATE proc [dbo].[sp_addnewcustomer]
        @CustomerFirstName           nvarchar(20)      = null
       , @CustomerLastName           nvarchar(30)     = null
       , @CustomerMiddleInitial      nvarchar(1)      = null
       , @Street                     nvarchar(50)      = null
       , @City                       nvarchar(20)     = null
       , @State                      char(2)          = null
       , @ZipCode                    char(10)         = null
       , @Email                      nvarchar(30)     = null
       , @HomePhone                  char(12)         = null
       , @WorkPhone                  char(12)         = null
       , @CellPhone                  char(12)         = null
       , @CustomerID                      int              OUTPUT
as
BEGIN TRY
If @CustomerLastName is null
     Begin
                   RAISERROR('first name cant be null',11,1)
    End
BEGIN TRAN
INSERT INTO [PiggyBank].[dbo].[Customer]
       ([CustomerFirstName] ,[CustomerLastName] ,[CustomerMiddleInitial] ,[Street] ,[City],[State] ,[ZipCode] ,[Email] ,[HomePhone])
VALUES
      ( @CustomerFirstName, @CustomerLastName, @CustomerMiddleInitial, @Street, @City, @State, @ZipCode, @Email, @HomePhone)
SET @CustomerID = SCOPE_IDENTITY()
Return @CustomerID

                                                                                       Catch
                                                                              ollback/
                                                               issing Code (R             t of
                                                    N O TE : M                  fit forma
                                                               ion) - Edited to
                                                    Transact
                                                    page



     Add Customer Stored Procedure
CREATE PROCEDURE [dbo].[sp_Deposit]
     @AccountID                  int              = null
    ,@CustomerID                 int              = null
    ,@TransactionAmount          money            = null
    ,@TransactionID              int              OUTPUT
AS
BEGIN TRY
DECLARE @NewBalance money, @CurrentBalance money
SET @NewBalance = (SELECT CurrentBalance
                      FROM dbo.Account
                      WHERE AccountID = @AccountID) + @TransactionAmount
    BEGIN TRAN
    IF NOT EXISTS     (SELECT AccountID
                                                                                                                   01
                      FROM dbo.Account                                                                     ID 1000
                                                                                                 to Account
                                                                                        of $2000
                      WHERE AccountID = @AccountID)
                                                                                Deposit
                                                                                          ber 2)
    BEGIN
                 RAISERROR ('Account does not exist',3,1)                       (row num
    END
    IF NOT EXISTS     (SELECT CustomerID
                      FROM dbo.Customer
                      WHERE CustomerID = @CustomerID)
    BEGIN
                 RAISERROR('Customer does not exist',3,1)
    END
BEGIN
INSERT INTO [PiggyBank].[dbo].[Transactions]
      ([AccountID],[TransactionTypeID],[CustomerID],[TransactionDate],[TransactionAmount],[NewBalance])
        VALUES
        (@AccountID,2,@CustomerID,GETDATE(),@TransactionAmount,@NewBalance)
    UPDATE dbo.Account
    SET CurrentBalance = @NewBalance
    WHERE AccountID = @AccountID


    SELECT @TransactionID = SCOPE_IDENTITY()




                 Deposit into Bank Account
CREATE TRIGGER trgDropTables
ON DATABASE FOR DROP_TABLE
AS
BEGIN TRAN
RAISERROR('TABLES ARE SET SO THAT THEY MAY NOT BE DROPPED FROM SYSTEM', 5,1)
ROLLBACK
GO


CREATE TRIGGER trgAlterTables
ON DATABASE FOR ALTER_TABLE
AS
BEGIN TRAN
RAISERROR('TABLES ARE SET SO THAT THEY MAY NOT BE ALTERED', 5,1)
ROLLBACK
GO


CREATE TRIGGER trgDropViews
ON DATABASE FOR DROP_VIEW
AS
BEGIN TRAN
RAISERROR('VIEWS ARE SET SO THAT THEY MAY NOT BE DROPPED FROM SYSTEM', 5,1)
ROLLBACK
GO


CREATE TRIGGER dbo.trgNODELETTRANSACTION
ON dbo.Transactions
AFTER DELETE
AS
BEGIN TRAN


RAISERROR('TRANSACTIONS CANNOT BE DELETED', 5,1)
ROLLBACK
GO




                       Triggers in the Database
SSIS – SQL Server
 Integration Services
Extract, Transfer & Load, Variables, Aggregation and
                      Advanced Package Integration
Control Flow




        Data Flow




ETL Subroutine in SSIS
SSRS – SQL Server
  Reporting Services
Design, User Interface and Multimedia Publication
Report Design in SSRS

Mais conteúdo relacionado

Mais procurados

Mais procurados (7)

My Portfolio
My PortfolioMy Portfolio
My Portfolio
 
Xml overview
Xml overviewXml overview
Xml overview
 
Benforta
BenfortaBenforta
Benforta
 
Relational / XML DB -SQL Server & Oracle Database
 Relational /  XML DB -SQL Server & Oracle Database Relational /  XML DB -SQL Server & Oracle Database
Relational / XML DB -SQL Server & Oracle Database
 
Xhtml tags reference
Xhtml tags referenceXhtml tags reference
Xhtml tags reference
 
Mongo db
Mongo dbMongo db
Mongo db
 
Practical guide to SQL basics
Practical guide to SQL basicsPractical guide to SQL basics
Practical guide to SQL basics
 

Destaque

Destaque (7)

Jessica Herndon Sql Portfolio
Jessica Herndon Sql PortfolioJessica Herndon Sql Portfolio
Jessica Herndon Sql Portfolio
 
News letter
News letterNews letter
News letter
 
SQL Portfolio
SQL PortfolioSQL Portfolio
SQL Portfolio
 
Kallkritik kalmar
Kallkritik kalmarKallkritik kalmar
Kallkritik kalmar
 
Chris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql PortfolioChris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql Portfolio
 
Relationship Database
Relationship DatabaseRelationship Database
Relationship Database
 
Sql Resume
Sql ResumeSql Resume
Sql Resume
 

Semelhante a Greg Lewis SQL Portfolio

Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence PortfolioChris Seebacher
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolioguest3ea163
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle SqlAhmed Yaseen
 
Kevin Bengtson Portfolio
Kevin Bengtson PortfolioKevin Bengtson Portfolio
Kevin Bengtson PortfolioKbengt521
 
May Woo Bi Portfolio
May Woo Bi PortfolioMay Woo Bi Portfolio
May Woo Bi Portfoliomaywoo
 
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 DavisRed Gate Software
 
Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Charles Givre
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introductionSmriti Jain
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineeringJulian Hyde
 
Work in TDW
Work in TDWWork in TDW
Work in TDWsaso70
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries InformationNishant Munjal
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Achmad Solichin
 
When to NoSQL and when to know SQL
When to NoSQL and when to know SQLWhen to NoSQL and when to know SQL
When to NoSQL and when to know SQLSimon Elliston Ball
 

Semelhante a Greg Lewis SQL Portfolio (20)

Marcus Matthews
Marcus MatthewsMarcus Matthews
Marcus Matthews
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolio
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle Sql
 
Kevin Bengtson Portfolio
Kevin Bengtson PortfolioKevin Bengtson Portfolio
Kevin Bengtson Portfolio
 
May Woo Bi Portfolio
May Woo Bi PortfolioMay Woo Bi Portfolio
May Woo Bi 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
 
Sql Server 2000
Sql Server 2000Sql Server 2000
Sql Server 2000
 
Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
SQL Reports in Koha
SQL Reports in KohaSQL Reports in Koha
SQL Reports in Koha
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Tactical data engineering
Tactical data engineeringTactical data engineering
Tactical data engineering
 
SQL
SQLSQL
SQL
 
Work in TDW
Work in TDWWork in TDW
Work in TDW
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
 
Les09
Les09Les09
Les09
 
When to NoSQL and when to know SQL
When to NoSQL and when to know SQLWhen to NoSQL and when to know SQL
When to NoSQL and when to know SQL
 
70433 Dumps DB
70433 Dumps DB70433 Dumps DB
70433 Dumps DB
 

Greg Lewis SQL Portfolio

  • 1. /2005 Portfolio Greg Lewis greg.lewis@ymail.com (310) 985 - 3324
  • 2. Table of Contents What is SetFocus 3 RDBMS Concepts 4 Writing Queries using SQL Server 2008 T SQL 7 Implementing a SQL Server Database 13 SSIS – SQL Server Integration Services 17 SSRS – SQL Server Reporting Services 19
  • 3. What is SetFocus? • The SetFocus SQL Master’s Program is an intensive, hands–on, project oriented program allowing knowledge and valuable experience putting the SQL skill set to use in a simulated work environment. • Over 300 hours of in-depth hands on experience focused on SQL. • SetFocus projects are real world projects that are distributed just as I would receive in a position. I received project specifications and was expected to identify best courses of action with deadlines set for completion.
  • 4. RDBMS Concepts Normalization and Database Objects
  • 5. • Displaying data to a user in a familiar form alleviates confusion when describing how the system will perform • In order to get the best performance from a database data needs to be organized. This helps it to function at its optimal efficiency. • Keys/constraints are needed to keep the Data Integrity and assist in the separation of duties amongst database programmers and administrators. Normalization - What and Why We normalize data into a computerized and logical model by converting the data from its real world or physical model.
  • 6. • Views – is a highly utilized tool in a SQL database and can combine data from two or more tables. It also can utilize tables, functions, and even other views to produce results. • Functions – performs specific tasks by taking one or more arguments and return a result as a SQL object. •Stored Procedures – are complete T SQL programs that may consist of SQL statements and functions. • Triggers – is a special form of a stored procedure and is automatically run when an event such as INSERT, UPDATE, DELETE occurs in a table. Similar to Schemabinding. Database Objects - Why Data retrieval needs to be as efficient as possible. Databases needs more tools to meet demands placed on them.
  • 7. Writing Queries using MS SQL Server 2008 T-SQL Single Table Queries, Views and Stored Procedures, Joins, Unions, and Advanced Queries
  • 8. • The Cheap Books form displays available books below a certain price. The user enters 15 in the txtUnitPrice form field. Return ISBN, title and publisher in order by title. Use JungleBooks DECLARE @txtUnitPrice int SET @txtUnitPrice = 15 SELECT B.ISBN as ISBN, B.Title as Title, B.Publisher as Publisher FROM dbo.Books as B WHERE B.UnitPrice < @txtUnitPrice ORDER BY b.Title • The Range of Customers form allows the user to view orders placed within a given range of customer IDs. The user enters 6 in the txtIDStart form field and 15 in txtIDEnd form field. Display all columns of data in order by Customer ID. Alias the columns in the result set as: ‘Order #’, ‘Cust ID’, ‘Order Date’. Use JungleBooks Declare @txtlDStart as int , @txtlDEnd as int Set @txtlDStart = 6 Set @txtlDEnd = 15 Select OrderDate as [Order Date], CustomerID as [Cust ID], OrderID as [Order #] From dbo.Orders Where OrderID BETWEEN @txtlDStart AND @txtlDEnd Order by [Cust ID] Single Table Queries
  • 9. •The Expired Cards page is a report on credit cards that have expired and credit cards that will expire soon. Output the customer ID, customer name and expiry date of the card for records with an expiry date prior to 30 days after the current date (today). Display the records by expiry date in descending order. Alias as: ‘ID’, ‘Name’, ‘Expires’. Use JungleBooks Declare @Expiration datetime Set @Expiration = DATEADD(day, 30, Getdate()) Select CustomerID as [ID], Name as [Name], Day(ExpiryDate)as [Expires] From dbo.Customers Where Day(ExpiryDate) < @Expiration Order by Expires DESC Advanced Single Table Query with Results
  • 10. • Write and execute a query on the Title, Item and Copy tables that returns the ISBN, copy_no, on_loan, title, translation, cover for rows in the copy table with an ISBN of 500 or 1000. Only available books should be displayed and hardback copies should be listed first. Use library Declare @onloan char(10) = 'N' Select Distinct I.isbn, C.copy_no, C.on_loan, T.title, I.translation,I.cover From dbo.title as T Join dbo.item as I on T.title_no = I.title_no Join dbo.copy as C on C.title_no = I.title_no Where I.isbn IN(500, 1000) and C.on_loan = @onloan Order by I.cover, C.on_loan • Retrieve the member’s full name and member_no from the Member table and the ISBN and log_date values fromthe Reservation table for member numbers 250, 341, and 1675. Order the results by member_no and log_date. You should show information for these members, even if they have no books on reserve. Use library Select M.firstname + N' ' + COALESCE(M.middleinitial, + N'') + N' ' + M.lastname as [Full Name], M.member_no, R.isbn, R.log_date From dbo.reservation as R Right Join dbo.member as M on R.member_no = M.member_no Where M.member_no IN(250, 341, 1675) Order by M.member_no, R.log_date Advanced Queries Using Joins
  • 11. Using joins and a UNION clause, write a query to retrieve a single list of members both adult and juvenile, who have reserved ISBN number 288. The list must include the ISBN, title, member_no and name (i.e.: Smith, John) of each member who has the reservation. Additionally, the list should indicate whether the member is an adult or a juvenile. Output the records by name. Use library Declare @reserved# int = 288, @txtAdult As Char(10) = 'Adult‘, @txtJuvenile As Char(10) = 'Juvenile' Select R.isbn as ISBN, T.title as Title, R.member_no as [Member No.], @txtAdult as 'Member Type' , M.lastname + N', ' + (M.middleinitial, + N'') + N' ' + M.firstname as FullName From dbo.item as I Join dbo.reservation as R On I.isbn = R.isbn Join dbo.member as M On R.member_no = M.member_no Join dbo.adult as A On M.member_no = A.member_no Join dbo.title as T On I.title_no = T.title_no Where R.isbn = @reserved# Union All Select R.isbn, T.title, M.member_no, @txtJuvenile, M.lastname + N', ' + M.middleinitial, + N'') + N' ' + M.firstname as FullName From dbo.item as I Join dbo.reservation as R On I.isbn = R.isbn Join dbo.member as M On R.member_no = M.member_no Join juvenile as J On M.member_no = J.member_no Join dbo.title as T On I.title_no = T.title_no Where R.isbn = @reserved# Order by FullName Join/Union Query with Results
  • 12. Create a view in the TSQLFundamentals2008 database that returns the orderid, day of the week (Spelled Out), the name of the month (spelled Out), the day of the month, and the year based on the order date in the sales.orders table USE TSQLFundamentals2008 Create VIEW [dbo].[MyDateView] AS SELECT orderid, DATENAME(dw, orderdate) AS [Day Name], DATENAME(MM, orderdate) AS [Month Name], DAY(orderdate) AS [Day Of Month], YEAR(orderdate) AS [Order Year] FROM Sales.Orders; Create a stored procedure in the TSQLFundamentals2008 database that returns the order ID, the order date, the ship country. The employee full name, and the company name. The ship country should be a parameter and the result set should be sorted by order date from most recent to oldest. pagef format o ed to fit USE [TSQLFundamentals2008] GO SET ANSI_NULLS ON GO Edit SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[usp_OrdersByCountry] @ShipCountry as VarChar(25)= 'USA' AS BEGIN SET NOCOUNT ON; Select O.orderid, O.orderdate, O.shipcountry, E.firstname + N' ' + E.lastname As Employee, C.companyname From Sales.Orders As O Inner Join Sales.Customers As C On C.custid = O.custid Inner Join HR.Employees As E On E.empid = O.empid Where O.shipcountry = @ShipCountry Order By O.orderdate Desc END View and Stored Procedure
  • 13. Implementing a Microsoft SQL Server Database Piggy Bank Piggy Bank is a database produced by SetFocus students ranging from the CREATE DATABASE script to all stored procedures, Functions, Views, and Triggers required so that banking transactions may be done in a clean efficient manner. Deposits, withdrawals, bank statements, etc. are just a few of the requirements considered in this project.
  • 14. CREATE proc [dbo].[sp_addnewcustomer] @CustomerFirstName nvarchar(20) = null , @CustomerLastName nvarchar(30) = null , @CustomerMiddleInitial nvarchar(1) = null , @Street nvarchar(50) = null , @City nvarchar(20) = null , @State char(2) = null , @ZipCode char(10) = null , @Email nvarchar(30) = null , @HomePhone char(12) = null , @WorkPhone char(12) = null , @CellPhone char(12) = null , @CustomerID int OUTPUT as BEGIN TRY If @CustomerLastName is null Begin RAISERROR('first name cant be null',11,1) End BEGIN TRAN INSERT INTO [PiggyBank].[dbo].[Customer] ([CustomerFirstName] ,[CustomerLastName] ,[CustomerMiddleInitial] ,[Street] ,[City],[State] ,[ZipCode] ,[Email] ,[HomePhone]) VALUES ( @CustomerFirstName, @CustomerLastName, @CustomerMiddleInitial, @Street, @City, @State, @ZipCode, @Email, @HomePhone) SET @CustomerID = SCOPE_IDENTITY() Return @CustomerID Catch ollback/ issing Code (R t of N O TE : M fit forma ion) - Edited to Transact page Add Customer Stored Procedure
  • 15. CREATE PROCEDURE [dbo].[sp_Deposit] @AccountID int = null ,@CustomerID int = null ,@TransactionAmount money = null ,@TransactionID int OUTPUT AS BEGIN TRY DECLARE @NewBalance money, @CurrentBalance money SET @NewBalance = (SELECT CurrentBalance FROM dbo.Account WHERE AccountID = @AccountID) + @TransactionAmount BEGIN TRAN IF NOT EXISTS (SELECT AccountID 01 FROM dbo.Account ID 1000 to Account of $2000 WHERE AccountID = @AccountID) Deposit ber 2) BEGIN RAISERROR ('Account does not exist',3,1) (row num END IF NOT EXISTS (SELECT CustomerID FROM dbo.Customer WHERE CustomerID = @CustomerID) BEGIN RAISERROR('Customer does not exist',3,1) END BEGIN INSERT INTO [PiggyBank].[dbo].[Transactions] ([AccountID],[TransactionTypeID],[CustomerID],[TransactionDate],[TransactionAmount],[NewBalance]) VALUES (@AccountID,2,@CustomerID,GETDATE(),@TransactionAmount,@NewBalance) UPDATE dbo.Account SET CurrentBalance = @NewBalance WHERE AccountID = @AccountID SELECT @TransactionID = SCOPE_IDENTITY() Deposit into Bank Account
  • 16. CREATE TRIGGER trgDropTables ON DATABASE FOR DROP_TABLE AS BEGIN TRAN RAISERROR('TABLES ARE SET SO THAT THEY MAY NOT BE DROPPED FROM SYSTEM', 5,1) ROLLBACK GO CREATE TRIGGER trgAlterTables ON DATABASE FOR ALTER_TABLE AS BEGIN TRAN RAISERROR('TABLES ARE SET SO THAT THEY MAY NOT BE ALTERED', 5,1) ROLLBACK GO CREATE TRIGGER trgDropViews ON DATABASE FOR DROP_VIEW AS BEGIN TRAN RAISERROR('VIEWS ARE SET SO THAT THEY MAY NOT BE DROPPED FROM SYSTEM', 5,1) ROLLBACK GO CREATE TRIGGER dbo.trgNODELETTRANSACTION ON dbo.Transactions AFTER DELETE AS BEGIN TRAN RAISERROR('TRANSACTIONS CANNOT BE DELETED', 5,1) ROLLBACK GO Triggers in the Database
  • 17. SSIS – SQL Server Integration Services Extract, Transfer & Load, Variables, Aggregation and Advanced Package Integration
  • 18. Control Flow Data Flow ETL Subroutine in SSIS
  • 19. SSRS – SQL Server Reporting Services Design, User Interface and Multimedia Publication