Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 16, 2016
0 parents commit 1ed631a
Show file tree
Hide file tree
Showing 367 changed files with 134,062 additions and 0 deletions.
Binary file added 9781430237716.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -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.


15 changes: 15 additions & 0 deletions README.md
@@ -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.
@@ -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
@@ -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)
);
@@ -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
@@ -0,0 +1,2 @@
/* T-SQL to retrieve SQL Server instances */
SELECT SQLServerInstance FROM dbo.dba_monitor_SQLServerInstances;
@@ -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;
@@ -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);
@@ -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;
@@ -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);
@@ -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 = ?;
@@ -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
@@ -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>

0 comments on commit 1ed631a

Please sign in to comment.