DECLARE @objname varchar(150), @type varchar(10), @usr varchar(20), @sql nvarchar(100);
SET @usr = "tempdwlogin';
DECLARE read_only_cur CURSOR FOR
SELECT sc.name + '.' + ob.name, ob.type
FROM sys.objects ob, sys.schemas sc
WHERE ob.schema_id = sc.schema_id
AND ob.type IN ('U', 'V', 'FN', 'IF', 'TF', 'FS', 'FT','P', 'PC');
OPEN read_only_cur;
FETCH NEXT FROM read_only_cur
INTO @objname, @type;
WHILE @@FETCH_STATUS = 0
BEGIN
IF @type IN ( 'U', 'V')
BEGIN
SET @sql = N'GRANT SELECT ON ' + @objname + N'TO ' + @usr;
EXEC sp_executesql @sql;
END
ELSE
BEGIN
SET @sql = N'GRANT EXECUTE ON ' + @objname + N'TO ' + @usr;
EXEC sp_executesql @sql;
END
FETCH NEXT FROM read_only_cur;
END;
CLOSE read_only_cur;
DEALLOCATE read_only_cur;
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.