Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

cdn.s3techtraining.com
from cdn.s3techtraining.com More from this publisher
17.06.2013 Views

Chapter 16: A Brief XML Primer SQL Server strips out any whitespace between tags, so if you create a schema collection with all sorts of pretty indentations for readability, SQL Server will remove them for the sake of efficient storage. Creating, Altering, and Dropping XML Schema Collections The CREATE, ALTER, and DROP notions for XML schema collections work in a manner that is mostly consistent with how other such statements have worked thus far in SQL Server. We’ll run through them here, but pay particular attention to the ALTER statement, as it is the one that has a few quirks we haven’t seen in other ALTER statements we’ve worked with. CREATE XML SCHEMA COLLECTION 490 Again, note that the default number of characters returned for text results in Management Studio is only 256 characters. If you’re using text view, you will want to go Tools ➪ Options ➪ Query Results ➪ SQL Server ➪ Results to Text and change the maximum number of characters displayed. Again, the CREATE is your typical CREATE syntax that we’ve seen throughout the book, and uses the AS keyword we’ve seen with stored procedures, views, and other less structured objects: CREATE XML SCHEMA COLLECTION [.] AS { | } So if, for example, we wanted to create an XML schema collection that is similar to the Production .ManuInstructionsSchemaCollection collection in AdventureWorks2008, we might execute something like the following: CREATE XML SCHEMA COLLECTION ProductDescriptionSchemaCollectionSummaryRequired AS ‘

Chapter 16: A Brief XML Primer ’; Note that the URL portion of the namespace declaration must be entered on a single line. It is shown here word wrapped onto multiple lines because there is a limit to the number of characters we can show per line in print. Make sure you include the entire URL on a single line. This one happens to be just like the Production.ManuInstructionsSchemaCollection schema collection, but I’ve altered the schema to require the summary element rather than having it optional. Since the basic structure is the same, I utilized the same namespaces. ALTER XML SCHEMA COLLECTION This one is just slightly different from other ALTER statements in the sense that it is limited to just adding new pieces to the collection. The syntax looks like this: ALTER XML SCHEMA COLLECTION [.] ADD { | } I would not be at all surprised if the functionality of this is boosted a bit in a later service pack, but, in the meantime, let me stress that this is a tool for adding to your schema collection rather than changing or removing what’s there. DROP XML SCHEMA COLLECTION This is one of those classic “does what it says” things and works just like any other DROP: DROP XML SCHEMA COLLECTION [.] 491

Chapter 16: A Brief XML Primer<br />

<strong>SQL</strong> <strong>Server</strong> strips out any whitespace between tags, so if you create a schema collection with all sorts of<br />

pretty indentations for readability, <strong>SQL</strong> <strong>Server</strong> will remove them for the sake of efficient storage.<br />

Creating, Altering, and Dropping XML Schema Collections<br />

The CREATE, ALTER, and DROP notions for XML schema collections work in a manner that is mostly consistent<br />

with how other such statements have worked thus far in <strong>SQL</strong> <strong>Server</strong>. We’ll run through them<br />

here, but pay particular attention to the ALTER statement, as it is the one that has a few quirks we<br />

haven’t seen in other ALTER statements we’ve worked with.<br />

CREATE XML SCHEMA COLLECTION<br />

490<br />

Again, note that the default number of characters returned for text results in Management<br />

Studio is only 256 characters. If you’re using text view, you will want to go<br />

Tools ➪ Options ➪ Query Results ➪ <strong>SQL</strong> <strong>Server</strong> ➪ Results to Text and change the<br />

maximum number of characters displayed.<br />

Again, the CREATE is your typical CREATE syntax that we’ve seen<br />

throughout the book, and uses the AS keyword we’ve seen with stored procedures, views, and other less<br />

structured objects:<br />

CREATE XML SCHEMA COLLECTION [.] <br />

AS { | }<br />

So if, for example, we wanted to create an XML schema collection that is similar to the Production<br />

.ManuInstructionsSchemaCollection collection in AdventureWorks<strong>2008</strong>, we might execute something<br />

like the following:<br />

CREATE XML SCHEMA COLLECTION ProductDescriptionSchemaCollectionSummaryRequired<br />

AS<br />

‘<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!