Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
4.3 KiB

  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  2. <html>
  3. <head>
  4. <title>Indexing Service: SQL Query Syntax Tips</title>
  5. <script language="JavaScript">
  6. version = navigator.appVersion
  7. if (version.substring(0,1) == "2") {document.writeln('<link rel="stylesheet" disable="true" type="text/css" href="/iishelp/common/cocss.css">')} else
  8. document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">')
  9. //></script>
  10. <META NAME="DESCRIPTION" CONTENT="Gives basic tips for building effective queries in SQL">
  11. </head>
  12. <body bgcolor="#FFFFFF">
  13. <p><font size=6><strong>Tips for Searching using SQL</strong></font></p>
  14. <!--Chaptoc-->
  15. <hr>
  16. <h3>The SELECT Statement</h3>
  17. <p>Use the SELECT statement to retrieve rows. The SELECT statement consists of:
  18. <ul>
  19. <li> the <I>SELECT-list</I> which identifies the columns (properties) of interest, </li>
  20. <li> the <I>FROM clause</I> which specifies the scope (the set of files) for the search, and </li>
  21. <li> the <I>WHERE clause</I> which is the search criteria.</li>
  22. </ul>
  23. If the results must be ordered, you can add an additional <I>ORDER BY</I> clause to return
  24. the rows in ascending or descending order.
  25. <p><b>Example</b>
  26. <p>
  27. <code>SELECT DocAuthor, size, DocTitle <br>
  28. FROM SCOPE(' "/IISSamples/ISSamples" ') WHERE CONTAINS(' "index server" ') > 0 ORDER BY size
  29. </code>
  30. <h4>The FROM Clause</h4>
  31. <p>The FROM clause of the SELECT statement is used to specify the files on which to perform the
  32. search; that is, use the FROM clause to define the query scope. You can use the SCOPE()�function,
  33. which is the main component of the FROM clause.
  34. The SCOPE function can take zero or more comma-separated Scope_Arguments (that is, <I>Traversal_Type</I> and
  35. <I>Path</I> combinations). You can specify SCOPE with an empty argument list, or (). This is the default
  36. scope that uses the virtual root ( / ) as its path. Each Scope_Argument must be surrounded by single
  37. quotes (see Examples below).
  38. <p>In addition to using Scope(), you can also refer to any one of a set of predefined views of
  39. Indexing Service properties that are often queried against. You can reference one of these pre-defined
  40. views in the FROM clause by specifying the pre-defined View_Name.
  41. <p><b>Examples</b>
  42. <p>
  43. <code>
  44. SELECT DocAuthor, size FROM SCOPE() WHERE size > 500000
  45. <p>
  46. SELECT DocAuthor, size <br>
  47. FROM SCOPE(' SHALLOW TRAVERSAL OF "D:\Contracts\open" ',' DEEP TRAVERSAL OF "/Reports/Year 97" ')<br>
  48. WHERE CONTAINS(DocAuthor, ' "John" ') > 0
  49. <p>
  50. SELECT * FROM EXTENDED_WEBINFO <br>
  51. WHERE CONTAINS(DocSubject, ' "index server" NEAR() "internet information server" ') > 0
  52. </code>
  53. <h4>The WHERE Clause</h4>
  54. <p>The WHERE clause of the SELECT statement specifies which rows in the virtual table defined by
  55. the FROM clause make up the resulting rowset. The WHERE clause consists of one or more search conditions (that is,
  56. one or more predicates combined with AND, OR and NOT) that filter out rows for which the search
  57. condition is false.
  58. <p><b>Examples</b>
  59. <p>
  60. <code>
  61. SELECT FileName, size FROM SCOPE() WHERE DocTitle = 'Financial Data' OR DocAuthor = 'John Smith'
  62. <p>
  63. SELECT FileName, DocAuthor FROM FILEINFO WHERE size < 10000 OR DocWordCount <= 800
  64. <p>
  65. SELECT DocTitle, FileName, write FROM SCOPE() <br>
  66. WHERE CONTAINS (' "Index" NEAR() "Server" NEAR() "Microsoft"') > 0 AND size < 5000
  67. </code>
  68. <h3>The ORDER BY Clause</h3>
  69. <p>The optional ORDER BY clause can be appended to the SELECT statement to sort the rows returned in the
  70. rowset according to a specified set of criteria. Results are sorted by default in ascending order.
  71. To sort in descending order, specify DESC after the column name.
  72. <p><b>Example</b>
  73. <code>
  74. <p>
  75. SELECT FileName, DocTitle, size, rank FROM SCOPE(' "/MyDocs/Specs97", "/YourDocs/Specs97" ')<br>
  76. WHERE FREETEXT (' "How do I index my HTML pages" ') > 0 ORDER BY rank, size DESC
  77. </code>
  78. <p><p>For a more detailed description of the SQL syntax supported in Indexing Service, including use of the
  79. <I>CONTAINS</I> and <I>FREETEXT</I> predicates as illustrated in the examples on this page, please refer
  80. to the <a href="/iishelp/ix/htm/ixseovr.htm">SQL Access To Indexing Service Data</a> page in the product documentation.
  81. <p>
  82. <hr class="iis" size="1">
  83. <p align="center"><em><a href="/iishelp/common/colegal.htm">&copy; 1997-1999 by Microsoft Corporation. All rights reserved.</a></em></p>
  84. </font>
  85. </body>
  86. </html>