SQL Server Scripts
- Go
back to the list of scripts.
Allow PUBLIC access to all objects
This script is also slightly dodgy... it allows the PUBLIC group to have unlimited access to all user objects in the database.
SET NOCOUNT ON
DECLARE @objectname varchar(80)
DECLARE @objecttype char(1)
DECLARE @objectname_header varchar(255)
DECLARE @UserName nvarchar(30)
SET @UserName='PUBLIC' --Specify your user here
-- Granting ALL Rights to UserName-------------------------------------------
PRINT ' '
PRINT 'Granting unlimited access to ' +@UserName
PRINT '----------------------------------------'
PRINT ' '
DECLARE tnames_cursor CURSOR FOR
SELECT Name, Type
FROM SysObjects
WHERE type in ('U', 'V', 'P')
ORDER BY Name
OPEN tnames_cursor
FETCH NEXT FROM tnames_cursor INTO @objectname, @objecttype
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
IF (@objecttype = 'P')
SET @objectname_header = 'GRANT EXECUTE ON DBO.' + @objectname + ' TO ' + @UserName
ELSE
SET @objectname_header = 'GRANT ALL ON DBO.' + @objectname + ' TO ' + @UserName
PRINT @objectname_header
EXEC (@objectname_header)
END
FETCH NEXT FROM tnames_cursor INTO @objectname, @objecttype
END
DEALLOCATE tnames_cursor
PRINT ' '
PRINT @UserName + ' has been given unlimited access to all user objects!!!'
PRINT ' '
(c)
Unknown source, but found on several websites and newsgroups.