Wednesday 12 February 2014

Somthings got a hold on .... Your Log

There are times when shrinking a log on a database is needed.  This could be if your transaction backups have failed for a period of time.  And have now grown.

However there are times when they dont shrink.  Here is a nice script to see why they dont:-


DECLARE @DatabaseName VARCHAR(50);

 SET @DatabaseName = 'YourDataBASE'

 

 SELECT name, recovery_model_desc, log_reuse_wait_desc

   FROM sys.databases

   WHERE name = @DatabaseName


 

Wednesday 5 February 2014

Nice case to work out the SQL version from the product level.


CASE compatibility_level
    WHEN 65  THEN 'SQL Server 6.5'
    WHEN 70  THEN 'SQL Server 7.0'
    WHEN 80  THEN 'SQL Server 2000'
    WHEN 90  THEN 'SQL Server 2005'
    WHEN 100 THEN 'SQL Server 2008/R2'
    WHEN 110 THEN 'SQL Server 2012'
    WHEN 120 THEN 'SQL Server 2014'

Fining all before a set char

Ever needed to find only the part of a fild before a set char.  Say just the name from an emails address? :-


SUBSTRING(Email,0, CHARINDEX('.',Email)) as Name