Stephen Forte's Blog

 RSS/Feedburner
      Home     Steve & The Tank       

  Friday, February 29, 2008

     SQL Server 2008 XML: XML DML Enhancements

Yesterday we discussed the changes to XQuery by allowing LET statements. Today the last XML enhancement is an "enhancement" to XML DML.

XML Data Manipulation Language (DML) is specific to MS SQL Server 2005 and 2008. It is a very useful feature that allows you to insert nodes to an existing XML instance, delete an element, or replace the value of (sort of an edit.) It works like this:

First let's create a table with an XML data type and insert a piece of XML into it:

Create table XMLTest1
    (
    Speaker_ID int primary key,
    SpeakerXML xml not null
    )

GO

Insert into XMLTest1
Values
(
    1,
    '
    <classes>
        <class name="Writing Secure Code for ASP .NET " />
        <class name="Using XQuery in SQL Server 2008" />
        <class name="SQL Server and Oracle Working Together" />
    </classes>
    '
    )

Now to insert an element into this table it is pretty easy, just use the XML modify method of the XML data type. Since our XML instance is in a SQL Server table we have to use the standard SQL UPDATE and SET syntax with a WHERE clause to get to the piece of XML in our table we are concerned with. You can see how easy it is to add an element to the table here:

Update XMLTest1
Set SpeakerXML.modify(
'insert
<class name="Using Linq to SQL" />
into /classes[1]'
)
Where Speaker_ID=1

If we select * from XMLTest1 WHERE Speaker_ID=1 the XML column looks like this now:

<classes>
  <class name="Writing Secure Code for ASP .NET " />
  <class name="Using XQuery in SQL Server 2008" />
  <class name="SQL Server and Oracle Working Together" />
  <class name="Using Linq to SQL" />
</classes>

SQL Server 2008 has an enhancement to this. You can substitute the XML element with a variable. For example let's create a variable here:

DECLARE @newElement xml
Set @newElement='<class name="ASP.NET Scalability"/>'

Now let's do the same insert as before, however, we will use the @newElement variable. This will enable you to select XML from other areas and stick it into a variable and then insert it into another XML instance. Here is the final piece:

Update XMLTest1
Set SpeakerXML.modify(
'insert
sql:variable("@newElement") 
into /classes[1]'
)
Where Speaker_ID=1

If we select * from XMLTest1 WHERE Speaker_ID=1 the XML column looks like this now:

<classes>
  <class name="Writing Secure Code for ASP .NET " />
  <class name="Using XQuery in SQL Server 2008" />
  <class name="SQL Server and Oracle Working Together" />
  <class name="Using Linq to SQL" />
  <class name="ASP.NET Scalability" />
</classes>

Not the greatest of new features, but a handy dandy feature to say the least.



SQL Server | Yukon Book

