데이터베이스 생성, 변경 및 제거

적용 대상:SQL ServerAzure SQL DatabaseAzure SQL Managed InstanceAzure Synapse Analytics

SMO에서 데이터베이스는 개체로 Database 표시됩니다.

수정하거나 제거할 개체를 Database 만들 필요는 없습니다. 컬렉션을 사용하여 데이터베이스를 참조할 수 있습니다.

제공된 코드 예제를 사용하려면 프로그래밍 환경, 프로그래밍 템플릿 및 애플리케이션을 만들 프로그래밍 언어를 선택해야 합니다. 자세한 내용은 Visual Studio .NET에서 Visual C# SMO 프로젝트 만들기를 참조하세요.

Visual Basic에서 데이터베이스 만들기, 변경 및 제거

이 코드 예제에서는 새 데이터베이스를 만듭니다. 파일 및 파일 그룹은 데이터베이스에 대해 자동으로 만들어집니다.

'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에서 데이터베이스 만들기, 변경 및 제거#

이 코드 예제에서는 새 데이터베이스를 만듭니다. 파일 및 파일 그룹은 데이터베이스에 대해 자동으로 만들어집니다.

{  
                //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에서 데이터베이스 만들기, 변경 및 제거

이 코드 예제에서는 새 데이터베이스를 만듭니다. 파일 및 파일 그룹은 데이터베이스에 대해 자동으로 만들어집니다.

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

참고 항목

Database