Friday, October 30, 2009

Change Schema of All tables and Procedure

Hi Friends

Few days ago I have restore my SQL Server 2005 database to SQL Server 2008 Database using xxx user, now when i have restore database by defaut SQL Server 2008 backup utility add schema of username to tables and store procedure, so to remove that schema from tables and procedure name please use below query

-- To Change Table Schema

SELECT 'ALTER SCHEMA dbo TRANSFER ' + s.Name + '.' + p.Name FROM sys.tables p INNER JOIN
sys.Schemas s on p.schema_id = s.schema_id WHERE s.Name = 'checkmate'

-- To Change Procedure Schema
SELECT 'ALTER SCHEMA dbo TRANSFER ' + s.Name + '.' + p.Name FROM sys.procedures p INNER JOIN
sys.Schemas s on p.schema_id = s.schema_id WHERE s.Name = 'checkmate'

Tuesday, March 31, 2009

JSON and XML data serialization using T-SQL

I suppose it shouldn't be an issue. The way to represent, store, and transfer object data is XML. Everyone seems to be agreed on that point.

At first glance, one might be surprised to think that a subset of a document markup language has become the standard way of moving complex data structures between objects and databases. However, XML is versatile. It has been used to create, by sheer effort and determination, a document format, a message packet format, a secure RPC channel (SOAP or XML-RPC.), a data format, and an object database. XML would seem to be the obvious choice for a data-serialization language, providing the means by which data is transported between modules, services and applications. There are so many tools around for XML that it would seem eccentric to question its supremacy. It is now an intrinsic part of SQL Server. Why should anyone ever bother with anything else?

Why avoid existing standards?

The problem is that XML doesn't do 'simple'. Often, all that the application designer actually wants to have is a programming-language-neutral, platform-agnostic, and transport-independent interchange mechanism for structured data (simple data types, associative arrays and lists). This is frustrating since XML should be ideal. Your data is tagged. You have given it semantic meaning. You can extend your xml data file with completely different data without the problem of compatibility. You can render and style your data. The trouble is that all this complexity and versatility comes at a cost. XML isn't fast. When AJAX programmers hit the performance problem of digesting XML, they turned to JSON and found, at that time, that it was around a hundred times quicker to process a 10K JSON data file in the browser than an XML file.

XML itself isn't intrinsically a cross-platform serialization format. It can be turned into one, but you are forced to invent your own format using XML first. WDDX (Web Distributed Data eXchange) came close to creating an XML serialisation format, but it has been abandoned (its envelope/ header/ body structure was later adopted by SOAP, along with its transport and interaction neutrality). XML-RPC and SOAP are sometimes suggested as being appropriate but they are full-blown RPC mechanisms with transports. To use them merely for serialisation of structured data is overkill.

Why should this matter? Normally it doesn't. The .NET tools for handling XML are highly developed, to the point where using XML on adequate hardware and network is as quick as anything else. There isn't a bottleneck under these circumstances. The problem lies in the new browser-based applications that are pulling data dynamically across the web. It is going to get worse when the Semantic Web kicks in. Developers seldom use low-powered machines or low-bandwidth connections, so are less aware of the importance of performance on the users' machine. They tend to just shrug and suggest that you buy a better CPU, or more memory. You can't do that if you don't 'own' the desktop device. Even if the difference in time to assimilate XML and JSON data is down to a factor of 10, it can make all the difference to the perceived performance of a browser-based application, particularly where you can't insist on minimum hardware requirements. You can solve design issues on the server end of an application by souping up the hardware, but you can't do that at the client end.

JSON, an expedient solution

Many AJAX programmers, myself included, hit a big problem with the performance of data-intensive applications, and the problems were solved by using JSON.

JSON (short for JavaScript Object Notation) is still very much in use. Google Data APIs and Yahoo Web Services can both serve data in JSON format. SPARQL will produce its results in JSON format.

It has been described as the 'Fat-free alternative to XML'. It provides a light-weight standard for representing the core data types by adopting a subset of the ECMAScript (JavaScript) standard. Unlike XML, it doesn't specify the character set, but assumes a Unicode representation of the data (defaulting to 16-bit). It represents just the data, not the transport. It is very easy to read and understand. It is actually a subset of the 'object literal notation' of Javascript, with some extra limitations to make it easier to implement a parser. It is an elegant shorthand syntax for encoding generic data structures in JavaScript, and so can be executed.

var myCustomer = eval("(" + JSON_CustomerObjectData + ")");

The client must, obviously, either have full trust in the server, pre-check with a Regex for well-formedness or use a validator, because the JSON is actually executable code that will be evaluated by the JavaScript engine.

Here is a simple SQL Call that produces an XML result.

use Northwind;

WITH XMLNAMESPACES ('uri1' as location,

                    'uri2' as contact,

                    DEFAULT 'uri2'

)

SELECT top 1 CustomerID as "@ID",

       CompanyName,

       Address as "location:Address/Street",

       City as "location:Address/City",

       Region as "location:Address/Region",

       PostalCode as "location:Address/Zip",

       Country as "location:Address/Country",

       ContactName as "contact:Contact/Name",

       ContactTitle as "contact:Contact/Title",

       Phone as "contact:Contact/Phone",

       Fax as "contact:Contact/Fax"

FROM Customers

FOR XML PATH('Customer'), ROOT('Customers'), ELEMENTS XSINIL


Produces XML like this


<Customers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="uri2"

xmlns:contact="uri2" xmlns:location="uri1">

  <Customer ID="ALFKI">

    <CompanyName>Alfreds FutterkisteCompanyName>

    <location:Address>

      <Street>Obere Str. 57Street>

      <City>BerlinCity>

      <Region xsi:nil="true" />

      <Zip>12209Zip>

      <Country>GermanyCountry>

    location:Address>

    <contact:Contact>

      <Name>Maria AndersName>

      <Title>Sales RepresentativeTitle>

      <Phone>030-0074321Phone>

      <Fax>030-0076545Fax>

    contact:Contact>

  Customer>

Customers>

… whereas the JSON contains …

