Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
SMO'da veritabanı nesnesi tarafından Database temsil edilir.
Değiştirmek veya kaldırmak için bir Database nesne oluşturmak gerekmez. Veritabanına bir koleksiyon kullanılarak başvurulabilir.
Example
Sağlanan herhangi bir kod örneğini kullanmak için programlama ortamını, programlama şablonunu ve uygulamanızın oluşturulacağı programlama dilini seçmeniz gerekir. Daha fazla bilgi için bkz. Visual Studio .NET'te Visual C# SMO Projesi Oluşturma.
Visual Basic'te Veritabanı Oluşturma, Değiştirme ve Kaldırma
Bu kod örneği yeni bir veritabanı oluşturur. Dosyalar ve dosya grupları veritabanı için otomatik olarak oluşturulur.
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Define a Database object variable by supplying the server and the database name arguments in the constructor.
Dim db As Database
db = New Database(srv, "Test_SMO_Database")
'Create the database on the instance of SQL Server.
db.Create()
'Reference the database and display the date when it was created.
db = srv.Databases("Test_SMO_Database")
Console.WriteLine(db.CreateDate)
'Remove the database.
db.Drop()
Visual C'de Veritabanı Oluşturma, Değiştirme ve Kaldırma#
Bu kod örneği yeni bir veritabanı oluşturur. Dosyalar ve dosya grupları veritabanı için otomatik olarak oluşturulur.
{
//Connect to the local, default instance of SQL Server.
Server srv;
srv = new Server();
//Define a Database object variable by supplying the server and the database name arguments in the constructor.
Database db;
db = new Database(srv, "Test_SMO_Database");
//Create the database on the instance of SQL Server.
db.Create();
//Reference the database and display the date when it was created.
db = srv.Databases["Test_SMO_Database"];
Console.WriteLine(db.CreateDate);
//Remove the database.
db.Drop();
}
PowerShell'de Veritabanı Oluşturma, Değiştirme ve Kaldırma
Bu kod örneği yeni bir veritabanı oluşturur. Dosyalar ve dosya grupları veritabanı için otomatik olarak oluşturulur.
#Get a server object which corresponds to the default instance
cd \sql\localhost\
$srv = get-item default
#Create a new database
$db = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database -argumentlist $srv, "Test_SMO_Database"
$db.Create()
#Reference the database and display the date when it was created.
$db = $srv.Databases["Test_SMO_Database"]
$db.CreateDate
#Drop the database
$db.Drop()