Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.80 KB | None | 0 0
  1. USE [AdventureWorks2008]
  2. GO
  3. ----zad1
  4. SELECT xml_schema_namespace(N'production',N'ProductDescriptionSchemaCollection');  
  5. GO
  6. --zad2
  7. SELECT TABLE_SCHEMA FROM INFORMATION_SCHEMA.COLUMNS
  8. WHERE DATA_TYPE = 'xml'
  9. GO
  10. --zad3
  11. CREATE XML SCHEMA COLLECTION ProductSchema AS '
  12. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  13. targetNamespace="http://www.microsoft.com/schemas/adventure-works/products"
  14. xmlns:prod="http://www.microsoft.com/schemas/adventure-works/products">
  15. <xs:element name="Product">
  16. <xs:complexType>
  17. <xs:sequence>
  18. <xs:element ref="prod:ProductID" />
  19. <xs:element ref="prod:ProductName" />
  20. <xs:element ref="prod:SupplierID" />
  21. <xs:element ref="prod:CategoryID" />
  22. <xs:element ref="prod:QuantityPerUnit" />
  23. <xs:element ref="prod:UnitPrice" />
  24. <xs:element ref="prod:UnitsInStock" />
  25. <xs:element ref="prod:UnitsOnOrder" />
  26. <xs:element ref="prod:ReorderLevel" />
  27. <xs:element ref="prod:Discontinued" />
  28. </xs:sequence>
  29. </xs:complexType>
  30. </xs:element>
  31. <xs:element name="ProductID" type="xs:integer" />
  32. <xs:element name="ProductName" type="xs:string" />
  33. <xs:element name="SupplierID" type="xs:integer" />
  34. <xs:element name="CategoryID" type="xs:integer" />
  35. <xs:element name="QuantityPerUnit" type="xs:string" />
  36. <xs:element name="UnitPrice" type="xs:double" />
  37. <xs:element name="UnitsInStock" type="xs:integer" />
  38. <xs:element name="UnitsOnOrder" type="xs:integer" />
  39. <xs:element name="ReorderLevel" type="xs:integer" />
  40. <xs:element name="Discontinued" type="xs:boolean" />
  41. </xs:schema>
  42. '
  43. GO
  44.  
  45. ALTER XML SCHEMA COLLECTION ProductSchema ADD
  46. '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  47. targetNamespace="http://www.microsoft.com/schemas/adventure-works/products"
  48. xmlns:prod="http://www.microsoft.com/schemas/adventure-works/products">
  49. <xs:element name="NewField" type="xs:boolean" />
  50. </xs:schema>'
  51.  
  52.  
  53. GO
  54. --zad5
  55. select tot.TotalPurchaseYTD from
  56. (SELECT Demographics.value('declare default element namespace
  57. "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey";
  58. (/IndividualSurvey//TotalPurchaseYTD)[1][. > 5000][. < 10000]', 'float') AS TotalPurchaseYTD
  59. FROM Person.Person) AS
  60. tot where tot.TotalPurchaseYTD is not null
  61. GO
  62.  
  63. --zad6
  64. SELECT Sum(Demographics.value('declare default element namespace
  65. "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey";
  66. (/IndividualSurvey/TotalChildren)[1]','int')) AS Children
  67. FROM Person.Person
  68. GO
  69.  
  70. ----zad7
  71. SELECT
  72. Resume.query('declare namespace
  73. ns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume";
  74. data(/ns:Resume[1]/ns:Address[1]/ns:Addr.Street)') FROM HumanResources.JobCandidate
  75. GO
  76.  
  77. -- zad4
  78.  
  79. CREATE TABLE ProductDoc (ID INT IDENTITY PRIMARY KEY, ProductDoc XML(ProductSchema) NOT NULL)
  80. GO
  81. drop table dbo.ProductDoc
  82. go
  83. DROP XML SCHEMA COLLECTION ProductSchema;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement