다음을 통해 공유


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

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

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

제공된 코드 예제를 사용하려면 응용 프로그램을 만들 프로그래밍 환경, 프로그래밍 템플릿 및 프로그래밍 언어를 선택해야 합니다. 자세한 내용은 방법: Visual Studio .NET에서 Visual Basic SMO 프로젝트 만들기 또는 방법: 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(); 
}

참고 항목

참조