SQL Server 2008 supports in-line variable initialization and compound assignment, a feature which developers have been enjoying for years. This feature saves lot of code and it makes it more readable.
In line Variable Assignment
--SQL Server 2005
DECLARE @i INT
SET @i = 1
SELECT @i AS VALUE
GO
--SQL Server 2008
DECLARE @i INT= 2
SELECT @i AS VALUE
GO
Compound Assignment:
--Simple variable
DECLARE @i INT= 3
SELECT @i += 1
SELECT @i
GO
--DML Statements
--Create table
CREATETABLE Color
(ID int, ColorName varchar(10))
GO
--Populate Staging table
INSERTINTO Color VALUES (1,'Red'),(2,'Blue'),(3,'Green')
GO
SELECT ColorName FROM Color WHERE ID = 1 --returns Red
UPDATE Color SET ColorName +='-B'
WHERE ID = 1
SELECT ColorName FROM Color WHERE ID = 1 --returns Red-B
SQL Server 2008 offers two different forms of data compression – Row and Page level compression.
Row Compression
Row level compression does not apply any algorithm to compress the data. It changes the physical storage format which is efficient in storing the numeric and fixed length character data types. It minimizes the metadata (column information, length, offset etc) associated with a row. No application changes are required when tables are enabled for compression.
This shares the common data between rows in a given page.It uses the both Row Compression and Prefix Compression.
Prefix Compression
For every column the duplicate prefixes are saved in the compressed information headers (CI) which reside after the page header. A reference number is assigned to the prefix and it is replaced on where the prefixes are used.
Dictionary Compression
All the duplicate values in the entire page are stored on the CI. Prefix compression is applicable to columns where as dictionary compression is applicable to the entire page.
--Check the savings is Page level compression is enabled
Compressing a table is a CPU intensive operation. There is an optional parameter called maxdop which can be used to specify the max number of processors we want the rebuild to use.
To compress a backup specify COMPRESSION in the WITH clause of the backup command.
Here is an example:
BACKUPDATABASE YourDatabaseName
TODISK='C:\YourDatabaseName.bak'
WITHINIT,COMPRESSION
Compressing a backup typically needs less I/O, because it is smaller so it increases the speed of the backup. But compression process consumes CPU usage.
By default backup compression is off.To enable it we can use the ‘backup compression default’ configuration.
Usemaster
Go
Execsp_configure'backup compression default','1'
GO
RECONFIGURE
You don’t have to specify anything to restore the compressed backup
After lots of confusion between DMF (Dynamic Management Functions) and DMF (Declarative Management Framework), a new name is given to be clear – Microsoft SQL Server 2008 Policy Based Management.
Policy Based Management allows to define and enforce the polices for configuring and managing SQL Servers across the enterprise. Here is just a brief description of the terminology.
Target – Object to be managed
Facet – Property of the object(target)
Condition – list of criteria for target’s facets
Policy - Set of conditions on the facets of a target
Evaluation Modes
On Demand – policy is evaluated only when manually run by admin
On change: Prevent – DDL triggers prevent policy violations
On Change: log only – Event notifications are used to check the policy when changes are made
On Schedule – SQL Agent job checks the policies for periodical violations