{

  Customers: {

    Customer: {

      ID: "ALFKI",

      CompanyName: "Alfreds Futterkiste",

      Address: {

        Street: "Obere Str. 57",

        City: "Berlin",

        Region: null,

        Zip: "12209",

        Country: "Germany"

      },

      Contact: {

        Name: "Maria Anders",

        Title: "Sales Representative",

        Phone: "030-0074321",

        Fax: "030-0076545"

      }

    }

  }

}

But was achieved with the delightfully simple SQL

select top 1 '

{

  Customers: {

    Customer: {

      CustomerID: "'+customerID+'",

      CompanyName: "'+CompanyName+'",

      Address: {

        Street: "'+Address+'",

        City: "'+City+'",

        Region: '+coalesce('"'+Region+'"','null')+',

        Zip: "'+PostalCode+'",

        Country: "'+Country+'"

      },

      Contact: {

        Name: "'+ContactName+'",

        Title: "'+ContactTitle+'",

        Phone: "'+Phone+'",

        Fax: "'+Fax+'"

      }

    }

  }

}'

FROM Customers

Of course, you will need to have a user-defined function to 'escape'  the strings, but that is not too taxing.  In practice, producing JSON code from a SQL result is even more simple than this. simple. All you need to do is to output in XML, and let the application layer convert the results with something like Json.NET. This tool will also allow you to convert LINQ to JSON, quickly convert .NET objects to JSON and back again and produce well formatted, indented JSON for debugging or display.  Getting data back uses the same easy route.  JSON can be converted to XML, and SQL Server can then digest the XML.

You’ll notice rather more difference between this JSON

{

  menu: {id: "file", value: "File",

    popup: {

      menuitem: [

        { value: "New", onclick: "CreateNewDoc()" },

        { value: "Open", onclick: "OpenDoc()" },

        { value: "Close", onclick: "CloseDoc()" }

      ]

    }

  }

}

And this XML:

<menu id="file" value="File">

  <popup>

    <menuitem value="New" onclick="CreateNewDoc()" />

    <menuitem value="Open" onclick="OpenDoc()" />

    <menuitem value="Close" onclick="CloseDoc()" />

  popup>

menu>

.. in that we have an array, delimited by [] (an example adapted from the example on the JSON site)

The JSON is very clear. It doesn't take a lot of figuring out. Show JSON data to anyone and it doesn't take long for them to figure it out. What is lacking when you compare it with the XML is the namespace information, of course. With JSON, both ends of the communication need to know about the data being transmitted.

In JavaScript, an object is just an associative array. JSON takes that syntax and makes it generally applicable. JSON syntax is pretty intuitive, and close to object notation in several languages. There are encryptors and decryptors in every current computer language, and validators on every platform. JSON wasn't invented as such; the object literal notation was merely discovered by developers and used to fill a requirement that wasn't being met elsewhere. The fact that it bypassed the restrictive same domain policy of the XmlHttpRequest object was a real bonus for the spread of JSON.

JSON has two drawbacks

  • both sides of the transfer have to understand the schema.
  • It cannot represent relational data.

Because of these drawbacks, JSON has spawned a superset called YAML (YAML Aint a Markup Language). YAML (not to be confused with YAML - "Yet Another Multicolumn Layout") allows you to represent both relational and object data, and is able to transfer the metadata. Its greatest importance to us is that it can represent relational data. YAML is primarily a data serialization language, like JSON. YAML is easier to read and more able to represent complex data models. The big problem with YAML is that it has not yet got the same maturity as JSON. It is dauntingly complex. It is a great piece of design but it hasn't got the weight of users behind it in the same way as JSON. However, if you need to transfer relational data between database and your application's objects, it is the only way to go. As a data-interchange format between different Relational databases, it would take some beating.

Tuesday, May 29, 2007

SQL Sever 2005

Hey we all are know about SQL Server 2000, but SQL Server 2005 have some more extra features so, every body want to know what is special in SQL Sever 2005

What is new in SQL Server 2005

  1. Enterprise Data Management
  2. Developer Productivity
  3. Business Intelligence
we are go through all above point in detail one by one so lets start with "Enterprise Data Management"

Enterprise Data Management
In today's connected world, data and the systems that manage that data must always be secure yet available to your users. With SQL Server 2005, users and information technology (IT) professionals across your organization will benefit from reduced application downtime, increased scalability and performance, and tight yet flexible security controls. SQL Server 2005 also includes many new and improved capabilities to help make your IT staff more productive. SQL Server 2005 includes key enhancements to enterprise data management in the following areas:
  • Manageability
  • Availability
  • Scalability
  • Security

Manageability

SQL Server 2005 makes it simpler and easier to deploy, manage, and optimize enterprise data and analytical applications. As an enterprise data management platform, it provides a single management console that enables data administrators anywhere in your organization to monitor, manage, and tune all of the databases and associated services across your enterprise. It provides an extensible management infrastructure that can be easily programmed using SQL Management Objects, enabling users to customize and extend their management environment and independent software vendors (ISVs) to build additional tools and functionality to further extend the capabilities that come out of the box.

SQL Server Management Studio

SQL Server 2005 simplifies management by providing one integrated management console to monitor and manage the SQL Server relational database, as well as Integration Services, Analysis Services, Reporting Services, Notification Services, and SQL Server Mobile Edition across large numbers of distributed servers and databases. Database administrators can perform several tasks at the same time, such as authoring and executing a query, viewing server objects, managing an object, monitoring system activity, and viewing online help. SQL Server Management Studio hosts a development environment for authoring, editing, and managing scripts and stored procedures using Transact-SQL, Multidimensional Expressions, XML for Analysis, and SQL Server Mobile Edition. Management Studio is readily integrated with source control. Management Studio also hosts tools for scheduling SQL Server Agent jobs and managing maintenance plans to automate daily maintenance and operation tasks. The integration of management and authoring in a single tool coupled with the ability to manage all types of servers provides enhanced productivity for database administrators.

SQL Server 2005 exposes more than 70 new measures of internal database performance and resource usage, ranging from memory, locking, and scheduling to transactions and network and disk I/O. These Dynamic Management Views (DMVs) provide greater transparency and visibility into the database and a powerful infrastructure for proactive monitoring of database health and performance.

SQL Management Objects

SQL Management Objects (SMO) is a new set of programming objects that exposes all of the management functionality of the SQL Server database. In fact, Management Studio was built with SQL Management Objects. SMO is implemented as a Microsoft .NET Framework assembly. You can use SMO to automate common SQL Server administrative tasks, such as programmatically retrieving configuration settings, creating new databases, applying Transact-SQL scripts, creating SQL Server Agent jobs, and scheduling backups. The SMO object model is a more secure, reliable, and scalable replacement for Distributed Management Objects (DMO), which was included with earlier versions of SQL Server.

Availability

Investments in high-availability technologies, additional backup and restore capabilities, and replication enhancements will enable enterprises to build and deploy highly available applications. Innovative high-availability features such as database mirroring, failover clustering, database snapshots, and enhanced online operations will minimize downtime and help to ensure that critical enterprise systems remain accessible. This section reviews these enhancements in greater detail.


Database Mirroring

Database mirroring allows continuous streaming of the transaction log from a source server to a single destination server. In the event of a failure of the primary system, applications can immediately reconnect to the database on the secondary server. The secondary instance detects failure of the primary server within seconds and accepts database connections immediately. Database mirroring works on standard server hardware and requires no special storage or controllers. Figure 1 shows the basic configuration of database mirroring.


Figure 1: Basic Configuration of Database Mirroring

Failover Clustering

Failover clustering is a high-availability solution that exploits Microsoft Windows Clustering Services to create fault-tolerant virtual servers that provide fast failover in the event of a database server failure. In SQL Server 2005, support for failover clustering has been extended to SQL Server Analysis Services, Notification Services, and SQL Server replication. The maximum number of cluster nodes has been increased to eight. SQL Server failover clustering is now a complete fault-tolerant server solution.


Availability FeatureDatabase MirroringFailover Clustering

Automatic Failover

Yes

Yes

Transparent Client Redirection

Yes, auto-redirect

Yes, reconnect to same IP

Impact on Overall Throughput

No impact to minimal

No impact

Zero Work Loss

Yes

Yes

Requires Certified Hardware

No

Yes

Provides Redundant Data

Yes

No

Database Snapshots

SQL Server 2005 introduces the ability for database administrators to create instant, read-only views of a database. This database snapshot provides a stable view without the time or storage overhead of creating a complete copy of the database. As the primary database diverges from the snapshot, the snapshot adds its own copy of pages as they are modified. As a result, the snapshot may be used to quickly recover from an accidental change to a database by simply reapplying the original pages from the snapshot to the primary database.

Fast Recovery

SQL Server 2005 improves the availability of SQL Server databases with a new and faster recovery option. Users can reconnect to a recovering database after the transaction log has been rolled forward. Earlier versions of SQL Server required users to wait until incomplete transactions had rolled back, even if the users did not need to access the affected parts of the database.

Dedicated Administrator Connection

SQL Server 2005 introduces a dedicated administrator connection to access a running server even if the server is not responding or is otherwise unavailable. This allows you to execute diagnostic functions or Transact-SQL statements so you can troubleshoot problems on a server. The connection is activated by members of the sysadmin fixed server role and is only available through the SQLCMD command prompt tool either locally or from a remote computer.

Online Operations (Index Operations and Restore)

The ability to create, rebuild, or drop an index online is an enhanced feature of SQL Server 2005 that augments the indexing capabilities of earlier versions of SQL Server. The online index option allows concurrent modifications (updates, deletes, and inserts) to the underlying table or clustered index data and any associated indexes during index data definition language (DDL) execution. With support for online index operations, you can add indexes without interfering with access to tables or other existing indexes. Additionally, the server workload allows index operations to take advantage of parallel processing. SQL Server 2005 also introduces the ability to perform a restore operation while an instance of SQL Server is running. Online restoration capabilities improve the availability of SQL Server because only the data that is being restored is unavailable. The rest of the database remains online and available. Earlier versions of SQL Server require that you bring a database offline before you restore the database.

Replication

Replication is designed to increase data availability by distributing the data across multiple database servers. Availability is increased by allowing applications to scale out the SQL Server read workload across databases. SQL Server 2005 offers enhanced replication using a new peer-to-peer model that provides a new topology in which databases can be synchronized transactionally with any identical peer database.

Scalability

Scalability advancements such as table partitioning, snapshot isolation, and 64-bit support will enable you to build and deploy your most demanding applications using SQL Server 2005. The partitioning of large tables and indexes significantly enhances query performance against very large databases.

Table and Index Partitioning

Table and index partitioning eases the management of large databases by facilitating the management of the database in smaller, more manageable chunks. While the concept of partitioning data across tables, databases, and servers is not new to the world of databases, SQL Server 2005 provides a new capability for the partitioning of tables across filegroups in a database. Horizontal partitioning allows for the division of a table into smaller groupings based on a partitioning scheme. Table partitioning is designed for very large databases, from hundreds of gigabytes to terabytes and beyond.

Snapshot Isolation

After data is copied, transformed, and archived to an analysis-oriented database, it must be maintained and/or rebuilt periodically. Users certainly benefit from looking at a transactionally consistent version of the database; however, the version of the data that they are viewing is no longer current. It can take many hours to build and index the data and that might not be what the user really needs. This is where snapshot isolation is helpful. The snapshot isolation level allows users to access the last row that was committed by using a transactionally consistent view of the database. This new isolation level provides the following benefits:

Increased data availability for read-only applications.

Nonblocking read operations allowed in an online transaction processing (OLTP) environment.

Automatic mandatory conflict detection for write transactions.

Simplified migration of applications from Oracle to SQL Server.

Replication Monitor

Replication Monitor is a tool that sets a new standard for ease of use in managing complex data replication operations with its intuitive user interface and wealth of data metrics.

Support for 64-bit System Itanium 2 and x64

