Tag Archives: ColumnStore

List All Extended Properties For All Objects In A Database

— By Lori Brown @SQLSupahStah

I was recently looking at a way to easily identify if any objects in a database were In-Memory. Since many times I am tasked with taking on systems that I have never seen before, I have learned that it is important to have ways of checking to see if some of the more specialized features of SQL are in use. With this information, I am better prepared to manage a new SQL instance without inadvertently causing issues or ignoring something that should be on my DBA radar. So, finding all things that are In-Memory is important since more and more of my clients are using newer versions of SQL.

I can easily find tables and indexes that are column store by using this query

— Tables with columnstore indexes — SQL 2012 +

select t.name as TablesWithColumnstoreInx, i.name as ColumnStoreIndex

from sys.indexes i

inner join sys.tables t

on i.object_id = t.object_id

where i.type = 5 or i.type = 6

But I was kind of stumped to find a good way to identify natively compiled stored procedures since as far as I could tell, those are identified only through extended properties. After doing some research, I found someone who had the idea to load up all of the extended properties into a table so that it could be joined to the sys.objects table to pass object_id’s into the OBJECTPROPERTYEX function and thereby returning a list of all extended properties for all objects. Unfortunately, I cannot find the original forum post that was so helpful again and am unable to provide a hat tip to the correct person. But, here is what I have settled on:

USE WideWorldImporters

GO

— Find extended properties on objects

CREATE TABLE #ObjectPropertyEXList (PropertyName nvarchar(50), PropertyAppliesTo nvarchar(256), PropertyDesc nvarchar(3000));

 

INSERT INTO #ObjectPropertyEXList (PropertyName, PropertyAppliesTo, PropertyDesc)

SELECT [PropertyName] = N’BaseType’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’Identifies the base type of the object. When the specified object is a SYNONYM, the base type of the underlying object is returned. Nonnull = Object type Base data type: char(2)’ 

UNION ALL SELECT [PropertyName] = N’CnstIsClustKey’, [PropertyAppliesToType] = N’Constraint’, [PropertyDesc] = N’PRIMARY KEY constraint with a clustered index. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’CnstIsColumn’, [PropertyAppliesToType] = N’Constraint’, [PropertyDesc] = N’CHECK, DEFAULT, or FOREIGN KEY constraint on a single column. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’CnstIsDeleteCascade’, [PropertyAppliesToType] = N’Constraint’, [PropertyDesc] = N’FOREIGN KEY constraint with the ON DELETE CASCADE option. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’CnstIsDisabled’, [PropertyAppliesToType] = N’Constraint’, [PropertyDesc] = N’Disabled constraint. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’CnstIsNonclustKey’, [PropertyAppliesToType] = N’Constraint’, [PropertyDesc] = N’PRIMARY KEY constraint with a nonclustered index. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’CnstIsNotRepl’, [PropertyAppliesToType] = N’Constraint’, [PropertyDesc] = N’Constraint is defined by using the NOT FOR REPLICATION keywords. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’CnstIsNotTrusted’, [PropertyAppliesToType] = N’Constraint’, [PropertyDesc] = N’Constraint was enabled without checking existing rows. Therefore, the constraint may not hold for all rows. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’CnstIsUpdateCascade’, [PropertyAppliesToType] = N’Constraint’, [PropertyDesc] = N’FOREIGN KEY constraint with the ON UPDATE CASCADE option. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’ExecIsAfterTrigger’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’AFTER trigger. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’ExecIsAnsiNullsOn’, [PropertyAppliesToType] = N’Transact-SQL function, Transact-SQL procedure, Transact-SQL trigger, view’, [PropertyDesc] = N’The setting of ANSI_NULLS at creation time. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’ExecIsDeleteTrigger’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’DELETE trigger. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’ExecIsFirstDeleteTrigger’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’The first trigger fired when a DELETE is executed against the table. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’ExecIsFirstInsertTrigger’, [PropertyAppliesToType] = N’Trigger‘, [PropertyDesc] = N’The first trigger fired when an INSERT is executed against the table. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’ExecIsFirstUpdateTrigger’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’The first trigger fired when an UPDATE is executed against the table. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’ExecIsInsertTrigger’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’INSERT trigger. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’ExecIsInsteadOfTrigger’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’INSTEAD OF trigger. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’ExecIsLastDeleteTrigger’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’Last trigger fired when a DELETE is executed against the table. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’ExecIsLastInsertTrigger’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’Last trigger fired when an INSERT is executed against the table. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’ExecIsLastUpdateTrigger’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’Last trigger fired when an UPDATE is executed against the table. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’ExecIsQuotedIdentOn’, [PropertyAppliesToType] = N’Transact-SQL function, Transact-SQL procedure, Transact-SQL trigger, view’, [PropertyDesc] = N’Setting of QUOTED_IDENTIFIER at creation time. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’ExecIsStartup’, [PropertyAppliesToType] = N’Procedure’, [PropertyDesc] = N’Startup procedure. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’ExecIsTriggerDisabled’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’Disabled trigger. 1 = True 0 = False Base data type: int’    

