0% found this document useful (0 votes)
47 views

New Features For Developers in SQL Server 2008

New features in SQL Server 2008 include enhanced IntelliSense for developers, inline variable initialization, compound operators, row constructors, and the MERGE statement to simplify merging data between tables. The document also outlines table-valued parameters, enhanced CONVERT and GROUPING SETS functions, the HIERARCHYID data type, LINQ to SQL, the ADO.NET Entity Framework, new memory dynamic management views, change data capture, lock escalation changes, sparse columns, filtered indexes, improved date/time data types, spatial data types, and the new FILESTREAM data type.

Uploaded by

vkscribdind
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

New Features For Developers in SQL Server 2008

New features in SQL Server 2008 include enhanced IntelliSense for developers, inline variable initialization, compound operators, row constructors, and the MERGE statement to simplify merging data between tables. The document also outlines table-valued parameters, enhanced CONVERT and GROUPING SETS functions, the HIERARCHYID data type, LINQ to SQL, the ADO.NET Entity Framework, new memory dynamic management views, change data capture, lock escalation changes, sparse columns, filtered indexes, improved date/time data types, spatial data types, and the new FILESTREAM data type.

Uploaded by

vkscribdind
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

New features for developers in SQL Server 2008

There are many new features that are designed for SQL Server 2008 developers.
IntelliSense
Microsoft IntelliSense available in SQL Server 2008 provides an array of options that make language
references easily accessible. When coding, it is not needed to leave the editor to perform searches on
language elements. The developer can keep his context, find the information he needs, insert language
elements directly into his code, and even have IntelliSense complete his typing for him.
Syntax enhancements
Inline variable initialization
-- Declare and initialize variable
DECLARE @count INT = 1;
Compound Operators;
-- Compound assignments
SET @count += 1;
SET @count /= 2;
SET @count *= 5;
SET @count %= 3;
SET @count -= 1;
Row Constructors (Table Value Constructors)
Transact-SQL is enhanced to allow multiple value inserts within a single INSERT statement; it
means multiple row predicates in the VALUES clause:
INSERT INTO Foo (keycol, datacol)
VALUES (1, 'Books'), (2, 'CDs'), (3, 'DVDs');

Merge Statement
One very common requirement is to merge source data to a target table. In earlier versions of SQL
Server this was accomplished by using separate INSERT and UPDATE statements. It involved checking if
key column exists to perform update and insert if not, or attempt an update first and then if not rows
were affected perform insert. Not to mention if we have to check if account is missing from the branch
office data and needs to be deleted from the central accounts table. That way we end up with multiple
(sometimes complex) statements to implement one transaction, accessing both source and target tables
multiple times.
SQL Server 2008 offers a lot more elegant way using the MERGE statement. MERGE statement allows
the developer to check for the existence of data before trying to insert the data. This check prior to
performing the INSERT statement allows the data to be updated. No longer is it necessary to create
complex joins in order to update data that exists and to insert data that does not already exist, all during
a single statement. MERGE statement also improves the performance of database as it passes through
data only once.
-- Update existing that changed and add missing
-- Use of predicates
MERGE INTO CentralOfficeAccounts AS C
-- Target
USING BranchOfficeAccounts AS B
-- Source

ON C.account_nbr = B.account_nbr
WHEN MATCHED
-- On match update
AND (C.company_name <> B.company_name -- Additional search conditions
OR C.primary_contact <> B.primary_contact
OR C.contact_phone <> B.contact_phone) THEN
UPDATE SET C.company_name = B.company_name,
C.primary_contact = B.primary_contact,
C.contact_phone = B.contact_phone
WHEN NOT MATCHED THEN
-- Add missing
INSERT (account_nbr, company_name, primary_contact, contact_phone)
VALUES
(B.account_nbr,
B.company_name,
B.primary_contact,
B.contact_phone);

Table-Valued Parameters
Table-valued parameters allow sending a table as parameter to the stored procedure:
/* Create a table type. */
CREATE TYPE LocationTableType AS TABLE
( LocationName VARCHAR(50)
, CostRate INT );
GO
/* Create a procedure to receive data for the table-valued parameter.
*/
CREATE PROCEDURE usp_InsertProductionLocation
@TVP LocationTableType READONLY
AS
SET NOCOUNT ON
INSERT INTO [AdventureWorks].[Production].[Location]
([Name]
,[CostRate]
,[Availability]
,[ModifiedDate])
SELECT *, 0, GETDATE()
FROM @TVP;
GO