Optimized for the Intel Itanium processor, SQL Server (64-bit) takes advantage of advanced memory addressing capabilities for essential resources such as buffer pools, caches, and sort heaps, reducing the need to perform multiple I/O operations to bring data in and out of memory from disk. Greater processing capacity without the penalties of I/O latency opens the door to new levels of application scalability. Windows Server 2003 x64 provides high performance for both 32-bit and 64-bit applications on the same system. The underlying architecture is based on 64-bit extensions to the industry-standard x86 instruction set, allowing today's 32-bit applications to run natively on x64 processors. At the same time, new 64-bit applications are executed in 64-bit mode, which processes more data per clock cycle, allows greater access to memory, and speeds numeric calculations. The result is a platform that takes advantage of the existing wealth of 32-bit applications while also providing a smooth migration path to 64-bit computing.

Security

SQL Server 2005 makes significant enhancements to the security model of the database platform, with the intention of providing more precise and flexible control to enable tighter security of the data. A considerable investment has been made in a number of features to provide a high level of security for your enterprise data including the following:

Enforcing policies for SQL Server login passwords in the authentication space.

Providing for more granularity in terms of specifying permissions at various scopes in the authorization space.

Allowing for the separation of owners and schemas in the security management space.

Authorization

A new security model in SQL Server 2005 allows administrators to manage permissions at a granular level and at a designated scope, making management of permissions easier as well as ensuring that the principle of least privileges is upheld. SQL Server 2005 lets you specify a context under which statements in a module execute. This feature also acts as an excellent mechanism for granular permission management.

Authentication

SQL Server 2005 clustering supports Kerberos authentication against a SQL Server 2005 virtual server. Administrators can specify Microsoft Windows-style policies on standard logins so that a consistent policy is applied across all accounts in the domain.

Native Encryption

SQL Server 2005 supports encryption capabilities within the database itself, fully integrated with a key management infrastructure. By default, client/server communications are encrypted. To centralize security assurance, server policy can be defined to reject unencrypted communications.

SQL Server and Trustworthy Computing

The Microsoft Trustworthy Computing initiative outlines a framework that defines the steps necessary to support more secure computing as well as measures that help you deploy and maintain a more secure environment. These steps help to protect the confidentiality, integrity, and availability of data and systems at every phase of the software life cycle—from design, to delivery, to maintenance. To uphold the four tenets of the Trustworthy Computing initiative, Microsoft and the SQL Server team have addressed the following issues:

Secure by design. The SQL Server development team conducted multiple security audits and spent more than two months studying SQL Server components and the interaction between them. For each potential security threat, the team did a threat analysis to evaluate the issue and completed additional design and testing work to neutralize potential security issues. Because of these design efforts, SQL Server 2005 includes many new server security features.

Secure by default. Upon installation, SQL Server 2005 chooses the right set of configuration values for all setup options, ensuring that when a new system is installed, it will be in a secure state by default.

Secure in deployment. Microsoft has created content to help organizations deploy SQL Server using the proper security credentials and to fully understand the steps and permissions required. SQL Server deployment tools provide the information necessary to understand the decisions you need to make during deployment. Security updates are easy to find and install—and if you choose the option, the updates install automatically. Tools are also available to help you assess and manage security risks across organizations.

Developer Productivity

SQL Server 2005 includes many new technologies that bring significant increases in developer productivity. From .NET Framework support to tight integration with Visual Studio, these features provide developers with the ability to more easily create secure, robust database applications at a lower cost. SQL Server 2005 enables developers to take advantage of existing skills across a variety of development languages while providing an end-to-end development environment for the database. Native XML capabilities also allow developers to build new classes of connected applications across any platform or device.

Enhancements for developer productivity include the following:

Expanded language support

Improved development tools

Extensibility

Improved data access

XML and Web services

Application framework

Expanded Language Support

Because the common language runtime (CLR) is hosted in the database engine, developers can choose from a variety of familiar languages to develop database applications, including Transact-SQL, Microsoft Visual Basic .NET, and Microsoft Visual C# .NET. Additionally, CLR hosting provides developers with increased flexibility with user-defined types and functions. The CLR also provides opportunities to use non-Microsoft code for rapid database application development.

CLR/.NET Framework Integration

With the release of SQL Server 2005, database programmers can now take full advantage of modern programming languages to implement functionality within the server as well as many assemblies of the Microsoft .NET Framework class library. Using CLR integration, you can code your stored procedures, functions, and triggers in the .NET Framework language of your choice. Microsoft Visual Basic .NET and the C# programming language both offer object-oriented constructs, structured exception handling, arrays, namespaces, and classes. Additionally, the .NET Framework provides thousands of classes and methods that have extensive built-in capabilities that you can easily use on the server side. Many tasks that were awkward or difficult to perform in Transact-SQL can be better accomplished by using managed code; additionally, two new types of database objects—aggregates and user-defined types—are available. You can now better use the knowledge and skills that you have already acquired to write in-process code. In short, SQL Server 2005 enables you to extend the database server to more easily perform appropriate computation and operations on the back end.

This integration between SQL Server and the CLR provides several major benefits:

Enhanced programming model. Programming languages that are compatible with the .NET Framework are in many respects richer than Transact-SQL, offering constructs and capabilities that were previously not available to SQL Server developers.

Enhanced safety and security. Managed code runs in a CLR environment, hosted by the database engine. This allows .NET Framework database objects to be safer and more secure than the extended stored procedures available in earlier versions of SQL Server.

User-defined types and aggregates. Two new database objects that expand the storage and querying capabilities of SQL Server are enabled by hosting the CLR.

Common development environment. Database development is integrated into the Microsoft Visual Studio 2005 development environment. You can use the same tools for developing and debugging database objects and scripts that you use to write middle-tier or client-tier .NET Framework components and services.

Performance and scalability. Because managed code compiles to native code prior to execution, you can achieve significant performance increases in some scenarios.

By using languages such as Visual Basic .NET and C#, you can capitalize on CLR integration to write code that has more complex logic and is more suited for computation tasks. Additionally, Visual Basic .NET and C# offer object-oriented capabilities such as encapsulation, inheritance, and polymorphism. You can easily organize related code into classes and namespaces, which means that you can more easily organize and maintain your code investments when you are working with large amounts of code. The ability to logically and physically organize code into assemblies and namespaces is a huge benefit that allows you to better find and relate different pieces of code in a large database implementation.

