Table.Grant Table.Grant Table.Grant Method

Definition

Grants the specified set of permissions to the specified grantees on the table.

Overloads

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

Grants the specified set of permissions to the grantees and the ability to grant the set of permissions to other users on the specified columns on the table under an assumed role.

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

Grants the specified set of permissions to the grantee and the ability to grant the set of permissions to other users on the specified columns on the table under an assumed role.

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

Grants the specified set of permissions to the grantees and the ability to grant the set of permissions to other users on the specified columns on the table.

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

Grants the specified set of permissions to the grantees and the ability to grant the set of permissions to other users on the table under an assumed role.

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

Grants the specified permission to the grantee and the ability to grant the specified set of permissions to other users on the specified columns on the table.

Grant(ObjectPermissionSet, String, Boolean, String) Grant(ObjectPermissionSet, String, Boolean, String) Grant(ObjectPermissionSet, String, Boolean, String)

Grants the specified set of permissions to the grantee and the ability to grant the set of permissions to other users on the table under an assumed role.

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

Grants access to the specified permission and the ability to grant access to other uses for the specified grantees on the table.

Grant(ObjectPermissionSet, String, String[]) Grant(ObjectPermissionSet, String, String[]) Grant(ObjectPermissionSet, String, String[])

Grants access to the specified permission on the specified columns for the specified grantee on the specified columns on the table.

Grant(ObjectPermissionSet, String, Boolean) Grant(ObjectPermissionSet, String, Boolean) Grant(ObjectPermissionSet, String, Boolean)

Grants access to the specified permission and the ability to grant access to other uses for the specified grantee on the table.

Grant(ObjectPermissionSet, String[]) Grant(ObjectPermissionSet, String[]) Grant(ObjectPermissionSet, String[])

Grants the specified set of permissions to the specified grantees on the table.

Grant(ObjectPermissionSet, String) Grant(ObjectPermissionSet, String) Grant(ObjectPermissionSet, String)

Grants the specified set of permissions to the specified grantee on the table.

Grant(ObjectPermissionSet, String[], String[]) Grant(ObjectPermissionSet, String[], String[]) Grant(ObjectPermissionSet, String[], String[])

Grants the specified set of permissions to the grantees to the specified columns on the table.

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

Grants the specified set of permissions to the grantees and the ability to grant the set of permissions to other users on the specified columns on the table under an assumed role.

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

An ObjectPermissionSet object that specifies the set of permissions.

granteeNames
String[]

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

columnNames
String[]

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

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the set of permissions to other users on the table.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the table. Otherwise, False.

asRole
String String String

A String value that specifies the role that the user assumes when granting the specified set of permissions to other users on the table. Use this parameter for grantees who are members of more than one role.

Implements

Examples

Granting, Revoking, and Denying Permissions

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

Grants the specified set of permissions to the grantee and the ability to grant the set of permissions to other users on the specified columns on the table under an assumed role.

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

An ObjectPermissionSet object that specifies the permission.

granteeName
String String String

A String value that specifies a grantee to be denied access to the permission.

columnNames
String[]

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

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the specified set of permissions to other users on the table.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the table. Otherwise, False.

asRole
String String String

A String value that specifies the role that the user assumes when granting the specified set of permissions to other users on the table. Use this parameter for grantees who are members of more than one role.

Implements

Examples

Granting, Revoking, and Denying Permissions

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

Grants the specified set of permissions to the grantees and the ability to grant the set of permissions to other users on the specified columns on the table.

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

An ObjectPermissionSet object that specifies the set of permissions.

granteeNames
String[]

A String array that specifies a 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 granted.

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the specified set of permissions to other users on the table.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the table. Otherwise, False.

Implements

Examples

Granting, Revoking, and Denying Permissions

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

Grants the specified set of permissions to the grantees and the ability to grant the set of permissions to other users on the table under an assumed role.

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

An ObjectPermissionSet object that specifies the set of permissions.

granteeNames
String[]

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

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the set of permissions to other users on the table.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the table. Otherwise, False.

asRole
String String String

A String value that specifies the role that the user assumes when granting the specified set of permissions to other users on the table. Use this parameter for grantees who are members of more than one role.

Implements

Examples

Granting, Revoking, and Denying Permissions

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

