lang_delete.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html><head>
  3. <title>SQLite Query Language: DELETE</title>
  4. <style type="text/css">
  5. body {
  6. margin: auto;
  7. font-family: Verdana, sans-serif;
  8. padding: 8px 1%;
  9. }
  10. a { color: #45735f }
  11. a:visited { color: #734559 }
  12. .logo { position:absolute; margin:3px; }
  13. .tagline {
  14. float:right;
  15. text-align:right;
  16. font-style:italic;
  17. width:240px;
  18. margin:12px;
  19. margin-top:58px;
  20. }
  21. .toolbar {
  22. font-variant: small-caps;
  23. text-align: center;
  24. line-height: 1.6em;
  25. margin: 0;
  26. padding:1px 8px;
  27. }
  28. .toolbar a { color: white; text-decoration: none; padding: 6px 12px; }
  29. .toolbar a:visited { color: white; }
  30. .toolbar a:hover { color: #80a796; background: white; }
  31. .content { margin: 5%; }
  32. .content dt { font-weight:bold; }
  33. .content dd { margin-bottom: 25px; margin-left:20%; }
  34. .content ul { padding:0px; padding-left: 15px; margin:0px; }
  35. /* rounded corners */
  36. .se { background: url(images/se.png) 100% 100% no-repeat #80a796}
  37. .sw { background: url(images/sw.png) 0% 100% no-repeat }
  38. .ne { background: url(images/ne.png) 100% 0% no-repeat }
  39. .nw { background: url(images/nw.png) 0% 0% no-repeat }
  40. </style>
  41. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  42. </head>
  43. <body>
  44. <div><!-- container div to satisfy validator -->
  45. <a href="lang.html">
  46. <h2 align="center">SQL As Understood By SQLite</h2></a><h1>DELETE</h1><h4><a href="syntaxdiagrams.html#delete-stmt">delete-stmt:</a></h4><blockquote> <img alt="syntax diagram delete-stmt" src="images/syntax/delete-stmt.gif"></img> </blockquote>
  47. <h4><a href="syntaxdiagrams.html#qualified-table-name">qualified-table-name:</a></h4><blockquote> <img alt="syntax diagram qualified-table-name" src="images/syntax/qualified-table-name.gif"></img> </blockquote>
  48. <p>The DELETE command is used to remove records from a table.
  49. The command consists of the "DELETE FROM" keywords followed by
  50. the name of the table from which records are to be removed.
  51. </p>
  52. <p>Without a WHERE clause, all rows of the table are removed.
  53. If a WHERE clause is supplied, then only those rows that match
  54. the expression are removed.</p>
  55. <h3>Restrictions on DELETE Statements Within CREATE TRIGGER</h3>
  56. <p>There are additional syntax restrictions on DELETE statements that
  57. occur within the body of a <a href="lang_createtrigger.html">CREATE TRIGGER</a> statement. The <i>table-name</i>
  58. must be unqualified.
  59. In other words, the <i>database-name</i><b>.</b> prefix
  60. on the table name is not allowed within triggers.
  61. The table from which to delete must be in the same
  62. database as the table to which the trigger is attached.</p>
  63. <p>The INDEXED BY and NOT INDEXED clauses are not allowed on DELETE
  64. statements within triggers.</p>
  65. <p>The LIMIT clause (described below) is unsupported within triggers.</p>
  66. <a name="trucateopt"></a>
  67. <h3>The Truncate Optimization</h3>
  68. <p>When the WHERE is omitted from a DELETE statement and the table
  69. being deleted has no triggers,
  70. SQLite uses an optimization to erase the entire table content
  71. without having to visit each row of the table individual.
  72. This "truncate" optimization makes the delete run much faster.
  73. Prior to SQLite version 3.6.5, the truncate optimization
  74. also meant that the sqlite3_changes() and
  75. sqlite3_total_changes() interfaces
  76. and the <a href="pragma.html#pragma_count_changes">count_changes pragma</a>
  77. will not actually return the number of deleted rows.
  78. That problem has been fixed as of version 3.6.5.
  79. <p>The truncate optimization can be permanently disabled for all queries
  80. by recompiling
  81. SQLite with the <a href="compile.html#omit_truncate_optimization">SQLITE_OMIT_TRUNCATE_OPTIMIZATION</a> compile-time switch.</p>
  82. <p>The truncate optimization can also be disabled at runtime using
  83. the sqlite3_set_authorizer() interface. If an authorizer callback
  84. returns SQLITE_IGNORE for an SQLITE_DELETE action code, then
  85. the DELETE operation will proceed but the truncate optimization will
  86. be bypassed and rows will be deleted one by one.</p>
  87. <h3>Use Of LIMIT</h3>
  88. <p>If SQLite is compiled with the <a href="compile.html#enable_update_delete_limit">SQLITE_ENABLE_UPDATE_DELETE_LIMIT</a>
  89. compile-time option, then the syntax of the DELETE statement is
  90. extended by the addition of optional ORDER BY and LIMIT clauses:</p>
  91. <h4><a href="syntaxdiagrams.html#delete-stmt-limited">delete-stmt-limited:</a></h4><blockquote> <img alt="syntax diagram delete-stmt-limited" src="images/syntax/delete-stmt-limited.gif"></img> </blockquote>
  92. <p>The optional LIMIT clause can be used to limit the number of
  93. rows deleted, and thereby limit the size of the transaction.
  94. The ORDER BY clause is used only to determine which rows fall
  95. within the LIMIT. The order in which rows are deleted is arbitrary
  96. and is not determined by the ORDER BY clause.</p>
  97. <p>The presence of a LIMIT clause defeats the truncate optimization
  98. causing all rows being deleted to be visited.</p>