<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Metadata &#8211; SQLpowered.com</title>
	<atom:link href="https://sqlpowered.com/script-category/metadata/feed/" rel="self" type="application/rss+xml" />
	<link>https://sqlpowered.com</link>
	<description>SQL Server + BI</description>
	<lastBuildDate>Sat, 31 Dec 2022 09:15:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://sqlpowered.com/wp-content/uploads/2020/07/FavIcon-e1594067873682-99x100.png</url>
	<title>Metadata &#8211; SQLpowered.com</title>
	<link>https://sqlpowered.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>List all tables and columns with user-friendly datatype names</title>
		<link>https://sqlpowered.com/script/list-all-tables-and-columns-with-user-friendly-datatype-names/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Tue, 06 Sep 2022 08:25:14 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=5496</guid>

					<description><![CDATA[SELECT [s].[name] [SchemaName], [t].[name] [TableName], [c].[name] [ColumnName], [tp].[name], CASE WHEN [tp].[name] IN ('bigint', 'int', 'smallint', 'tinyint', 'real', 'float', 'bit', 'date', 'datetime', 'geography', 'geometry', 'hierarchyid', 'image', 'smallmoney', 'money', 'ntext', 'text', 'timestamp', 'smalldatetime', 'sql_variant', 'sysname', 'uniqueidentifier', 'xml') THEN [tp].[name] WHEN [tp].[name] IN ('nchar', 'nvarchar', 'varbinary', 'varchar' ) AND [c].[max_length] = -1 THEN...]]></description>
										<content:encoded><![CDATA[<pre class="EnlighterJSRAW" data-enlighter-language="sql">SELECT [s].[name] [SchemaName], [t].[name] [TableName], [c].[name] [ColumnName], [tp].[name],
	CASE
		WHEN [tp].[name] IN ('bigint', 'int', 'smallint', 'tinyint', 'real', 'float',
							 'bit', 'date', 'datetime', 'geography', 'geometry', 'hierarchyid', 
							 'image', 'smallmoney', 'money', 'ntext', 'text', 'timestamp', 'smalldatetime', 
							 'sql_variant', 'sysname', 'uniqueidentifier', 'xml')
			THEN [tp].[name]
		WHEN [tp].[name] IN ('nchar', 'nvarchar', 'varbinary', 'varchar' ) AND [c].[max_length] = -1
			THEN [tp].[name] + '(max)'
		WHEN [tp].[name] IN ('nchar', 'nvarchar') AND [c].[max_length] &lt;&gt; -1
			THEN [tp].[name] + '(' + CAST([c].[max_length]/2 AS VARCHAR(10)) + ')'
		WHEN [tp].[name] IN ('binary', 'char', 'varbinary', 'varchar' ) AND [c].[max_length] &lt;&gt; -1
			THEN [tp].[name] + '(' + CAST([c].[max_length] AS VARCHAR(10)) + ')'
		WHEN [tp].[name] IN ( 'decimal', 'numeric')
			THEN [tp].[name] + '(' + CAST([c].[precision] AS VARCHAR(10)) + ', ' + CAST([c].[scale] AS VARCHAR(10)) + ')'
		WHEN [tp].[name] IN ('datetime2', 'datetimeoffset', 'time' )
			THEN [tp].[name] + '(' + CAST([c].[scale] AS VARCHAR(10)) + ')'
		WHEN [tp].[name] IN ('datetime2', 'datetimeoffset',   'time' )
			THEN [tp].[name] + '(' + CAST([c].[scale] AS VARCHAR(10)) + ')'
		ELSE [tp].[name]
	END, [c].[scale], [c].[precision], [c].[max_length]
FROM [sys].[tables] [t]
	INNER JOIN [sys].[columns] [c] ON [c].[object_id] = [t].[object_id]
	INNER JOIN [sys].[schemas] [s] ON [s].[schema_id] = [t].[schema_id]
	INNER JOIN [sys]. [tp] ON [tp].[system_type_id] = [c].[system_type_id] AND [tp].[user_type_id] = [c].[user_type_id]
ORDER BY [s].[name], [t].[name], [c].[name]</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Primary Keys List</title>
		<link>https://sqlpowered.com/script/primary-keys-list/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Thu, 07 Oct 2021 08:45:18 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=5209</guid>

					<description><![CDATA[This script is very useful in case we need to check if all our primary keys are also clustered. If not, then RID Lookup (Heap) will be used instead of Clustered Index Seek with all consequences related to it. SELECT [s].[name] [Schema_Name], [o].[name] AS [Object_Name], [o].[type_desc] [Object_Type], [ix].[name] AS [Primary_Key_Name],...]]></description>
										<content:encoded><![CDATA[<p>This script is very useful in case we need to check if all our primary keys are also clustered. If not, then RID Lookup (Heap) will be used instead of Clustered Index Seek with all consequences related to it.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">SELECT
	[s].[name] [Schema_Name],
    [o].[name] AS [Object_Name],
	[o].[type_desc] [Object_Type],
	[ix].[name] AS [Primary_Key_Name],
    [ic].[index_column_id] AS [Column_Id],
    [c].[name] AS [Column_Name], 
	[ix].[type_desc] [Index_Type]
FROM [sys].[objects] [o]
	INNER JOIN [sys].[schemas] [s] ON [s].[schema_id] = [o].[schema_id]
    INNER JOIN [sys].[indexes] [ix] ON [o].[object_id] = [ix].[object_id] AND [ix].[is_primary_key] = 1
    INNER JOIN [sys].[index_columns] [ic] ON [ic].[object_id] = [ix].[object_id] AND [ic].[index_id] = [ix].[index_id]
    INNER JOIN [sys].[columns] [c] ON [ix].[object_id] = [c].[object_id] AND [c].[column_id] = [ic].[column_id]
ORDER BY [s].[name], [o].[name], [c].[Column_Id]</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Number of Rows and Data and Indexes Space Used Per Table</title>
		<link>https://sqlpowered.com/script/number-of-rows-and-data-and-indexes-space-used-per-table/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Tue, 10 Aug 2021 06:03:36 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=5199</guid>

					<description><![CDATA[This query is extracted from the Disk Usage by Top Table report in SQL Server Management Studio. SELECT [a3].[name] AS [schemaname], [a2].[name] AS [tablename], [a1].[rows] AS [row_count], ( [a1].[reserved] + ISNULL ([a4].[reserved], 0)) * 8 AS [reserved], [a1].[data] * 8 AS [data], ( CASE WHEN ( [a1].[used] + ISNULL ([a4].[used],...]]></description>
										<content:encoded><![CDATA[<p>This query is extracted from the Disk Usage by Top Table report in SQL Server Management Studio.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">SELECT
		[a3].[name] AS [schemaname], [a2].[name] AS [tablename], [a1].[rows] AS [row_count],
		( [a1].[reserved] + ISNULL ([a4].[reserved], 0)) * 8 AS [reserved],
		[a1].[data] * 8 AS [data],
		( CASE
			WHEN ( [a1].[used] + ISNULL ([a4].[used], 0)) &gt; [a1].[data] THEN
		( [a1].[used] + ISNULL ([a4].[used], 0)) - [a1].[data]
			ELSE
				0
		END ) * 8 AS [index_size],
		( CASE
			WHEN ( [a1].[reserved] + ISNULL ([a4].[reserved], 0)) &gt; [a1].[used] THEN
		( [a1].[reserved] + ISNULL ([a4].[reserved], 0)) - [a1].[used]
			ELSE
				0
		END ) * 8 AS [unused]
FROM	(	SELECT	[ps].[object_id],
					SUM (CASE WHEN ( [ps].[index_id] &lt; 2 ) THEN	[ps].[row_count] ELSE 0	END) AS [rows],
					SUM ([ps].[reserved_page_count]) AS [reserved],
					SUM (
						CASE
							WHEN ( [ps].[index_id] &lt; 2 ) THEN
						( [ps].[in_row_data_page_count] + [ps].[lob_used_page_count] + [ps].[row_overflow_used_page_count] )
							ELSE
						( [ps].[lob_used_page_count] + [ps].[row_overflow_used_page_count] )
						END) AS [data],
					SUM ([ps].[used_page_count]) AS [used]
			FROM	[sys].[dm_db_partition_stats] [ps]
			WHERE [ps].[object_id] NOT IN ( SELECT [object_id] FROM	[sys].[tables] WHERE [is_memory_optimized] = 1 )
			GROUP BY [ps].[object_id] ) AS [a1]
	LEFT OUTER JOIN ( SELECT	[it].[parent_id], SUM ([ps].[reserved_page_count]) AS [reserved], SUM ([ps].[used_page_count]) AS [used]
					  FROM	[sys].[dm_db_partition_stats] [ps]
							INNER JOIN [sys].[internal_tables] [it] ON ( [it].[object_id] = [ps].[object_id] )
					  WHERE [it].[internal_type] IN ( 202, 204 )
					  GROUP BY [it].[parent_id] ) AS [a4] ON ( [a4].[parent_id] = [a1].[object_id] )
	INNER JOIN [sys].[all_objects] [a2] ON ( [a1].[object_id] = [a2].[object_id] )
	INNER JOIN [sys].[schemas] [a3] ON ( [a2].[schema_id] = [a3].[schema_id] )
WHERE [a2].[type] &lt;&gt; N'S' AND [a2].[type] &lt;&gt; N'IT'
ORDER BY schemaname, tablename</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Generate UNION ALL views for all tables from all databases with the same schema</title>
		<link>https://sqlpowered.com/script/generate-union-all-views-for-all-tables-from-all-databases-with-the-same-schema/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sun, 26 May 2019 21:30:49 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=3162</guid>

					<description><![CDATA[This scritp can be used to generate views to UNION ALL rows from all tables within two or more databases with the same schema. Replace $SCHEMA_SOURCE_DB$ with the name of the database you will take the schema from. All databases in the [db] list must have the same schema. Requires...]]></description>
										<content:encoded><![CDATA[<p>This scritp can be used to generate views to UNION ALL rows from all tables within two or more databases with the same schema. Replace $SCHEMA_SOURCE_DB$ with the name of the database you will take the schema from.</p>
<ul>
<li>All databases in the [db] list must have the same schema.</li>
<li>Requires SQL 2017 and above because of STRING_AGG() function is used</li>
</ul>
<pre class="lang:tsql decode:true">;WITH [db] AS
(
	SELECT [d].[name] [DbName]
	FROM [sys].[databases] [d]
	WHERE [d].[name] LIKE 'FILTER%'
),
[tbl] AS
(
SELECT [s].[name] [SchemaName], [t].[name] [TableName], [db].[DbName],
'	SELECT ''' + [db].[DbName] + ''' DbName, ' + STRING_AGG('[' + CAST([c].[name] AS NVARCHAR(MAX)) + ']', ', ') WITHIN GROUP (ORDER BY [c].[column_id] ASC) + CHAR(13) + 
'	FROM [' + [db].[DbName] + '].[' + [s].[name] + '].[' + [t].[name] + ']' +
CASE
	WHEN LEAD([t].[name], 1) OVER(ORDER BY [t].[name]) = ISNULL([t].[name], [t].[name]) THEN CHAR(13) + CHAR(13) + '	UNION ALL' + CHAR(13) + CHAR(13)
	ELSE ''
END [Stmt]
FROM [$SCHEMA_SOURCE_DB$].[sys].[tables] [t]
	INNER JOIN [$SCHEMA_SOURCE_DB$].[sys].[schemas] [s] ON [s].[schema_id] = [t].[schema_id]
	INNER JOIN [$SCHEMA_SOURCE_DB$].[sys].[columns] [c] ON [c].[object_id] = [t].[object_id]
	CROSS JOIN [db]
GROUP BY [db].[DbName], [s].[name], [t].[name]
)
SELECT 
	[tbl].[SchemaName], [tbl].[TableName], 
	'CREATE VIEW [dbo].[v_' + [tbl].[SchemaName] + '_' + [tbl].[TableName] + ']' + CHAR(13) + 
	'AS' + CHAR(13) + 
	STRING_AGG(CAST([Stmt] AS NVARCHAR(MAX)), '') WITHIN GROUP (ORDER BY [Stmt] ASC) + CHAR(13) + 
	'GO' + 
	CHAR(13)
FROM [tbl]
GROUP BY [tbl].[SchemaName], [tbl].[TableName]
ORDER BY [tbl].[SchemaName], [tbl].[TableName]</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>List of database tables with column names divided by comma</title>
		<link>https://sqlpowered.com/script/list-of-database-tables-with-column-names-divided-by-comma/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sun, 26 May 2019 20:27:49 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=3161</guid>

					<description><![CDATA[SELECT [t].[name] TableName, STRING_AGG([c].[name], ', ') WITHIN GROUP (ORDER BY [c].[column_id] ASC) [ColList] FROM [db.api-bd-slcr.yarmill.com].[sys].[tables] [t] INNER JOIN [db.api-bd-slcr.yarmill.com].[sys].[schemas] [s] ON [s].[schema_id] = [t].[schema_id] INNER JOIN [db.api-bd-slcr.yarmill.com].[sys].[columns] [c] ON [c].[object_id] = [t].[object_id] WHERE [s].[name] = 'dbo' AND [t].[name] &#60;&#62; '__RefactorLog' GROUP BY [t].[name] GO &#160;]]></description>
										<content:encoded><![CDATA[<pre class="lang:tsql decode:true ">SELECT [t].[name] TableName, STRING_AGG([c].[name], ', ') WITHIN GROUP (ORDER BY [c].[column_id] ASC) [ColList]
FROM [db.api-bd-slcr.yarmill.com].[sys].[tables] [t]
	INNER JOIN [db.api-bd-slcr.yarmill.com].[sys].[schemas] [s] ON [s].[schema_id] = [t].[schema_id]
	INNER JOIN [db.api-bd-slcr.yarmill.com].[sys].[columns] [c] ON [c].[object_id] = [t].[object_id]
WHERE [s].[name] = 'dbo' AND [t].[name] &lt;&gt; '__RefactorLog'
GROUP BY [t].[name]
GO</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Check for name of an object in all databases</title>
		<link>https://sqlpowered.com/script/check-for-name-of-an-object-in-all-databases/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Thu, 28 Mar 2019 09:43:10 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=3059</guid>

					<description><![CDATA[With following script we can easy iterate all databases on instance and search inside routines (views, procedures, functions etc.) for name of some object i.e. in case we would like to rename linked server and we need to know where it is currently used. For sure we can use this...]]></description>
										<content:encoded><![CDATA[<p>With following script we can easy iterate all databases on instance and search inside routines (views, procedures, functions etc.) for name of some object i.e. in case we would like to rename linked server and we need to know where it is currently used.</p>
<p>For sure we can use this script to search for any string we are interested in.</p>
<pre class="lang:tsql decode:true ">DECLARE @ObjectName sysname
DECLARE @Command NVARCHAR(MAX)

SET @ObjectName = 'THE_OBJECT'

SET @Command = 
'IF ''?'' NOT IN(''master'', ''model'', ''msdb'', ''tempdb'') 
BEGIN 
	USE ? 

	SELECT DB_NAME()

	SELECT DB_NAME() [DbName], [o].[name] [ObjectName], [o].[type_desc] [ObjectType]
	FROM [sys].[sql_modules] [sm]
		INNER JOIN [sys].[objects] [o] ON [o].[object_id] = [sm].[object_id]
	WHERE [definition] LIKE ''%' + @ObjectName + '%'' OR [definition] LIKE ''%\[' + @ObjectName + '\]%'' ESCAPE ''\''
	ORDER BY [ObjectName]
END'

EXEC [sys].[sp_MSforeachdb] @Command
GO</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>List Foreign Key Relations</title>
		<link>https://sqlpowered.com/script/list-foreign-key-relations/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Fri, 09 Mar 2018 09:07:32 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=2373</guid>

					<description><![CDATA[SELECT [ro].[name] [PKtable], [rc].[name] [PKcolumn], [po].[name] [FKtable], [pc].[name] [FKcolumn], [fk].[name] [FKname] FROM [sys].[foreign_keys] [fk] INNER JOIN [sys].[all_objects] [po] ON [po].[object_id] = [fk].[parent_object_id] INNER JOIN [sys].[all_objects] [ro] ON [ro].[object_id] = [fk].[referenced_object_id] INNER JOIN [sys].[foreign_key_columns] [fkc] ON [fkc].[constraint_object_id] = [fk].[object_id] AND [fkc].[parent_object_id] = [fk].[parent_object_id] AND [fkc].[referenced_object_id] = [fk].[referenced_object_id] INNER JOIN [sys].[columns] [pc]...]]></description>
										<content:encoded><![CDATA[<pre class="lang:tsql decode:true">SELECT [ro].[name] [PKtable], [rc].[name] [PKcolumn], [po].[name] [FKtable], [pc].[name] [FKcolumn], [fk].[name] [FKname]
FROM [sys].[foreign_keys] [fk]
	INNER JOIN [sys].[all_objects] [po] ON [po].[object_id] = [fk].[parent_object_id]
	INNER JOIN [sys].[all_objects] [ro] ON [ro].[object_id] = [fk].[referenced_object_id]
	INNER JOIN [sys].[foreign_key_columns] [fkc] ON [fkc].[constraint_object_id] = [fk].[object_id] AND
													[fkc].[parent_object_id] = [fk].[parent_object_id] AND
													[fkc].[referenced_object_id] = [fk].[referenced_object_id]
	INNER JOIN [sys].[columns] [pc] ON [pc].[object_id] = [fk].[parent_object_id] AND [pc].[column_id] = [fkc].[parent_column_id]
	INNER JOIN [sys].[columns] [rc] ON [rc].[object_id] = [fk].[referenced_object_id] AND [rc].[column_id] = [fkc].[referenced_column_id]
ORDER BY [ro].[name], [rc].[name], [po].[name], [pc].[name]
</pre>
<p>Including object schema:</p>
<pre class="lang:tsql decode:true ">SELECT [rs].[name] [PKschema], [ro].[name] [PKtable], [rc].[name] [PKcolumn], [ps].[name] [FKschema], [po].[name] [FKtable], [pc].[name] [FKcolumn], [fk].[name] [FKname]
FROM [sys].[foreign_keys] [fk]
	INNER JOIN [sys].[all_objects] [po] ON [po].[object_id] = [fk].[parent_object_id]
	INNER JOIN [sys].[schemas] [ps] ON [ps].[schema_id] = [po].[schema_id]
	INNER JOIN [sys].[all_objects] [ro] ON [ro].[object_id] = [fk].[referenced_object_id]
	INNER JOIN [sys].[schemas] [rs] ON [rs].[schema_id] = [ro].[schema_id]
	INNER JOIN [sys].[foreign_key_columns] [fkc] ON [fkc].[constraint_object_id] = [fk].[object_id] AND
													[fkc].[parent_object_id] = [fk].[parent_object_id] AND
													[fkc].[referenced_object_id] = [fk].[referenced_object_id]
	INNER JOIN [sys].[columns] [pc] ON [pc].[object_id] = [fk].[parent_object_id] AND [pc].[column_id] = [fkc].[parent_column_id]
	INNER JOIN [sys].[columns] [rc] ON [rc].[object_id] = [fk].[referenced_object_id] AND [rc].[column_id] = [fkc].[referenced_column_id]
ORDER BY [ro].[name], [rc].[name], [po].[name], [pc].[name]</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Compressed Tables List</title>
		<link>https://sqlpowered.com/script/compressed-tables-list/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Fri, 09 Mar 2018 09:06:43 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=2372</guid>

					<description><![CDATA[SELECT [t].[name] [TableName], [i1].[name] [IndexName], [i1].[type_desc] [IndexType], [fg].[name] AS [FileGroupName], [p].[partition_number] AS [PartitionNumber], CAST([p].[rows] AS FLOAT) AS [RowCount], [p].[data_compression] AS [DataCompression], [p].[data_compression_desc] [DataCompressionDesc] FROM [sys].[tables] AS [t] INNER JOIN [sys].[indexes] AS [i1] ON [i1].[object_id] = [t].[object_id] INNER JOIN [sys].[partitions] AS [p] ON [p].[object_id]=CAST([t].[object_id] AS INT) AND [p].[index_id]=[i1].[index_id] INNER JOIN [sys].[indexes]...]]></description>
										<content:encoded><![CDATA[<pre class="EnlighterJSRAW" data-enlighter-language="sql">SELECT
	[t].[name] [TableName],
	[i1].[name] [IndexName],
	[i1].[type_desc] [IndexType],
	[fg].[name] AS [FileGroupName],
	[p].[partition_number] AS [PartitionNumber],
	CAST([p].[rows] AS FLOAT) AS [RowCount],
	[p].[data_compression] AS [DataCompression],
	[p].[data_compression_desc] [DataCompressionDesc]
FROM [sys].[tables] AS [t]
	INNER JOIN [sys].[indexes] AS [i1] ON [i1].[object_id] = [t].[object_id]
	INNER JOIN [sys].[partitions] AS [p] ON [p].[object_id]=CAST([t].[object_id] AS INT) AND [p].[index_id]=[i1].[index_id]
	INNER JOIN [sys].[indexes] AS [i2] ON [p].[object_id] = [i2].[object_id] AND [p].[index_id] = [i2].[index_id]
	LEFT OUTER JOIN [sys].[destination_data_spaces] AS [dds] ON [dds].[partition_scheme_id] = [i2].[data_space_id] AND [dds].[destination_id] = [p].[partition_number]
	LEFT OUTER JOIN [sys].[partition_schemes] AS [ps] ON [ps].[data_space_id] = [i2].[data_space_id]
	LEFT OUTER JOIN [sys].[partition_range_values] AS [prv] ON [prv].[boundary_id] = [p].[partition_number] AND [prv].[function_id] = [ps].[function_id]
	LEFT OUTER JOIN [sys].[filegroups] AS [fg] ON  [fg].[data_space_id] = [dds].[data_space_id] OR [fg].[data_space_id] = [i2].[data_space_id]
WHERE [p].[data_compression] &lt;&gt; 0
ORDER BY [TableName], [IndexName], [PartitionNumber] ASC
GO</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>List of Tables with Columns, Data Types and Primary Key and Identity information</title>
		<link>https://sqlpowered.com/script/list-of-tables-with-columns-data-types-and-primary-key-and-identity-information/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Fri, 09 Mar 2018 09:05:36 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=2371</guid>

					<description><![CDATA[SELECT SCHEMA_NAME([t].[schema_id]) [SchemaName], [t].[Name] [TableName], [c].[column_id] [ColumnId], [c].[name] [ColumnName], [tp].[name] [TypeName], [c].[max_length] [MaxLength], [c].[Precision], [c].[Scale], (SELECT COUNT(*) FROM [sys].[indexes] AS [i] INNER JOIN [sys].[index_columns] AS [ic] ON [i].[OBJECT_ID] = [ic].[OBJECT_ID] AND [i].[index_id] = [ic].[index_id] WHERE [i].[is_primary_key] = 1 AND [i].[object_id] = [t].[object_id] AND [ic].[column_id] = [c].[column_id]) [IsPK], [c].[is_identity] [IsIdentity] FROM...]]></description>
										<content:encoded><![CDATA[<pre class="lang:default decode:true ">SELECT
	SCHEMA_NAME([t].[schema_id]) [SchemaName], 
	[t].[Name] [TableName], 
	[c].[column_id] [ColumnId], 
	[c].[name] [ColumnName], 
	[tp].[name] [TypeName], 
	[c].[max_length] [MaxLength], 
	[c].[Precision], 
	[c].[Scale], 
	(SELECT COUNT(*) 
	 FROM [sys].[indexes] AS [i] 
		INNER JOIN [sys].[index_columns] AS [ic] ON [i].[OBJECT_ID] = [ic].[OBJECT_ID] AND [i].[index_id] = [ic].[index_id]
	 WHERE [i].[is_primary_key] = 1 AND [i].[object_id] = [t].[object_id] AND [ic].[column_id] = [c].[column_id]) [IsPK],
	[c].[is_identity] [IsIdentity]
FROM [sys].[tables] [t]
	INNER JOIN [sys].[columns] [c] ON [t].[object_id] = [c].[object_id]
	INNER JOIN [sys]. [tp] ON [tp].[system_type_id] = [c].[system_type_id] AND [c].[user_type_id] = [tp].[user_type_id]
ORDER BY [t].[name], [c].[column_id]</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>List of all Columns with Default Constraint participating in Foreign Key</title>
		<link>https://sqlpowered.com/script/list-of-all-columns-with-default-constraint-participating-in-foreign-key/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Fri, 09 Mar 2018 08:32:54 +0000</pubDate>
				<guid isPermaLink="false">https://sqlpowered.com/?post_type=script&#038;p=2368</guid>

					<description><![CDATA[SELECT CONCAT([s].[name],'.',[t].[name]) [Table], [fk].[name] [ForeignKey], [c].[name] [Column], [dc].[name] [DefaultConstraint], [dc].[definition] [Default] FROM [sys].[foreign_key_columns] [fkc] INNER JOIN [sys].[foreign_keys] [fk] ON [fkc].[constraint_object_id] = [fk].[object_id] INNER JOIN [sys].[columns] [c] ON [c].[object_id] = [fkc].[parent_object_id] AND [c].[column_id] = [fkc].[parent_column_id] INNER JOIN [sys].[tables] [t] ON [t].[object_id] = [fkc].[parent_object_id] INNER JOIN [sys].[schemas] [s] ON [s].[schema_id] = [t].[schema_id]...]]></description>
										<content:encoded><![CDATA[<pre class="lang:default decode:true ">SELECT
	CONCAT([s].[name],'.',[t].[name]) [Table],
    [fk].[name] [ForeignKey],
    [c].[name] [Column],
    [dc].[name] [DefaultConstraint],
    [dc].[definition] [Default]       
FROM [sys].[foreign_key_columns] [fkc] 
	INNER JOIN [sys].[foreign_keys] [fk] ON [fkc].[constraint_object_id] = [fk].[object_id]
	INNER JOIN [sys].[columns] [c] ON [c].[object_id] = [fkc].[parent_object_id] AND [c].[column_id] = [fkc].[parent_column_id]
	INNER JOIN [sys].[tables] [t] ON [t].[object_id] = [fkc].[parent_object_id]
	INNER JOIN [sys].[schemas] [s] ON [s].[schema_id] = [t].[schema_id]
	INNER JOIN [sys].[default_constraints] [dc] ON [dc].[parent_object_id] = [fkc].[parent_object_id] AND [dc].[parent_column_id] = [fkc].[parent_column_id]</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
