2010-07-05 6 views

Répondre

1

Oui, vous pouvez scripter les autorisations de sécurité (y compris au niveau des colonnes) à l'aide de l'instruction GRANT.

Si vous souhaitez utiliser le SSMS pour écrire les informations, attribuez les autorisations dans Securables et cliquez sur le bouton Script en haut de l'écran.

alt text http://img337.imageshack.us/img337/7236/scriptperm.png

Voici un exemple des autorisations de niveau colonne script avec T-SQL:

USE master 
GO 

/* Create test database */ 
CREATE DATABASE StackO 
GO 

USE StackO 
GO 

/* Create a table */ 
CREATE TABLE TestSelect (
    RowID INT NOT NULL, 
    RowValue VARCHAR(1) NOT NULL, 
    RowProperty VARCHAR(1) NOT NULL 
) 

/* Populate with data */ 
INSERT TestSelect VALUES (1,'A','X'),(2,'A','Y') 

/* Create a user */ 
CREATE USER SO_User WITHOUT LOGIN 

/* Grant the user SELECT permissions on RowID and RowValue */ 
GRANT SELECT ON TestSelect (RowID) TO SO_User 
GO 

GRANT SELECT ON TestSelect (RowValue) TO SO_User 
GO 

/* Deny user SELECT permissions on RowProperty */ 
DENY SELECT ON TestSelect (RowProperty) TO SO_User 
GO 

/* Test the permissions */ 
EXECUTE AS USER = 'SO_User' 
GO 

/* Confirm select on RowID and RowValue */ 
SELECT RowID, RowValue FROM TestSelect 
GO 

/* Confirm error message on RowProperty */ 
SELECT RowProperty FROM TestSelect 
GO 

/* Go back to regular user */ 
REVERT 
GO 

/* Cleanup */ 
USE master 
GO 

DROP DATABASE StackO 
GO 

Et les résultats:

RowID  RowValue 
----------- -------- 
1   A 
2   A 

Msg 230, Level 14, State 1, Line 3 
The SELECT permission was denied on the column 'RowProperty' 
of the object 'TestSelect", database 'SO', schema 'dbo'. 
+0

Merci - Je ne l'ai pas remarqué le bouton Script . – chris