Managed code is more efficient than Transact-SQL at processing numbers and managing complicated execution logic, and provides extensive support for string handling, regular expressions, and so on. Also, with the functionality that is available in the .NET Framework class library, you have full access to thousands of prebuilt classes and routines that you can access easily from any stored procedure, trigger, or user-defined function. Everything from improved string-handling functions, math functions, date operations, access to system resources, advanced encryption algorithms, file access, image processing, and XML data manipulation is easily accessible from managed stored procedures, functions, triggers, and aggregates.

One of the major benefits of managed code is type safety. Before managed code is executed, the CLR performs several checks through a process known as verification to ensure that the code is safe to run. For example, the code is checked to ensure that memory is not read that has not been written to.

Transact-SQL Enhancements

Transact-SQL has long been the basis for all SQL Server programmability. SQL Server 2005 provides many new language capabilities for developing scalable database applications. These enhancements include error handling, new recursive query capabilities, and support for new SQL Server Database Engine capabilities. Transact-SQL enhancements in SQL Server 2005 increase your expressive powers in query writing, allowing you to improve the performance of your code and extend your error management capabilities. The continuous effort that is being put into enhancing Transact-SQL shows a firm belief in its significant role in SQL Server.

Improved Development Tools

Developers will be able to use one development tool for Transact-SQL, XML, Multidimensional Expressions (MDX), and XML for Analysis (XMLA). Integration with the Visual Studio development environment will provide more efficient development and debugging of line-of-business and business intelligence (BI) applications.

Business Intelligence Development Studio

The Business Intelligence Development Studio is a common development environment for building BI solutions based on Visual Studio including a database engine, analysis services, and reporting services. Use the Business Intelligence Development Studio graphical user interface (GUI) to design SQL Server Integration Services (SSIS) packages for data-management applications. SSIS packages are designed, developed, and debugged in Business Intelligence Development Studio by dragging tasks from the toolbox, setting their properties, and connecting tasks with precedence constraints. Figure 2 shows the interface in Visual Studio for Business Intelligence Development Studio.

Figure 2: Business Intelligence Development Studio Interface in Visual Studio

Figure 2: Business Intelligence Development Studio Interface in Visual Studio

Visual Studio Integration

SQL Server 2005 and Visual Studio 2005 together provide deeper levels of integration between the database and the application development environment than ever before. Developers now have the ability to create CLR stored procedures, functions, user-defined types, and user-defined aggregates directly from within the Visual Studio development environment. They can deploy these new database objects directly from Visual Studio without having to switch tools. Visual Studio 2005 directly supports all of the new SQL Server data types, such as native XML. You can also add your CLR database objects to the same source control system that you use for all you Visual Studio projects, thus providing an even greater level of integration and security to your development processes.

Cross-Tier and Cross-Language Debugging

SQL Server 2005 and Visual Studio 2005 together provide even deeper integration in the area of application debugging. The combination lets you seamlessly debug both CLR and Transact-SQL code using the same Visual Studio debugging interface, and allows you to debug from CLR to Transact-SQL and back again, regardless of the location of the code, whether it is on the developer computer or stored in the SQL Server database.

Extensibility

User-Defined Types and Aggregates

User-defined types in SQL Server 2005 are not an object relational extensibility mechanism. They are a way to extend the scalar type system of the database. The scalar type system includes the columnar types that ship with SQL Server (types such as int, nvarchar, uniqueidentifier, and so on). With user-defined types, you can define your own type that can be used for column definitions, for example. Create a user-defined type if your type really is an atomic value that is appropriate to be modeled as a column.

Use user-defined types if you need to define your own scalar type. Example scenarios for such types include custom date/time data types in various calendars, and currency data types. With user-defined types, you can create a single object that exposes all the behaviors that are available on the type, and encapsulate, or hide, the underlying data that is stored by the type. Everyone that needs to access the data has to use the user-defined type programmatic interface. Taking advantage of existing functionality in the .NET Framework (such as the internationalization or calendar functionality) is another strong reason to consider implementing your type as a user-defined type.

In a number of scenarios, you may need to perform aggregations over data. This includes performing statistical calculations, such as avg, stddev, and so on. If the desired aggregation function is not directly supported as a built-in aggregate function, you have three ways to perform a custom aggregation in SQL Server 2005:

Write the aggregation as a user-defined aggregate.

Write the aggregate using a CLR stored procedure.

Use a server-side cursor.

SQL Management Objects

SQL Management Objects (SMO) is the management object model for SQL Server 2005. SMO represents significant design and architectural improvements for the SQL Server management object model. It is a simple-to-use but rich object model that is based on .NET Framework managed code. SMO is the primary tool for developing database management applications using .NET Framework. SMO is used by every dialog box in SQL Server Management Studio, and every administrative action that you can perform in SQL Server Management Studio you can also accomplish by using SMO.

The new SMO object model and the Microsoft Windows Management Instrumentation (WMI) application programming interfaces (APIs) replace SQL-DMO. Where possible, SMO incorporates similar objects as SQL-DMO for ease of use. You can still use SQL Server 2005 with SQL-DMO, but SQL-DMO will not be updated to manage features that are specific to SQL Server 2005.

Analysis Management Objects

Analysis Management Objects (AMO) allows client applications to access the range of administrative commands and capabilities available to Analysis Services using an object library that can provide object-level validation capabilities, instead of having to manually generate DDL scripts for Analysis Services commands and the often-lengthy contents of the Analysis Services Scripting Language (ASSL) ObjectDefinition element. Applications using AMO can either connect and work directly with objects on an Analysis Services instance, or create such objects without an existing connection and persist the metadata for later deployment. AMO also "wraps" ASSL commands and elements.

Improved Data Access and Web Services

In SQL Server 2005, you can develop XML Web services in the database tier, making SQL Server an HTTP listener. This provides a new type of data access capability for applications that are centralized around Web services. In SQL Server 2005, you can use HTTP to access SQL Server directly, without using a middle-tier listener such as Microsoft Internet Information Services (IIS). SQL Server exposes a Web service interface to allow the execution of SQL statements and invocation of functions and procedures. Query results are returned in XML format and can take advantage of the Visual Studio Web services infrastructure.

ADO.NET 2.0/ADOMD.NET

