Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning Regular Expressions 2005.pdf
Скачиваний:
95
Добавлен:
17.08.2013
Размер:
25.42 Mб
Скачать

Regular Expression Functionality in SQL Server 2000

Figure 16-12

How It Works

The pattern Ad% matches last names that begin with the character A, followed by the character d.

The pattern A[^d]% matches last names that begin with the character A followed by any character but d. The character class [^d] signifies any character but d.

The pattern A[^a-k]% matches last names that begin with A and have a second character not in the range a through k. The % metacharacter matches zero or more characters of any kind in the third and later characters of the last name.

Using Full-Text Search

SQL Server Full-Text Search was introduced in SQL Server 7.0. Full-Text Search isn’t an integral part of SQL Server 2000 at all, because it uses the MSSearch service component, originally derived from

Indexing Server, to create indexes that are external to SQL Server. Because the full-text indexes are external to SQL Server, they are not updated automatically in the way that regular indexes are updated.

379

Chapter 16

A full-text index is contained in a full-text catalog. A full-text catalog is stored in the file system, not in a SQL Server database, although the catalog and its indexes are administered through the database. The full-text catalog for an instance of SQL Server 2000 must reside on the hard disk that is local to the SQL Server instance.

The following table summarizes a comparison between full-text indexes and SQL Server indexes.

Full-Text Index

SQL Server 2000 Index

 

 

Grouped into full-text catalogs.

Not grouped.

Only one catalog per SQL Server

 

database that s full-text indexed.

 

Stored in the file system. Administered

Stored in connection with the database with which

through the relational database with

they are associated.

which they are associated.

 

Maximum of one full-text index per

More than one index is permitted per table.

SQL Server table.

 

Population of the full-text index can occur

Updated automatically when data is inserted,

on a scheduled basis, in response to

deleted, or updated.

change of data, or manually.

 

SQL Server 2000 Enterprise Manager,

SQL Server 2000 Enterprise Manager, wizards, or

wizards, or stored procedures are used

Transact-SQL statements are used to create and

to create, manage, or drop full-text indexes.

drop regular indexes.

 

 

To use full-text search functionality, the relevant full-text indexes must first be created. In this example, you will add full-text indexing related to the pubs database. You can use several techniques to create full-text indexing. The technique using the SQL Server 2000 Enterprise Manager is described here.

Try It Out

Enabling and Creating a Full-Text Index

1.Open SQL Server 2000 Enterprise Manager, and in the left pane, navigate to the pubs database so that it is highlighted as shown in Figure 16-13.

2.Double-click the Full-Text Catalog icons to confirm whether or not any full-text catalogs already exist on the pubs database. The likelihood is that there are none.

3.Click the Back button (a left-pointing arrow) situated near the top-left corner of the Enterprise Manager, and click the titles table.

4.From the Tools menu, select Full-Text Indexing. The initial screen of the Full-Text Indexing Wizard, shown in Figure 16-14, is displayed.

380

Regular Expression Functionality in SQL Server 2000

Figure 16-13

Figure 16-14

381

Chapter 16

5.Click the Next button. There is only one possible index on the titles table, so no other option is available from the drop-down list.

Figure 16-15 shows the screen where you may be offered a choice about which column to use for indexing. (As previously noted, in the titles table of the pubs database, there is only one option.)

Figure 16-15

6.On the next screen, check the check boxes for the title and notes columns, and click the Next button.

Figure 16-16 shows the screen where the selection of columns to index is made.

382

Figure 16-16

 

Regular Expression Functionality in SQL Server 2000

7.Choose a name for the catalog. I called the one I created on my machine Chap16.

8.Optionally, you can choose a location for the catalog that is different from the default location.

9.Click the Next button. So far, you have specified the creation of a catalog and index, and what they will contain. Now you need to specify when they are to be populated with the indexing information.

10.On the next screen, you are asked to specify options for populating the index. Click the New Catalog Schedule button. Figure 16-17 shows the appearance.

Figure 16-17

11.In the next window, specify a time to populate the index. Select the Full Population and One Time radio buttons.

12.Assuming that you want to populate the index straight away, choose an appropriate time a few minutes later than the current time. Figure 16-18 shows the appearance.

13.Click OK; then click Next; and finally, click Finish.

You will see some messages as the Full-Text Indexing Wizard attempts to implement the choices you have made on the various screens of the wizard. Assuming that there are no errors, you should see a screen that appears similar to Figure 16-19.

The message tells you that the index has not yet been populated. Assuming that you have opted in Step 11 to do a full population at a time only a few minutes away, you may want to wait until that time arrives and the population takes place.

383

Chapter 16

Figure 16-18

Figure 16-19

14.With the pubs database selected in Enterprise Manager, double-click the Full-Text Indexes option. If Chap16 (or whatever you chose to call your index) has been created correctly, it will be displayed there. If population hasn’t started, you will see Idle in the Status column, and the Last Population Date column will be blank.

You have the option to carry out a full population under manual control.

15.Right-click the Chap16 catalog, and in the context menu, click the Start Full Population option, which is shown in Figure 16-20.

The pubs database is small, so on a fast machine, full population is almost instantaneous. Once the catalog has been populated, you will see a date and a time displayed in the Last Population Date column. Figure 16-21 shows the appearance when population has completed.

The description of the process of full-text indexing has been pretty detailed, because if you fail to set the catalog and index up correctly, you won’t be able to work through the following examples. Assuming that all has gone well, you are now ready to explore full-text search functionality.

384

Regular Expression Functionality in SQL Server 2000

Figure 16-20

Figure 16-21

385