Skip to content

Commit

Permalink
Descriptios provided in extended properties. Some minor warnings erad…
Browse files Browse the repository at this point in the history
…icated.
  • Loading branch information
jamiekt committed Jan 12, 2014
1 parent 5c9314e commit 095138f
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 23 deletions.
1 change: 1 addition & 0 deletions TSQLCodeLibrary/TSQLCodeLibrary.sqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Build Include="jt\Stored Procedures\TableStats.sql" />
<Build Include="jt\Stored Procedures\AllPermissions.sql" />
<Build Include="jt\Stored Procedures\GetPartitionRowTallies.sql" />
<Build Include="jt\Views\vwCodeLibraryDescriptions.sql" />
</ItemGroup>
<ItemGroup>
<ArtifactReference Include="$(DacPacRootPath)\Extensions\Microsoft\SQLDB\Extensions\SqlServer\110\SqlSchemas\master.dacpac">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ BEGIN
SELECT @vNewObjectName = 'FK_' + @vFKTableName + '_' + @vPKTableName + '_' + @vCurObjectCount

IF @pExecuteSQL = 1
EXEC SP_RENAME @vCurObjectName, @vNewObjectName, 'OBJECT'
EXEC sp_rename @vCurObjectName, @vNewObjectName, 'OBJECT'

IF @pPrintSQL = 1
SELECT @vNewObjectName, @vCurObjectName
Expand All @@ -100,7 +100,7 @@ BEGIN
SELECT DISTINCT
CONSTRAINT_NAME AS CurObjectName
INTO #CHKs
FROM INFORMATION_SCHEMA.table_constraints
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE TABLE_NAME = @vTableName AND
CONSTRAINT_TYPE = 'CHECK'
ORDER BY CONSTRAINT_NAME
Expand All @@ -123,7 +123,7 @@ BEGIN
SELECT @vNewObjectName = 'CK_' + @vTableName + '_' + @vCurObjectCount

IF @pExecuteSQL = 1
EXEC SP_RENAME @vCurObjectName, @vNewObjectName, 'OBJECT'
EXEC sp_rename @vCurObjectName, @vNewObjectName, 'OBJECT'

IF @pPrintSQL = 1
SELECT @vNewObjectName, @vCurObjectName
Expand All @@ -145,36 +145,36 @@ BEGIN
IF OBJECT_ID('TEMPDB..#Indexes') IS NOT NULL
DROP TABLE #Indexes

SELECT OBJECT_NAME(si.ID) as TableName,
SELECT OBJECT_NAME(si.id) as TableName,
si.name as IndexName,
(CASE WHEN OBJECTPROPERTY(scon.constid, 'IsPrimaryKey') = 1 THEN 1 ELSE 0 END) as bPrimary,
(CASE WHEN INDEXPROPERTY(si.ID, si.NAME, 'IsClustered') = 1 THEN 1 ELSE 0 END) as bCLustered,
(CASE WHEN INDEXPROPERTY(si.id, si.name, 'IsClustered') = 1 THEN 1 ELSE 0 END) as bClustered,
max(sk.keyno) as NumCols
INTO #Indexes
FROM SYSINDEXES si
FROM sysindexes si
INNER JOIN
SYSINDEXKEYS sk
sysindexkeys sk
ON
si.id = sk.id and
si.indid = sk.indid
INNER JOIN
SYSCOLUMNS sc
syscolumns sc
ON
sk.id = sc.id and
sk.colid = sc.colid
LEFT OUTER JOIN SYSCONSTRAINTS scon
LEFT OUTER JOIN sysconstraints scon
ON
si.id = scon.id and
si.name = object_name(scon.constid)
WHERE INDEXPROPERTY(si.id, si.name, 'IsStatistics') = 0 AND
OBJECT_NAME(si.ID) = @vTableName
GROUP BY OBJECT_NAME(si.ID),
OBJECT_NAME(si.id) = @vTableName
GROUP BY OBJECT_NAME(si.id),
si.name,
(CASE WHEN OBJECTPROPERTY(scon.constid, 'IsPrimaryKey') = 1 THEN 1 ELSE 0 END),
(CASE WHEN INDEXPROPERTY(si.ID, si.NAME, 'IsClustered') = 1 THEN 1 ELSE 0 END)
(CASE WHEN INDEXPROPERTY(si.id, si.name, 'IsClustered') = 1 THEN 1 ELSE 0 END)
ORDER BY
OBJECT_NAME(si.ID),
(CASE WHEN INDEXPROPERTY(si.ID, si.NAME, 'IsClustered') = 1 THEN 1 ELSE 0 END) DESC,
OBJECT_NAME(si.id),
(CASE WHEN INDEXPROPERTY(si.id, si.name, 'IsClustered') = 1 THEN 1 ELSE 0 END) DESC,
si.name

SELECT @vObjectCount = @@ROWCOUNT,
Expand All @@ -198,7 +198,7 @@ BEGIN
@vCurObjectName = @vTableName + '.' + @vCurObjectName

IF @pExecuteSQL = 1
EXEC SP_RENAME @vCurObjectName, @vNewObjectName, 'INDEX'
EXEC sp_rename @vCurObjectName, @vNewObjectName, 'INDEX'

IF @pPrintSQL = 1
SELECT @vNewObjectName, @vCurObjectName
Expand Down
3 changes: 3 additions & 0 deletions TSQLCodeLibrary/jt/Stored Procedures/AllPermissions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ ON rm.role_principal_id = p.principal_id
order by 1';
SET @SQL = rePLACE(@SQL,'@dbName',@dbName)
EXEC (@SQL)