Much is new in the next version of ADO.NET. From new support for query change notifications to Multiple Active Result Sets (MARS), ADO.NET evolves dataset access and manipulation to achieve greater scalability and flexibility.

Query Notification

SQL Server 2005 introduces notification support for SQL Server queries. You can use this support to send a command to SQL Server and to request that a notification be generated if executing the same command again produces different results from those obtained initially. You accomplish this by using a dependency object that detects when the underlying data is changed. Commands that are sent to the server through any of the client APIs such as ADO.NET, OLE DB, Open Database Connectivity (ODBC), Microsoft ActiveX Data Objects (ADO), or Simple Object Access Protocol (SOAP) may include a tag that requires a notification. For each statement that is executed as part of the request, the server creates a notification subscription that fires once for each statement that is included in the request. Notifications are delivered through a SQL Service Broker queue that applications can poll, and use activation services or blocking statements that return whenever the notifications are available. Query notifications are useful for enabling the caching of results in applications such as database-driven Web sites. Figure 3 shows the query notification process.

Figure 3: Query Notification

Figure 3: Query Notification

MARS

Multiple Active Result Sets (MARS) provides the means to have more than one pending request per connection, in particular to have more than one default result set open per connection. Default result sets are forward-only, read-only result sets. For default result sets, the client drivers transparently retrieve the data in large chunks (Tabular Data Stream buffer-sized chunks) so that application requests are satisfied without a round trip to the server (as in the case of server cursors). The application can use a simple row-at-a-time programming model without compromising performance. The MARS feature removes the current restriction in which an open default result set blocks the driver from sending requests to the server until the entire result set is consumed.

Transparent Failover for Data Mirroring

SQL Server 2005 supports a "hot spare" capability through database mirroring. If a SQL Server instance fails, work can be shifted to the backup server automatically. This requires an instance to witness the failover known as (not surprisingly) the witness instance. Hot spare scenarios require that existing client connections must "know" to fail over (establish a connection with the new server instance), as well. It is suboptimal for client connections to produce an error on the next attempted access and to have to be manually "failed over" by client programming. SqlClient in ADO.NET 2.0 supports client failover without special programming of the application program.

XML Support

Advancements such as the native XML data type and XQuery help organizations seamlessly connect internal and external systems. SQL Server 2005 supports both relational and XML data natively, so enterprises can store, manage, and analyze data in the format that best suits their needs. Support for existing and emerging open standards such as Hypertext Transfer Protocol (HTTP), XML, Simple Object Access Protocol (SOAP), XQuery, and XML Schema definition language (XSD) also facilitate communication across extended enterprise systems.

XML Data Type

XML can model complex data; it is not limited to the scalar types that are supported by SQL Server. As such, a string-based, built-in data type such as char or varchar does not suffice to make full and effective use of the power and the numerous advantages of XML. For example, if XML is stored as a string, you can insert or select an entire document, or even retrieve contiguous bytes from it, but you cannot query into the contents of the document itself. By providing the XML data type, SQL Server 2005 allows you to query portions of an XML document, validate that the document conforms to an XML schema, and even modify the contents of the XML document in place. It also integrates traditional, relational data with data in unstructured or semistructured XML documents in ways that are not possible with SQL Server 2000. In SQL Server 2005, XML data is stored as binary large objects (BLOBs) in an internal representation that allows efficient reparsing and some compression.

A collection of XML schemas can be associated with a column of type XML. This provides validation for constraints, inserts, and updates, and typing of values inside stored XML data, as well as optimizations for storage and query processing. SQL Server 2005 also provides several DDL statements for managing schemas on the server.

XQuery

The XML Query Language, or XQuery, is an intelligent and robust language that is optimized for querying all types of XML data. With XQuery, you can run queries against variables and columns of the XML data type using the latter's associated methods. As with many XML standards, the World Wide Web Consortium (W3C) oversees the development of XQuery. XQuery evolved from a query language called Quilt, which was itself based on a variety of other query languages such as the XML Path Language (XPath) version 1.0, XML Query Language (XQL), and SQL. It also contains XPath 2.0 as a subset. Therefore, if you have experience using XPath 1.0, you can capitalize on your skills and do not have to learn an entirely new query language. There are, however, significant enhancements that go beyond XPath 1.0, such as typing, special functions, and support for better iteration, sorting of results, and construction.

SQL Server 2005 ships with deep XQuery capabilities that allow for XML object manipulation in the data tier. It supports a statically typed subset of the XQuery 1.0 Working Draft of November 15, 2003.

Web Services Support

In SQL Server 2005, you can develop XML Web services in the database tier, making SQL Server an HTTP listener. This provides a new type of data access capability for applications that are centralized around Web services. In SQL Server 2005, you can use HTTP to access SQL Server directly without using a middle-tier listener such as Microsoft Internet Information Services (IIS). SQL Server exposes a Web service interface to allow the execution of SQL statements and invocation of functions and procedures. Query results are returned in XML format and can take advantage of the Visual Studio Web services infrastructure.

XML for Analysis Services

XML for Analysis Services (XMLA) is the native, standards-based protocol for communicating with the Analysis Services server. New kinds of applications are enabled and easy to develop—applications that integrate analytics with operations in real time. With XMLA as the native protocol, Analysis Services clients can be configured to have a zero footprint, and each server is automatically a Web service. A light-footprint Win32 layer is available for backward compatibility with tools that work with Analysis Services 2000 on OLE DB for OLAP, ADOMD, and ADOMD.NET. Many users will continue to use the ADOMD.NET object model to build custom applications on Analysis Services.

Application Framework

SQL Server 2005 introduces a new SQL Server application framework that includes Service Broker, Notification Services, SQL Server Mobile, and SQL Server Express. Service Broker is a distributed application framework that provides reliable asynchronous messaging at the database-to-database level.

Service Broker

Over the last 10 years, the proliferation of e-commerce applications has created the need for increased workflow management across database applications. When an online customer places an order for a book, this order needs to commit transactions into the inventory, shipping, and credit card systems, and needs to send an order confirmation using another Web application. Waiting for each of these processes to happen in order does not scale well. SQL Server 2005 provides a new scalable architecture for building asynchronous message routing. Figure 4 outlines the Service Broker architecture.

Figure 4: Service Broker Architecture

