Database Database Database Constructors

Definition

Overloads

Database() Database() Database()

Initializes a new instance of the Database class.

Database(Server, String) Database(Server, String)

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

Database() Database() Database()

Initializes a new instance of the Database class.

public:
 Database();
public Database ();
Public Sub New ()

Examples

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()  

Remarks

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.

Database(Server, String) Database(Server, String)

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

public:
 Database(Microsoft::SqlServer::Management::Smo::Server ^ server, System::String ^ name);
public Database (Microsoft.SqlServer.Management.Smo.Server server, string name);
Parameters
server
Server Server Server

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

name
String String String

A String value that specifies the name of the database.

Examples

VB

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()  

Applies to