Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Dynamic delete schemas

Author  Topic 

djcarpen11
Starting Member

25 Posts

Posted - 2010-06-14 : 07:01:28
How do I make the below sql acutally execute? with out cutting and pasting the results into the ssms?

declare @sql nvarchar(500)

set @sql= 'SELECT ''DROP SCHEMA [''+''''+Name +''];'' FROM sys.schemas Where Name <>N''dbo'''

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-14 : 07:14:48
exec(@sql)



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

djcarpen11
Starting Member

25 Posts

Posted - 2010-06-14 : 07:16:15
Thanks for the reply,

all the exec (SQL) does is results of the statment, it deson't actually execute the drop commands.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-14 : 07:18:51
[code]DECLARE @SQL NVARCHAR(MAX)

SET @SQL = (
SELECT 'DROP SCHEMA ' + QUOTENAME(Name) + ';'
FROM sys.schemas
WHERE Name NOT IN (N'dbo', N'guest', N'INFORMATION_SCHEMA', N'sys')
FOR XML PATH('')
)

PRINT @SQL
--EXEC(@SQL)[/code]

N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -