Table.Deny Table.Deny Table.Deny Method

Definition

Denies the specified set of permissions for the specified grantees on the table.

Overloads

Deny(ObjectPermissionSet, String) Deny(ObjectPermissionSet, String) Deny(ObjectPermissionSet, String)

Denies the specified set of permissions for the specified grantee on the table.

Deny(ObjectPermissionSet, String[]) Deny(ObjectPermissionSet, String[]) Deny(ObjectPermissionSet, String[])

Denies the specified set of permissions for the specified grantees on the table.

Deny(ObjectPermissionSet, String, Boolean) Deny(ObjectPermissionSet, String, Boolean) Deny(ObjectPermissionSet, String, Boolean)

Denies the specified set of permissions for the specified grantee and other users to whom the grantee granted the specified set of permissions on the table.

Deny(ObjectPermissionSet, String, String[]) Deny(ObjectPermissionSet, String, String[]) Deny(ObjectPermissionSet, String, String[])

Denies the specified set of permissions to the grantee on the specified columns on the table.

Deny(ObjectPermissionSet, String[], Boolean) Deny(ObjectPermissionSet, String[], Boolean) Deny(ObjectPermissionSet, String[], Boolean)

Denies the specified permission for the specified grantees on the table.

Deny(ObjectPermissionSet, String[], String[]) Deny(ObjectPermissionSet, String[], String[]) Deny(ObjectPermissionSet, String[], String[])

Denies the specified set of permissions for the grantees on the specified columns on the table.

Deny(ObjectPermissionSet, String, String[], Boolean) Deny(ObjectPermissionSet, String, String[], Boolean) Deny(ObjectPermissionSet, String, String[], Boolean)

Denies the specified set of permissions for the specified grantee and other users to whom the grantee granted the specified set of permissions on the specified columns on the table.

Deny(ObjectPermissionSet, String[], String[], Boolean) Deny(ObjectPermissionSet, String[], String[], Boolean) Deny(ObjectPermissionSet, String[], String[], Boolean)

Denies the specified set of permissions for the specified grantees and other users to whom the grantee granted the specified set of permissions on the specified columns on the table.

Deny(ObjectPermissionSet, String) Deny(ObjectPermissionSet, String) Deny(ObjectPermissionSet, String)

Denies the specified set of permissions for the specified grantee on the table.

public:
 virtual void Deny(Microsoft::SqlServer::Management::Smo::ObjectPermissionSet ^ permission, System::String ^ granteeName);
public void Deny (Microsoft.SqlServer.Management.Smo.ObjectPermissionSet permission, string granteeName);
Public Sub Deny (permission As ObjectPermissionSet, granteeName As String)
Parameters
permission
ObjectPermissionSet ObjectPermissionSet ObjectPermissionSet

An ObjectPermissionSet object value that specifies the permission.

granteeName
String String String

A String value that specifies the grantee to be denied the specified set of permissions on the table.

Implements

Examples

The following code example shows how to grant guest accounts permission to select table elements, and then revoke the permission by using the Deny method.

The following database schema is used for this snippet.

//CREATE DATABASE MYTESTDB;  
//GO  

//USE MYTESTDB;  
//GO  

//CREATE TABLE TABLE1(  
//    id int,  
//    name varchar(32)  
//);  
//GO  

C#

Server srv = new Server("(local)");  

Database db = srv.Databases["MYTESTDB"];  

Table tb = db.Tables[0];  

ObjectPermissionSet objPermissionSet = new ObjectPermissionSet(ObjectPermission.Select);  
objPermissionSet.Select = true;  
tb.Grant(objPermissionSet, "Guest");  
tb.Deny(objPermissionSet, "Guest");  

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("MYTESTDB")  
$tb = $db.Tables[0]  

$objPermissionSet = new-object Microsoft.SqlServer.Management.Smo.ObjectPermissionSet([Microsoft.SqlServer.Management.Smo.ObjectPermission]::Select)  
$objPermissionSet.Select = $TRUE  
$tb.Grant($objPermissionSet, "Guest")  
$tb.Deny($objPermissionSet, "Guest")  

Deny(ObjectPermissionSet, String[]) Deny(ObjectPermissionSet, String[]) Deny(ObjectPermissionSet, String[])

Denies the specified set of permissions for the specified grantees on the table.

public:
 virtual void Deny(Microsoft::SqlServer::Management::Smo::ObjectPermissionSet ^ permission, cli::array <System::String ^> ^ granteeNames);
