Beruflich Dokumente
Kultur Dokumente
Querying Metadata,
XML, and Full-Text
Indexes
Module 7: Querying Metadata, XML, and Full-Text
Indexes
Querying Metadata
Overview of XML
Compatibility Views
Name Type_desc
SELECT name, type_desc Product USER_TABLE
FROM sys.tables; Employee USER_TABLE
Customer USER_TABLE
Information
Schema
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'Product';
Information Schema View Examples
COLUMN_NAME
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS Name
TABLE_NAME
SELECT TABLE_NAME
vIndividualCustomer
FROM INFORMATION_SCHEMA.VIEWS
vPersonDemographics
WHERE TABLE_SCHEMA = NSales';
vSalesPerson
vStoreWithContacts
TABLE_NAME
SELECT TABLE_NAME
AddressType
FROM INFORMATION_SCHEMA.TABLES
StateProvince
WHERE TABLE_SCHEMA = NPerson';
BusinessEntity
ContactType
Dynamic Management Views and Functions
Examples
Category View Function
Execution dm_exec_requests dm_exec_sql_text
sp_databases DATABASEPROPERTY
sp_tables COLUMNPROPERTY
sp_columns OBJECTPROPERTY
sp_statistics COL_LENGTH
sp_pkeys DB_NAME
sp_fkeys DB_ID
Scenario 1:
Sharing structured data between systems
Scenario 2:
Sharing data on the Internet
Scenario 3:
Encoding documents
Scenario 4:
Serializing data
XML
Business Scenarios Where XML Is Used
Scenario 1:
Insurance Claims
Scenario 2:
Automobile Manufacturer and Parts Suppliers I
Scenario 3:
Automobile Manufacturer and Parts Suppliers II
Scenario 4:
Content Management System
Scenario 5:
Customer Survey
XML
How SQL Server 2008 Implements XML
The XML data type is a built-in data type in SQL Server for storing
and interacting with XML data
The XML data type supports five methods for interacting with the
data that it contains
Accepts XQuery statements to retrieve elements of
Query
the XML data
SELECT Cust.CustomerID,
OrderHeader.CustomerID,
OrderHeader.SalesOrderID,
OrderHeader.Status,
Cust.CustomerType
FROM Sales.Customer Cust, Sales.SalesOrderHeader OrderHeader
WHERE Cust.CustomerID = OrderHeader.CustomerID
ORDER BY Cust.CustomerID
FOR XML AUTO {RAW(ElementName) | EXPLICIT}
SELECT @xml_text =
'<root><person LastName="White" FirstName="Johnson"/>
<person LastName="Green" FirstName="Marjorie"/>
<person LastName="Carson" FirstName="Cheryl"/></root>'
SELECT * FROM
OPENXML(@i, '/root/person') WITH (LastName nvarchar(50),
FirstName nvarchar(50))
EXEC sp_xml_removedocument @i
LastName FirstName
White Johnson
Green Marjorie
Carson Cheryl
Querying XML Using XQuery
SELECT Instructions.query('
declare namespace AWMI="http://schemas.microsoft.com
/sqlserver/2004/07/adventureworks/ProductModelManuInstructions";
for $T in //AWMI:tool
let $L := //AWMI:Location[.//AWMI:tool[.=data($T)]]
return
<tool desc="{data($T)}" Locations="{data($L/@LocationID)}"/>
') as Result
FROM Production.ProductModel
where ProductModelID=7
Result
<tool desc=hammer Locations=30/>
Generating XML-Based Reports
Use Cases
Full population
Results
Full-Text
Query
Index Data Table
Query Processor
How to Implement Full-Text Indexes in SQL
Server 2008
Full-Text Functions
Results:
We had to run in gym class
The politician decided to run for office
Full-Text Search
Results:
We had to run in gym class
The politician decided to run for office
My car is not running
He had to rest after he ran a mile
Doctors say running is a healthy hobby
The CONTAINS Predicate
SELECT Name
FROM Production.Product
WHERE CONTAINS(Name, ' "Chain*" ');
SELECT Title
FROM Production.Document
WHERE FREETEXT (Document, 'vital safety components' );
Logon information