Figure 4: Service Broker Architecture

The Service Broker technology allows internal or external processes to send and receive streams of reliable, asynchronous messages by using extensions to normal Transact-SQL data manipulation language. Messages are sent to a queue in the same database as the sender, to another database in the same instance of SQL Server, or to another instance of SQL Server either on the same server or on a remote server.

Microsoft SQL Server Notification Services is a platform for developing and deploying applications that generate and send notifications to users. Notifications are personalized, timely messages that can be sent to a variety of devices.

Notifications reflect subscriber preferences. The subscriber enters a subscription to express an interest in information, such as "Notify me when the stock price of Adventure Works reaches $70.00," or "Notify me when the strategy document my team is writing is updated."

A notification can be generated and sent to the user as soon as a triggering event occurs, or it can be generated and sent on a predetermined schedule that the user specifies. The user's subscription specifies when the notification should be generated and sent.

Notifications can be sent to a various devices, such as to a user's mobile phone, personal digital assistant (PDA), Microsoft Windows Messenger, or e-mail account. Because these devices often accompany the user, notifications are ideal for sending high-priority information.

SQL Server Mobile Edition

SQL Server 2000 shipped with SQL Server 2000 Windows CE Edition, which is now SQL Server Mobile Edition version 3.0. A number of new key features in SQL Server Mobile Edition relate to developers:

You can create a SQL Server Mobile Edition database on the desktop or on the device, directly from SQL Server Management Studio. You can also manipulate the schema of the SQL Server Mobile Edition database directly from Management Studio, regardless of whether the database resides on the mobile device or on the desktop. You can use SQL Server Management Studio to run queries that target a SQL Server Mobile Edition database on the device or on the desktop. You can also take advantage of new SQL Server Mobile Edition features that include an XML showplan rendered in a graphical user interface format just like native SQL Server and the ability to use query hints to override the query optimizer in SQL Server Mobile Edition. For the first time, you can control the optimization plan on a device.

You can now code against SQL Server Integration Services (SSIS) objects to exchange data.

The new SqlCeResult set is derived from the SQLResult set that is in SQL Server 2005. This allows SQL Server Mobile Edition to have a true, scrollable, and updateable cursor. It also allows binding to data objects that are on devices.

You can code an application to synchronize data while leaving the main application open and you can have two separate applications access the same database on the device at the same time.

You can get notifications that you can code into status bars that will give the synchronization status. Previously, you had no way to know how far synchronization had progressed, to notify users that a device had not stopped responding.

You can maintain the small size of the database through a much more aggressive page reclamation policy.

You can share parameterized query code with SQL Server syntax.

SQL Server Express

More than ever, developers are making the most of relational databases to provide a rich end-user experience. Protecting and managing information inside these applications is critical. Microsoft SQL Server Express helps developers build robust and reliable applications by providing a free, easy-to-use, and robust database. Too often, database systems are overly complex for building simple applications. Microsoft Visual Studio 2005 and SQL Server Express reduce this complexity by providing a simple but powerful development environment for building data-driven applications. Developers can design schemas, add data, and query local databases, all inside the Visual Studio 2005 environment. If developers need more advanced database features, then SQL Server Express can be seamlessly upgraded to more sophisticated versions of SQL Server. Figure 5 shows the Query Editor interface in SQL Server Express Manager.

Figure 5: The Query Editor in SQL Server Express Manager

Figure 5: The Query Editor in SQL Server Express Manager

A new graphical user interface tool called SQL Server Express Manager (XM) is freely available as a separate Web download. XM allows easy database management and query analysis capabilities, has a small download size, and will be freely redistributable. XM supports connections to SQL Server Express and other SQL Server 2005 editions, SQL Server 2000, and MSDE 2000. A simplified connection dialog box guides the user through the selection of the instance and the authentication methods to be used. Both local and remote connections are possible using XM. Object Explorer enumerates and displays the common objects used, such as the instance, tables, stored process, and so on, in a hierarchical manner and helps the user visualize access to the database.

All database management functionalities are available by invoking the right-click context menu from Object Explorer. Some of the database management options to be exposed include creating and modifying databases, tables, logins, and users. Many of these common database operations are available as task wizards that guide the user through the process, while many others are available as tabbed window documents. For instance, XM provides a New/Edit Database document for creating new databases and editing existing databases.

Many database users prefer to manage their servers using Transact-SQL, because this approach offers finer-grained control than using the graphical user interface. The Query Editor in XM lets users develop and execute Transact-SQL statements and scripts. The Query Editor has rich features such as keyword color-coding and a results pane that returns results in a data grid. Error messages, if any, are also shown in the results pane.

Business Intelligence

SQL Server 2005 furthers Microsoft leadership in the area of business intelligence (BI) through innovations in scalability, data integration, development tools, and rich analytics. SQL Server 2005 enables scalable BI by putting critical, timely information in the hands of employees across your organization. From the CEO to the information worker, employees will be able to quickly and easily harness data to make better decisions faster. The comprehensive integration, analysis, and reporting capabilities of SQL Server 2005 enable companies to extend the value of their existing applications, regardless of the underlying platform. BI features include enhancements in the following areas:

An end-to-end integrated business intelligence platform

Integration Services

Analysis Services

Reporting Services

Integration with the Microsoft Office System

End-to-End Integrated Business Intelligence Platform

SQL Server 2005 is a complete BI platform that provides the features, tools, and functionality to build both classic and innovative kinds of analytical applications. The following information introduces the tools that you will use to build an analytical application, and highlights new functionality that makes it easier than ever to build and manage complex BI systems.

The SQL Server 2005 BI toolset delivers end-to-end BI application integration:

Design. Business Intelligence Development Studio is the first integrated development environment designed for the BI developer. Built on Visual Studio 2005, Business Intelligence Development Studio delivers a rich, integrated, professional development platform for BI system developers. Debugging, source control, and script and code development are available for all components of the BI platform.

Integrate. SQL Server Integration Services (SSIS) has been rewritten to perform complex data integration, transformation, and synthesis at high speed for very large data volumes. Business Intelligence Development Studio makes building and debugging packages positively fun. Integration Services, Analysis Services, and Reporting Services work together to present a seamless view of data from heterogeneous sources.