public void Deny (Microsoft.SqlServer.Management.Smo.ObjectPermissionSet permission, string[] granteeNames);
Public Sub Deny (permission As ObjectPermissionSet, granteeNames As String())
Parameters
permission
ObjectPermissionSet ObjectPermissionSet ObjectPermissionSet

An ObjectPermissionSet object value that specifies the permission.

granteeNames
String[]

A String array that specifies a list of grantees to be denied the specified set of permissions on the table.

Implements

Examples

The following code example shows how to grant an array of grantee accounts permission to select table elements, and then revoke the permission by using the Deny method. The grantees account array is a placeholder for any array of defined user accounts.

The following database schema is used for this snippet.

//CREATE DATABASE MYTESTDB;  
//GO  

//USE MYTESTDB;  
//GO  

//CREATE TABLE TABLE1(  
//    id int,  
//    name varchar(32)  
//);  
//GO  

C#

Server srv = new Server("(local)");  

Database db = srv.Databases["MYTESTDB"];  

Table tb = db.Tables[0];  

ObjectPermissionSet objPermissionSet = new ObjectPermissionSet(ObjectPermission.Select);  
objPermissionSet.Select = true;  
tb.Grant(objPermissionSet, Grantees)  
tb.Deny(objPermissionSet, Grantees)  

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("MYTESTDB")  
$tb = $db.Tables[0]  

$objPermissionSet = new-object Microsoft.SqlServer.Management.Smo.ObjectPermissionSet([Microsoft.SqlServer.Management.Smo.ObjectPermission]::Select)  
$objPermissionSet.Select = $TRUE  
$tb.Grant($objPermissionSet, grantees)  
$tb.Deny($objPermissionSet, grantees)  

Deny(ObjectPermissionSet, String, Boolean) Deny(ObjectPermissionSet, String, Boolean) Deny(ObjectPermissionSet, String, Boolean)

Denies the specified set of permissions for the specified grantee and other users to whom the grantee granted the specified set of permissions on the table.

public:
 virtual void Deny(Microsoft::SqlServer::Management::Smo::ObjectPermissionSet ^ permission, System::String ^ granteeName, bool cascade);
public void Deny (Microsoft.SqlServer.Management.Smo.ObjectPermissionSet permission, string granteeName, bool cascade);
Public Sub Deny (permission As ObjectPermissionSet, granteeName As String, cascade As Boolean)
Parameters
permission
ObjectPermissionSet ObjectPermissionSet ObjectPermissionSet

An ObjectPermissionSet object value that specifies the permission.

granteeName
String String String

A String value that specifies the grantee to be denied the specified set of permissions on the table.

cascade
Boolean Boolean Boolean

A Boolean property that specifies whether the users to whom the grantee granted the specified set of permission are also denied access to the specified set of permissions on the table.

If True, the grantee and the users to whom the grantee granted the specified set of permissions are all denied the specified set of permissions.

If False, only the grantee is denied the specified set of permissions.

Implements

Examples

The following code example shows how to grant guest accounts permission to select table elements, and then revoke the permission by using the Deny method. The account grantee is a placeholder for any defined user account.

The following Database schema is used for this snippet.

//CREATE DATABASE MYTESTDB;  
//GO  

//USE MYTESTDB;  
//GO  

//CREATE TABLE TABLE1(  
//    id int,  
//    name varchar(32)  
//);  
//GO  

C#

Server srv = new Server("(local)");  

Database db = srv.Databases["MYTESTDB"];  

Table tb = db.Tables[0];  

ObjectPermissionSet objPermissionSet = new ObjectPermissionSet(ObjectPermission.Select);  
objPermissionSet.Select = true;  
tb.Grant(objPermissionSet, grantee);  
tb.Deny(objPermissionSet, grantee, true);  

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("MYTESTDB")  
$tb = $db.Tables[0]  

$objPermissionSet = new-object Microsoft.SqlServer.Management.Smo.ObjectPermissionSet([Microsoft.SqlServer.Management.Smo.ObjectPermission]::Select)  
$objPermissionSet.Select = $TRUE  
$tb.Grant($objPermissionSet, grantee)  
$tb.Deny($objPermissionSet, grantee, $TRUE)  

Deny(ObjectPermissionSet, String, String[]) Deny(ObjectPermissionSet, String, String[]) Deny(ObjectPermissionSet, String, String[])

Denies the specified set of permissions to the grantee on the specified columns on the table.

public:
 virtual void Deny(Microsoft::SqlServer::Management::Smo::ObjectPermissionSet ^ permission, System::String ^ granteeName, cli::array <System::String ^> ^ columnNames);