UNION ALL SELECT [PropertyName] = N’ExecIsTriggerNotForRepl’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’Trigger defined as NOT FOR REPLICATION. 1 = True 0 = False Base data type: int’    

UNION ALL SELECT [PropertyName] = N’ExecIsUpdateTrigger’, [PropertyAppliesToType] = N’Trigger’, [PropertyDesc] = N’UPDATE trigger. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’ExecIsWithNativeCompilation’, [PropertyAppliesToType] = N’Transact-SQL Procedure’, [PropertyDesc] = N’Procedure is natively compiled. 1 = True 0 = False Base data type: int Applies to: SQL Server 2014 through SQL Server 2017.’  

UNION ALL SELECT [PropertyName] = N’HasAfterTrigger’, [PropertyAppliesToType] = N’Table, view’, [PropertyDesc] = N’Table or view has an AFTER trigger. 1 = True 0 = False Base data type: int’    

UNION ALL SELECT [PropertyName] = N’HasDeleteTrigger’, [PropertyAppliesToType] = N’Table, view’, [PropertyDesc] = N’Table or view has a DELETE trigger. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’HasInsertTrigger’, [PropertyAppliesToType] = N’Table, view’, [PropertyDesc] = N’Table or view has an INSERT trigger. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’HasInsteadOfTrigger’, [PropertyAppliesToType] = N’Table, view’, [PropertyDesc] = N’Table or view has an INSTEAD OF trigger. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’HasUpdateTrigger’, [PropertyAppliesToType] = N’Table, view’, [PropertyDesc] = N’Table or view has an UPDATE trigger. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’IsAnsiNullsOn’, [PropertyAppliesToType] = N’Transact-SQL function, Transact-SQL procedure, table, Transact-SQL trigger, view’, [PropertyDesc] = N’Specifies that the ANSI NULLS option setting for the table is ON, meaning all comparisons against a null value evaluate to UNKNOWN. This setting applies to all expressions in the table definition, including computed columns and constraints, for as long as the table exists. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’IsCheckCnst’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’CHECK constraint. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsConstraint’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’Constraint. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’IsDefault’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’Bound default. 1 = True 0 = False Base data type: int Applies to: SQL Server 2008 through SQL Server 2016.’  

UNION ALL SELECT [PropertyName] = N’IsDefaultCnst’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’DEFAULT constraint. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsDeterministic’, [PropertyAppliesToType] = N’Scalar and table-valued functions, view’, [PropertyDesc] = N’The determinism property of the function or view. 1 = Deterministic 0 = Not Deterministic Base data type: int’