Analyze. Microsoft Data Mining has always been easy to use. Now it is even better with the addition of important new algorithms, including Association Rules, Time Series, Regression Trees, Sequence Clustering, Neural Network, and Naïve Bayes. SQL Server 2005 blurs the lines between relational and multidimensional databases. You can store data in the relational database, in the multidimensional database, or use the new Proactive Cache feature to get the best of both worlds. Important new analytical capabilities have been added to Analysis Services cubes as well; these include key performance indicator (KPI) framework, MDX scripts, and other built-in advanced business analytics. The Reporting Services report delivery and management framework enables easy distribution of complex analytics to the widest possible audience.

Report. Reporting Services extends the Microsoft BI platform to reach the business user who needs to consume the analysis. Reporting Services is an enterprise-managed reporting environment, embedded and managed through Web services. Reports can be personalized and delivered in a variety of formats, with a range of interactivity and printing options. Complex analyses can reach a broad audience through the distribution of reports as a data source for downstream BI. New with SQL Server 2005 is the reporting tool, Report Builder.

Manage. SQL Server Management Studio integrates the management of all SQL Server 2005 components. BI practitioners will benefit from this extension of the server abilities you expect from the relational engine—scalability, reliability, availability, programmability, and so on—to the full set of BI platform components.

Integration Services

SQL Server 2005 includes a redesigned enterprise data extraction, transformation, and loading (ETL) platform, called SQL Server Integration Services (SSIS). SSIS enables organizations to more easily integrate and analyze data from multiple heterogeneous information sources. By analyzing data across an array of operational systems, organizations may gain a competitive edge through a holistic understanding of their business.

Enterprise ETL Platform

This new platform is the successor to the popular feature in SQL Server 2000 called Data Transformation Services (DTS). SSIS is completely new for SQL Server 2005. SSIS provides the breadth of features and very high-scale performance that is necessary to build enterprise-class ETL applications. SSIS is fully programmable, embeddable, and extensible—characteristics that make it an ideal ETL platform.

Beyond Traditional ETL

SQL Server 2005 supports nontraditional data (Web Services, XML) out of the box, in the following ways:

SSIS brings analytics to the data without persisting the data.

Data mining and text mining can be done in the data flow.

Data mining and analytics are brought to the data flow for data quality and data cleansing.

Analysis Services

With SQL Server 2005, Analysis Services provides, for the first time, a unified and integrated view of all your business data as the foundation for your traditional reporting, online analytical processing (OLAP) analysis, and data mining.

Unified Dimensional Model

By combining the best aspects of traditional OLAP analysis and relational reporting, Analysis Services provides a metadata model that covers both sets of needs. A set of cubes and dimensions defined in Analysis Services is referred to as a Unified Dimensional Model (UDM). The UDM is a central metadata repository defining business entities, business logic, calculations, and metrics that serves as the source for all reports, spreadsheets, OLAP browsers, KPIs, and analytical applications.

Using the powerful new Data Source View feature, the UDM is mapped to a host of heterogeneous back-end data sources, providing a complete and integrated picture of the business regardless of the location of the data.

With the UDM's friendly descriptions of the business entities, navigation hierarchies, multiple perspectives, and even automatic translations to native languages, users will find it easy to explore the corporate business data.

Data Mining

SQL Server 2005 Data Mining is the BI technology that helps you build complex analytical models, and integrate those models with your business operations. Analysis Services establishes new ground for data mining. By creating an easy-to-use, extensible, accessible, and flexible platform, Analysis Services data mining capabilities introduce data mining to organizations that previously would never have considered a data mining solution.

Through an enterprise-class architecture, a deep integration with the SQL Server family of BI tools, and a rich set of other tools, APIs, and algorithms, SQL Server enables the creation of a new breed of intelligent applications that enhance productivity, increase profits, and reduce costs by providing customized data-driven solutions to a broad range of business problems.

Reporting Services

Reporting Services extends the Microsoft BI platform to reach the information worker who needs access to business data. Reporting Services is a server-based enterprise reporting environment, managed through Web services. Reports can be delivered in a variety of formats, with a range of interactivity and printing options. Complex analyses can reach a broad audience through the distribution of reports as a data source for downstream BI.

As an integrated component of SQL Server 2005, Reporting Services provides the following:

A high-performance engine for processing and formatting reports.

A complete set of tools for creating, managing, and viewing reports.

An extensible architecture and open interfaces for embedding reports or integrating reporting solutions in diverse IT environments.

Relational and OLAP Reports

Reports built on relational data are useful but the ability to add additional analytic capabilities makes such reporting powerful. Reporting Services allows you to easily build reports together or separately. SQL Server 2005 supports both relational and OLAP data and provides a query editor for both, including SQL Query Editor and MDX Query Editor.

Report Builder

Report Builder, a new component of SQL Server 2005 Reporting Services, allows business users to create their own reports using a user-friendly model of their data. Report Builder takes advantage of the Reporting Services platform to bring ad hoc reporting to all end users. Users create and edit reports with the Report Builder client application. The Report Builder user interface is built on top of familiar Microsoft Office paradigms such as Microsoft Excel and Microsoft PowerPoint. Figure 6 shows a sample Report Builder report.

Figure 6: Design Reports with Report Builder

Figure 6: Design Reports with Report Builder

Report Builder is a ClickOnce application deployed through the browser. Users start by selecting report layout templates containing predefined data sections such as tables, matrices, and charts. They drag and drop report items from the model to the design surface and set constraints to filter the report data. The model contains all of the necessary information for the Report Builder to automatically generate the source query and retrieve the requested data. The Report Builder also allows users to:

Add text and formatting to reports.

Create new fields and calculations defined using the model.

Preview, print, and publish reports.

Export report data to formats such as Microsoft Excel.

Integration with the Microsoft Office System

Reports served up by the Report Server in Reporting Services can run in the context of Microsoft SharePoint Portal Server and Microsoft Office System applications such as Microsoft Word and Microsoft Excel. You can use SharePoint features to subscribe to reports, create new versions of reports, and distribute reports. You can also open reports in Word or Excel to view HTML versions of the reports.