Tuesday, May 15, 2012

Grant EXECUTE permission to all stored procedures

SELECT 'GRANT EXECUTE ON OBJECT::[' + ROUTINE_NAME + '] TO ' + @TO + ';'
FROM INFORMATION_SCHEMA.ROUTINES


Where @TO is the database role or user


Thursday, May 3, 2012

Remove Hypothetical Indexes Generated by SQL DTA

Here is the sql statement to generate the scripts to drop hypothetical indexes that were generated by SQL Database Engine Tunning Advisor (DTA).


SELECT 'DROP INDEX [' + s.[name] + '] ON [' + object_name(s.[object_id]) +'] '
FROM sys.stats AS s
INNER JOIN sys.indexes AS i
    ON s.name=i.name
WHERE i.is_hypothetical=1 and s.[name] LIKE '_dta_ind%'


SELECT 'DROP STATISTICS  [' + object_name(s.[object_id]) + '].[' + s.[name] + '] '
FROM sys.stats AS s
WHERE s.name like '_dta_stat%'