I am trying to change the rights of the tables in my databas. To do this I would like to use a cursor that look for the tables name and grant the proper permissions to all the tables. The problem I have at this time is that all my script does at this time is to print me the information.
I have attatch a copy of my script and I would like if anyone have a suggestion to my problem.
---------------------------------------------------------
DECLARE @UID INT
SET @UID = (SELECT UID FROM SYSUSERS WHERE NAME = 'test')
DECLARE @TBName VARCHAR (255)
DECLARE @SQL varchar (255)
DECLARE @DBOWNER VARCHAR (255)
set @DBOWNER = 'test'
DECLARE TableCursor CURSOR FOR
SELECT NAME FROM SYSOBJECTS WHERE UID = @UID
DECLARE @Command VARCHAR (255)
OPEN TableCursor
FETCH NEXT FROM TABLECURSOR INTO @TBNAME
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'Changing Owner of ' + (@DBOWNER) +'.' + (@tbname)
set @SQL = 'GRANT REFERENCES, SELECT, UPDATE, INSERT, DELETE ON ' + @DBOWNER +'.' + @tbname
SELECT @sql = @sql + ' TO John, Mary, Mark'
FETCH NEXT FROM TABLECURSOR INTO @TBNAME
END
CLOSE TABLECURSOR
DEALLOCATE TABLECURSOR
----------------------------------------------------------
Thanks!
I have attatch a copy of my script and I would like if anyone have a suggestion to my problem.
---------------------------------------------------------
DECLARE @UID INT
SET @UID = (SELECT UID FROM SYSUSERS WHERE NAME = 'test')
DECLARE @TBName VARCHAR (255)
DECLARE @SQL varchar (255)
DECLARE @DBOWNER VARCHAR (255)
set @DBOWNER = 'test'
DECLARE TableCursor CURSOR FOR
SELECT NAME FROM SYSOBJECTS WHERE UID = @UID
DECLARE @Command VARCHAR (255)
OPEN TableCursor
FETCH NEXT FROM TABLECURSOR INTO @TBNAME
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'Changing Owner of ' + (@DBOWNER) +'.' + (@tbname)
set @SQL = 'GRANT REFERENCES, SELECT, UPDATE, INSERT, DELETE ON ' + @DBOWNER +'.' + @tbname
SELECT @sql = @sql + ' TO John, Mary, Mark'
FETCH NEXT FROM TABLECURSOR INTO @TBNAME
END
CLOSE TABLECURSOR
DEALLOCATE TABLECURSOR
----------------------------------------------------------
Thanks!