UNION ALL SELECT [PropertyName] = N’IsEncrypted’, [PropertyAppliesToType] = N’Transact-SQL function, Transact-SQL procedure, table, Transact-SQL trigger, view’, [PropertyDesc] = N’Indicates that the original text of the module statement was converted to an obfuscated format. The output of the obfuscation is not directly visible in any of the catalog views in SQL Server 2005. Users without access to system tables or database files cannot retrieve the obfuscated text. However, the text is available to users that can either access system tables over the DAC port or directly access database files. Also, users that can attach a debugger to the server process can retrieve the original procedure from memory at run time. 1 = Encrypted 0 = Not encrypted Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsExecuted’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’Specifies the object can be executed (view, procedure, function, or trigger). 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’IsExtendedProc’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’Extended procedure. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’IsForeignKey’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’FOREIGN KEY constraint. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’IsIndexed’, [PropertyAppliesToType] = N’Table, view’, [PropertyDesc] = N’A table or view with an index. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’IsIndexable’, [PropertyAppliesToType] = N’Table, view’, [PropertyDesc] = N’A table or view on which an index may be created. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsInlineFunction’, [PropertyAppliesToType] = N’Function’, [PropertyDesc] = N’Inline function. 1 = Inline function 0 = Not inline function Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsMSShipped’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’An object created during installation of SQL Server. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’IsPrecise’, [PropertyAppliesToType] = N’Computed column, function, user-defined type, view’, [PropertyDesc] = N’Indicates whether the object contains an imprecise computation, such as floating point operations. 1 = Precise 0 = Imprecise Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’IsPrimaryKey’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’PRIMARY KEY constraint. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsProcedure’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’Procedure. 1 = True 0 = False Base data type: int’    

UNION ALL SELECT [PropertyName] = N’IsQuotedIdentOn’, [PropertyAppliesToType] = N’CHECK constraint, DEFAULT definition, Transact-SQL function, Transact-SQL procedure, table, Transact-SQL trigger, view’, [PropertyDesc] = N’Specifies that the quoted identifier setting for the object is ON, meaning double quotation marks delimit identifiers in all expressions involved in the object definition. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsQueue’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’Service Broker Queue 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsReplProc’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’Replication procedure. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’IsRule’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’Bound rule. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’IsScalarFunction’, [PropertyAppliesToType] = N’Function’, [PropertyDesc] = N’Scalar-valued function. 1 = Scalar-valued function 0 = Not scalar-valued function Base data type: int’   

UNION ALL SELECT [PropertyName] = N’IsSchemaBound’, [PropertyAppliesToType] = N’Function, Procedure, view’, [PropertyDesc] = N’A schema bound function or view created by using SCHEMABINDING. 1 = Schema-bound 0 = Not schema-bound Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsSystemTable’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’System table. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsSystemVerified’, [PropertyAppliesToType] = N’Computed column, function, user-defined type, view’, [PropertyDesc] = N’The precision and determinism properties of the object can be verified by SQL Server. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsTable’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’IsTableFunction’, [PropertyAppliesToType] = N’Function’, [PropertyDesc] = N’Table-valued function. 1 = Table-valued function 0 = Not table-valued function Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’IsTrigger’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’Trigger. 1 = True 0 = False Base data type: int’    

UNION ALL SELECT [PropertyName] = N’IsUniqueCnst’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’UNIQUE constraint. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’IsUserTable’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’User-defined table. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’IsView’, [PropertyAppliesToType] = N’View’, [PropertyDesc] = N’View. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’OwnerId’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’Owner of the object. System_CAPS_noteNote The schema owner is not necessarily the object owner. For example, child objects (those where parent_object_id is nonnull) will always return the same owner ID as the parent. Nonnull = Database user ID of the object owner. NULL = Unsupported object type, or object ID is not valid. Base data type: int’

UNION ALL SELECT [PropertyName] = N’SchemaId’, [PropertyAppliesToType] = N’Any schema-scoped object’, [PropertyDesc] = N’The ID of the schema associated with the object. Nonnull = Schema ID of the object. Base data type: int’  

UNION ALL SELECT [PropertyName] = N’SystemDataAccess’, [PropertyAppliesToType] = N’Function, view’, [PropertyDesc] = N’Object accesses system data, system catalogs or virtual system tables, in the local instance of SQL Server. 0 = None 1 = Read Base data type: int’  

UNION ALL SELECT [PropertyName] = N’TableDeleteTrigger’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a DELETE trigger. >1 = ID of first trigger with the specified type. Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’TableDeleteTriggerCount’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’The table has the specified number of DELETE triggers. Nonnull = Number of DELETE triggers Base data type: int’  

UNION ALL SELECT [PropertyName] = N’TableFullTextMergeStatus’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Whether a table that has a full-text index that is currently in merging. 0 = Table does not have a full-text index, or the full-text index is not in merging. 1 = The full-text index is in merging. Applies to: SQL Server 2008 through SQL Server 2016.’ 

UNION ALL SELECT [PropertyName] = N’TableFullTextBackgroundUpdateIndexOn’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’The table has full-text background update index (autochange tracking) enabled. 1 = TRUE 0 = FALSE Base data type: int Applies to: SQL Server 2008 through SQL Server 2016.’  

UNION ALL SELECT [PropertyName] = N’TableFulltextCatalogId’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’ID of the full-text catalog in which the full-text index data for the table resides. Nonzero = Full-text catalog ID, associated with the unique index that identifies the rows in a full-text indexed table. 0 = Table does not have a full-text index. Base data type: int Applies to: SQL Server 2008 through SQL Server 2016.’  

UNION ALL SELECT [PropertyName] = N’TableFullTextChangeTrackingOn’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has full-text change-tracking enabled. 1 = TRUE 0 = FALSE Base data type: int Applies to: SQL Server 2008 through SQL Server 2016.’  

UNION ALL SELECT [PropertyName] = N’TableFulltextDocsProcessed’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Number of rows processed since the start of full-text indexing. In a table that is being indexed for full-text search, all the columns of one row are considered as part of one document to be indexed. 0 = No active crawl or full-text indexing is completed. > 0 = One of the following: The number of documents processed by insert or update operations since the start of full, incremental, or manual change tracking population. The number of rows processed by insert or update operations since change tracking with background update index population was enabled, the full-text index schema changed, the full-text catalog rebuilt, or the instance of SQL Server restarted, and so on. NULL = Table does not have a full-text index. Base data type: int Note   This property does not monitor or count deleted rows. Applies to: SQL Server 2008 through SQL Server 2016.’

UNION ALL SELECT [PropertyName] = N’TableFulltextFailCount’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’The number of rows that full-text search did not index. 0 = The population has completed. >0 = One of the following: The number of documents that were not indexed since the start of Full, Incremental, and Manual Update change tracking population. For change tracking with background update index, the number of rows that were not indexed since the start of the population, or the restart of the population. This could be caused by a schema change, rebuild of the catalog, server restart, and so on NULL = Table does not have a Full-Text index. Base data type: int Applies to: SQL Server 2008 through SQL Server 2016.’ 

UNION ALL SELECT [PropertyName] = N’TableFulltextItemCount’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Nonnull = Number of rows that were full-text indexed successfully. NULL = Table does not have a full-text index. Base data type: int Applies to: SQL Server 2008 through SQL Server 2016.’ 

UNION ALL SELECT [PropertyName] = N’TableFulltextKeyColumn’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’ID of the column associated with the single-column unique index that is part of the definition of a full-text index and semantic index. 0 = Table does not have a full-text index. Base data type: int Applies to: SQL Server 2008 through SQL Server 2016.’  

UNION ALL SELECT [PropertyName] = N’TableFulltextPendingChanges’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Number of pending change tracking entries to process. 0 = change tracking is not enabled. NULL = Table does not have a full-text index. Base data type: int Applies to: SQL Server 2008 through SQL Server 2016.’    

