Export (0) Print
Expand All

Database Constructor

 

Applies To: SQL Server 2016 Preview

Initializes a new instance of the Database class.

Namespace:   Microsoft.SqlServer.Management.Smo
Assembly:  Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)

NameDescription
System_CAPS_pubmethodDatabase()

Initializes a new instance of the Database class.

System_CAPS_pubmethodDatabase(Server, String)

Initializes a new instance of the Database class on the specified server and with the specified name.

Return to top

Database Constructor ()

Initializes a new instance of the Database class.

public Database()

The default constructor initializes any fields to their default values.

You will have to specify which server is the parent of the database before you can create a database.

Legacy Code Example

VB

Dim srv As Server
srv = New Server()

'Create a new database by using the default constructor.
Dim db As Database
db = New Database
db.Name = "New_Database"
db.Parent = srv
db.Create()

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$db.Name = "New_Database"
$db.Parent = $srv
$db.Create()

Return to top

Database Constructor (Server, String)

Initializes a new instance of the Database class on the specified server and with the specified name.

public Database(
	Server server,
	string name
)

Parameters

server
Type: Microsoft.SqlServer.Management.Smo.Server

A Server object that represents the instance of SQL Server on which the database exists.

name
Type: System.String

A String value that specifies the name of the database.

Legacy Code Example

VB

Code snippet is not found. Confirm that the code snippet name 'SMO How to' is correct.

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = New-Object Microsoft.SqlServer.Management.Smo.Database($srv, "Test_SMO_Database")
$db.Create()
Write-Host $db.CreateDate
$db.Drop()
Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft