开发者

How do I use Powershell to detach a SQL Server database?

开发者 https://www.devze.com 2022-12-14 20:17 出处:网络
I am sure that this can be achieved by loading the SQL Server Management Objects assemblies but I am curious as to whether the \'Start Powershell\' item in 开发者_高级运维the context menu within SQL S

I am sure that this can be achieved by loading the SQL Server Management Objects assemblies but I am curious as to whether the 'Start Powershell' item in 开发者_高级运维the context menu within SQL Server Management Studio 2008 will give me a headstart.


The SMO Server class has a DetachDatabase method that you can use from Start PowerShell. From the server level in sqlps you can use something like this:

PS SQLSERVER:\SQL\Z002>get-childitem | foreach{$_.DetachDatabase("pubs",$false)}

See the MSDN docs for detailed info on DetachDatabase:

0

精彩评论

暂无评论...
验证码 换一张
取 消