UNION ALL SELECT [PropertyName] = N’TableFulltextPopulateStatus’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’0 = Idle. 1 = Full population is in progress. 2 = Incremental population is in progress. 3 = Propagation of tracked changes is in progress. 4 = Background update index is in progress, such as autochange tracking. 5 = Full-text indexing is throttled or paused. 6 = An error has occurred. Examine the crawl log for details. For more information, see the Troubleshooting Errors in a Full-Text Population (Crawl) section of Populate Full-Text Indexes. Base data type: int Applies to: SQL Server 2008 through SQL Server 2016.’  

UNION ALL SELECT [PropertyName] = N’TableFullTextSemanticExtraction’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table is enabled for semantic indexing. 1 = True 0 = False Base data type: int Applies to: SQL Server 2012 through SQL Server 2016.’

UNION ALL SELECT [PropertyName] = N’TableHasActiveFulltextIndex’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has an active full-text index. 1 = True 0 = False Base data type: int Applies to: SQL Server 2008 through SQL Server 2016.’   

UNION ALL SELECT [PropertyName] = N’TableHasCheckCnst’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a CHECK constraint. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’TableHasClustIndex’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a clustered index. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’TableHasDefaultCnst’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a DEFAULT constraint. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’TableHasDeleteTrigger’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a DELETE trigger. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’TableHasForeignKey’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a FOREIGN KEY constraint. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’TableHasForeignRef’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table is referenced by a FOREIGN KEY constraint. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’TableHasIdentity’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has an identity column. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’TableHasIndex’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has an index of any type. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’TableHasInsertTrigger’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Object has an INSERT trigger. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’TableHasNonclustIndex’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’The table has a nonclustered index. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’TableHasPrimaryKey’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a primary key. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’TableHasRowGuidCol’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a ROWGUIDCOL for a uniqueidentifier column. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’TableHasTextImage’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a text, ntext, or image column. 1 = True 0 = False Base data type: int’  

UNION ALL SELECT [PropertyName] = N’TableHasTimestamp’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a timestamp column. 1 = True 0 = False Base data type: int’

UNION ALL SELECT [PropertyName] = N’TableHasUniqueCnst’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a UNIQUE constraint. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’TableHasUpdateTrigger’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’The object has an UPDATE trigger. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’TableHasVarDecimalStorageFormat’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table is enabled for vardecimal storage format. 1 = True 0 = False’  

UNION ALL SELECT [PropertyName] = N’TableInsertTrigger’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has an INSERT trigger. >1 = ID of first trigger with the specified type. Base data type: int’    

UNION ALL SELECT [PropertyName] = N’TableInsertTriggerCount’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’The table has the specified number of INSERT triggers. >0 = The number of INSERT triggers. Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’TableIsFake’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table is not real. It is materialized internally on demand by the Database Engine. 1 = True 0 = False Base data type: int’   

UNION ALL SELECT [PropertyName] = N’TableIsLockedOnBulkLoad’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table is locked because a bcp or BULK INSERT job. 1 = True 0 = False Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’TableIsMemoryOptimized’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table is memory optimized 1 = True 0 = False Base data type: int For more information, see In-Memory OLTP (In-Memory Optimization). Applies to: SQL Server 2014 through SQL Server 2016.’  

UNION ALL SELECT [PropertyName] = N’TableIsPinned’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table is pinned to be held in the data cache. 0 = False This feature is not supported in SQL Server 2005 and later versions.’  

UNION ALL SELECT [PropertyName] = N’TableTextInRowLimit’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has text in row option set. > 0 = Maximum bytes allowed for text in row. 0 = text in row option is not set. Base data type: int’

UNION ALL SELECT [PropertyName] = N’TableUpdateTrigger’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has an UPDATE trigger. > 1 = ID of first trigger with the specified type. Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’TableUpdateTriggerCount’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has the specified number of UPDATE triggers. > 0 = The number of UPDATE triggers. Base data type: int’ 

