﻿DROP PROCEDURE IF EXISTS sp_ElozoTanevesViewokTorlese
GO

CREATE PROCEDURE sp_ElozoTanevesViewokTorlese
   @pintezmenyId INT
  ,@pintezmenyAzonosito NVARCHAR(MAX)
  ,@pkovTanevId INT
WITH EXECUTE AS 'kreta_tech_user'
AS
BEGIN
  SET NOCOUNT ON

  DECLARE @schemaName NVARCHAR(MAX) = CONCAT(N'KR_', @pintezmenyAzonosito, N'_Schema')

  DECLARE @viewsXml XML =
    (SELECT v.name AS ViewName
    FROM sys.views v
      INNER JOIN sys.schemas s ON s.schema_id = v.schema_id
        AND s.name = @schemaName
    FOR XML PATH (N'ViewNames'))

  EXEC sp_Global_DeleteViews @schemaName, @viewsXml
  EXEC sp_Global_CreateSchemaViews @pintezmenyId, @pintezmenyAzonosito, @pkovTanevId
END
GO