Rebuild All Index

DECLARE @TableName sysname declare @cmd varchar(250) DECLARE cur_showfragmentation CURSOR FOR SELECT OBJECT_NAME(ind.OBJECT_ID) AS TableName --ind.name AS IndexName, indexstats.index_type_desc AS IndexType, --indexstats.avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats INNER JOIN sys.indexes ind ON ind.object_id = indexstats.object_id AND ind.index_id = indexstats.index_id WHERE indexstats.avg_fragmentation_in_percent > 30 ORDER BY indexstats.avg_fragmentation_in_percent DESC OPEN cur_showfragmentation FETCH NEXT FROM cur_showfragmentation INTO…
Read More

Query for find SQL Processes and the SQL Command

SELECT sysprc.spid, DB_NAME(sysprc.dbid) AS database_name, sysprc.login_time, sysprc.last_batch, sysprc.status, sysprc.hostname, sysprc.[program_name], sysprc.cmd, sysprc.loginame, OBJECT_NAME(sqltxt.objectid) AS [object_name], sqltxt.text FROM master.sys.sysprocesses sysprc OUTER APPLY master.sys.dm_exec_sql_text(sysprc.sql_handle) sqltxt
Read More

Get Ascii from Field

DECLARE @Lunghezza int, @Carat varchar(10), @ValueAscii varchar(10), @x int, @valore varchar(1000) set @valore = (SELECT CAMPO FROM TABELLA WHERE ...) set @Lunghezza = (select len(CAMPO)FROM TABELLA WHERE ...) set @x= 0 while @x <> @Lunghezza begin set @Carat = SUBSTRING(@valore,@x,1) set @ValueAscii = ASCII(@Carat) print 'Carattere:' + @Carat + ' Ascii: ' + @ValueAscii set…
Read More