UNION ALL SELECT [PropertyName] = N’UserDataAccess’, [PropertyAppliesToType] = N’Function, View’, [PropertyDesc] = N’Indicates the object accesses user data, user tables, in the local instance of SQL Server. 1 = Read 0 = None Base data type: int’  

UNION ALL SELECT [PropertyName] = N’TableHasColumnSet’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Table has a column set. 0 = False 1 = True For more information, see Use Column Sets.’  

UNION ALL SELECT [PropertyName] = N’Cardinality’, [PropertyAppliesToType] = N’Table (system or user-defined), view, or index’, [PropertyDesc] = N’The number of rows in the specified object. Applies to: SQL Server 2012 through SQL Server 2016.’ 

UNION ALL SELECT [PropertyName] = N’TableTemporalType’, [PropertyAppliesToType] = N’Table’, [PropertyDesc] = N’Specifies the type of table. 0 = non-temporal table 1 = history table for system-versioned table 2 = system-versioned temporal table Applies to: SQL Server 2016 Community Technology Preview 2 (CTP2) through SQL Server 2016.’    

;

 

–List all object properties for a given object

— Uncomment filters to find specific things

SELECT

op.PropertyName

, o.*

FROM sys.objects o

cross apply #ObjectPropertyEXList op

WHERE OBJECTPROPERTYEX(o.object_id, op.PropertyName) = 1

— AND op.PropertyName = ‘ExecIsWithNativeCompilation’ — uncomment this to look for a specific property

— AND o.type = ‘P’ — uncomment this to look for a specific object type

— AND o.name = ‘Colors_Archive’ — uncomment this to look for a specific object by name

ORDER BY o.name

 

/* List of object types

 

AF = Aggregate function (CLR)

C = CHECK constraint

D = DEFAULT (constraint or stand-alone)

F = FOREIGN KEY constraint,FN = SQL scalar function

FS = Assembly (CLR) scalar-function

FT = Assembly (CLR) table-valued function

IF = SQL inline table-valued function

IT = Internal table

P = SQL Stored Procedure

PC = Assembly (CLR) stored-procedure

PG = Plan guide

PK = PRIMARY KEY constraint

R = Rule (old-style, stand-alone)

RF = Replication-filter-procedure

S = System base table

SN = Synonym

SO = Sequence object

U = Table (user-defined)

V = View

SQ = Service queue

TA = Assembly (CLR) DML trigger

TF = SQL table-valued-function

TR = SQL DML trigger

TT = Table type

UQ = UNIQUE constraint

X = Extended stored procedure

ET = External Table

*/

 

DROP TABLE #ObjectPropertyEXList

 

I have verified that all extended properties that are loaded into #ObjectPropertyEXList are from the most recent list on Microsoft (https://docs.microsoft.com/en-us/sql/t-sql/functions/objectpropertyex-transact-sql ) and have also tried to provide some extra ways to filter for data so read the comments carefully.

Here are my results when I look only for objects that are natively compiled:

Blog_20180125_1

And here are the results when I list all extended properties on a single object:

Blog_20180125_2

Hey look!! The Colors_Archive table is a temporal table!! Good to know!!

If the person who was so helpful in creating the extended properties table will let me know who they are, I will be happy to extend proper credit where it is due. I really could not find the source again despite several tries.

Hopefully you, the reader, will find this helpful. If you make improvements and would like to pass them along, please feel free to let me know and I will update this post with your ideas.

For more information about blog posts, concepts and definitions, further explanations, or questions you may have…please contact us at SQLRxSupport@sqlrx.com. We will be happy to help! Leave a comment and feel free to track back to us. We love to talk tech with anyone in our SQL family!

 

SQL 2016 – Partitioning An Existing Table With A Columnstore Index

— by Lori Brown @SQLSupahStah