GO
EXEC sp_addextendedproperty @level0name='jt',@level0type='SCHEMA',@level1name='AllPermissions',@level1type='PROCEDURE',@name='CodeLibraryDescription',@value='All permissions granted to any user, either directly or via role membership.';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ BEGIN
';
SET @sql = REPLACE(@sql,'@dbName',@dbName)
EXEC (@sql)
END
END

GO
EXEC sp_addextendedproperty @level0name='jt',@level0type='SCHEMA',@level1name='GetPartitionRowTallies',@level1type='PROCEDURE',@name='CodeLibraryDescription',@value='Tally of rows per partition in a given database.';
5 changes: 4 additions & 1 deletion TSQLCodeLibrary/jt/Stored Procedures/GetTableRowTallies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ BEGIN
SELECT name,row_count = SUM(row_count)
FROM #t
GROUP BY name;
END
END

GO
EXEC sp_addextendedproperty @level0name='jt',@level0type='SCHEMA',@level1name='GetTableRowTallies',@level1type='PROCEDURE',@name='CodeLibraryDescription',@value='Tally of rows per table in a given database.';
4 changes: 3 additions & 1 deletion TSQLCodeLibrary/jt/Stored Procedures/TableStats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,6 @@ [email protected]
SELECT *
FROM @table_metrics;

;
;
GO
EXEC sp_addextendedproperty @level0name='jt',@level0type='SCHEMA',@level1name='TableStats',@level1type='PROCEDURE',@name='CodeLibraryDescription',@value='Stats per table. Provides Rowcount, Does it have a clustered index?, Is the primary key clustered?, Number of columns, Number of unique, none-primary keys, Number of none unique columns';
5 changes: 4 additions & 1 deletion TSQLCodeLibrary/jt/Stored Procedures/tempdbStats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ SELECT SUM(user_object_reserved_page_count) AS [user object pages used],
FROM tempdb.sys.dm_db_file_space_usage;
--Determining the Total Amount of Space (Free and Used)
SELECT SUM(size)*1.0/128 AS [size in MB]
FROM tempdb.sys.database_files
FROM tempdb.sys.database_files

GO
EXEC sp_addextendedproperty @level0name='jt',@level0type='SCHEMA',@level1name='tempdbStats',@level1type='PROCEDURE',@name='CodeLibraryDescription',@value='Loads of useful information about tempdb.';
4 changes: 3 additions & 1 deletion TSQLCodeLibrary/jt/Views/vwAllSessions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ from sys.dm_exec_sessions s
left outer join sys.dm_exec_connections c
on c.session_id = s.session_id
left outer join sys.dm_exec_requests r
on r.session_id = s.session_id
on r.session_id = s.session_id
GO
EXEC sp_addextendedproperty @level0name='jt',@level0type='SCHEMA',@level1name='vwAllSessions',@level1type='VIEW',@name='CodeLibraryDescription',@value='All current sessions, plus info from sys.dm_exec_requests';
4 changes: 3 additions & 1 deletion TSQLCodeLibrary/jt/Views/vwBufferusagePerDB.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ FROM sys.dm_os_buffer_descriptors
GROUP BY [database_id], [is_modified] WITH CUBE
) AS SourceTable
PIVOT(SUM([SizeInMB]) FOR [State] IN (Clean, Dirty, Total)) AS PivotTable
ORDER BY [DatabaseName]
ORDER BY [DatabaseName]
GO
EXEC sp_addextendedproperty @level0name='jt',@level0type='SCHEMA',@level1name='vwBufferUsagePerDB',@level1type='VIEW',@name='CodeLibraryDescription',@value='Show buffer usage per database.';
4 changes: 3 additions & 1 deletion TSQLCodeLibrary/jt/Views/vwCacheUsagePerTable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ SELECT TOP 20 DB_NAME(database_id) AS 'Database'
, SUM(dirtyPage) AS 'Dirty Pages'
FROM memusage_CTE
GROUP BY database_id, object_id, index_id
ORDER BY COUNT(*) DESC
ORDER BY COUNT(*) DESC
GO
EXEC sp_addextendedproperty @level0name='jt',@level0type='SCHEMA',@level1name='vwCacheUsagePerTable',@level1type='VIEW',@name='CodeLibraryDescription',@value='Show cache usage per table. Taken from a blog by Steve Hindmarsh at http://sqlblogcasts.com/blogs/steveh/archive/2010/04/02/dbcc-memusage-in-2008.aspx';
7 changes: 6 additions & 1 deletion TSQLCodeLibrary/jt/Views/vwdiskfileLatency.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ JOIN sys.master_files AS mf
--WHERE vfs.file_id = 2 -- log files
-- ORDER BY Latency DESC
-- ORDER BY ReadLatency DESC
ORDER BY WriteLatency DESC;
ORDER BY WriteLatency DESC;

GO
EXEC sp_addextendedproperty @level0name='jt',@level0type='SCHEMA',@level1name='vwdiskfileLatency',@level1type='VIEW',@name='CodeLibraryDescription',@value='Show disk file latency. Gotten from Paul Randal at http://www.sqlskills.com/BLOGS/PAUL/category/IO-Subsystems.aspx';


0 comments on commit 095138f

Please sign in to comment.