Sunday, 25 July 2021

OBJECTPROPERTY in SQL Server

 It Returns information about schema-scoped objects in the current database. This function cannot be used for objects that are not schema-scoped, such as data definition language (DDL) triggers and event notifications.

Refer the list of Object properties:

https://docs.microsoft.com/en-us/sql/t-sql/functions/objectproperty-transact-sql?view=sql-server-ver15

Below is sql script to get the list of properties for the db object.

SELECT

SCH.name AS SCHEMA_NAME

,TBL.name AS TABLE_NAME

,TBL.object_id

,TBL.type_desc AS TableType

,TBL.create_date AS DateCreated

,TBL.modify_date AS DAteModified

,TBL.uses_ansi_nulls

,TBL.text_in_row_limit

,TBL.large_value_types_out_of_row

,TBL.is_tracked_by_cdc AS IsCDCTracked

,TBL.lock_escalation_desc

,DSP.name AS LobDataSpace

,DSP1.name AS FilestreamDataSpace

,CAST(NULL AS VARCHAR(250)) AS DataSpace

,CAST(NULL AS VARCHAR(250)) AS DataSpaceType

,CAST(NULL AS SMALLINT) AS NoColumns

,CAST(NULL AS BIT) AS IsHeap

,CAST(NULL AS BIT) AS NoIndexes

,CAST(NULL AS BIGINT) AS NoRows

,OBJECTPROPERTY(TBL.object_id, 'HasAfterTrigger') AS HasAfterTrigger

,OBJECTPROPERTY(TBL.object_id, 'HasDeleteTrigger') AS HasDeleteTrigger

,OBJECTPROPERTY(TBL.object_id, 'HasInsertTrigger') AS HasInsertTrigger

,OBJECTPROPERTY(TBL.object_id, 'HasInsteadOfTrigger') AS HasInsteadOfTrigger

,OBJECTPROPERTY(TBL.object_id, 'HasUpdateTrigger') AS HasUpdateTrigger

,OBJECTPROPERTY(TBL.object_id, 'IsAnsiNullsOn') AS IsAnsiNullsOn

,OBJECTPROPERTY(TBL.object_id, 'IsEncrypted') AS IsEncrypted

,OBJECTPROPERTY(TBL.object_id, 'IsIndexed') AS IsIndexed

,OBJECTPROPERTY(TBL.object_id, 'IsIndexable') AS IsIndexable

,OBJECTPROPERTY(TBL.object_id, 'IsQuotedIdentOn') AS IsQuotedIdentOn

,OBJECTPROPERTY(TBL.object_id, 'IsSystemTable') AS IsSystemTable

,OBJECTPROPERTY(TBL.object_id, 'IsUserTable') AS IsUserTable

,OBJECTPROPERTY(TBL.object_id, 'DeleteTriggerCount') AS DeleteTriggerCount

,OBJECTPROPERTY(TBL.object_id, 'FullTextBackgroundUpdateIndexOn') AS FullTextBackgroundUpdateIndexOn

,OBJECTPROPERTY(TBL.object_id, 'FulltextCatalogId') AS FulltextCatalogId

,OBJECTPROPERTY(TBL.object_id, 'FulltextChangeTrackingOn') AS FulltextChangeTrackingOn

,OBJECTPROPERTY(TBL.object_id, 'FulltextKeyColumn') AS FulltextKeyColumn

,OBJECTPROPERTY(TBL.object_id, 'HasActiveFulltextIndex') AS HasActiveFulltextIndex

,OBJECTPROPERTY(TBL.object_id, 'HasCheckCnst') AS HasCheckCnst

,OBJECTPROPERTY(TBL.object_id, 'HasClustIndex') AS HasClustIndex

,OBJECTPROPERTY(TBL.object_id, 'HasDefaultCnst') AS HasDefaultCnst

,OBJECTPROPERTY(TBL.object_id, 'HasForeignKey') AS HasForeignKey

,OBJECTPROPERTY(TBL.object_id, 'HasForeignRef') AS HasForeignRef

,OBJECTPROPERTY(TBL.object_id, 'HasIdentity') AS HasIdentity

,OBJECTPROPERTY(TBL.object_id, 'HasIndex') AS HasIndex

,OBJECTPROPERTY(TBL.object_id, 'HasNonclustIndex') AS HasNonclustIndex

,OBJECTPROPERTY(TBL.object_id, 'HasPrimaryKey') AS HasPrimaryKey

,OBJECTPROPERTY(TBL.object_id, 'HasRowGuidCol') AS HasRowGuidCol

,OBJECTPROPERTY(TBL.object_id, 'HasTextImage') AS HasTextImage

,OBJECTPROPERTY(TBL.object_id, 'HasTimestamp') AS HasTimestamp

,OBJECTPROPERTY(TBL.object_id, 'HasUniqueCnst') AS HasUniqueCnst

,OBJECTPROPERTY(TBL.object_id, 'HasVarDecimalStorageFormat') AS HasVarDecimalStorageFormat

,OBJECTPROPERTY(TBL.object_id, 'InsertTriggerCount') AS InsertTriggerCount

,OBJECTPROPERTY(TBL.object_id, 'TextInRowLimit') AS TextInRowLimit

,OBJECTPROPERTY(TBL.object_id, 'UpdateTriggerCount') AS UpdateTriggerCount

,OBJECTPROPERTY(TBL.object_id, 'HasColumnSet') AS HasColumnSet

                

FROM        sys.schemas AS SCH

                                                INNER JOIN sys.tables AS TBL

                                                ON SCH.schema_id = TBL.schema_id

                                                LEFT OUTER JOIN sys.data_spaces DSP1

                                                ON TBL.filestream_data_space_id = DSP1.data_space_id

                                                LEFT OUTER JOIN sys.data_spaces DSP

                                                ON TBL.lob_data_space_id = DSP.data_space_id

                     

 

 See the result   


No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts