Aracılığıyla paylaş


Oluşturma, değiştirme ve veritabanları kaldırma

smo, veritabanı tarafından temsil edilen Databasenesnesini.

It's not oluşturmak için gerekli bir Databasenesneyi değiştirmek veya görüneceği şekilde kaldırmak için Veritabanı, bir koleksiyonu kullanarak başvurulabilir.

Örnek

Sunulan kod örneklerinden herhangi birini kullanmak için, programlama ortamını, programlama şablonunu ve uygulamanızı oluşturacağınız programlama dilini seçmeniz gerekecektir. Daha fazla bilgi için, bkz. Visual Studio'da Visual Basic smo proje oluşturun.NET veya Visual Studio'da Visual C# smo proje oluşturun.NET.

Oluşturma, değiştirme ve Visual Basic'te bir veritabanı kaldırma

Bu kod örneği, yeni bir veritabanı oluşturur. Dosyaları ve dosya gruplarını 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()

Oluşturma, değiştirme ve bir veritabanı Visual C# içinde kaldırma

Bu kod örneği, yeni bir veritabanı oluşturur. Dosyaları ve dosya gruplarını 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();
            }

{
                //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();
            }

Oluşturma, değiştirme ve PowerShell içinde bir veritabanı kaldırma

Bu kod örneği, yeni bir veritabanı oluşturur. Dosyaları ve dosya gruplarını 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()

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

Ayrıca bkz.

Başvuru

Database