Monday, 3 July 2017

Drop common table in two database


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)

No comments:

Post a Comment

React Hooks - custom Hook

  v CustomHook Ø React allows us to create our own hook which is known as custom hook. Example – 1 localStorage Demo Step-1 Create ...