me,myself,english and programming..

MSSQL – Useful query for my reference

This will me my reference of SQL statement. I will update this post if I find anything that I feel useful for me..and for you. :)

1. Check for temporary table and Drop table if exist.

IF object_id('tempdb..#myTempTable') IS NOT NULL drop table #myTempTable

2. Convert SQL string to HEX

select CONVERT(varbinary(100),'select getdate() as MyDateInHex')

3. Execute HEX value.

declare @s nvarchar(100)
set @s=cast(0x73656C65637420676574646174652829206173204D7944617465496E486578
AS VARCHAR(100))
EXEC(@S);--

4. Backup Log file

BACKUP log myDB WITH truncate_ONLY

5. Shrink log file

DBCC SHRINKFILE(myDB_Log, 30)

 

to be continue.. :)

Post a Comment