Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Granting permissions

Author  Topic 

Sarat
Constraint Violating Yak Guru

265 Posts

Posted - 2003-08-12 : 17:11:34
Hi,
Is there a way to grant permissions for about 100 tables out of 10,000 without having to go to each table if you know the table names but they cannot be categorized by any property (name/type etc.)?
Thanks,
Sarat.

**To be intoxicated is to feel sophisticated, but not be able to say it.**

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-08-12 : 17:14:24
We have naming standards here, so I grant permissions according to the naming standards as well as according to the type. If you can come up with a select that gets the 100 tables, then just modify the select below and the role name. If you can not come up with a select, then it would be a manual process.


CREATE PROC isp_Grant_Permissions
AS

SET NOCOUNT ON

DECLARE @objName varchar(80)
DECLARE @objType char(2)
DECLARE grant_perms_on_sps CURSOR FOR
SELECT name, type
FROM SYSOBJECTS
WHERE (
(type = 'P' AND name LIKE 'usp[_]%')
OR
(type = 'FN' AND name LIKE 'udf[_]%')
OR
(type = 'TF' AND name LIKE 'udf[_]%')
OR
(type = 'U')
OR
(type = 'V' AND name LIKE 'v[_]%')
)
AND
uid = 1
AND
status > -1

OPEN grant_perms_on_sps
FETCH NEXT FROM grant_perms_on_sps
INTO @objName, @objType

WHILE @@FETCH_STATUS = 0
BEGIN
IF @objType NOT IN ('TF', 'U', 'V')
BEGIN
EXEC ('GRANT EXECUTE ON dbo.' + @objName + ' TO SomeRole')
EXEC ('GRANT EXECUTE ON dbo.' + @objName + ' TO SomeRole')
END

ELSE
BEGIN
EXEC ('GRANT SELECT ON dbo.' + @objName + ' TO SomeRole')
END

FETCH NEXT FROM grant_perms_on_sps
INTO @objName, @objType
END

CLOSE grant_perms_on_sps
DEALLOCATE grant_perms_on_sps

GO



Tara
Go to Top of Page

Sarat
Constraint Violating Yak Guru

265 Posts

Posted - 2003-08-12 : 17:55:34
Tara, I appreciate you prompt help!
Thanks,
Sarat

**To be intoxicated is to feel sophisticated, but not be able to say it.**
Go to Top of Page
   

- Advertisement -