0
Wie kann ich folgenden Code ohne while-Schleife schreiben? Gibt es einen alternativen Weg, um while-Schleife in diesem Fall zu vermeiden?alternative Lösung für while-Schleife in sql
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
Hier CommonTables enthalten Liste der Tabellen, die in 2 Datenbanken gemeinsam sind (DB1 und DB2)
Vielen Dank :) Es funktioniert gut –