Enhanced CONVERT Function


The CONVERT function now supports multiple conversion styles, giving developers more control over
the output of the function.
GROUPING SETS Operator
The new GROUPING SETS operator lets you specify multiple groupings of data (or grouping sets) in a
single query and gain more control over the aggregations the query returns.
HIERARCHYID data type
SQL Server 2008 added a new feature to help with modeling hierarchical relationships: the HIERARCHYID
data type. It provides compact storage and convenient methods to manipulate hierarchies. In a way it is
very much like optimized materialized path. In addition, the SqlHierarchyId CLR data type is available for
client applications. One important limitation: It does not automatically represent a tree, the application
has to define the relationships and enforce all rules.
LINQ

SQL Server 2008 enhances LINQ by providing a new LINQ to SQL provider that allows developers to issue
LINQ commands directly against SQL Server tables and columns. This will reduce the amount of time it
takes to create new data queries. LINQ to SQL should not be used due to the inability of production
DBAs to control code, its security and performance, or to effectively troubleshoot potential issues.

ADO.NET Entity Framework


When developing against databases, developers use higher-level objects that they map to individual
database tables and columns. These objects, also known as entities, represent the data needed for
database applications and, therefore, the developer doesn't need to understand the actual storage
structure of the data and schema of the database. The new ADO.NET Entity Framework now allows
developers to create database queries using these entities. The abstracting of the underlying database
structure allows developers to be more productive.
Memory DMVs
SQL Server 2008 added five new memory dynamic management views:
sys.dm_os_memory_brokers is useful for identifying and diagnosing possible memory pressure issues
with regular T-SQL querying. It generates memory usage recommendations for memory consumers;
sys.dm_os_memory_nodes returns information on physical NUMA memory nodes;
sys.dm_os_nodes - tied to the SQL OS architecture, this view has stats like active_worker_count and
avg_load_balance, and returns information on SQL OS nodes;
sys.dm_os_process_memory returns complete information about memory allocated to SQL Server
process space;
sys.dm_os_sys_memory returns system-wide memory statistics.
Change Data Capture (CDC)
CDC records DML activity on designated tables. CDC works by scanning the transaction log for a
designated table's 'captured columns' whose content has changed and then making those changes,
available for data synchronizing purposes, in a relational format.
Lock Escalation Changes
SQL Server 2008 includes the ability to disable lock escalation per table as well as the ability to specify
partition-level lock escalation instead of table-level lock escalation, also per table. A potential problem
with this new mechanism: applications that used to rely on the blocking nature of exclusive table locks
may now exhibit deadlocks if partition-level escalation is turned on in production, therefore thorough
testing is required prior to implementation.
Sparse columns
Sparse columns are ordinary columns that have an optimized storage for null values. Sparse columns
reduce the space requirements for NULL values at the cost of more overhead to retrieve not NULL
values. Consider using sparse columns when the space saved is at least 20-40%.
Filtered indexes
Filtered indexes allow creating an index filtered with WHERE clause:
-- Index to filter on frequently queried values
CREATE NONCLUSTERED INDEX ix_SouthEastRegion
ON Regions (region_cd)
INCLUDE(region_name, region_phone)
WHERE region_cd = 'SE';

New Date/time data types


SQL Server 2008 introduces enhancements to the existing date and time data types. The most important
changes are the addition of separate DATE and TIME data types. The DATETIME2 data type adds more
precision to the existing DATETIME data type, and DATETIMEOFFSET provides support for time zones.
Different data types will translate to improved performance for many queries since there will no longer
be a need to perform an operation on the data before it can be used in the query.
Spatial Data types
When creating newer database structures, database developers often find themselves stretching the
structure of databases in order to implement mapping applications. SQL Server 2008 helps to address
this issue with new spatial data types. The two spatial data types, GEOGRAPHY and GEOMETRY, allow
developers to store location-specific data directly into the database without having to break those data
elements down into formats that fit other standard data types.
FILESTREAM data type
The new FILESTREAM data type in SQL Server 2008 offers a new way of storing unstructured data
(images, documents, video, etc.). Up until now the two standard ways to store such data have been
either in the database as BLOB objects or as files outside of the database. FILESTREAM provides the best
of both worlds, storing unstructured data in the file system while maintaining transactional consistency
with other structured data. FILESTREAM doesnt have a 2GB storage limitation. Filestream should not be
used in our production environment since it doesnt allow database mirroring Dells enterprise DR
solution.

You might also like