0
whileループを使用せずに次のコードを書くにはどうすればよいですか?この場合、whileループを回避する別の方法はありますか?SQLのwhileループの代替ソリューション
ここSELECT @count = COUNT(*) from CommonTables
While(@count > 0)
BEGIN
select top 1 @Sname = Schema_name,@Tname = Name from CommonTables
SET @sql = ''
SET @sql = 'insert into #Temp1 select '''[email protected]+''','''[email protected]+''',column_name,data_type,character_maximum_length FROM '[email protected]+'.information_schema.columns
WHERE table_name = '''[email protected]+''' and TABLE_SCHEMA = '''[email protected]+''''
EXEC SP_EXECUTESQL @SQL
SET @sql = ''
SET @sql = 'insert into #Temp2 select '''[email protected]+''','''[email protected]+''',column_name,data_type,character_maximum_length FROM '[email protected]+'.information_schema.columns
WHERE table_name = '''[email protected]+''' and TABLE_SCHEMA = '''[email protected]+''''
EXEC SP_EXECUTESQL @SQL
DELETE from CommonTables where Name = @Tname and Schema_name = @Sname
SELECT @count = COUNT(*) from CommonTables
END
CommonTablesは全くループを必要としない2つのデータベース(DB1とDB2)
ある1つのsp_executeに組み合わせることができます –