Commit 929eb44a authored by O'Reilly Media, Inc's avatar O'Reilly Media, Inc
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
+7 −0
Changes for Learning Microsoft Transact - SQL - Working Files/Chapter 1/No Work Files.rtf: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural

\f0\fs24 \cf0 No work files for this lesson...}
 No newline at end of file
+12 −0
Changes for Learning Microsoft Transact - SQL - Working Files/Chapter 10/Creating A View.sql: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
-- Creating a View

Use AdventureWorks2012

SELECT * FROM Sales.SalesOrderDetail

CREATE VIEW vOrders
AS
SELECT SalesOrderID, OrderQty, ProductID, LineTotal
FROM Sales.SalesOrderDetail

SELECT * FROM vOrders
 No newline at end of file
+11 −0
Changes for Learning Microsoft Transact - SQL - Working Files/Chapter 10/Creating a Function.sql: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
Nonclustered indexes
A nonclustered index provides a ‘what-if’ view of data within a table
It creates a virtual index that the database engine can use when searching for data
Nonclustered indexes do not affect the physical storage order of the data in a table
There can be up to 999 nonclustered indexes on a table in SQL Server

Too much of a good thing…

Nonclustered indexes require constant updating as data is inserted and modified in the table

Too many nonclustered indexes will slow down table updates
+17 −0
Changes for Learning Microsoft Transact - SQL - Working Files/Chapter 10/Creating a Stored Procedure.sql: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
-- Stored Procedures

SELECT ProductID, SUM(OrderQty) Orders, AVG(UnitPrice) 'Avg Price', SUM(LineTotal) Total
FROM Sales.SalesOrderDetail
WHERE ProductID=776
GROUP BY ProductID


CREATE PROC ProdOrders
AS
SELECT ProductID, SUM(OrderQty) Orders, AVG(UnitPrice) 'Avg Price', SUM(LineTotal) Total
FROM Sales.SalesOrderDetail
WHERE ProductID=776
GROUP BY ProductID

EXEC ProdOrders
+28 −0
Changes for Learning Microsoft Transact - SQL - Working Files/Chapter 10/Stored Procedure Input Parameters.sql: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
-- Stored Procedures
-- Input Parameters

SELECT ProductID, SUM(OrderQty) Orders, AVG(UnitPrice) 'Avg Price', SUM(LineTotal) Total
FROM Sales.SalesOrderDetail
WHERE ProductID=776 -- We need to change the ProductID when we call the procedure
GROUP BY ProductID

-- Here's the original procedure
CREATE PROC ProdOrders
AS
SELECT ProductID, SUM(OrderQty) Orders, AVG(UnitPrice) 'Avg Price', SUM(LineTotal) Total
FROM Sales.SalesOrderDetail
WHERE ProductID=776
GROUP BY ProductID


-- Here's the new procedure that accepts input parameters
CREATE PROC ProdOrdersIP
@ID int
AS
SELECT ProductID, SUM(OrderQty) Orders, AVG(UnitPrice) 'Avg Price', SUM(LineTotal) Total
FROM Sales.SalesOrderDetail
WHERE ProductID=@ID
GROUP BY ProductID

EXEC ProdOrdersIP 778
Loading