Database.SymmetricKeys Database.SymmetricKeys Database.SymmetricKeys Property

Definition

Gets a collection of SymmetricKey objects. Each SymmetricKey object represents a symmetric key defined on the database.

public:
 property Microsoft::SqlServer::Management::Smo::SymmetricKeyCollection ^ SymmetricKeys { Microsoft::SqlServer::Management::Smo::SymmetricKeyCollection ^ get(); };
[Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcObject(Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcContainerRelationship.ObjectContainer, Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcContainerCardinality.ZeroToAny, typeof(Microsoft.SqlServer.Management.Smo.SymmetricKey))]
public Microsoft.SqlServer.Management.Smo.SymmetricKeyCollection SymmetricKeys { get; }
Public ReadOnly Property SymmetricKeys As SymmetricKeyCollection
Property Value

A SymmetricKeyCollection object that represents all the symmetric keys defined on the database.

Examples

VB

'Connect to the local, default instance of SQL Server.  
Dim srv As Server  
srv = New Server  

'Reference the AdventureWorks2012 database.  
Dim db As Database  
db = srv.Databases("AdventureWorks2012")  

'Display all the symmetric keys in the database.  
Dim sk As SymmetricKey  
For Each sk In db.SymmetricKeys  
   Console.WriteLine(sk.Name)  
Next  

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("AdventureWorks2012")  

Foreach ($sk in $db.SymmetricKeys)  
{  
   Write-Host $sk.Name  
}  

Remarks

Specific symmetric keys can be referenced by using this collection by specifying the name of the symmetric key. To add a new symmetric key to the collection, call the symmetric key constructor SymmetricKey, or its overload.

Applies to