Sql2005 xml

491 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Sql2005 xml

  1. 1. XML Enables SQL Server to be a Complete Data PlatformExploit the XML Capabilities of SQL Server 2005 by Jason Follas<br />
  2. 2. Vanity<br />
  3. 3. Jason Follas<br />
  4. 4. Technical Architect<br />
  5. 5. User Group Leader<br />
  6. 6. Microsoft MVP – SQL Server<br />
  7. 7. Motorcycle Enthusiast<br />
  8. 8. 232,582,657-1<br />Astronomy, Prime Numbers, Guitar<br />
  9. 9. Serious Addiction to the World of Warcraft<br />
  10. 10. Primer<br />
  11. 11. Before we begin, let’s establish a base level of knowledge<br />
  12. 12. demo<br />
  13. 13. XML Enables SQL Server to be a Complete Data PlatformExploit the XML Capabilities of SQL Server 2005 by Jason Follas<br />
  14. 14. Act I<br />
  15. 15. Today's data world is full of XML-based data sources<br />
  16. 16. <XML><br />Every database developer should be able to move data into and out of XML<br />SQL<br />
  17. 17. XML translation in middle-tier can be inflexible and may even increase network overhead<br />
  18. 18. Move XML handling into the database to improve overall integration<br />
  19. 19. Utilize SQL Server 2005 for database solutions that need to use XML data<br /><XML><br />
  20. 20. Act II, Scene 1<br />
  21. 21. Interpret XML as More Than Just Text Using the XML Data Type<br />
  22. 22. XML is a First-Class Citizen data type<br />INT<br />DATETIME<br />VARCHAR<br />XML<br />
  23. 23. Used in columns, variables, parameters, and return types<br />
  24. 24. Serialize to and parse from string representation<br />
  25. 25. Full support for typed XML using Schema<br />
  26. 26. Has methods that offer inspection and extraction of data from the XML<br />
  27. 27. exist()<br />
  28. 28. query() and value()<br />
  29. 29. nodes()<br />
  30. 30. XML columns can be indexed for faster access to the contained data<br />
  31. 31. Primary XML Index<br />
  32. 32. Secondary XML Indexes (value, path, property)<br />
  33. 33. Examples of when a secondary should be considered<br />
  34. 34. demo<br />
  35. 35. Act II, Scene 2<br />
  36. 36. Harness the Data in XML Using the XQuery Language<br />
  37. 37. Path expressions<br />
  38. 38. Location steps<br />
  39. 39. Attributes<br />
  40. 40. Predicates<br />
  41. 41. FLWOR statement<br />FORLETWHEREORDER BYRETURN<br />
  42. 42. For and Return<br />
  43. 43. Where<br />
  44. 44. Order By<br />
  45. 45. XQuery Functions<br />
  46. 46. Data Accessor Functions string() and data()<br />
  47. 47. Functions that act on data (numeric, string, context, aggregate functions)<br />
  48. 48. SQL Server Extension Functions sql:column() and sql:variable()<br />
  49. 49. demo<br />
  50. 50. Act II, Scene 3<br />
  51. 51. Create XML From Relational Data Using the FOR XML Clause<br />
  52. 52. Return XML from queries instead of rowsets<br /><XML><br />SQL<br />
  53. 53. RAW Mode<br />SELECT * FROM Employee FOR XML RAW('Employee')<br /><Employee EmployeeID="2" Federal_ID="000-00-0001" Name="Andrew Miller" DOB="1968-05-01T00:00:00" StartDate="2000-01-01T00:00:00" ManagerFK="3" /><br /><Employee EmployeeID="3" Federal_ID="000-00-0002" Name="Bert Parkins" DOB="1947-12-31T00:00:00" StartDate="2000-01-01T00:00:00" /><br />
  54. 54. AUTO Mode<br />SELECT * FROM Employee FOR XML AUTO<br /><Employee EmployeeID="2" Federal_ID="000-00-0001" Name="Andrew Miller" DOB="1968-05-01T00:00:00" StartDate="2000-01-01T00:00:00" ManagerFK="3" /><br /><Employee EmployeeID="3" Federal_ID="000-00-0002" Name="Bert Parkins" DOB="1947-12-31T00:00:00" StartDate="2000-01-01T00:00:00" /><br />
  55. 55. Nested FOR XML Queries<br />SELECT [EmployeeID],<br /> [Name],<br /> ( SELECT [EmployeeID],<br /> [Name]<br /> FROM [Employee]<br /> WHERE ManagerFK = E.EmployeeID<br /> FOR<br /> XML AUTO, TYPE<br /> ) DirectReports<br />FROM [Employee] E<br />FOR XML RAW('Employee')<br /><Employee EmployeeID="2" Name="Andrew Miller"><br /> <DirectReports><br /> <Employee EmployeeID="5" Name="Dave Murrel" /><br /> </DirectReports><br /></Employee><br /><Employee EmployeeID="3" Name="Bert Parkins"><br /> <DirectReports><br /> <Employee EmployeeID="2" Name="Andrew Miller" /><br /> <Employee EmployeeID="4" Name="Brad Barnes" /><br /> </DirectReports><br /></Employee><br />
  56. 56. Control the structure of the resulting XML<br />
  57. 57. PATH Mode<br />
  58. 58. TYPE Mode<br />
  59. 59. EXPLICIT Mode<br />
  60. 60. Add necessary complexity to the resulting XML<br />
  61. 61. NULL values and XSINIL <br />
  62. 62. Generate Schemas<br />
  63. 63. Adding Namespaces <br />
  64. 64. demo<br />
  65. 65. Does moving XML handling into the database improve overall design?<br />
  66. 66. Act III<br />
  67. 67. Developers unaware of SQL Server’s XML abilities are doing extra work<br />
  68. 68. Utilize SQL Server 2005 for database solutions that need to use XML data<br /><XML><br />
  69. 69. XML enables SQL Server to be a complete Data Platform<br />
  70. 70. XML and SQL Server – A Great Combination<br />
  71. 71. JASON FOLLAS<br />http://jasonf-blog.blogspot.com<br />(soon moving to)<br />http://jasonfollas.com<br />jason@jasonfollas.com<br />

×