I recently ran across a data warehouse that did have the largest table partitioned. We were migrating up to SQL 2016 and we wanted to make sure that the partitions were still working and in place. Since I felt I needed to refresh my table partitioning skills, I decided to conduct a small scale test of partitioning up an existing table by year and to make it more fun, I wanted to have a columnstore index present to see how interesting things could be.

I am using the Fact.Purchase table in the new WideWorldImportersDW database. WideWorldImporters replaces AdventureWorks and can be researched and downloaded from here: https://blogs.technet.microsoft.com/dataplatforminsider/2016/06/09/wideworldimporters-the-new-sql-server-sample-database/

I did a little querying in the Fact.Purchase table and found that the Date Key column is great to use to partition it by year. And, I found that the dates in the table are generally from 2013 through 2016.

First you have to add the filegroups that will be used for the table once it is partitioned. I have added 4 filegroups for years 2013 – 2016.

blog_20170224_1

Once that is done, I have to add an .NDF file for each filegroup and map the file to the correct filegroup.

blog_20170224_2

 

Next I need a partition function and a partition scheme.

USE [WideWorldImportersDW]

GO

CREATE PARTITION FUNCTION [PF_Purch_Year](date) AS RANGE RIGHT FOR VALUES (‘2014-01-01’, ‘2015-01-01’, ‘2016-01-01’)

GO

CREATE PARTITION SCHEME [PS_Purch_Year] AS PARTITION [PF_Purch_Year] TO (Purch2013, Purch2014, Purch2015, Purch2016)

GO

What I am basically doing is setting parameters or boundaries for objects that use the PF_PURCH_YEAR function to place date values older than 01/01/2014 into the Purch2013 filegroup, values between 01/01/2014 and 01/01/2015 into the Purch2014 filegroup, values between 01/01/2015 and 01/01/2016 into the Purch2015 filegroup and finally everything newer than or equal to 01/01/2016 into the Purch2016 filegroup.

blog_20170224_3

Now that I have everything set up, I have to move the data to it. However, I cannot do that with an existing clustered index. I have to drop the clustered index and rebuild it with the partition scheme. This does get a bit confusing if you are trying to move existing things as you will see.

I first dropped all my indexes. Of course I had scripted them all out for rebuild but ran into trouble when I tried to build them again.

USE [WideWorldImportersDW]

GO

DROP INDEX [CCX_Fact_Purchase] ON [Fact].[Purchase]

GO

ALTER TABLE [Fact].[Purchase] DROP CONSTRAINT [PK_Fact_Purchase]

GO

DROP INDEX [FK_Fact_Purchase_Date_Key] ON [Fact].[Purchase]

GO

DROP INDEX [FK_Fact_Purchase_Stock_Item_Key] ON [Fact].[Purchase]

GO

DROP INDEX [FK_Fact_Purchase_Supplier_Key] ON [Fact].[Purchase]

GO

 

Here we go trying to rebuild….this is where it gets interesting…

USE [WideWorldImportersDW]

GO

CREATE CLUSTERED COLUMNSTORE INDEX [CCX_Fact_Purchase] ON [Fact].[Purchase]

WITH (DROP_EXISTING = OFF)

ON PS_Purch_Year ([Date Key])

GO

I received an error:

Msg 35316, Level 16, State 1, Line 3

The statement failed because a columnstore index must be partition-aligned with the base table. Create the columnstore index using the same partition function and same (or equivalent) partition scheme as the base table. If the base table is not partitioned, create a nonpartitioned columnstore index.

 

Uh oh! This meant that the table had already been part of a different partition scheme. I did not think to look for that before I started. Ugh! I thought that it must be easy to change the base table partition alignment and it is but it is not super intuitive. Since I had already dropped all my indexes, I figured that I needed to recreate the original clustered index on the old partition since that would be how the base table is associated with anything. I rebuilt it using the old partition. So far so good. When I tried rebuilding it with DROP_EXISTING = ON I received the same error as before. After thinking about it for a bit, I dropped everything again but this time created a regular clustered index on the new partition to align the base table. This worked!