Friday, February 29, 2008 12:00:54 PM (Eastern Standard Time, UTC-05:00)
Comments [1]  |  Trackback Related posts:
SQL Server 2008 RC0-Lost a Few Hours
Impedance Mismatch
SQL Server 2008 XML: XQuery Enhancements
SQL Server 2008 XML: XSD Enhancements-Union and List Types
SQL Server 2008 February CTP Installed: New XSD Features for XML Data
Programming SQL Server 2005 in French, Italian and Polish
Tracked by:
"http://yesihavemoneyy.com" (http://yesihavemoneyy.com) [Pingback]
"http://realvideopornoo.com" (http://realvideopornoo.com) [Pingback]
"http://tubepornoss.com" (http://tubepornoss.com) [Pingback]
"http://morningside.edu/mics/_notes/pages/coumadin/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/soma/index.html" (http://morningside.e... [Pingback]
"http://morningside.edu/mics/_notes/pages/lipitor/index.html" (http://morningsid... [Pingback]
"http://morningside.edu/mics/_notes/pages/tramadol/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/rainbow-brite/index.html" (http://morn... [Pingback]
"http://blastpr.com/wiki/js/pages/effexor/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://blastpr.com/wiki/js/pages/ultram/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/lexapro/index.html" (http://morningsid... [Pingback]
"http://morningside.edu/mics/_notes/pages/celebrex/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/nexium/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/claritin/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/cialis/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/prilosec/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/lexapro/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://blastpr.com/wiki/js/pages/melatonin/index.html" (http://blastpr.com/wiki... [Pingback]
"http://morningside.edu/mics/_notes/pages/celexa/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/celebrex/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/clomid/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/celexa/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/coumadin/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/hoodia/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/prilosec/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/clomid/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/cymbalta/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/melatonin/index.html" (http://mornings... [Pingback]
"http://morningside.edu/mics/_notes/pages/paxil/index.html" (http://morningside.... [Pingback]
"http://morningside.edu/mics/_notes/pages/viagra/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/claritin/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/ultram/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/viagra/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/06712704/index.h... [Pingback]
"http://entartistes.ca/images/images/docs/81367526/index.html" (http://entartist... [Pingback]
"http://swellhead.netswellhead.net/docs/84545083/index.html" (http://swellhead.n... [Pingback]
"http://split-dalmatia.com/split-dalmatia.com/images/docs/34320152/index.html" (... [Pingback]
"http://discussgod.com/cpstyles/docs/25383456/index.html" (http://discussgod.com... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/82710340/index.h... [Pingback]
"http://thebix.com/includes/compat/docs/29852280/index.html" (http://thebix.com/... [Pingback]
"http://blog.netmedia.hr/wp-includes/js/docs/91708760/index.html" (http://blog.n... [Pingback]
"http://martinrozon.com/images/photos/docs/43274485/index.html" (http://martinro... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/48335156/index.html" ... [Pingback]
"http://coolioness.com/attachments/docs/03698289/index.html" (http://coolioness.... [Pingback]
"http://blog.netmedia.hr/wp-includes/js/docs/84238305/index.html" (http://blog.n... [Pingback]
"http://realestate.hr/templates/css/docs/71546796/index.html" (http://realestate... [Pingback]
"http://thebix.com/includes/compat/docs/10152421/index.html" (http://thebix.com/... [Pingback]
"http://seo4u.at/images/docs/76783685/index.html" (http://seo4u.at/images/docs/7... [Pingback]
"http://vladan.strigo.net/wp-includes/js/docs/86309858/index.html" (http://vlada... [Pingback]
"http://pddownloads.com/docs/21991908/index.html" (http://pddownloads.com/docs/2... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/68291686/index.h... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/52060005/index.html" ... [Pingback]
"http://discussgod.com/cpstyles/docs/43932298/index.html" (http://discussgod.com... [Pingback]
"http://entartistes.ca/images/images/docs/28212733/index.html" (http://entartist... [Pingback]
"http://legambitdufou.org/Library/docs/15090396/index.html" (http://legambitdufo... [Pingback]
"http://pspdesktops.com/fileupload/store/docs/33460308/index.html" (http://pspde... [Pingback]
"http://hrvatska.biz/wp-includes/js/docs/80692203/index.html" (http://hrvatska.b... [Pingback]
"http://pddownloads.com/docs/15972574/index.html" (http://pddownloads.com/docs/1... [Pingback]
"http://thejohnslater.com/pix/img/docs/86193101/index.html" (http://thejohnslate... [Pingback]
"http://witze-humor.de/templates/images/docs/69259068/index.html" (http://witze-... [Pingback]
"http://blog.netmedia.hr/wp-includes/js/docs/08493171/index.html" (http://blog.n... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/36483653/index.html" ... [Pingback]
"http://realestate.hr/templates/css/docs/28593877/index.html" (http://realestate... [Pingback]
"http://vladan.strigo.net/wp-includes/js/docs/09763218/index.html" (http://vlada... [Pingback]
"http://swellhead.netswellhead.net/docs/79619129/index.html" (http://swellhead.n... [Pingback]
"http://ipsilon.hr/ipsilon.hr/cms/4/lib/docs/24066563/index.html" (http://ipsilo... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/37348396/index.html" ... [Pingback]
"http://slaterjohn.com/downloads/2col/51579700/index.html" (http://slaterjohn.co... [Pingback]
"http://lecouac.org/ecrire/lang/docs/20007231/index.html" (http://lecouac.org/ec... [Pingback]
"http://coolioness.com/attachments/docs/58150246/index.html" (http://coolioness.... [Pingback]
"http://split-dalmatia.com/split-dalmatia.com/images/docs/84431573/index.html" (... [Pingback]
"http://martinrozon.com/images/photos/docs/75270452/index.html" (http://martinro... [Pingback]
"http://ipsilon.hr/ipsilon.hr/cms/4/lib/docs/55227677/index.html" (http://ipsilo... [Pingback]
"http://pspdesktops.com/fileupload/store/docs/18769945/index.html" (http://pspde... [Pingback]
"http://thejohnslater.com/pix/img/docs/73486930/index.html" (http://thejohnslate... [Pingback]
"http://seo4u.at/images/docs/68897595/index.html" (http://seo4u.at/images/docs/6... [Pingback]
"http://legambitdufou.org/Library/docs/64933533/index.html" (http://legambitdufo... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/70471394/index.html" ... [Pingback]
"http://realestate.hr/templates/css/docs/36157459/index.html" (http://realestate... [Pingback]
"http://legambitdufou.org/Library/docs/38152786/index.html" (http://legambitdufo... [Pingback]
"http://thejohnslater.com/pix/img/docs/42082955/index.html" (http://thejohnslate... [Pingback]
"http://slaterjohn.com/downloads/2col/28436634/index.html" (http://slaterjohn.co... [Pingback]
"http://martinrozon.com/images/photos/docs/82037625/index.html" (http://martinro... [Pingback]
"http://coolioness.com/attachments/docs/75395149/index.html" (http://coolioness.... [Pingback]
"http://add2rss.com/img/design/docs/45658867/index.html" (http://add2rss.com/img... [Pingback]
"http://temerav.com/images/menu/96509501/index.html" (http://temerav.com/images/... [Pingback]
"http://sevainc.com/bad_denise/img/3/clomid/" (http://sevainc.com/bad_denise/img... [Pingback]
"http://jemnemelodierecords.sk/img/viagra/" (http://jemnemelodierecords.sk/img/v... [Pingback]
"http://sevainc.com/bad_denise/img/11/tramadol/" (http://sevainc.com/bad_denise/... [Pingback]
"http://easytravelcanada.info/js/pages/6/lipitor/" (http://easytravelcanada.info... [Pingback]
"http://easytravelcanada.info/js/pages/7/melatonin/" (http://easytravelcanada.in... [Pingback]
"http://easytravelcanada.info/js/pages/7/nexium/" (http://easytravelcanada.info/... [Pingback]
"http://easycanada.info/js/pages/cialis/" (http://easycanada.info/js/pages/ciali... [Pingback]
"http://easytravelcanada.info/js/pages/12/zoloft/" (http://easytravelcanada.info... [Pingback]
"http://sevainc.com/bad_denise/img/10/synthroid/" (http://sevainc.com/bad_denise... [Pingback]
"http://easytravelcanada.info/js/pages/6/lexapro/" (http://easytravelcanada.info... [Pingback]
"http://sevainc.com/bad_denise/img/8/paxil/" (http://sevainc.com/bad_denise/img/... [Pingback]
"http://abaffydesign.com/la/img/viagra/" (http://abaffydesign.com/la/img/viagra/... [Pingback]
"http://birds.sk/img/cialis/" (http://birds.sk/img/cialis/) [Pingback]
"http://sevainc.com/bad_denise/img/9/rainbow-brite/" (http://sevainc.com/bad_den... [Pingback]
"http://easytravelcanada.info/js/pages/3/clomid/" (http://easytravelcanada.info/... [Pingback]
"http://sevainc.com/bad_denise/img/7/nexium/" (http://sevainc.com/bad_denise/img... [Pingback]
"http://easytravelcanada.info/js/pages/9/prozac/" (http://easytravelcanada.info/... [Pingback]
"http://sevainc.com/bad_denise/img/4/cymbalta/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://abaffydesign.com/la/img/cialis/" (http://abaffydesign.com/la/img/cialis/... [Pingback]
"http://sevainc.com/bad_denise/img/6/lexapro/" (http://sevainc.com/bad_denise/im... [Pingback]
"http://sevainc.com/bad_denise/img/8/prilosec/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://easytravelcanada.info/js/pages/11/tramadol/" (http://easytravelcanada.in... [Pingback]
"http://sevainc.com/bad_denise/img/9/prozac/" (http://sevainc.com/bad_denise/img... [Pingback]
"http://easytravelcanada.info/js/pages/12/wellbutrin/" (http://easytravelcanada.... [Pingback]
"http://simpletravelcanada.info/js/pages/27277365/" (http://simpletravelcanada.i... [Pingback]
"http://easytravelcanada.info/js/pages/1/celebrex/" (http://easytravelcanada.inf... [Pingback]
"http://simplecanada.info/js/pages/13912893/" (http://simplecanada.info/js/pages... [Pingback]
"http://easymexico.info/images/img/viagra/" (http://easymexico.info/images/img/v... [Pingback]
"http://sevainc.com/bad_denise/img/2/celexa/" (http://sevainc.com/bad_denise/img... [Pingback]
"http://easytravelcanada.info/js/pages/11/ultram/" (http://easytravelcanada.info... [Pingback]
"http://adventure-traveling.com/images/img/cialis/" (http://adventure-traveling.... [Pingback]
"http://easytravelcanada.info/js/pages/3/claritin/" (http://easytravelcanada.inf... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/mother-and-daugther-sex-s... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/anal-sex-shemale.html" (h... [Pingback]
"http://odin.net/images/pages/35694472/study-on-penis-size.html" (http://odin.ne... [Pingback]
"http://odin.net/images/pages/52807681/index.html" (http://odin.net/images/pages... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/list-of-teen-sites.html" (... [Pingback]
"http://odin.net/images/pages/52807681/drug-test-shop-penis.html" (http://odin.n... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/anime-preteen-sex.html" (... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/my-little-girl-song.html"... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/ravon-nude.html" (http://... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/baby-shower-graphics.html... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/access-to-sex-web-sites.h... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/xxx-asian-anal-milf-free.... [Pingback]
"http://odin.net/images/pages/35694472/stories-housewives-seducing-husbands-frie... [Pingback]
"http://odin.net/images/pages/35694472/sexy-female-escorts-in-delhi.html" (http:... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/pictures-of-black-girls.h... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/asian-massage-ct.html" (h... [Pingback]
"http://odin.net/images/pages/52807681/favorite-sex-positions.html" (http://odin... [Pingback]
"http://odin.net/images/pages/35694472/babe-tv.html" (http://odin.net/images/pag... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/chyna-porn-movie.html" (ht... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/erotic-literature-for-wome... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/granny-movie-thumbs.html"... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/xpress-train-hentai-movie.... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/pics-of-sexy-women-in-wes... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/taylor-hayes-free-pics.ht... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/cheerleader-erotic-stories... [Pingback]
"http://odin.net/images/pages/35694472/celeb-up-skirts.html" (http://odin.net/im... [Pingback]
"http://odin.net/images/pages/52807681/life-teen-mass-balboa.html" (http://odin.... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/dress-up-online-games-for-... [Pingback]
"http://odin.net/images/pages/35694472/index.html" (http://odin.net/images/pages... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/adult-synchronized-skate-... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/busty-ebony-retro-sylvia-... [Pingback]
"http://odin.net/images/pages/52807681/hidden-sex-cameras.html" (http://odin.net... [Pingback]
"http://odin.net/images/pages/52807681/sexy-co-eds.html" (http://odin.net/images... [Pingback]
"http://odin.net/images/pages/52807681/the-girls-next-door-centerfold.html" (htt... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/adult-film-star-listings.... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/girls-that-lick-ass.html" ... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/adult-free-gay-porn.html" ... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/adult-porn-comic.html" (ht... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/hentai-spider-man.html" (h... [Pingback]
"http://odin.net/images/pages/52807681/female-piercing-pics.html" (http://odin.n... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/short-stories-moral-lesson... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/teen-nude-school-bus.html... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/fucking-icons.html" (http:... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/cute-hairstyle-for-young-... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/hot-russian-models-teen-ag... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/asian-climate.html" (http:... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/penis-too-small.html" (htt... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/free-sex-torrent.html" (ht... [Pingback]
"http://odin.net/images/pages/35694472/baby-got-back-by-throwdown.html" (http://... [Pingback]
"http://odin.net/images/pages/35694472/janet-jackson-bikini.html" (http://odin.n... [Pingback]












newtelligence dasBlog 2.0.7226.0

Copyright © 2008 Stephen Forte. Available under the Creative Commons Attribution 3.0 License.

 The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way