Advertisement
iokevins

Phil Factor's It_Depends(...), with enhancements

Nov 26th, 2018
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 19.68 KB | None | 0 0
  1. IF OBJECT_ID (N'dbo.It_Depends') IS NOT NULL
  2.   DROP FUNCTION dbo.It_Depends
  3. GO
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8.  
  9. CREATE FUNCTION dbo.It_Depends (
  10.      @ObjectName              NVARCHAR(200)
  11.     ,@ObjectsOnWhichItDepends BIT
  12. )
  13.  
  14. RETURNS @References TABLE (
  15.      ThePath           NVARCHAR(MAX) --the ancestor objects delimited by a N'/'
  16.     ,TheFullEntityName NVARCHAR(200)
  17.     ,TheType           NVARCHAR(20)
  18.     ,iteration         INT
  19. )
  20.  
  21. /*
  22.    Summary: Phil Factor's It_Depends(...) function
  23.    
  24.             This Table function returns a a table giving the dependencies of
  25.             the object whose name is supplied as a parameter.
  26.  
  27.             At the moment, only objects are allowed as a parameter, You can
  28.             specify whether you want those objects that rely on the object,
  29.             or those on whom the object relies.
  30.  
  31.    Constraints:
  32.  
  33.      *
  34.  
  35.    Note(s):
  36.  
  37.      * Compatibility: SQL Server 2005+
  38.  
  39.      * Blog post overview and comments:
  40.        https://www.red-gate.com/simple-talk/sql/t-sql-programming/dependencies-and-references-in-sql-server/
  41.  
  42.      * Adapted from source code published at:
  43.        https://www.red-gate.com/simple-talk/wp-content/uploads/imported/2284-ItDepends.html
  44.  
  45.      * TODO: Must add assemblies, must allow entities such as types to be
  46.        specified
  47.  
  48.      * Returns (in this example output, we have set @ObjectName=ObjectTableName
  49.        and @ObjectsOnWhichItDepends=0, to retrieve objects dependent on  
  50.        ObjectTableName):
  51.  
  52.        THEPATH                                            THEFULLENTITYNAME              THETYPE ITERATION
  53.        -------------------------------------------------- -----------------------------  ------- ---------
  54.        dbo.ObjectTableName                                dbo.ObjectTableName            U       1
  55.        dbo.ObjectTableName/dbo.ReferencingStoredProcedure dbo.ReferencingStoredProcedure P       2
  56.        ...
  57.  
  58.      * Example usage:
  59.  
  60.             /*
  61.              * AdventureWorks.Employee: objects that depend on it
  62.              * Note: function SPACE(...) indents rows to indicate hierarchical
  63.              * relationships
  64.              */
  65.  
  66.             USE AdventureWorks
  67.             SELECT      [Result] =
  68.                         SPACE(F.iteration * 4) +
  69.                         F.TheFullEntityName +
  70.                         N' (' + RTRIM(F.TheType) + N')'
  71.  
  72.               FROM      dbo.It_Depends(N'Employee', 0) F
  73.  
  74.             ORDER BY    F.ThePath
  75.  
  76.             /*
  77.              * AdventureWorks.Employee: objects that it depends on
  78.              * Note: function SPACE(...) indents rows to indicate hierarchical
  79.              * relationships
  80.              */
  81.  
  82.             USE AdventureWorks
  83.             SELECT      [Result] =
  84.                         SPACE(F.iteration * 4) +
  85.                         F.TheFullEntityName +
  86.                         N' (' + RTRIM(F.TheType) + N')'
  87.  
  88.               FROM      dbo.It_Depends(N'Employee', 1) F
  89.  
  90.             ORDER BY    F.ThePath
  91.  
  92.    Date(s): 2015-09-01 PF  Initial revision
  93.             2015-09-20 PF  Allowed both types of dependencies, returned full
  94.                            detail table
  95.             2016-03-28 JB  Add the schema name consistently to column
  96.                            "@DatabaseDependencies.TheReferredEntity" by adding
  97.                            an INNER JOIN to sys.schemas and modifying the
  98.                            SELECT clause
  99.             2016-10-25 KS  Insert the current dependency object type
  100.                            (DatabaseDependencies.EntityType) instead of the
  101.                            parent dependency object type
  102.                            (previousReferences.TheType), in the INSERT INTO
  103.                            SELECT clause
  104.             2018-11-25 KLS Column sys.sql_expression_dependencies.referenced_id
  105.                            is NULLable, so substitute with lookup
  106.                            OBJECT_ID(sys.sql_expression_dependencies.referenced_entity_name)
  107.                            when inserting soft dependencies into table
  108.                            variable DatabaseDepencies. Sequences EntityType
  109.                            changed from SYN to SEQ. Qualified object names
  110.                            and used aliases consistently. Converted to return
  111.                            Unicode N*CHAR types.
  112.             2018-11-27 KLS SQL inline table-valued function ('IF') type added
  113.                            as acceptable soft dependency
  114. */
  115.  
  116. AS
  117.  
  118. BEGIN
  119.  
  120. DECLARE     @DatabaseDependencies TABLE ( EntityName        NVARCHAR(200)
  121.                                          ,EntityType        NCHAR(5)
  122.                                          ,DependencyType    NCHAR(4)
  123.                                          ,TheReferredEntity NVARCHAR(200)
  124.                                          ,TheReferredType   NCHAR(5)
  125.                                         )
  126.  
  127. /*
  128.  * Populate @DatabaseDependencies via multiple UNION ALL statements, one for
  129.  * each hard and soft dependency type. Table of hard references:
  130.  * https://www.red-gate.com/simple-talk/wp-content/uploads/imported/2284-Dependencies.png
  131.  */
  132.  
  133. INSERT INTO @DatabaseDependencies ( EntityName
  134.                                    ,EntityType
  135.                                    ,DependencyType
  136.                                    ,TheReferredEntity
  137.                                    ,TheReferredType
  138.                                   )
  139.  
  140. -- Tables that reference UDTs
  141.  
  142. SELECT       [EntityName] =
  143.              OBJECT_SCHEMA_NAME(O.object_id) + N'.' + O.name
  144.             ,[EntityType]        = O.type
  145.             ,[DependencyType]    = N'hard'
  146.             ,[TheReferredEntity] = TY.name
  147.             ,[TheReferredType]   = N'UDT'
  148.  
  149.   FROM      sys.objects AS O
  150.  
  151.             INNER JOIN sys.columns AS C
  152.             ON C.object_id = O.object_id
  153.  
  154.             INNER JOIN sys.types AS TY
  155.             ON TY.user_type_id = C.user_type_id
  156.  
  157.  WHERE      TY.is_user_defined = 1
  158.  
  159. UNION ALL
  160.  
  161. -- UDTTs that reference UDTs
  162.  
  163. SELECT       [EntityName] =
  164.              OBJECT_SCHEMA_NAME(TT.type_table_object_id) + N'.' + TT.name
  165.             ,[EntityType]       = N'UDTT'
  166.             ,[DependencyType]   = N'hard'
  167.             ,[TheReferredEntity]= TY.name
  168.             ,[TheReferredType]  = N'UDT'
  169.  
  170.   FROM      sys.table_types AS TT
  171.  
  172.             INNER JOIN sys.columns AS C
  173.             ON C.object_id = TT.type_table_object_id
  174.  
  175.             INNER JOIN sys.types AS TY
  176.             ON TY.user_type_id = C.user_type_id
  177.  
  178.  WHERE      TY.is_user_defined = 1
  179.  
  180. UNION ALL
  181.  
  182. -- Tables/views that reference triggers
  183.  
  184. SELECT       [EntityName] =
  185.              OBJECT_SCHEMA_NAME(OBJECT_CHILD.object_id) + N'.' + OBJECT_CHILD.name
  186.             ,[EntityType]        = OBJECT_CHILD.type
  187.             ,[DependencyType]    = N'hard'
  188.             ,[TheReferredEntity] =
  189.              OBJECT_SCHEMA_NAME(OBJECT_PARENT.object_id) + N'.' + OBJECT_PARENT.name
  190.             ,[TheReferredType]   = OBJECT_PARENT.type
  191.  
  192.   FROM      sys.objects AS OBJECT_PARENT
  193.  
  194.             INNER JOIN sys.objects AS OBJECT_CHILD
  195.             ON OBJECT_CHILD.parent_object_id = OBJECT_PARENT.object_id
  196.  
  197.  WHERE      OBJECT_CHILD.type = N'TR'
  198.  
  199. UNION ALL
  200.  
  201. -- Tables that reference defaults via columns (only default objects)
  202.  
  203. SELECT       [EntityName] =
  204.              OBJECT_SCHEMA_NAME(OBJECT_COLUMNS.object_id) + N'.' + OBJECT_NAME(OBJECT_COLUMNS.object_id)
  205.             ,[EntityType]        = N'U'
  206.             ,[DependencyType]    = N'hard'
  207.             ,[TheReferredEntity] =
  208.              OBJECT_SCHEMA_NAME(O.object_id) + N'.' + O.name
  209.             ,[TheReferredType]   = O.type
  210.  
  211.   FROM      sys.objects AS O
  212.  
  213.             INNER JOIN sys.columns AS OBJECT_COLUMNS
  214.             ON OBJECT_COLUMNS.default_object_id = O.object_id
  215.  
  216.  WHERE      O.parent_object_id = 0
  217.  
  218. UNION ALL
  219.  
  220. -- Types that reference defaults (only default objects)
  221.  
  222. SELECT       [EntityName]        = TYPES.name
  223.             ,[EntityType]        = N'UDT'
  224.             ,[DependencyType]    = N'hard'
  225.             ,[TheReferredEntity] =
  226.              OBJECT_SCHEMA_NAME(O.object_id) + N'.' + O.name
  227.             ,[TheReferredType]   = O.type
  228.  
  229.   FROM      sys.objects AS O
  230.  
  231.             INNER JOIN sys.types AS TYPES
  232.             ON TYPES.default_object_id = O.object_id
  233.  
  234.  WHERE      O.parent_object_id = 0
  235.  
  236. UNION ALL
  237.  
  238. -- Tables that reference rules via columns
  239.  
  240. SELECT       [EntityName] =
  241.              OBJECT_SCHEMA_NAME(OBJECT_COLUMNS.object_id) + N'.' + OBJECT_NAME(OBJECT_COLUMNS.object_id)
  242.             ,[EntityType]        = N'U'
  243.             ,[DependencyType]    = N'hard'
  244.             ,[TheReferredEntity] =
  245.              OBJECT_SCHEMA_NAME(O.object_id) + N'.' + O.name
  246.             ,[TheReferredType]   = O.type
  247.  
  248.   FROM      sys.objects AS O
  249.  
  250.             INNER JOIN sys.columns AS OBJECT_COLUMNS
  251.             ON OBJECT_COLUMNS.rule_object_id = O.object_id
  252.  
  253. UNION ALL
  254.  
  255. -- Types that reference rules
  256.  
  257. SELECT       [EntityName]        = TYPES.name
  258.             ,[EntityType]        = N'UDT'
  259.             ,[DependencyType]    = N'hard'
  260.             ,[TheReferredEntity] =
  261.              OBJECT_SCHEMA_NAME(O.object_id) + N'.' + O.name
  262.             ,[TheReferredType]   = O.type
  263.  
  264.   FROM      sys.objects AS O
  265.  
  266.             INNER JOIN sys.types AS TYPES
  267.             ON TYPES.rule_object_id = O.object_id
  268.  
  269. UNION ALL
  270.  
  271. -- Tables that reference XmlSchemaCollections
  272.  
  273. SELECT       [EntityName] =
  274.              OBJECT_SCHEMA_NAME(OBJECT_COLUMNS.object_id) + N'.' + OBJECT_NAME(OBJECT_COLUMNS.object_id)
  275.             ,[EntityType]        = N'U'
  276.             ,[DependencyType]    = N'hard'
  277.             ,[TheReferredEntity] = X.name
  278.             ,[TheReferredType]   = N'XMLC'
  279.  
  280.   FROM      sys.columns AS OBJECT_COLUMNS --should we eliminate views?
  281.  
  282.             INNER JOIN sys.xml_schema_collections AS X
  283.             ON X.xml_collection_id = OBJECT_COLUMNS.xml_collection_id
  284.  
  285. UNION ALL
  286.  
  287. -- Table types that reference XmlSchemaCollections
  288.  
  289. SELECT       [EntityName] =
  290.              OBJECT_SCHEMA_NAME(OBJECT_COLUMNS.object_id) + N'.' + OBJECT_NAME(OBJECT_COLUMNS.object_id)
  291.             ,[EntityType]        = N'UDTT'
  292.             ,[DependencyType]    = N'hard'
  293.             ,[TheReferredEntity] = X.name
  294.             ,[TheReferredType]   = N'XMLC'
  295.  
  296.   FROM      sys.columns AS OBJECT_COLUMNS
  297.  
  298.             INNER JOIN sys.table_types AS TT
  299.             ON TT.type_table_object_id = OBJECT_COLUMNS.object_id
  300.  
  301.             INNER JOIN sys.xml_schema_collections AS X
  302.             ON X.xml_collection_id = OBJECT_COLUMNS.xml_collection_id
  303.  
  304. UNION ALL
  305.  
  306. -- Procedures that reference XmlSchemaCollections
  307.  
  308. SELECT       [EntityName] =
  309.              OBJECT_SCHEMA_NAME(PARAMS.object_id) + N'.' + O.name
  310.             ,[EntityType]        = O.type
  311.             ,[DependencyType]    = N'hard'
  312.             ,[TheReferredEntity] = X.name
  313.             ,[TheReferredType]   = N'XMLC'
  314.  
  315.   FROM      sys.parameters AS PARAMS
  316.  
  317.             INNER JOIN sys.xml_schema_collections AS X
  318.             ON X.xml_collection_id = PARAMS.xml_collection_id
  319.  
  320.             INNER JOIN sys.objects AS O
  321.             ON O.object_id = PARAMS.object_id
  322.  
  323. UNION ALL
  324.  
  325. -- Table references table
  326.  
  327. SELECT       [EntityName] =
  328.              OBJECT_SCHEMA_NAME(TBL.object_id) + N'.' + TBL.name
  329.             ,[EntityType]        = TBL.type
  330.             ,[DependencyType]    = N'hard'
  331.             ,[TheReferredEntity] =
  332.              OBJECT_SCHEMA_NAME(referenced_object_id) + N'.' + OBJECT_NAME(referenced_object_id)
  333.             ,[TheReferredType]   = N'U'
  334.  
  335.   FROM      sys.foreign_keys AS FK
  336.  
  337.             INNER JOIN sys.tables AS TBL
  338.             ON TBL.object_id = FK.parent_object_id
  339.  
  340. UNION ALL
  341.  
  342. -- UDT references types
  343.  
  344. SELECT       [EntityName] =
  345.              OBJECT_SCHEMA_NAME(PARAMS.object_id) + N'.' + O.name
  346.             ,[EntityType]        = O.type
  347.             ,[DependencyType]    = N'hard'
  348.             ,[TheReferredEntity] = PARAM_TYPES.name
  349.             ,[TheReferredType]   = N'UDT'
  350.  
  351.   FROM      sys.parameters AS PARAMS
  352.  
  353.             INNER JOIN sys.types AS PARAM_TYPES
  354.             ON PARAMS.user_type_id = PARAM_TYPES.user_type_id
  355.             AND PARAM_TYPES.is_user_defined <> 0
  356.  
  357.             INNER JOIN sys.objects AS O
  358.             ON O.object_id = PARAMS.object_id
  359.  
  360. UNION ALL
  361.  
  362. -- Table, view references partition scheme
  363.  
  364. SELECT       [EntityName] =
  365.              OBJECT_SCHEMA_NAME(O.object_id) + N'.' + O.name
  366.             ,[EntityType]        = O.type
  367.             ,[DependencyType]    = N'hard'
  368.             ,[TheReferredEntity] = PS.name
  369.             ,[TheReferredType]   = N'PS'
  370.  
  371.   FROM      sys.indexes AS IDX
  372.  
  373.             INNER JOIN sys.partitions AS P
  374.             ON IDX.object_id = P.object_id AND IDX.index_id = P.index_id
  375.  
  376.             INNER JOIN sys.partition_schemes AS PS
  377.             ON IDX.data_space_id = PS.data_space_id
  378.  
  379.             INNER JOIN sys.objects AS O
  380.             ON O.object_id = IDX.object_id
  381.  
  382. UNION ALL
  383.  
  384. -- Partition scheme references partition function
  385.  
  386. SELECT       [EntityName]        = PS.name
  387.             ,[EntityType]        = N'PS'
  388.             ,[DependencyType]    = N'hard'
  389.             ,[TheReferredEntity] =
  390.              OBJECT_SCHEMA_NAME(O.object_id) + N'.' + O.name
  391.             ,[TheReferredType]   = O.type
  392.  
  393.   FROM      sys.partition_schemes AS PS
  394.  
  395.             INNER JOIN sys.objects AS O
  396.             ON PS.function_id = O.object_id
  397.  
  398. UNION ALL
  399.  
  400. -- Plan guide references sp, udf (and triggers?)
  401.  
  402. SELECT       [EntityName]        = PG.name
  403.             ,[EntityType]        = N'PG'
  404.             ,[DependencyType]    = N'hard'
  405.             ,[TheReferredEntity] =
  406.              OBJECT_SCHEMA_NAME(O.object_id) + N'.' + O.name
  407.             ,[TheReferredType]   = O.type
  408.  
  409.   FROM      sys.objects AS O
  410.  
  411.             INNER JOIN sys.plan_guides AS PG
  412.             ON PG.scope_object_id = O.object_id
  413.  
  414. UNION ALL
  415.  
  416. -- Synonym refrences object
  417.  
  418. SELECT       [EntityName]        = S.name
  419.             ,[EntityType]        = N'SYN'
  420.             ,[DependencyType]    = N'hard'
  421.             ,[TheReferredEntity] =
  422.              OBJECT_SCHEMA_NAME(O.object_id) + N'.' + O.name
  423.             ,[TheReferredType]   = O.type
  424.  
  425.   FROM      sys.objects AS O
  426.  
  427.             INNER JOIN sys.synonyms AS S
  428.             ON object_id(S.base_object_name) = O.object_id
  429.  
  430. UNION ALL
  431.  
  432. -- Sequences that reference UDTTs
  433.  
  434. SELECT       [EntityName]        = S.name
  435.             ,[EntityType]        = N'SEQ'
  436.             ,[DependencyType]    = N'hard'
  437.             ,[TheReferredEntity] =
  438.              OBJECT_SCHEMA_NAME(O.object_id) + N'.' + O.name
  439.             ,[TheReferredType]   = O.type
  440.  
  441.   FROM      sys.objects AS O
  442.  
  443.             INNER JOIN sys.sequences AS S
  444.             ON S.user_type_id = O.object_id
  445.  
  446. UNION ALL
  447.  
  448. -- Soft dependencies
  449.  
  450. SELECT      DISTINCT
  451.              [EntityName] =
  452.              COALESCE(OBJECT_SCHEMA_NAME(SED.Referencing_ID) + N'.', N'') +
  453.              OBJECT_NAME(SED.Referencing_ID)
  454.  
  455.             ,[EntityType] = REFERENCING_OBJECT.type
  456.             ,[DependencyType] = N'soft'
  457.  
  458.             ,[TheReferredEntity] =
  459.              COALESCE(REFERENCED_SCHEMA.name + N'.', N'') + --likely schema name
  460.              COALESCE(SED.referenced_entity_name, N'')   --very likely entity name
  461.  
  462.             ,[TheReferredType] = REFERENCED_OBJECT.type
  463.  
  464.   FROM      sys.sql_expression_dependencies AS SED
  465.  
  466.             INNER JOIN sys.objects AS REFERENCING_OBJECT
  467.             ON SED.referencing_id = REFERENCING_OBJECT.object_ID
  468.  
  469.             INNER JOIN (sys.objects AS REFERENCED_OBJECT
  470.  
  471.                         INNER join sys.schemas AS REFERENCED_SCHEMA
  472.                         on REFERENCED_OBJECT.schema_id = REFERENCED_SCHEMA.schema_id
  473.                        )
  474.             ON OBJECT_ID(SED.referenced_entity_name) = REFERENCED_OBJECT.object_ID
  475.  
  476.  WHERE      SED.referencing_Class = 1
  477.    AND      SED.referenced_class = 1
  478.            /*
  479.             * sys.objects (Transact-SQL) type values, via:
  480.             * https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-objects-transact-sql?view=sql-server-2017
  481.             */
  482.    AND      REFERENCING_OBJECT.type IN ( N'FN' -- SQL scalar function
  483.                                         ,N'IF' -- SQL inline table-valued function
  484.                                         ,N'P'  -- SQL Stored Procedure
  485.                                         ,N'TF' -- SQL table-valued-function
  486.                                         ,N'TR' -- SQL DML trigger
  487.                                         ,N'U'  -- Table (user-defined)
  488.                                         ,N'V'  -- View
  489.                                        )
  490. ;
  491.  
  492. /*
  493.  * Process the dependencies
  494.  *
  495.  */
  496.  
  497. DECLARE @RowCount INT
  498.  
  499. DECLARE @ii INT
  500.  
  501. -- Firstly we put in the object as a seed.
  502. INSERT INTO @References ( ThePath
  503.                          ,TheFullEntityName
  504.                          ,theType
  505.                          ,iteration
  506.                         )
  507.  
  508. SELECT       [ThePath]           = COALESCE(OBJECT_SCHEMA_NAME(O.object_id) + N'.', N'') + O.name
  509.             ,[TheFullEntityName] = COALESCE(OBJECT_SCHEMA_NAME(O.object_id) + N'.', N'') + O.name
  510.             ,[theType]           = O.type
  511.             ,[iteration ]        = 1
  512.  
  513.   FROM      sys.objects AS O
  514.  
  515.  WHERE      O.name LIKE @ObjectName
  516.  
  517. -- Then we just pull out the dependencies at each level. watching out for
  518. -- self-references and circular references
  519. SELECT       @rowcount = @@ROWCOUNT
  520.             ,@ii = 2
  521.  
  522. -- If we are looking for objects on which it depends
  523. IF @ObjectsOnWhichItDepends <> 0
  524.  
  525.   WHILE @ii < 20 AND @rowcount > 0
  526.   BEGIN
  527.     INSERT INTO @References ( ThePath, TheFullEntityName, theType, iteration )
  528.     SELECT      DISTINCT
  529.                  [ThePath] =
  530.                  PREVIOUS_REFERENCES.ThePath + N'/' + DATABASE_DEPENDENCIES.TheReferredEntity
  531.                 ,[TheFullEntityName] = DATABASE_DEPENDENCIES.TheReferredEntity
  532.                 ,[theType]           = DATABASE_DEPENDENCIES.TheReferredType
  533.                 ,[iteration]         = @ii
  534.  
  535.       FROM      @DatabaseDependencies AS DATABASE_DEPENDENCIES
  536.  
  537.                 INNER JOIN @References AS PREVIOUS_REFERENCES
  538.                 ON PREVIOUS_REFERENCES.TheFullEntityName = DATABASE_DEPENDENCIES.EntityName
  539.                 AND PREVIOUS_REFERENCES.iteration = @ii - 1
  540.  
  541.      WHERE      DATABASE_DEPENDENCIES.TheReferredEntity <> DATABASE_DEPENDENCIES.EntityName
  542.        AND      DATABASE_DEPENDENCIES.TheReferredEntity NOT IN (SELECT RSUB_EXISTING.TheFullEntityName FROM @References RSUB_EXISTING)
  543.  
  544.     SELECT  @rowcount = @@rowcount
  545.     SELECT  @ii = @ii + 1
  546.   END
  547.  
  548. ELSE
  549.  
  550. -- We are looking for objects that depend on it.
  551. WHILE @ii < 20 AND @rowcount > 0
  552.   BEGIN
  553.     INSERT INTO @References ( ThePath
  554.                              ,TheFullEntityName
  555.                              ,theType
  556.                              ,iteration
  557.                             )
  558.     SELECT      DISTINCT
  559.                  [ThePath] =
  560.                  PREVIOUS_REFERENCES.ThePath + N'/' + DATABASE_DEPENDENCIES.EntityName
  561.                 ,[TheFullEntityName] = DATABASE_DEPENDENCIES.EntityName
  562.                 ,[theType]           = DATABASE_DEPENDENCIES.EntityType
  563.                 ,[iteration]         = @ii
  564.  
  565.       FROM      @DatabaseDependencies AS DATABASE_DEPENDENCIES
  566.  
  567.                 INNER JOIN @References AS PREVIOUS_REFERENCES
  568.                 ON PREVIOUS_REFERENCES.TheFullEntityName = DATABASE_DEPENDENCIES.TheReferredEntity
  569.                 AND PREVIOUS_REFERENCES.iteration = @ii - 1
  570.  
  571.      WHERE      DATABASE_DEPENDENCIES.TheReferredEntity <> DATABASE_DEPENDENCIES.EntityName
  572.        AND      DATABASE_DEPENDENCIES.EntityName NOT IN (SELECT RSUB_EXISTING.TheFullEntityName FROM @References RSUB_EXISTING)
  573.  
  574.     SELECT  @rowcount = @@rowcount
  575.     SELECT  @ii = @ii + 1
  576.   END
  577.  
  578. RETURN
  579. END
  580. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement