reference.RepoObjectColumn_reference_FirstResultSet - V

type: V ( view ), modify_date: 2022-01-05 18:06:34

RepoObject_guid: 6B90291C-9D61-EB11-84DC-A81E8446D5B0

Description

Examples

Entity Diagram

entity-reference.repoobjectcolumn_reference_firstresultset

Columns

Table 1. Columns of reference.RepoObjectColumn_reference_FirstResultSet - V
PK Column Name Data Type NULL? ID

varchar(37)

NOT NULL

bit

NULL

bit

NULL

bit

NULL

nvarchar(128)

NULL

nvarchar(128)

NULL

int

NULL

int

NULL

bigint

NULL

uniqueidentifier

NULL

uniqueidentifier

NULL

nvarchar(128)

NULL

char(2)

NULL

nvarchar(128)

NULL

nvarchar(128)

NOT NULL

int

NULL

int

NULL

bigint

NULL

uniqueidentifier

NOT NULL

uniqueidentifier

NULL

nvarchar(128)

NOT NULL

char(2)

NULL

Foreign Key Diagram

entity_1_1_fk-reference.repoobjectcolumn_reference_firstresultset

References

Object Reference Diagram - 1 1

entity_1_1_objectref-reference.repoobjectcolumn_reference_firstresultset

Object Reference Diagram - Referenced - 30 0

entity_30_0_objectref-reference.repoobjectcolumn_reference_firstresultset

Object Reference Diagram - Referencing - 0 30

entity_0_30_objectref-reference.repoobjectcolumn_reference_firstresultset

Column Reference Diagram

entity_1_1_colref-reference.repoobjectcolumn_reference_firstresultset

Indexes

idx_RepoObjectColumn_reference_FirstResultSet__1

idx_RepoObjectColumn_reference_FirstResultSet__2

idx_RepoObjectColumn_reference_FirstResultSet__3

idx_RepoObjectColumn_reference_FirstResultSet__4

idx_RepoObjectColumn_reference_FirstResultSet__5

Column Details

_

InformationSource

InformationSource

varchar(37)

NOT NULL

is_referenced_object

is_referenced_object

bit

NULL

is_referencing_object_equal_referenced_object

is_referencing_object_equal_referenced_object

bit

NULL

referenced_column_name

referenced_column_name

nvarchar(128)

NULL

referenced_entity_name

referenced_entity_name

nvarchar(128)

NULL

referenced_id

referenced_id

int

NULL

referenced_minor_id

referenced_minor_id

int

NULL

referenced_node_id

referenced_node_id

bigint

NULL

referenced_RepoObject_guid

referenced_RepoObject_guid

uniqueidentifier

NULL

referenced_RepoObjectColumn_guid

referenced_RepoObjectColumn_guid

uniqueidentifier

NULL

referenced_schema_name

referenced_schema_name

nvarchar(128)

NULL

referenced_type

referenced_type

char(2)

NULL

referencing_entity_name

referencing_entity_name

nvarchar(128)

NOT NULL

Referenced Columns

referencing_RepoObject_guid

referencing_RepoObject_guid

uniqueidentifier

NOT NULL

referencing_schema_name

referencing_schema_name

nvarchar(128)

NOT NULL

referencing_type

referencing_type

char(2)

NULL

Referenced Columns

sql_modules_definition

reference.RepoObjectColumn_reference_FirstResultSet - V script
--"common" references
--these should be "common" columns in views, not containing expressions
--Attention: views on views are "resolved" like views on the underlaying tables!
--it looks like we don't get references between views here!
CREATE View [reference].[RepoObjectColumn_reference_FirstResultSet]
As
--
Select
    referencing_id                                = ro.SysObject_id
  , referencing_minor_id                          = roc.SysObjectColumn_column_id
  , referencing_node_id                           = Cast(ro.SysObject_id As BigInt) * 10000 + roc.SysObjectColumn_column_id
  , referenced_id                                 = roc2.SysObject_id
  , referenced_minor_id                           = roc2.SysObjectColumn_column_id
  , referenced_node_id                            = Cast(roc2.SysObject_id As BigInt) * 10000 + roc2.SysObjectColumn_column_id
  , referencing_RepoObject_guid                   = ros.RepoObject_guid
  , referencing_RepoObjectColumn_guid             = roc.RepoObjectColumn_guid
  , referenced_RepoObject_guid                    = roc2.RepoObject_guid
  , referenced_RepoObjectColumn_guid              = roc2.RepoObjectColumn_guid
  , referencing_type                              = ro.SysObject_type
  , referencing_schema_name                       = ro.SysObject_schema_name
  , referencing_entity_name                       = ro.SysObject_name
  , referencing_column_name                       = ros.target_column_name
  , referenced_schema_name                        = ros.source_schema_name
  , referenced_entity_name                        = ros.source_table_name
  , referenced_column_name                        = ros.source_column_name
  , referenced_type                               = roc2.SysObject_type
  , InformationSource                             = 'sys.dm_exec_describe_first_result_set'
  , is_referencing_object_equal_referenced_object = Cast(Case
                                                             When ros.RepoObject_guid = roc2.RepoObject_guid
                                                                 Then
                                                                 1
                                                             Else
                                                                 0
                                                         End As Bit)
  --Flag, if the [referenced_RepoObject_guid] is a referenced object in [repo].[RepoObject_reference__union]
  , is_referenced_object                          =
    (
        Select
            Top 1
            Cast(1 As Bit)
        From
            reference.RepoObject_reference_T As ro_r
        Where
            ro_r.referencing_RepoObject_guid    = ros.RepoObject_guid
            And ro_r.referenced_RepoObject_guid = roc2.RepoObject_guid
    )
  , ros.is_hidden
From
    reference.RepoObjectSource_FirstResultSet As ros
    Inner Join
        repo.RepoObject                       As ro
            On
            ros.RepoObject_guid        = ro.RepoObject_guid

    Left Join
        repo.RepoObjectColumn_gross           As roc
            On
            ro.SysObject_schema_name   = roc.SysObject_schema_name
            And ro.SysObject_name      = roc.SysObject_name
            And ros.target_column_name = roc.SysObjectColumn_name

    Left Join
        repo.RepoObjectColumn_gross           As roc2
            On
            ros.source_schema_name     = roc2.SysObject_schema_name
            And ros.source_table_name  = roc2.SysObject_name
            And ros.source_column_name = roc2.SysObjectColumn_name
            And ros.source_server_name Is Null
--exclude reference on self (target column = source column)
Where
    Not (
            ro.SysObject_schema_name = ros.source_schema_name
            And ro.SysObject_name = ros.source_table_name
            And ros.target_column_name = ros.source_column_name
        )
    --exclude source 'sys
    --todo: make this an option via parameter
    And Not ros.source_schema_name = 'sys'