I have written the below to populate/create tables (t_) from all of the corresponding views (v_) in my database. I converted a previous script from using a cursor to improve running speed. Is there anything else I can do to make this more performant.Any help is appreciated.Please see code below.USE [Database]GO/****** Object:  StoredProcedure [dbo].[P_populate_tables_from_views]    Script Date: 22/11/2016 16:15:17 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER   PROCEDURE [dbo].[P_populate_tables_from_views] @dropTables BITASDECLARE @viewName NVARCHAR(100);DECLARE @formattedTableName NVARCHAR(100);DECLARE @dropTableSql NVARCHAR(MAX);DECLARE @viewId intSET @viewId = (SELECT MIN(object_id) FROM sys.views)WHILE @viewId IS NOT NULLBEGINSET @viewName = (SELECT name FROM sys.views where object_id = @viewId)PRINT 'Time: ' + CONVERT(varchar, SYSDATETIME(), 121)PRINT('Processing ' + @viewName)SET @formattedTableName = REPLACE(@viewName,'v_','t_');IF @dropTables = 1BEGIN    SET @dropTableSql = 'IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '''+@formattedTableName+''')) DROP TABLE '+@formattedTableName    EXEC (@dropTableSql);ENDIF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @formattedTableName))    BEGIN        EXEC('TRUNCATE TABLE '+@formattedTableName)        EXEC('INSERT INTO '+@formattedTableName +' SELECT * FROM '+ @viewName)     END    ELSE    BEGIN        EXEC ('SELECT * INTO '+@formattedTableName+' FROM '+@viewName);    ENDSET @viewId = (SELECT MIN(object_id) FROM sys.views WHERE object_id > @viewId)END
SQL Procedure to populate or create tables from views - performance issues
performance;sql;cursor