ALTER TABLE [Fact].[Purchase] ADD CONSTRAINT [PK_Fact_Purchase] PRIMARY KEY CLUSTERED

(

[Purchase Key] ASC,

[Date Key] ASC

)ON PS_Purch_Year ([Date Key])

GO

 

Now the base table is aligned with the partition scheme that I wanted it on but I need the clustered index to be the columnstore index. We have to drop and create again and everything falls into place.

ALTER TABLE [Fact].[Purchase] DROP CONSTRAINT [PK_Fact_Purchase]

GO

USE [WideWorldImportersDW]

GO

CREATE CLUSTERED COLUMNSTORE INDEX [CCX_Fact_Purchase] ON [Fact].[Purchase]

WITH (DROP_EXISTING = OFF)

ON PS_Purch_Year ([Date Key])

GO

ALTER TABLE [Fact].[Purchase] ADD CONSTRAINT [PK_Fact_Purchase] PRIMARY KEY NONCLUSTERED

(

[Purchase Key] ASC,

[Date Key] ASC

)ON PS_Purch_Year ([Date Key])

GO

CREATE NONCLUSTERED INDEX [FK_Fact_Purchase_Date_Key] ON [Fact].[Purchase]

(

[Date Key] ASC

)ON PS_Purch_Year ([Date Key])

GO

CREATE NONCLUSTERED INDEX [FK_Fact_Purchase_Stock_Item_Key] ON [Fact].[Purchase]

(

[Stock Item Key] ASC

)ON PS_Purch_Year ([Date Key])

GO

CREATE NONCLUSTERED INDEX [FK_Fact_Purchase_Supplier_Key] ON [Fact].[Purchase]

(

[Supplier Key] ASC

)ON PS_Purch_Year ([Date Key])

GO

 

Success!!!! Now I just needed to make sure that things are where I expect them to be. I pilfered the following queries from MSDN…

SELECT *

FROM sys.tables AS t

JOIN sys.indexes AS i

ON t.[object_id] = i.[object_id]

JOIN sys.partition_schemes ps

ON i.data_space_id = ps.data_space_id

WHERE t.name = ‘Purchase’;

GO

blog_20170224_4

blog_20170224_5

As you scroll across the above results I can see that all my indexes are in the PS_Purch_Year partition scheme.

SELECT t.name AS TableName, i.name AS IndexName, p.partition_number, p.partition_id, i.data_space_id,

f.function_id, f.type_desc, r.boundary_id, r.value AS BoundaryValue

FROM sys.tables AS t

JOIN sys.indexes AS i

ON t.object_id = i.object_id

JOIN sys.partitions AS p

ON i.object_id = p.object_id AND i.index_id = p.index_id

JOIN sys.partition_schemes AS s

ON i.data_space_id = s.data_space_id

JOIN sys.partition_functions AS f

ON s.function_id = f.function_id

LEFT JOIN sys.partition_range_values AS r

ON f.function_id = r.function_id and r.boundary_id = p.partition_number

WHERE t.name = ‘Purchase’

ORDER BY p.partition_number;

 

This query shows the boundaries.

blog_20170224_6

I also found a really handy query created by David Peter Hansen that gives you info on partitions on a table much more concisely. https://davidpeterhansen.com/view-partitions-in-sql-server/  As they say….go read the whole thing. J

blog_20170224_7

I hope this helps someone who wants to partition an existing table. I did this on my own system with a small table and not a production system so please be sure to test your process against a test system before you accidentally cause an issue in production.

For more information about blog posts, concepts and definitions, further explanations, or questions you may have…please contact us at SQLRx@sqlrx.com. We will be happy to help! Leave a comment and feel free to track back to us. Visit us at www.sqlrx.com!