declare @tab1 table
(
[TName] [nvarchar] (250)
)
insert into @tab1
select t1.name from dbname1.sys.tables T1 JOIN
dbname2.SYS.TABLES T2 ON
T1.NAME = T2.NAME
order by t1.name
declare @SQL nvarchar(max)
SELECT @SQL = STUFF((SELECT ' Drop Table ' + quotename(TABLE_SCHEMA) + '.' + quotename(TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES WHERE Table_Name in (select TName from @tab1)
FOR XML PATH('')),1,2,'')
SET @SQL = @SQL
PRINT @SQL
EXECUTE (@SQL)
(
[TName] [nvarchar] (250)
)
insert into @tab1
select t1.name from dbname1.sys.tables T1 JOIN
dbname2.SYS.TABLES T2 ON
T1.NAME = T2.NAME
order by t1.name
declare @SQL nvarchar(max)
SELECT @SQL = STUFF((SELECT ' Drop Table ' + quotename(TABLE_SCHEMA) + '.' + quotename(TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES WHERE Table_Name in (select TName from @tab1)
FOR XML PATH('')),1,2,'')
SET @SQL = @SQL
PRINT @SQL
EXECUTE (@SQL)
No comments:
Post a Comment