Wednesday, 23 July 2014

Query Cache SELECT Options

SELECT SQL_CACHE id, name FROM customer;
SELECT SQL_NO_CACHE id, name FROM customer;
 
More... 

Enable the query cache in MySQL to Improve Performance

To see the cache size: 
mysql> SHOW VARIABLES LIKE 'query_cache_size';  

 
To manage the cache size:
mysql> SET GLOBAL query_cache_size = 16777216;

 
More... 


 

Tuesday, 8 July 2014

MS SQL SERVER - String Comparison

Sometimes, comparing 2 strings can be a bit tricky in MS SQL Server. For example, if there is a field of name as varchar(n), containing the value of "Microsoft", it is actually treated as "Microsoft        " (fill the rest of field with spaces). Therefore using = always return wrong answer. Using LIKE however, return those strings which contains word Microsoft which is not the desired answer. The solution is to use PATTERN MATCHING as follow:

SELECT "Microsoft        " = "Microsoft[ ]%"

[ ]% represents the spaces


SQL: Generate a range of numbers

SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n FROM       (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),      (VALU...