XML IN THE DATABASE: THE XML DATA TYPE

XML IN THE DATABASE: THE XML DATA TYPE < ! This fails with an unknown encoding error > < ?xml version= 1.0 encoding= i-bogus ?> XML data type columns can have NULL constraints (the default nullability is the current default of your SQL Server session). CHECK constraints based on the XML Infoset model are supported, using methods that are specific to the XML type. Although we ll talk about the methods in more detail in the next chapter, a typical check constraint on an XML type is shown next. pdoc must have a person element as a child of the people root CREATE TABLE xmltab( id INTEGER PRIMARY KEY, pdoc XML CHECK (pdoc.exist( /people/person )=1) ) Because XML data types follow the XML Infoset data model, they are constrained not by relational constraints, but by a collection of one or more XMLschemas. SQLServer s XMLdata type supports schema validation. We will explore this in detail in the next section. The XML data type supports an implicit conversion from any character or National character data type, but not from other SQL Server data types. This includes CHAR, VARCHAR, NCHAR, and NVARCHAR. You can use CAST or CONVERTto convert BINARY, VARBINARY, TEXT, NTEXT, and IMAGEdata types to the XML data type for storage as well. Casting from TEXT and NTEXT is permitted to enable forward compatibility for users who have stored their XML data in these data types in previous versions of SQL Server. Casting from the BINARY data types is useful for features like SQL Server Service Broker that can communicate using binary or XML. In addition, you can store a SQL_VARIANTdata type into an XMLdata type table after casting it to a character-based type. Listing 8-1 shows inserting rows into a table containing an XMLdata type. Listing 8-1: Inserting Rows into a Table with an XML Data Type CREATE TABLE xml_tab( the_id INTEGER PRIMARY_KEY IDENTITY, xml_col XML) GO

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Cheap Web Hosting services

Bookmark the permalink.

Comments are closed.