public void Deny (Microsoft.SqlServer.Management.Smo.ObjectPermissionSet permission, string granteeName, string[] columnNames);
Public Sub Deny (permission As ObjectPermissionSet, granteeName As String, columnNames As String())
Parameters
permission
ObjectPermissionSet ObjectPermissionSet ObjectPermissionSet

An ObjectPermissionSet object value that specifies the set of permissions.

granteeName
String String String

A String value that specifies the grantee to be denied the specified set of permissions.

columnNames
String[]

A String array value that specifies the list of columns for which the permission is denied.

Implements

Examples

The following code example shows how to grant guest accounts permission to select table elements, and then revoke the permission with the Deny method.

The following Database schema is used for this snippet.

//CREATE DATABASE MYTESTDB;  
//GO  

//USE MYTESTDB;  
//GO  

//CREATE TABLE TABLE1(  
//    id int,  
//    name varchar(32)  
//);  
//GO  

C#

Server srv = new Server("(local)");  
Database db = srv.Databases["MYTESTDB"];  

Table tb = db.Tables[0];  

ObjectPermissionSet objPermissionSet = new ObjectPermissionSet(ObjectPermission.Select);  
objPermissionSet.Select = true;  
tb.Grant(objPermissionSet, "Guest");  

String[] tbColNames = new string[tb.Columns.Count];  
int n = 0;  
foreach (Column i in tb.Columns)  
{  
tbColNames[n] = i.Name;  
n++;  
}  
tb.Deny(objPermissionSet, "Guest", tbColNames);  

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("MYTESTDB")  
$tb = $db.Tables[0]  

$objPermissionSet = new-object Microsoft.SqlServer.Management.Smo.ObjectPermissionSet([Microsoft.SqlServer.Management.Smo.ObjectPermission]::Select)  
$objPermissionSet.Select = $TRUE  
$tb.Grant($objPermissionSet, "Guest")  
$tbColNames = @()  
foreach ($c in $tb.Columns)  
{  
   $tbColNames = $tbColNames + $c.Name  
   Write-Host $tbColNames  
}  
$tb.Deny($objPermissionSet, "Guest", $tbColNames)  

Deny(ObjectPermissionSet, String[], Boolean) Deny(ObjectPermissionSet, String[], Boolean) Deny(ObjectPermissionSet, String[], Boolean)

Denies the specified permission for the specified grantees on the table.

public:
 virtual void Deny(Microsoft::SqlServer::Management::Smo::ObjectPermissionSet ^ permission, cli::array <System::String ^> ^ granteeNames, bool cascade);
public void Deny (Microsoft.SqlServer.Management.Smo.ObjectPermissionSet permission, string[] granteeNames, bool cascade);
Public Sub Deny (permission As ObjectPermissionSet, granteeNames As String(), cascade As Boolean)
Parameters
permission
ObjectPermissionSet ObjectPermissionSet ObjectPermissionSet

An ObjectPermissionSet object value that specifies the permission.

granteeNames
String[]

A String array that specifies a list of grantees to be denied the specified set of permissions.

cascade
Boolean Boolean Boolean

A Boolean property that specifies whether users, to whom the grantee granted the specified set of permission, are also denied access to the specified set of permissions on the table.

If True, the grantee and users to whom the grantee granted the specified set of permissions are all denied the specified set of permissions.

If False, only the grantee is denied the specified set of permissions.

Implements

Examples

The following code example shows how to grant guest accounts permission to select table elements, and then revoke the permission by usuing the Deny method. The grantees account array is a placeholder for any array of defined user accounts.

The following database schema is used for this snippet.

//CREATE DATABASE MYTESTDB;  
//GO  

//USE MYTESTDB;  
//GO  

//CREATE TABLE TABLE1(  
//    id int,  
//    name varchar(32)  
//);  
//GO  

C#

Server srv = new Server("(local)");  
Database db = srv.Databases["MYTESTDB"];  

Table tb = db.Tables[0];  

ObjectPermissionSet objPermissionSet = new ObjectPermissionSet(ObjectPermission.Select);  
objPermissionSet.Select = true;  
tb.Grant(objPermissionSet, grantees);  
tb.Deny(objPermissionSet, grantees, true);  

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("MYTESTDB")  
$tb = $db.Tables[0]  

$objPermissionSet = new-object Microsoft.SqlServer.Management.Smo.ObjectPermissionSet([Microsoft.SqlServer.Management.Smo.ObjectPermission]::Select)  
$objPermissionSet.Select = $TRUE  
$tb.Grant($objPermissionSet, grantees)  
$tb.Deny($objPermissionSet, grantees, $TRUE)  

