PowerShell for Windows Admins

Jun 26 2013   4:09PM GMT

Dropping a database

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

A question came up on the forum regarding dropping a database & I realised it was something I hadn’t done before.

SMO provides a set of classes for managing SQL Server. You get SMO when you install the SQL Server management tools

Import the module to load SMO assemblies

import-module sqlps

get the server object and view the databases
$server = New-Object Microsoft.SqlServer.Management.Smo.Server(“w12scorc”)
$server.Databases

view the target database
$server.databases["mydb"]

drop the database and view the databases again
$server.databases["mydb"].Drop()
$server.databases

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: