﻿CREATE OR ALTER PROCEDURE [dev].[uspSchemaUpdateRegisteredSPFN]
AS
BEGIN
  SET NOCOUNT ON;

  DECLARE CursorSPFN CURSOR LOCAL FOR
    SELECT Name 
    FROM [dev].[VersionInfoSPFN]
    WHERE IsSchemaUpdated = 0
    ORDER BY IsProcedure, RegisteredAt
    FOR UPDATE OF IsSchemaUpdated
​
  DECLARE @name nvarchar(255)
​
  OPEN CursorSPFN
  FETCH NEXT FROM CursorSPFN INTO @name
​
  WHILE @@FETCH_STATUS = 0 BEGIN
​
    EXEC dev.uspCreateSchemaSPFN @name
​
    UPDATE [dev].[VersionInfoSPFN] SET
       IsSchemaUpdated = 1
    WHERE CURRENT OF CursorSPFN
    
​
    FETCH NEXT FROM CursorSPFN INTO @name
  END
​
  CLOSE CursorSPFN
  DEALLOCATE CursorSPFN
​
END
GO
