你可以使用光標的FOM表和循環列表通過這一點。然後添加更多表格,您只需將它們添加到list_of_tables:
declare @tablename nvarchar(128);
declare @sqlquery nvarchar(max);
declare d cursor for
select tablename from (
select 'Table1' as tablename
union
select 'Table2' as tablename
union
select 'Table3' as tablename) as list_of_tables;
open d;
fetch next from d into @tablename;
while @@fetch_status = 0
begin
set @sqlquery = 'SELECT * INTO SCHEMA.' + QUOTENAME(@TableName) + '
FROM
OPENQUERY (LINKEDSERVER,''SELECT * FROM ' + QUOTENAME(@TableName)+ ''');'
exec (@sqlquery);
fetch next from d into @tablename;
end;
close d;
deallocate d;
不能這樣做。只需編制你需要的表格。 – Jeremy
你是怎麼說出來的? – user3007811
創建一個將轉移所有表的sql腳本。將其保存爲存儲過程或常規SQL腳本,然後在需要傳輸數據時執行。如果定期調度,則創建一個sql作業以定期調用存儲過程來移動數據。 – Jeremy