Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7625367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:10:58+00:00 2026-05-31T05:10:58+00:00

Using SQL Server 2008 R2 I’d like to create a table with the following

  • 0

Using SQL Server 2008 R2

I’d like to create a table with the following columns

[id] INT IDENTITY(1,1) NOT NULL,
[user_id] INT NOT NULL,
[date] DATE NOT NULL,
[timestamp] DATETIME NOT NULL,
[xml_data] XML NOT NULL

with the primary key on the identity column and a non-clustered index on user_id and date that covers xml_data and timestamp.

However, I notice that I can’t add xml_data to the INCLUDE statement in the index. Sad face, since that’s going to result in an RID lookup when a user searches on user_id and date.

What’s the best way to store xml data that will be queried?

I figure my choices are

  1. Stick with xml and have well-formatted data but take the query hit
  2. Use a VARCHAR(MAX) with unknown pros/cons
  3. Use a VARBINARY(MAX) with unknown pros/cons

Note: I doubt I’ll be able to restrict the length of the string to even something like 8000.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:10:59+00:00Added an answer on May 31, 2026 at 5:10 am

    If you have XML – store it as XML, for two main reasons:

    • it’s optimized for XML storage – it’s not stored as just plain text, it’s actually tokenized and stored more efficiently than plain text

    • you can actually query the XML when it’s stored as type XML

    But: you cannot just index a XML column like that. Any index in SQL Server can be a maximum of 900 bytes long – an XML column could be up to 2 GB in size.

    If you want to index your XML column, have a look at XML Indexes in SQL Server 2005 – it’s a separate type of index designed to handle queries into XML very efficiently.

    Another way to speed up your XML queries could be to “surface” certain pieces of your XML that you query on often onto the parent table, by means of a stored function that extract that piece of information from the XML, and stores it as a computed persisted column on the parent table. Once it’s stored there, you can query it just like any other column, and you can index it, too! It only works for single pieces of information, however (e.g. the OrderNumber from your order – you only ever have one of those) – it can’t be applied to collections of data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2008. Example table : CREATE table dbo.blobtest (id int primary key
I'm using SQL Server 2008. Say I create a temporary table like this one:
using sql server 2008 I would like to take a table that has 11
Using : SQL Server 2008, Entity Framework I am summing columns in a table
I'm using SQL Server 2008. I'd like to create a backup (.bak file) of
I am using SQL Server 2008. I have a table like below: ID Name
I am using SQL Server 2008. I have a table like this: UnitId ParentId
Using SQL Server 2008, is there a way to allow inserts to a table
I'm using SQL Server 2008 and I would like to use a sproc to
I am using SQL Server 2008 management studio to execute the following SQL statements,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.