quinta-feira, 6 de novembro de 2014

SQL Backup types: Full and Differential, not Incremental

When using SQL Server backup remember it does not use the incremental mode, so, when recovering something like following picture (Full + many differentials), select the FULL plus the ONE differential you want, not more than one. It`s not going to cause an error, but its effect is the same of selecting the older one from your list. Generally, for the most up to date backup just select the full plus the most recent differential.








 If you select just the differential the message below (pt-br) will be presented










The incremental mode is not supported in 2008 R2 (at least), which is used to save every changes from the last incremental backup. Differential is always referencing the full backup, while incremental references the last incremental.
More about backup types is very easy to find in Internet. Good searchs.

sexta-feira, 19 de setembro de 2014

selecting varchar: Is null or is empty?

When using TSql to check if a varchar is null or is empty we can remember:
- A nullable varchar is
1. not null when store a string or an empty string;
2. null only when not initialized, even with an empty string.

update fied1 = 'A string', field2 = '', field3 = null

We have:
Select * from table where field1 is null (0 row)
Select * from table where field2 is null (0 row)
Select * from table where field3 is null (1 row)
Select * from table where field1 = '' (0 row)
Select * from table where field2 = '' (1 row*)
Select * from table where field3 = '' (0 row)
Select * from table where (field2 = '' and field2 is null) (0 row) 
Select * from table where (field2 = '' and field2 is NOT null) (1 row**)

Well, the objective is to pay attention to our predicates of where clause, because sometimes some results are not expected when selecting empty strings

* this can be true for any amount of spaces
** pay special attention to this predicates working together

/*------------------------

Select * from select_varchar where field1 is null 
Select * from select_varchar where field2 is null 
Select * from select_varchar where field3 is null 
Select * from select_varchar where field1 = '' 
Select * from select_varchar where field2 = '' 
Select * from select_varchar where field3 = '' 
Select * from select_varchar where (field2 = '' and field2 is null) 
Select * from select_varchar where (field2 = '' and field2 is NOT null) 

------------------------*/
field1     field2     field3
---------- ---------- ----------

(0 row(s) affected)

field1     field2     field3
---------- ---------- ----------

(0 row(s) affected)

field1     field2     field3
---------- ---------- ----------
A String              NULL

(1 row(s) affected)

field1     field2     field3
---------- ---------- ----------

(0 row(s) affected)

field1     field2     field3
---------- ---------- ----------
A String              NULL

(1 row(s) affected)

field1     field2     field3
---------- ---------- ----------

(0 row(s) affected)

field1     field2     field3
---------- ---------- ----------

(0 row(s) affected)

field1     field2     field3
---------- ---------- ----------
A String              NULL

(1 row(s) affected)