Deny(ObjectPermissionSet, String[], String[]) Deny(ObjectPermissionSet, String[], String[]) Deny(ObjectPermissionSet, String[], String[])

Denies the specified set of permissions for the grantees on the specified columns on the table.

public:
 virtual void Deny(Microsoft::SqlServer::Management::Smo::ObjectPermissionSet ^ permission, cli::array <System::String ^> ^ granteeNames, cli::array <System::String ^> ^ columnNames);
public void Deny (Microsoft.SqlServer.Management.Smo.ObjectPermissionSet permission, string[] granteeNames, string[] columnNames);
Public Sub Deny (permission As ObjectPermissionSet, granteeNames As String(), columnNames As String())
Parameters
permission
ObjectPermissionSet ObjectPermissionSet ObjectPermissionSet

An ObjectPermissionSet object value that specifies the set of permissions.

granteeNames
String[]

A String array value that specifies the list of grantees to be denied access to the set of permissions.

columnNames
String[]

A String array value that specifies the list of columns to which the set of permissions is denied.

Implements

Examples

The following code example shows how to grant an array of grantee accounts permission to select table elements, and then revoke the permission by using the Deny method. The grantees account array is a placeholder for any array of defined user accounts.

The following database schema is used for this snippet.

//CREATE DATABASE MYTESTDB;  
//GO  

//USE MYTESTDB;  
//GO  

//CREATE TABLE TABLE1(  
//    id int,  
//    name varchar(32)  
//);  
//GO  

C#

Server srv = new Server("(local)");  
Database db = srv.Databases["MYTESTDB"];  

Table tb = db.Tables[0];  

ObjectPermissionSet objPermissionSet = new ObjectPermissionSet(ObjectPermission.Select);  
objPermissionSet.Select = true;  
tb.Grant(objPermissionSet, grantees);  

String[] tbColNames = new string[tb.Columns.Count];  
int n = 0;  
foreach (Column i in tb.Columns)  
{  
   tbColNames[n] = i.Name;  
  n++;  
}  
tb.Deny(objPermissionSet, grantees, tbColNames);  

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("MYTESTDB")  
$tb = $db.Tables[0]  

$objPermissionSet = new-object Microsoft.SqlServer.Management.Smo.ObjectPermissionSet([Microsoft.SqlServer.Management.Smo.ObjectPermission]::Select)  
$objPermissionSet.Select = $TRUE  
$tb.Grant($objPermissionSet, grantees)  
$tbColNames = @()  
foreach ($c in $tb.Columns)  
{  
   $tbColNames = $tbColNames + $c.Name  
}  
$tb.Deny($objPermissionSet, grantees, $tbColNames)  

Deny(ObjectPermissionSet, String, String[], Boolean) Deny(ObjectPermissionSet, String, String[], Boolean) Deny(ObjectPermissionSet, String, String[], Boolean)

Denies the specified set of permissions for the specified grantee and other users to whom the grantee granted the specified set of permissions on the specified columns on the table.

public:
 virtual void Deny(Microsoft::SqlServer::Management::Smo::ObjectPermissionSet ^ permission, System::String ^ granteeName, cli::array <System::String ^> ^ columnNames, bool cascade);
public void Deny (Microsoft.SqlServer.Management.Smo.ObjectPermissionSet permission, string granteeName, string[] columnNames, bool cascade);
Public Sub Deny (permission As ObjectPermissionSet, granteeName As String, columnNames As String(), cascade As Boolean)
Parameters
permission
ObjectPermissionSet ObjectPermissionSet ObjectPermissionSet

An ObjectPermissionSet object value that specifies the set of permissions.

granteeName
String String String

A String value that specifies the grantee to be denied access to the set of permissions.

columnNames
String[]

A String array value that specifies the list of columns to which the set of permissions is denied.

cascade
Boolean Boolean Boolean

A Boolean property that specifies whether users, to whom the grantee granted the specified set of permission, are also denied access to the specified set of permissions on the table.

If True, the grantee and users to whom the grantee granted the specified set of permissions are all denied the specified set of permissions.

If False, only the grantee is denied the specified set of permissions.

Implements

Examples

The following code example shows how to grant an array of grantee accounts permission to select table elements, and then revoke the permission by using the Deny method. The grantee account is a placeholder for any defined user account.

The following database schema is used for this snippet.

//CREATE DATABASE MYTESTDB;  
//GO  

