Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 16, 2016
0 parents
commit 1ed631a
Showing
367 changed files
with
134,062 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Freeware License, some rights reserved | ||
|
||
Copyright (c) 2012 Andy Leonard, Matt Masson, Tim Mitchell, Jessica Moss, and Michelle Ufford | ||
|
||
Permission is hereby granted, free of charge, to anyone obtaining a copy | ||
of this software and associated documentation files (the "Software"), | ||
to work with the Software within the limits of freeware distribution and fair use. | ||
This includes the rights to use, copy, and modify the Software for personal use. | ||
Users are also allowed and encouraged to submit corrections and modifications | ||
to the Software for the benefit of other users. | ||
|
||
It is not allowed to reuse, modify, or redistribute the Software for | ||
commercial use in any way, or for a user�s educational materials such as books | ||
or blog articles without prior permission from the copyright holder. | ||
|
||
The above copyright notice and this permission notice need to be included | ||
in all copies or substantial portions of the software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#Apress Source Code | ||
|
||
This repository accompanies [*SQL Server 2012 Integration Services Design Patterns*](http://www.apress.com/9781430237716) by Andy Leonard, Matt Masson, Tim Mitchell, Jessica Moss, and Michelle Ufford (Apress, 2012). | ||
|
||
![Cover image](9781430237716.jpg) | ||
|
||
Download the files as a zip using the green button, or clone the repository to your machine using Git. | ||
|
||
##Releases | ||
|
||
Release v1.0 corresponds to the code in the published book, without corrections or updates. | ||
|
||
##Contributions | ||
|
||
See the file Contributing.md for more information on how you can contribute to this repository. |
26 changes: 26 additions & 0 deletions
26
SQL Server 2012 Integration Services Design Patterns/Ch01/CH01_L01.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
USE [master]; | ||
GO | ||
|
||
/* Check to see if the database already exists; if it does exist, do nothing */ | ||
IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'dbaCentralLogging') | ||
BEGIN | ||
/* Create a database to store our Chapter 1 examples */ | ||
CREATE DATABASE [dbaCentralLogging] | ||
ON PRIMARY | ||
( | ||
NAME = N'dbaCentralLogging' | ||
, FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\dbaCentralLogging.mdf' | ||
, SIZE = 1024MB | ||
, MAXSIZE = UNLIMITED | ||
, FILEGROWTH = 1024MB | ||
) | ||
LOG ON | ||
( | ||
NAME = N'dbaCentralLogging_log' | ||
, FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\dbaCentralLogging_log.ldf' | ||
, SIZE = 256MB | ||
, MAXSIZE = UNLIMITED | ||
, FILEGROWTH = 256MB | ||
); | ||
END | ||
GO |
16 changes: 16 additions & 0 deletions
16
SQL Server 2012 Integration Services Design Patterns/Ch01/CH01_L02.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
USE dbaCentralLogging; | ||
GO | ||
|
||
/* Check to see if the table already exists; if it does, drop it */ | ||
IF (SELECT OBJECT_ID('dbo.dba_monitor_SQLServerInstances')) IS NOT NULL | ||
DROP TABLE dbo.dba_monitor_SQLServerInstances; | ||
|
||
/* Create a table to store the instances we wish to monitor */ | ||
CREATE TABLE dbo.dba_monitor_SQLServerInstances | ||
( | ||
SQLServerInstance NVARCHAR(128) | ||
, LastMonitored SMALLDATETIME NULL | ||
|
||
CONSTRAINT PK_dba_monitor_SQLServerInstances | ||
PRIMARY KEY CLUSTERED(SQLServerInstance) | ||
); |
16 changes: 16 additions & 0 deletions
16
SQL Server 2012 Integration Services Design Patterns/Ch01/CH01_L03.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
USE dbaCentralLogging; | ||
GO | ||
|
||
/* Clean up the dbo.dba_monitor_SQLServerInstances table */ | ||
TRUNCATE TABLE dbo.dba_monitor_SQLServerInstances; | ||
|
||
/* Example code to populate the dba_monitor_SQLServerInstances table */ | ||
INSERT INTO dbo.dba_monitor_SQLServerInstances | ||
( | ||
SQLServerInstance | ||
) | ||
SELECT @@SERVERNAME -- The name of the server that hosts the central repository | ||
UNION ALL | ||
SELECT 'YourSQLServer' -- Example of a SQL Server instance | ||
UNION ALL | ||
SELECT 'YourSQLServer\Instance'; -- Example of a server with multiple instances |
2 changes: 2 additions & 0 deletions
2
SQL Server 2012 Integration Services Design Patterns/Ch01/CH01_L04.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* T-SQL to retrieve SQL Server instances */ | ||
SELECT SQLServerInstance FROM dbo.dba_monitor_SQLServerInstances; |
23 changes: 23 additions & 0 deletions
23
SQL Server 2012 Integration Services Design Patterns/Ch01/CH01_L05.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* T-SQL to retrieve current data and log file sizes for all databases on the server */ | ||
SELECT GETDATE() AS [captureDate] | ||
, @@SERVERNAME AS [serverName] | ||
, instance_name AS [databaseName] | ||
, SUM( | ||
CASE | ||
WHEN counter_name = 'Data File(s) Size (KB)' | ||
THEN cntr_value | ||
END | ||
) AS 'dataSizeInKB' | ||
, SUM( | ||
CASE | ||
WHEN counter_name = 'Log File(s) Size (KB)' | ||
THEN cntr_value | ||
END | ||
) AS 'logSizeInKB' | ||
FROM sys.dm_os_performance_counters | ||
WHERE counter_name IN ('Data File(s) Size (KB)' | ||
, 'Log File(s) Size (KB)') | ||
/* optional: remove _Total to avoid accidentially | ||
double-counting in queries */ | ||
AND instance_name <> '_Total' | ||
GROUP BY instance_name; |
23 changes: 23 additions & 0 deletions
23
SQL Server 2012 Integration Services Design Patterns/Ch01/CH01_L06.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
USE dbaCentralLogging; | ||
GO | ||
|
||
/* Check to see if the table already exists; if it does, drop it */ | ||
IF (SELECT OBJECT_ID('dbo.dba_monitor_databaseGrowth')) IS NOT NULL | ||
DROP TABLE dbo.dba_monitor_databaseGrowth; | ||
|
||
/* T-SQL to create a table to store data and log file size information */ | ||
CREATE TABLE dbo.dba_monitor_databaseGrowth | ||
( | ||
log_id INT IDENTITY(1,1) | ||
, captureDate DATETIME | ||
, serverName NVARCHAR(128) | ||
, databaseName SYSNAME | ||
, fileSizeInKB BIGINT | ||
, logSizeInKB BIGINT | ||
|
||
CONSTRAINT PK_dba_monitor_databaseGrowth | ||
PRIMARY KEY NONCLUSTERED(log_id) | ||
); | ||
|
||
CREATE CLUSTERED INDEX CIX_dba_monitor_databaseGrowth | ||
ON dbo.dba_monitor_databaseGrowth(captureDate, serverName, databaseName); |
92 changes: 92 additions & 0 deletions
92
SQL Server 2012 Integration Services Design Patterns/Ch01/CH01_L07.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* T-SQL to retrieve unused indexes */ | ||
|
||
/* Create a variable to hold a list of indexes */ | ||
DECLARE @Indexes TABLE | ||
( serverName NVARCHAR(128) | ||
, schemaName SYSNAME | ||
, schemaID INT | ||
, databaseName SYSNAME | ||
, databaseID INT | ||
, tableName SYSNAME | ||
, objectID INT | ||
, indexName SYSNAME | ||
, indexID INT | ||
, indexType NVARCHAR(60) | ||
, isPrimaryKey BIT | ||
, isUnique BIT | ||
, isFiltered BIT | ||
, isPartitioned BIT | ||
, numberOfRows BIGINT | ||
, totalPages BIGINT); | ||
|
||
/* Iterate through all databases */ | ||
INSERT INTO @Indexes (serverName, schemaName, schemaID, databaseName, databaseID, tableName, objectID, indexName, indexID, indexType, isUnique, isPrimaryKey, isFiltered, isPartitioned, numberOfRows, totalPages) | ||
EXECUTE sys.sp_MSforeachdb | ||
' USE ?; | ||
SELECT @@SERVERNAME | ||
, SCHEMA_NAME(t.schema_id) | ||
, t.schema_id | ||
, DB_NAME() | ||
, DB_ID() | ||
, t.name | ||
, t.object_id | ||
, i.name | ||
, i.index_id | ||
, i.type_desc | ||
, i.is_primary_key | ||
, i.is_unique | ||
, i.has_filter | ||
, CASE WHEN COUNT(p.partition_id) > 1 THEN 1 ELSE 0 END | ||
, SUM(p.rows) | ||
, SUM(au.total_pages) | ||
FROM sys.tables AS t WITH (NOLOCK) | ||
JOIN sys.indexes AS i WITH (NOLOCK) | ||
ON i.object_id = t.object_id | ||
JOIN sys.partitions AS p WITH (NOLOCK) | ||
ON p.object_id = i.object_id | ||
AND p.index_id = i.index_id | ||
JOIN sys.allocation_units AS au WITH (NOLOCK) | ||
ON au.container_id = p.partition_id | ||
WHERE i.index_id <> 0 /* exclude heaps */ | ||
GROUP BY SCHEMA_NAME(t.schema_id) | ||
, t.schema_id | ||
, t.name | ||
, t.object_id | ||
, i.name | ||
, i.index_id | ||
, i.type_desc | ||
, i.has_filter | ||
, i.is_unique | ||
, i.is_primary_key;'; | ||
|
||
/* Retrieve index stats for return to our central repository */ | ||
SELECT GETDATE() AS [captureDate] | ||
, i.serverName | ||
, i.schemaName | ||
, i.databaseName | ||
, i.tableName | ||
, i.indexName | ||
, i.indexType | ||
, i.isFiltered | ||
, i.isPartitioned | ||
, i.numberOfRows | ||
, ddius.user_seeks AS [userSeeksSinceReboot] | ||
, ddius.user_scans AS [userScansSinceReboot] | ||
, ddius.user_lookups AS [userLookupsSinceReboot] | ||
, ddius.user_updates AS [userUpdatesSinceReboot] | ||
, (i.totalPages * 8) / 1024 AS [indexSizeInMB] /* pages are 8KB */ | ||
, dosi.sqlserver_start_time AS [lastReboot] | ||
FROM @Indexes AS i | ||
JOIN sys.dm_db_index_usage_stats AS ddius | ||
ON i.databaseID = ddius.database_id | ||
AND i.objectID = ddius.object_id | ||
AND i.indexID = ddius.index_id | ||
CROSS APPLY sys.dm_os_sys_info AS dosi | ||
WHERE /* exclude system databases */ | ||
i.databaseName NOT IN ('master', 'msdb', 'tempdb', 'model') | ||
/* exclude unique indexes; assume they are serving a business function */ | ||
AND i.isUnique = 0 | ||
/* exclude primary keys; assume they are serving a business function */ | ||
AND i.isPrimaryKey = 0 | ||
/* no seeks have been performed since the last server reboot */ | ||
AND user_seeks = 0; |
33 changes: 33 additions & 0 deletions
33
SQL Server 2012 Integration Services Design Patterns/Ch01/CH01_L08.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
USE dbaCentralLogging; | ||
GO | ||
|
||
/* Check to see if the table already exists; if it does, drop it */ | ||
IF (SELECT OBJECT_ID('dbo.dba_monitor_unusedIndexes')) IS NOT NULL | ||
DROP TABLE dbo.dba_monitor_unusedIndexes; | ||
|
||
/* T-SQL to create the a table to log unused index information */ | ||
CREATE TABLE dbo.dba_monitor_unusedIndexes | ||
( log_id INT IDENTITY(1,1) | ||
, captureDate DATETIME | ||
, serverName NVARCHAR(128) | ||
, schemaName SYSNAME | ||
, databaseName SYSNAME | ||
, tableName SYSNAME | ||
, indexName SYSNAME | ||
, indexType NVARCHAR(60) | ||
, isFiltered BIT | ||
, isPartitioned BIT | ||
, numberOfRows BIGINT | ||
, userSeeksSinceReboot BIGINT | ||
, userScansSinceReboot BIGINT | ||
, userLookupsSinceReboot BIGINT | ||
, userUpdatesSinceReboot BIGINT | ||
, indexSizeInMB BIGINT | ||
, lastReboot DATETIME | ||
|
||
CONSTRAINT PK_dba_monitor_unusedIndexes | ||
PRIMARY KEY NONCLUSTERED(log_id) | ||
); | ||
|
||
CREATE CLUSTERED INDEX CIX_dba_monitor_unusedIndexes | ||
ON dbo.dba_monitor_unusedIndexes(captureDate); |
4 changes: 4 additions & 0 deletions
4
SQL Server 2012 Integration Services Design Patterns/Ch01/CH01_L09.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* T-SQL to update the LastMonitored value in dba_monitor_SQLServerInstances */ | ||
UPDATE dbo.dba_monitor_SQLServerInstances | ||
SET LastMonitored = GETDATE() | ||
WHERE SQLServerInstance = ?; |
17 changes: 17 additions & 0 deletions
17
SQL Server 2012 Integration Services Design Patterns/Ch01/MetadataCollection.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{159641D6-6404-4A2A-AE62-294DE0FE8301}") = "MetadataCollection", "MetadataCollection\MetadataCollection.dtproj", "{DFBEAD3A-5D73-49B6-A7B4-D216867ED9C0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Development|Default = Development|Default | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DFBEAD3A-5D73-49B6-A7B4-D216867ED9C0}.Development|Default.ActiveCfg = Development | ||
{DFBEAD3A-5D73-49B6-A7B4-D216867ED9C0}.Development|Default.Build.0 = Development | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
13 changes: 13 additions & 0 deletions
13
... Integration Services Design Patterns/Ch01/MetadataCollection/MetadataCollection.database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Database xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200" xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200" xmlns:ddl300="http://schemas.microsoft.com/analysisservices/2011/engine/300" xmlns:ddl300_300="http://schemas.microsoft.com/analysisservices/2011/engine/300/300" xmlns:dwd="http://schemas.microsoft.com/DataWarehouse/Designer/1.0" dwd:design-time-name="2758c364-3200-4951-8672-1c2692d23312" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"> | ||
<ID>MetadataCollection</ID> | ||
<Name>MetadataCollection</Name> | ||
<CreatedTimestamp>0001-01-01T00:00:00Z</CreatedTimestamp> | ||
<LastSchemaUpdate>0001-01-01T00:00:00Z</LastSchemaUpdate> | ||
<LastProcessed>0001-01-01T00:00:00Z</LastProcessed> | ||
<State>Unprocessed</State> | ||
<LastUpdate>0001-01-01T00:00:00Z</LastUpdate> | ||
<DataSourceImpersonationInfo> | ||
<ImpersonationMode>Default</ImpersonationMode> | ||
<ImpersonationInfoSecurity>Unchanged</ImpersonationInfoSecurity> | ||
</DataSourceImpersonationInfo> | ||
</Database> |
Oops, something went wrong.