482 Chapter11•SQLServerXMLSupport /*customerPhone–VARCHAR(255)*/'555-8746', '<customer><address1>123MainStreet</address1><city>Newark </city><state>DE</state><zip>14785</zip> </customer>') INSERTINTOXML_Table( [customerName], [customerPhone], [customerAddress] )VALUES( /*customerName-VARCHAR(255)*/'JenniferLiddle', /*customerPhone–VARCHAR(255)*/'555-2497', '<customer><address1>45AndrewStreet</address1><city>Clifton </city><state>AH</state><zip>18783</zip> </customer>') To create the primary key for this table, you will use the code shown in Figure 11.3. Figure 11.3 Create Primary XML Index CREATEPRIMARYXMLINDEX[PK_XML_Data_customerAddress] ONXML_Table(customerAddress) Secondary XML indexes are also created on a XML data type column. There are three types of secondary XML indexes (see Table 11.1). Secondary Index Description PATH XML index helps with queries that use XML path expressions. VALUE XML index helps with queries that search for values anywhere in the XML document. PROPERY XML index helps with queries that retrieve particular object properties from within an XML document. Table 11.1 Secondary XML Index Types SQLServerXMLSupport•Chapter11 483 To create a secondary XML index, you must use the CREATE XML INDEX statement. Figure 11.4 shows the syntax for the CREATE XML INDEX. Using the table you created in Figure 11.5, XML_Table, you will create a secondary XML index on the customerAddress column. CREATEXMLINDEXindex_name ONtable_name(xml_column_name) [USINGXMLINDEXxml_index_name [FOR{VALUE|PATH|PROPERTY}] Figure 11.4 CREATE XML INDEX Syntax CREATEXMLINDEX[SD_XML_Data_customerAddress] ONXML_Table(customerAddress) USINGXMLINDEX[PK_XML_Data_customerAddress] FORVALUE Figure 11.5 CREATE XML INDEX Usage Along with creating primary and secondary indexes on XML data type columns, you can also modify these indexes. The ALTER INDEX Transact-SQL DDL statement can be used to modify existing XML indexes. In Figure 11.6, you will modify your secondary index, DB_XML_Data_customerAddress, to turn ALLOW_ ROW_LOCKS OFF. XML indexes are ENABLED by default, but you can DISABLE an XML index. To do so, you set the XML index to DISABLE. You will DISABLE the secondary instance that you created (see Figure 11.7). ALTERINDEX[SD_XML_Data_customerAddress]ONXML_Table SET(ALLOW_ROW_LOCKS=OFF) Figure 11.6 ALTER INDEX Usage ALTERINDEX[SD_XML_Data_customerAddress]onXML_TableDISABLE Figure 11.7 Using ALTER INDEX to DISABLE an Index 484 Chapter11•SQLServerXMLSupport Of course you can drop XML indexes. You use the DROP INDEX Transact- SQL DDL statement. If you drop the primary XML index, any secondary indexes that are present are also dropped. In Figure 11.8, you will drop the secondary index. Ex a m Wa r n i n g SQL Server HTTP endpoints are not supported on SQL Server 2008 Express Edition. HTTP Endpoints In SQL Server 2008, HTTP endpoints provide SQL server developers with new capabilities for using Web Services within SQL Server. It is worth noting that Web Services are not new to SQL Server 2008. SQL Server 2005 introduced HTTP endpoints and allowed you to consume Web Services and map them to SQL Server objects. DROPINDEX[SD_XML_Data_customerAddress]ONXML_Table Figure 11.8 Using DROP INDEX to DROP an XML Index Ex a m Wa r n i n g Native XML Web Services (SOAP/HTTP endpoints) has been deprecated in SQL Server 2008 Http Endpoints Defined HTTP endpoint enables developers to expose stored procedures and functions within a database as methods that can be called from any application using SOAP. SQL Server listens for HTTP requests natively on the server and then processes them; this requires fewer outside components to administer and easy application development and deployment. HTTP endpoint supports protocols such as HTTP, TCP, and payloads such as SOAP, TSQL, SERVICE BROKER, and Database Mirroring. SQLServerXMLSupport•Chapter11 485 Endpoint Can Interface to a Stored Procedure SQL Server stored procedures can be exposed to the HTTP endpoint, making any database object that can be executed or accessed in a stored procedure available to the endpoint. You will see an example of this in the next section. As always, it is very important to consider database security when setting up database objects to be accessed through an endpoint. Be sure to verify that the data that is being made available is safe for exposure to a web service. Underlying stored procedure calls or tables may inadvertently provide more access than intended. Always make sure that you are familiar with the data and any restrictions before providing access. How to Create the Endpoint To create an HTTP endpoint, you first need to determine what object you want to expose from SQL Server. You can expose stored procedures or user-defined functions as the endpoints for the mapping. In this example, you will create a stored procedure that will select against the tblhost table and tbl_host_thresholds table to return the first computer name in the results (see Figure 11.9). Next, you will create the endpoint for this procedure so that it can be used by an application. You can use the Create a 10-point command, as shown in Figure 11.10. CREATEPROCEDURE[dbo].[spGetThresholds] AS selectTop1b.csnamefromtblhost_thresholdsa innerjointblhostbona.hostid=b.id Figure 11.9 CREATE PROCEDURE Code for spGetThresholds CREATEENDPOINT[GetThresholds] STATE=STARTED ASHTTP ( PATH=N'/Thresholds', PORTS=(CLEAR), AUTHENTICATION=(NTLM,KERBEROS,INTEGRATED), SITE=N'W2K3SRVR', Figure 11.10 CREATE ENDPOINT Code for GetThresholds 486 Chapter11•SQLServerXMLSupport CLEAR_PORT=80, COMPRESSION=DISABLED) FORSOAP ( WEBMETHOD'Thresholds'( NAME=N'[MS70432].[dbo].[spGetThresholds]', SCHEMA=DEFAULT, FORMAT=ALL_RESULTS), BATCHES=DISABLED, WSDL=DEFAULT, SESSIONS=DISABLED, SESSION_TIMEOUT=60, DATABASE=N'MS70432', NAMESPACE=N'http://MS70432/Thresholds', SCHEMA=STANDARD, CHARACTER_SET=XML ) The CREATE ENDPOINT has a number of key elements. You will see in your code that the STATE argument is set to STARTED, indicating that the HTTP endpoint listener is running. Review Table 11.2 for the options available for this argument. STATE Argument Description STARTED Endpoint is started and is actively listening for connections. STOPPED Endpoint is stopped. In this state, the server listens to port requests but returns errors to clients. DISABLED Endpoint is disabled. In this state, the server does not listen to the endpoint port or respond to any attempted requests to use the endpoint. Table 11.2 Settings Available for the STATE Argument . drop the secondary index. Ex a m Wa r n i n g SQL Server HTTP endpoints are not supported on SQL Server 2008 Express Edition. HTTP Endpoints In SQL Server 2008, HTTP endpoints provide SQL server. within SQL Server. It is worth noting that Web Services are not new to SQL Server 2008. SQL Server 2005 introduced HTTP endpoints and allowed you to consume Web Services and map them to SQL Server. methods that can be called from any application using SOAP. SQL Server listens for HTTP requests natively on the server and then processes them; this requires fewer outside components to administer