Grants the specified permission to the grantee and the ability to grant the specified set of permissions to other users on the specified columns on the table.

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

An ObjectPermissionSet object that specifies the set of permissions.

granteeName
String String String

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

columnNames
String[]

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

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the specified set of permissions to other users on the table.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the table. Otherwise, False.

Implements

Examples

Granting, Revoking, and Denying Permissions

See Also

Grant(ObjectPermissionSet, String, Boolean, String) Grant(ObjectPermissionSet, String, Boolean, String) Grant(ObjectPermissionSet, String, Boolean, String)

Grants the specified set of permissions to the grantee and the ability to grant the set of permissions to other users on the table under an assumed role.

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

An ObjectPermissionSet object that specifies the set of permissions.

granteeName
String String String

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

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the specified set of permissions to other users on the table.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the table. Otherwise, False.

asRole
String String String

A String value that specifies the role that the user assumes when granting the specified set of permissions to other users on the table. Use this parameter for grantees who are members of more than one role.

Implements

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

Grants access to the specified permission and the ability to grant access to other uses for the specified grantees on the table.

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

An ObjectPermissionSet object that specifies the set of permissions.

granteeNames
String[]

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

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the specified set of permissions to other users on the table.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the table. Otherwise, False.

Implements

Examples

The following code example shows how to grant a grantee account permission to select table elements of the second table column. The grantee account is a placeholder for any 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, 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, $TRUE)  

Grant(ObjectPermissionSet, String, String[]) Grant(ObjectPermissionSet, String, String[]) Grant(ObjectPermissionSet, String, String[])

Grants access to the specified permission on the specified columns for the specified grantee on the specified columns on the table.

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

An ObjectPermissionSet object that specifies the set of permissions.

granteeName
String String String

A String value that specifies the grantee to be granted 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 granted.

Implements

Examples

The following code example shows how to grant a grantee account permission to select table elements of the second table column. The grantee account is a placeholder for any 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];  
String[] col = new String[1];  
col[0] = tb.Columns[0].Name;  
col[1] = tb.Columns[1].Name  

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

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]  
$col = @($tb.Columns[0].Name, $tb.Columns[1].Name)  

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

Grant(ObjectPermissionSet, String, Boolean) Grant(ObjectPermissionSet, String, Boolean) Grant(ObjectPermissionSet, String, Boolean)

Grants access to the specified permission and the ability to grant access to other uses for the specified grantee on the table.

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

An ObjectPermissionSet object that specifies the set of permissions.

granteeName
String String String

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

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the set of permissions to other users on the table.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the table. Otherwise, False.

Implements

Examples

The following code example shows how to grant a grantee account permission to select table elements. The grantee account is a placeholder for any 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, 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, $TRUE)  
See Also

Grant(ObjectPermissionSet, String[]) Grant(ObjectPermissionSet, String[]) Grant(ObjectPermissionSet, String[])

Grants the specified set of permissions to the specified grantees on the table.

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

An ObjectPermissionSet object that specifies the set of permissions.

granteeNames
String[]

A String array that lists the grantees to be granted 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. The grantees account array is a placeholder for any defined array of 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);  

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)  

Grant(ObjectPermissionSet, String) Grant(ObjectPermissionSet, String) Grant(ObjectPermissionSet, String)

Grants the specified set of permissions to the specified grantee on the table.

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

An ObjectPermissionSet object that specifies the set of permissions.

granteeName
String String String

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

Implements

Examples

The following code example shows how to grant a grantee account permission to select table elements. 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);  

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)  

Grant(ObjectPermissionSet, String[], String[]) Grant(ObjectPermissionSet, String[], String[]) Grant(ObjectPermissionSet, String[], String[])

Grants the specified set of permissions to the grantees to the specified columns on the table.

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

An ObjectPermissionSet object that specifies the set of permissions.

granteeNames
String[]

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

columnNames
String[]

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

Implements

Examples

The following code example shows how to grant a grantee account permission to select table elements of the second table column. The grantees account array is a placeholder for any defined array of 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];  
String[] col = new String[1];  
col[0] = tb.Columns[0].Name;  
col[1] = tb.Columns[1].Name  

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

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]  
$col = @($tb.Columns[0].Name, $tb.Columns[1].Name)  

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

Applies to