- SQL Server Reference Guide
- Introduction
- SQL Server Reference Guide Overview
- Table of Contents
- Microsoft SQL Server Defined
- SQL Server Editions
- SQL Server Access
- Informit Articles and Sample Chapters
- Online Resources
- Microsoft SQL Server Features
- SQL Server Books Online
- Clustering Services
- Data Transformation Services (DTS) Overview
- Replication Services
- Database Mirroring
- Natural Language Processing (NLP)
- Analysis Services
- Microsot SQL Server Reporting Services
- XML Overview
- Notification Services for the DBA
- Full-Text Search
- SQL Server 2005 - Service Broker
- Using SQL Server as a Web Service
- SQL Server Encryption Options Overview
- SQL Server 2008 Overview
- SQL Server 2008 R2 Overview
- SQL Azure
- The Utility Control Point and Data Application Component, Part 1
- The Utility Control Point and Data Application Component, Part 2
- Microsoft SQL Server Administration
- The DBA Survival Guide: The 10 Minute SQL Server Overview
- Preparing (or Tuning) a Windows System for SQL Server, Part 1
- Preparing (or Tuning) a Windows System for SQL Server, Part 2
- Installing SQL Server
- Upgrading SQL Server
- SQL Server 2000 Management Tools
- SQL Server 2005 Management Tools
- SQL Server 2008 Management Tools
- SQL Azure Tools
- Automating Tasks with SQL Server Agent
- Run Operating System Commands in SQL Agent using PowerShell
- Automating Tasks Without SQL Server Agent
- Storage – SQL Server I/O
- Service Packs, Hotfixes and Cumulative Upgrades
- Tracking SQL Server Information with Error and Event Logs
- Change Management
- SQL Server Metadata, Part One
- SQL Server Meta-Data, Part Two
- Monitoring - SQL Server 2005 Dynamic Views and Functions
- Monitoring - Performance Monitor
- Unattended Performance Monitoring for SQL Server
- Monitoring - User-Defined Performance Counters
- Monitoring: SQL Server Activity Monitor
- SQL Server Instances
- DBCC Commands
- SQL Server and Mail
- Database Maintenance Checklist
- The Maintenance Wizard: SQL Server 2000 and Earlier
- The Maintenance Wizard: SQL Server 2005 (SP2) and Later
- The Web Assistant Wizard
- Creating Web Pages from SQL Server
- SQL Server Security
- Securing the SQL Server Platform, Part 1
- Securing the SQL Server Platform, Part 2
- SQL Server Security: Users and other Principals
- SQL Server Security – Roles
- SQL Server Security: Objects (Securables)
- Security: Using the Command Line
- SQL Server Security - Encrypting Connections
- SQL Server Security: Encrypting Data
- SQL Server Security Audit
- High Availability - SQL Server Clustering
- SQL Server Configuration, Part 1
- SQL Server Configuration, Part 2
- Database Configuration Options
- 32- vs 64-bit Computing for SQL Server
- SQL Server and Memory
- Performance Tuning: Introduction to Indexes
- Statistical Indexes
- Backup and Recovery
- Backup and Recovery Examples, Part One
- Backup and Recovery Examples, Part Two: Transferring Databases to Another System (Even Without Backups)
- SQL Profiler - Reverse Engineering An Application
- SQL Trace
- SQL Server Alerts
- Files and Filegroups
- Partitioning
- Full-Text Indexes
- Read-Only Data
- SQL Server Locks
- Monitoring Locking and Deadlocking
- Controlling Locks in SQL Server
- SQL Server Policy-Based Management, Part One
- SQL Server Policy-Based Management, Part Two
- SQL Server Policy-Based Management, Part Three
- Microsoft SQL Server Programming
- An Outline for Development
- Database
- Database Services
- Database Objects: Databases
- Database Objects: Tables
- Database Objects: Table Relationships
- Database Objects: Keys
- Database Objects: Constraints
- Database Objects: Data Types
- Database Objects: Views
- Database Objects: Stored Procedures
- Database Objects: Indexes
- Database Objects: User Defined Functions
- Database Objects: Triggers
- Database Design: Requirements, Entities, and Attributes
- Business Process Model Notation (BPMN) and the Data Professional
- Business Questions for Database Design, Part One
- Business Questions for Database Design, Part Two
- Database Design: Finalizing Requirements and Defining Relationships
- Database Design: Creating an Entity Relationship Diagram
- Database Design: The Logical ERD
- Database Design: Adjusting The Model
- Database Design: Normalizing the Model
- Creating The Physical Model
- Database Design: Changing Attributes to Columns
- Database Design: Creating The Physical Database
- Database Design Example: Curriculum Vitae
- NULLs
- The SQL Server Sample Databases
- The SQL Server Sample Databases: pubs
- The SQL Server Sample Databases: NorthWind
- The SQL Server Sample Databases: AdventureWorks
- The SQL Server Sample Databases: Adventureworks Derivatives
- UniversalDB: The Demo and Testing Database, Part 1
- UniversalDB: The Demo and Testing Database, Part 2
- UniversalDB: The Demo and Testing Database, Part 3
- UniversalDB: The Demo and Testing Database, Part 4
- Getting Started with Transact-SQL
- Transact-SQL: Data Definition Language (DDL) Basics
- Transact-SQL: Limiting Results
- Transact-SQL: More Operators
- Transact-SQL: Ordering and Aggregating Data
- Transact-SQL: Subqueries
- Transact-SQL: Joins
- Transact-SQL: Complex Joins - Building a View with Multiple JOINs
- Transact-SQL: Inserts, Updates, and Deletes
- An Introduction to the CLR in SQL Server 2005
- Design Elements Part 1: Programming Flow Overview, Code Format and Commenting your Code
- Design Elements Part 2: Controlling SQL's Scope
- Design Elements Part 3: Error Handling
- Design Elements Part 4: Variables
- Design Elements Part 5: Where Does The Code Live?
- Design Elements Part 6: Math Operators and Functions
- Design Elements Part 7: Statistical Functions
- Design Elements Part 8: Summarization Statistical Algorithms
- Design Elements Part 9:Representing Data with Statistical Algorithms
- Design Elements Part 10: Interpreting the Data—Regression
- Design Elements Part 11: String Manipulation
- Design Elements Part 12: Loops
- Design Elements Part 13: Recursion
- Design Elements Part 14: Arrays
- Design Elements Part 15: Event-Driven Programming Vs. Scheduled Processes
- Design Elements Part 16: Event-Driven Programming
- Design Elements Part 17: Program Flow
- Forming Queries Part 1: Design
- Forming Queries Part 2: Query Basics
- Forming Queries Part 3: Query Optimization
- Forming Queries Part 4: SET Options
- Forming Queries Part 5: Table Optimization Hints
- Using SQL Server Templates
- Transact-SQL Unit Testing
- Index Tuning Wizard
- Unicode and SQL Server
- SQL Server Development Tools
- The SQL Server Transact-SQL Debugger
- The Transact-SQL Debugger, Part 2
- Basic Troubleshooting for Transact-SQL Code
- An Introduction to Spatial Data in SQL Server 2008
- Performance Tuning
- Performance Tuning SQL Server: Tools and Processes
- Performance Tuning SQL Server: Tools Overview
- Creating a Performance Tuning Audit - Defining Components
- Creating a Performance Tuning Audit - Evaluation Part One
- Creating a Performance Tuning Audit - Evaluation Part Two
- Creating a Performance Tuning Audit - Interpretation
- Creating a Performance Tuning Audit - Developing an Action Plan
- Understanding SQL Server Query Plans
- Performance Tuning: Implementing Indexes
- Performance Monitoring Tools: Windows 2008 (and Higher) Server Utilities, Part 1
- Performance Monitoring Tools: Windows 2008 (and Higher) Server Utilities, Part 2
- Performance Monitoring Tools: Windows System Monitor
- Performance Monitoring Tools: Logging with System Monitor
- Performance Monitoring Tools: User Defined Counters
- General Transact-SQL (T-SQL) Performance Tuning, Part 1
- General Transact-SQL (T-SQL) Performance Tuning, Part 2
- General Transact-SQL (T-SQL) Performance Tuning, Part 3
- Performance Monitoring Tools: An Introduction to SQL Profiler
- Performance Tuning: Introduction to Indexes
- Performance Monitoring Tools: SQL Server 2000 Index Tuning Wizard
- Performance Monitoring Tools: SQL Server 2005 Database Tuning Advisor
- Performance Monitoring Tools: SQL Server Management Studio Reports
- Performance Monitoring Tools: SQL Server 2008 Activity Monitor
- The SQL Server 2008 Management Data Warehouse and Data Collector
- Performance Monitoring Tools: Evaluating Wait States with PowerShell and Excel
- Practical Applications
- Choosing the Back End
- The DBA's Toolbox, Part 1
- The DBA's Toolbox, Part 2
- Scripting Solutions for SQL Server
- Building a SQL Server Lab
- Using Graphics Files with SQL Server
- Enterprise Resource Planning
- Customer Relationship Management (CRM)
- Building a Reporting Data Server
- Building a Database Documenter, Part 1
- Building a Database Documenter, Part 2
- Data Management Objects
- Data Management Objects: The Server Object
- Data Management Objects: Server Object Methods
- Data Management Objects: Collections and the Database Object
- Data Management Objects: Database Information
- Data Management Objects: Database Control
- Data Management Objects: Database Maintenance
- Data Management Objects: Logging the Process
- Data Management Objects: Running SQL Statements
- Data Management Objects: Multiple Row Returns
- Data Management Objects: Other Database Objects
- Data Management Objects: Security
- Data Management Objects: Scripting
- Powershell and SQL Server - Overview
- PowerShell and SQL Server - Objects and Providers
- Powershell and SQL Server - A Script Framework
- Powershell and SQL Server - Logging the Process
- Powershell and SQL Server - Reading a Control File
- Powershell and SQL Server - SQL Server Access
- Powershell and SQL Server - Web Pages from a SQL Query
- Powershell and SQL Server - Scrubbing the Event Logs
- SQL Server 2008 PowerShell Provider
- SQL Server I/O: Importing and Exporting Data
- SQL Server I/O: XML in Database Terms
- SQL Server I/O: Creating XML Output
- SQL Server I/O: Reading XML Documents
- SQL Server I/O: Using XML Control Mechanisms
- SQL Server I/O: Creating Hierarchies
- SQL Server I/O: Using HTTP with SQL Server XML
- SQL Server I/O: Using HTTP with SQL Server XML Templates
- SQL Server I/O: Remote Queries
- SQL Server I/O: Working with Text Files
- Using Microsoft SQL Server on Handheld Devices
- Front-Ends 101: Microsoft Access
- Comparing Two SQL Server Databases
- English Query - Part 1
- English Query - Part 2
- English Query - Part 3
- English Query - Part 4
- English Query - Part 5
- RSS Feeds from SQL Server
- Using SQL Server Agent to Monitor Backups
- Reporting Services - Creating a Maintenance Report
- SQL Server Chargeback Strategies, Part 1
- SQL Server Chargeback Strategies, Part 2
- SQL Server Replication Example
- Creating a Master Agent and Alert Server
- The SQL Server Central Management System: Definition
- The SQL Server Central Management System: Base Tables
- The SQL Server Central Management System: Execution of Server Information (Part 1)
- The SQL Server Central Management System: Execution of Server Information (Part 2)
- The SQL Server Central Management System: Collecting Performance Metrics
- The SQL Server Central Management System: Centralizing Agent Jobs, Events and Scripts
- The SQL Server Central Management System: Reporting the Data and Project Summary
- Time Tracking for SQL Server Operations
- Migrating Departmental Data Stores to SQL Server
- Migrating Departmental Data Stores to SQL Server: Model the System
- Migrating Departmental Data Stores to SQL Server: Model the System, Continued
- Migrating Departmental Data Stores to SQL Server: Decide on the Destination
- Migrating Departmental Data Stores to SQL Server: Design the ETL
- Migrating Departmental Data Stores to SQL Server: Design the ETL, Continued
- Migrating Departmental Data Stores to SQL Server: Attach the Front End, Test, and Monitor
- Tracking SQL Server Timed Events, Part 1
- Tracking SQL Server Timed Events, Part 2
- Patterns and Practices for the Data Professional
- Managing Vendor Databases
- Consolidation Options
- Connecting to a SQL Azure Database from Microsoft Access
- SharePoint 2007 and SQL Server, Part One
- SharePoint 2007 and SQL Server, Part Two
- SharePoint 2007 and SQL Server, Part Three
- Querying Multiple Data Sources from a Single Location (Distributed Queries)
- Importing and Exporting Data for SQL Azure
- Working on Distributed Teams
- Professional Development
- Becoming a DBA
- Certification
- DBA Levels
- Becoming a Data Professional
- SQL Server Professional Development Plan, Part 1
- SQL Server Professional Development Plan, Part 2
- SQL Server Professional Development Plan, Part 3
- Evaluating Technical Options
- System Sizing
- Creating a Disaster Recovery Plan
- Anatomy of a Disaster (Response Plan)
- Database Troubleshooting
- Conducting an Effective Code Review
- Developing an Exit Strategy
- Data Retention Strategy
- Keeping Your DBA/Developer Job in Troubled Times
- The SQL Server Runbook
- Creating and Maintaining a SQL Server Configuration History, Part 1
- Creating and Maintaining a SQL Server Configuration History, Part 2
- Creating an Application Profile, Part 1
- Creating an Application Profile, Part 2
- How to Attend a Technical Conference
- Tips for Maximizing Your IT Budget This Year
- The Importance of Blue-Sky Planning
- Application Architecture Assessments
- Transact-SQL Code Reviews, Part One
- Transact-SQL Code Reviews, Part Two
- Cloud Computing (Distributed Computing) Paradigms
- NoSQL for the SQL Server Professional, Part One
- NoSQL for the SQL Server Professional, Part Two
- Object-Role Modeling (ORM) for the Database Professional
- Business Intelligence
- BI Explained
- Developing a Data Dictionary
- BI Security
- Gathering BI Requirements
- Source System Extracts and Transforms
- ETL Mechanisms
- Business Intelligence Landscapes
- Business Intelligence Layouts and the Build or Buy Decision
- A Single Version of the Truth
- The Operational Data Store (ODS)
- Data Marts – Combining and Transforming Data
- Designing Data Elements
- The Enterprise Data Warehouse — Aggregations and the Star Schema
- On-Line Analytical Processing (OLAP)
- Data Mining
- Key Performance Indicators
- BI Presentation - Client Tools
- BI Presentation - Portals
- Implementing ETL - Introduction to SQL Server 2005 Integration Services
- Building a Business Intelligence Solution, Part 1
- Building a Business Intelligence Solution, Part 2
- Building a Business Intelligence Solution, Part 3
- Tips and Troubleshooting
- SQL Server and Microsoft Excel Integration
- Tips for the SQL Server Tools: SQL Server 2000
- Tips for the SQL Server Tools – SQL Server 2005
- Transaction Log Troubles
- SQL Server Connection Problems
- Orphaned Database Users
- Additional Resources
- Tools and Downloads
- Utilities (Free)
- Tool Review (Free): DBDesignerFork
- Aqua Data Studio
- Microsoft SQL Server Best Practices Analyzer
- Utilities (Cost)
- Quest Software's TOAD for SQL Server
- Quest Software's Spotlight on SQL Server
- SQL Server on Microsoft's Virtual PC
- Red Gate SQL Bundle
- Microsoft's Visio for Database Folks
- Quest Capacity Manager
- SQL Server Help
- Visual Studio Team Edition for Database Professionals
- Microsoft Assessment and Planning Solution Accelerator
- Aggregating Server Data from the MAPS Tool
Although there's been a lot of hype about Extensible Markup Language (XML), in reality it isn't very complex. At its core it's a text file with special characters (tags) similar to those of Hypertext Markup Language (HTML). But I don't mean that XML isn't powerful — it is.
HTML has a finite set of tags, and is used to provide special instructions to web browsers to display text and graphics. XML tags, on the other hand, are not predefined. You define them to mean what you want, and it's left up to the consuming program to figure out what they're used for.
That flexibility allows XML to be used to transfer data between various software packages — from databases to word processors, from spreadsheets to databases. Not only that, but the systems running the software don't even have to be similar — for example, you can use the same XML file (called a document) between Macintosh equipment, Sun servers, and Microsoft operating systems.
XML files are structured documents. What that means is that the document is laid out in a particular way, and uses tags to indicate special words or sections of the document. You're probably used to seeing HTML documents with tags indicating bold, underlining, or other presentation methods. These tags "bookend" a word (or even a letter), causing the browser to interpret the tag as a formatting code. You've probably seen raw HTML like this:
This is <B>Bold</B>.The <B> tag starts the boldfacing, and the </B> tag ends it. XML is similar, but tags are used for data, not just formatting. That means that you can have an XML document that defines the last-name field from the pubs database found in SQL Server like this:
<au_lname>Woody</au_lname>
The above example is just a snippet of what an XML document might contain. A more complete document might look like this:
<?xml version ='1.0' encoding = 'UTF-8'?> <authors> <author> <au_id = '123-12-1234'> <au_lname>Woody</au_lname> <au_fname>Buck</au_fname> </author> </authors>
You can type this XML document with any text editor. What makes it XML is the first line — and an interpreter. You see, until the file is read by something, it's just text. The client application (Internet Explorer, for example) has to know how to deal with the file.
Just for fun, open Notepad and type or copy the lines you see above. Save the file with the extension .XML and then double-click that file (if you have an Internet browser installed). You'll notice that the file arranges itself in a self-collapsing hierarchy — which is ideal for database-type applications.
One final note about XML. Although HTML is quite forgiving about tag-matching and case-sensitivity, XML is not. If you don’t match the tags and tag order in your XML document, it won’t be "well-formed” and it won’t work properly. Also, XML is case-sensitive, meaning that <Name> is different than <name>.
XML and SQL Server 2000
Microsoft SQL Server 2000 has XML interpreters built into a dynamic link library (DLL). This DLL can read and write XML. Although SQL Server 2000 ships with native XML support, you'll need to obtain and apply various service packs to your installation if you want to exploit the latest XML features. You'll also need Microsoft's Internet Information Server (IIS) to use the XML features.
Using the web server, data can be queried directly from the database in the user's browser. Normally this is done within an HTML page. The data can be formatted using XML style sheets to produce a very rich client experience.
XML can also be queried out of the database with SELECT statements, and SQL Server 2000 supports the XPath XML query language. The process for accessing data as XML is to read the document into memory with a stored procedure, and then select data out of the resulting recordset like a table. When you're done, you release the document from memory.
SQL Server 2000 can also store XML data directly in the database, using the dt:type attribute. While this isn't done a great deal, it allows an entire document to reside in one field of a database!
SQL Server 2000 includes XML, and the buzz is that Yukon (the next release of SQL Server) will extend that support. With the support currently available in SQL Server 2000, you can do the following:
- Use HTTP to access SQL Server
- Use XDR (XML-Data Reduced) schemas and XPath queries
- Access XML data using the SELECT statement and the FOR XML clause
- Write XML data using OPENXML
- Use SQLOLEDB to conform XML documents into command text and to return the result sets as a stream
Creating and Accessing XML Data with SQL Server 2000
Here's the flow for producing XML documents using SQL Server 2000:
Before you can use XML with SQL Server, you need to configure the SQL Server 2000 XML product with extensions for Internet Information Server (IIS). You can install IIS on the same computer as SQL Server 2000, or on another machine.
Create three directories. (Anywhere is fine, but jot down where they are.)
The first directory acts as the main web site for the XML access (called the root).
The second directory (usually made under the first) is for the templates that SQL Server 2000 uses in IIS for XML. Templates are special XML documents that store queries.
Finally, create a directory (also under the first) that will house the schema. Schemas are references for data that XML documents need.
After you create the directories, tie them to IIS using virtual directories. To do this, click Configure SQL XML Support in IIS in the SQL Server Tools program group. This process will lead you through a wizard that will point IIS to the directories you made earlier. This wizard will also configure the security of how the queries will be handled and other important settings. (The default settings are fine for this test, but you check Books Online later for more information about what they do.)
Now that the SQL Server and web site are configured, users can enter queries in the address bar of their web browser to display the data, or you can create predefined queries (called templates) stored on the server. This second method is the type seen most often.
Creating XML queries isn't difficult to learn. The key concept is adding FOR XML AUTO to the end of most Transact-SQL language queries. The FOR XML query structures the data for XML, and the AUTO part is an XML mode. This mode allows you to format the XML into the type that the application needs. Here's a quick chart of those modes:
Mode |
Description |
AUTO |
A nested XML tree. AUTO sets the tables in the FROM clause as an XML element. |
RAW |
Each row in the query is an XML element with a generic identifier row. |
EXPLICIT |
Lets you specify the shape of the XML tree. |
For this test, enter the following command in your browser's URL bar (assuming that you pointed your data source to the pubs database earlier):
SELECT * FROM authors FOR XML AUTO
The XML implementation in SQL Server 2000 continues to evolve—even if you follow the instructions I've given, there's more to do. Microsoft has release several service packs to enhance the XML extensions for SQL Server. When you perform these upgrades, you'll get new versions of the XML documentation as well.
XML and SQL Server 2005
SQL Server 2005 fully implements XML right inside the engine of the product. The primary improvements you’ll see in this version are the inclusion of XML as a native data type, new enhancements of the FOR XML statement and an implementation of the XQuery language.
The ability to store data natively as XML is a great new feature. Although XML can be stored out on the file system, there are times when it makes sense to store XML inside of the database. You have great control over the security of the data in a database, and the XML data is part of the maintenance schedule when it is in the database. You can even index the XML data for speedy access.
But not everything is well represented as XML. If your data is hierarchical, has a sparse structure, and you want to query or update the data based on its structure, then it may make sense to store data as an XML document. Otherwise, you should stick with standard columns.
It’s easy to create and use an XML column in your database. You simply use the same syntax as any table, like this:
CREATE TABLE TestTable (C1 XML) GO To insert data into that table, you can use a variable, read an XML document, or just enter an element manually, like this: INSERT INTO TestTable VALUES('<Customer Name="Buck Woody" />') GO
With SQL Server 2005, you can use the FOR XML predicate on the SELECT statement as before, but you can also use the sp_xml_preparedocument stored procedure and the OPENXML statement to work with XML documents in your queries.
XQuery is a new standard way of querying XML data. SQL Server 2005 includes XQuery language constructs that you can use within a SELECT statement. I won’t cover that here, but I will show you how to use it in other tutorials.
InformIT Articles and Sample Chapters
We have a sample chapter on creating well-formed XML documents from the book Teach Yourself XML in 21 Days.
Books and eBooks
Need a complete reference on XML? Check out this Special Edition of Using XML, 2nd Edition.
Online Resources
It’s a bit difficult to navigate, but this is the lead article in Books Online on XML in 2005.