Search This Blog

Saturday, February 21, 2009

How To Detach All User Database?

SQL 2005
===========

select 'EXEC sp_detach_db @dbname = N'''+RTRIM ( name)+''','''+'true''' from sys.sysdatabases where dbid>6 and name not like 'distribution'


SQL 2000
==========

select 'EXEC sp_detach_db @dbname = N'''+RTRIM ( name)+''','''+'true''' from sysdatabases where dbid>4 and name not like 'distribution'

No comments: