Database.Events Database.Events Database.Events Property

정의

데이터베이스와 연결된 이벤트를 가져옵니다. Gets the events associated with the database.

public:
 property Microsoft::SqlServer::Management::Smo::DatabaseEvents ^ Events { Microsoft::SqlServer::Management::Smo::DatabaseEvents ^ get(); };
public Microsoft.SqlServer.Management.Smo.DatabaseEvents Events { get; }
Public ReadOnly Property Events As DatabaseEvents
속성 값

A DatabaseEvents 데이터베이스 이벤트를 나타내는 개체입니다. A DatabaseEvents object that represents the database events.

예제

VBVB

PowerShellPowerShell

Function MyCreateEventHandler($sender, $e)  
{  
   Write-Host "A table has just been added to the AdventureWorks2012 database."  
}  
Function MyDropEventHandler($sender, $e)  
{  
   Write-Host "A table has just been dropped from the AdventureWorks2012 database."  
}  
$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("AdventureWorks2012")  

$databaseCreateEventSet = new-object Microsoft.SqlServer.Management.Smo.DatabaseEventSet  
$databaseCreateEventSet.CreateTable = $TRUE  
$serverCreateEventHandler = new-object Microsoft.SqlServer.Management.Smo.ServerEventHandler(AddressOf MyCreateEventHandler)  
$db.Events.SubscribeToEvents(databaseCreateEventSet, serverCreateEventHandler)  
$databaseDropEventSet = new-object Microsoft.SqlServer.Management.Smo.DatabaseEventSet  
$databaseDropEventSet.DropTable = $TRUE  

$serverDropEventHandler = new-object Microsoft.SqlServer.Management.Smo.ServerEventHandler(AddressOf MyDropEventHandler)  
$db.Events.SubscribeToEvents(databaseDropEventSet, serverDropEventHandler)  
$db.Events.StartEvents()  

$tb = new-object Microsoft.SqlServer.Management.Smo.Table($db, "Test Table")  
$mycol1 = new-object Microsoft.SqlServer.Management.Smo.Column($tb, "Name", [Microsoft.SqlServer.Management.Smo.DataType]::NChar(50))  
$mycol1.Collation = "Latin1_General_CI_AS"  
$mycol1.Nullable = $FALSE  
$tb.Columns.Add($mycol1)  
$tb.Create()  

$tb.Drop()  
$y = 0  
For ($x=1; $x -le 1000000000; $x++)  
{  
   $y = $x*2  
}  
$db.Events.StopEvents()  

설명

Events 속성은 데이터베이스와 연결된 WMI(Windows Management Instrumentation) 이벤트 또는 서버 이벤트를 참조합니다.The Events property refers to server events or Windows Management Instrumentation (WMI) events that are associated with the database.

적용 대상