Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 22nd, 2009, 11:20 AM
Authorized User
 
Join Date: Jun 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Server 2008 XML

I have bought several hundred dollars worth of books and none of them can give me a simple straight answer. I'm a beginner at the game of XML. I would like to store a very simple XML file into a SQL Server 2008 table. I tried to store the XML data using Edit the first 200 command. The server told me that the colums of the table were read only. I tried the Create Table method. No success. I've searched the web for a simple straight answer. I'm so frustrated right now I could spit nails. Is there a simple way to store XML data into a SQL Server 2008 table?

And while we are on the subject, is there a simple way to have the eXist server find an XML file stored in INetPub? eXist seems to store its XML files in a mystery spot. I would love to know where that spot is so that I can store my own XML files there.
 
Old March 22nd, 2009, 12:32 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

Hi
There is a lot of information about using XML in SQL Server 2008 on MSDN. The section for using it in tables is at http://msdn.microsoft.com/en-us/library/bb510446.aspx but admittedly it is not all clear.

Here is a simple example for creating a table with an untyped (xml is not validated) xml column, then inserting and selecting the data:

sql Code:
-- create the table - note the XML datatype
CREATE TABLE XmlSample (
    ID INT PRIMARY KEY,
    SampleData XML NOT NULL
);

-- add a row - xml is added the same way as a normal VARCHAR etc.
INSERT INTO XmlSample (ID, SampleData) VALUES (1, '
    <Root>
        <Foo name="bob">
            <Bar />
        </Foo>
        <Foo name="dave">
            <Bar />
        </Foo>
    </Root>
'
);

-- get data back - SSMS lets you click the XML cell and show the full document
SELECT * FROM XmlSample;

(I am using SQL Server 2005, but I can't see any changes required for 2008. Please correct me if I'm wrong)

HTH
Phil





Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing SQL Server 2008 Express Edition with Tools Kevin7777 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 March 8th, 2009 05:14 AM
SQL 2008 will not run on Windows 2008? dkrus Book: Professional Microsoft SQL Server 2008 Administration ISBN: 978-0-470-24796-9 1 February 23rd, 2009 12:34 PM
Article: Script Task (.NET) in SQL Server 2008 Integration Services (SSIS) jminatel BOOK: Professional Microsoft SQL Server 2008 Integration Services ISBN: 978-0-470-24795-2 0 February 4th, 2009 12:52 AM
SQL Server 2005 XML: FOR XML PATH -> cdata? stoves SQL Server 2005 1 July 8th, 2008 02:40 AM
sql server xml mjmcs13 XML 1 February 12th, 2007 12:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.