//USE MYTESTDB;  
//GO  

//CREATE TABLE TABLE1(  
//    id int,  
//    name varchar(32)  
//);  
//GO  

C#

Server srv = new Server("(local)");  
Database db = srv.Databases["MYTESTDB"];  

Table tb = db.Tables[0];  

ObjectPermissionSet objPermissionSet = new ObjectPermissionSet(ObjectPermission.Select);  
objPermissionSet.Select = true;  
tb.Grant(objPermissionSet, grantee);  

String[] tbColNames = new string[tb.Columns.Count];  
int n = 0;  
foreach (Column i in tb.Columns)  
{  
   tbColNames[n] = i.Name;  
   n++;  
}  
tb.Deny(objPermissionSet, grantee, tbColNames, true);  

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("MYTESTDB")  
$tb = $db.Tables[0]  

$objPermissionSet = new-object Microsoft.SqlServer.Management.Smo.ObjectPermissionSet([Microsoft.SqlServer.Management.Smo.ObjectPermission]::Select)  
$objPermissionSet.Select = $TRUE  
$tb.Grant($objPermissionSet, grantee)  
$tbColNames = @()  
foreach ($c in $tb.Columns)  
{  
   $tbColNames = $tbColNames + $c.Name  
}  
$tb.Deny($objPermissionSet, grantee, $tbColNames, $TRUE)  

Deny(ObjectPermissionSet, String[], String[], Boolean) Deny(ObjectPermissionSet, String[], String[], Boolean) Deny(ObjectPermissionSet, String[], String[], Boolean)

Denies the specified set of permissions for the specified grantees and other users to whom the grantee granted the specified set of permissions on the specified columns on the table.

public:
 virtual void Deny(Microsoft::SqlServer::Management::Smo::ObjectPermissionSet ^ permission, cli::array <System::String ^> ^ granteeNames, cli::array <System::String ^> ^ columnNames, bool cascade);
public void Deny (Microsoft.SqlServer.Management.Smo.ObjectPermissionSet permission, string[] granteeNames, string[] columnNames, bool cascade);
Public Sub Deny (permission As ObjectPermissionSet, granteeNames As String(), columnNames As String(), cascade As Boolean)
Parameters
permission
ObjectPermissionSet ObjectPermissionSet ObjectPermissionSet

An ObjectPermissionSet object value that specifies the set of permissions.

granteeNames
String[]

A String array value that specifies the list of grantees to be denied access to the set of permissions.

columnNames
String[]

A String array value that specifies the list of columns to which the set of permissions is denied.

cascade
Boolean Boolean Boolean

A Boolean property that specifies whether users, to whom the grantee granted the specified set of permission, are also denied access to the specified set of permissions on the table.

If True, the grantee and users to whom the grantee granted the specified set of permissions are all denied the specified set of permissions.

If False, only the grantee is denied the specified set of permissions.

Implements

Examples

The following code example shows how to grant an array of grantee accounts permission to select table elements, and then revoke the permission by using the Deny method. The grantees account array is a placeholder for any array of defined user accounts.

The following database schema is used for this snippet.

//CREATE DATABASE MYTESTDB;  
//GO  

//USE MYTESTDB;  
//GO  

//CREATE TABLE TABLE1(  
//    id int,  
//    name varchar(32)  
//);  
//GO  

C#

Server srv = new Server("(local)");  
Database db = srv.Databases["MYTESTDB"];  

Table tb = db.Tables[0];  

ObjectPermissionSet objPermissionSet = new ObjectPermissionSet(ObjectPermission.Select);  
objPermissionSet.Select = true;  
tb.Grant(objPermissionSet, grantees);  

String[] tbColNames = new string[tb.Columns.Count];  
int n = 0;  
foreach (Column i in tb.Columns)  
{  
   tbColNames[n] = i.Name;  
   n++;  
}  
tb.Deny(objPermissionSet, grantees, tbColNames, true);  

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("MYTESTDB")  
$tb = $db.Tables[0]  

$objPermissionSet = new-object Microsoft.SqlServer.Management.Smo.ObjectPermissionSet([Microsoft.SqlServer.Management.Smo.ObjectPermission]::Select)  
$objPermissionSet.Select = $TRUE  
$tb.Grant($objPermissionSet, grantees)  
$tbColNames = @()  
foreach ($c in $tb.Columns)  
{  
   $tbColNames = $tbColNames + $c.Name  
}  
$tb.Deny($objPermissionSet, grantees, $tbColNames, $TRUE)  

Applies to