Hex Artifact Content
Not logged in

Artifact 7c048675f80cd9e1a69f7a9f02ded1dcb19c2c85:

Wiki page [Drop-RenameTable and RenameColumn] by sandro 2019-12-24 11:09:17.
0000: 44 20 32 30 31 39 2d 31 32 2d 32 34 54 31 31 3a  D 2019-12-24T11:
0010: 30 39 3a 31 37 2e 36 38 36 0a 4c 20 44 72 6f 70  09:17.686.L Drop
0020: 2d 52 65 6e 61 6d 65 54 61 62 6c 65 5c 73 61 6e  -RenameTable\san
0030: 64 5c 73 52 65 6e 61 6d 65 43 6f 6c 75 6d 6e 0a  d\sRenameColumn.
0040: 50 20 66 63 37 35 35 38 61 62 62 35 61 30 64 65  P fc7558abb5a0de
0050: 62 36 31 64 66 31 39 62 62 34 36 64 33 66 62 62  b61df19bb46d3fbb
0060: 33 66 35 39 62 33 66 65 66 66 0a 55 20 73 61 6e  3f59b3feff.U san
0070: 64 72 6f 0a 57 20 31 32 35 32 34 0a 42 61 63 6b  dro.W 12524.Back
0080: 20 74 6f 20 3c 61 20 68 72 65 66 3d 22 68 74 74   to <a href="htt
0090: 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69  ps://www.gaia-gi
00a0: 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 62 73  s.it/fossil/libs
00b0: 70 61 74 69 61 6c 69 74 65 2f 77 69 6b 69 3f 6e  patialite/wiki?n
00c0: 61 6d 65 3d 35 2e 30 2e 30 2d 64 6f 63 22 3e 35  ame=5.0.0-doc">5
00d0: 2e 30 2e 30 2d 64 6f 63 20 6d 61 69 6e 20 70 61  .0.0-doc main pa
00e0: 67 65 3c 2f 61 3e 3c 68 72 3e 3c 62 72 3e 0d 0a  ge</a><hr><br>..
00f0: 3c 68 31 3e 49 6e 74 72 6f 64 75 63 74 69 6f 6e  <h1>Introduction
0100: 3c 2f 68 31 3e 0d 0a 41 6c 6c 20 68 69 73 74 6f  </h1>..All histo
0110: 72 69 63 61 6c 20 76 65 72 73 69 6f 6e 73 20 6f  rical versions o
0120: 66 20 3c 62 3e 53 51 4c 69 74 65 33 3c 2f 62 3e  f <b>SQLite3</b>
0130: 20 68 61 76 65 20 61 6c 77 61 79 73 20 70 72 65   have always pre
0140: 73 65 6e 74 65 64 20 73 65 76 65 72 61 6c 20 6c  sented several l
0150: 69 6d 69 74 61 74 69 6f 6e 73 20 61 66 66 65 63  imitations affec
0160: 74 69 6e 67 20 74 68 65 20 69 6d 70 6c 65 6d 65  ting the impleme
0170: 6e 74 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 73  ntation of the s
0180: 74 61 6e 64 61 72 64 20 53 51 4c 20 73 74 61 74  tandard SQL stat
0190: 65 6d 65 6e 74 20 3c 62 3e 41 4c 54 45 52 20 54  ement <b>ALTER T
01a0: 41 42 4c 45 3c 2f 62 3e 3a 0d 0a 3c 75 6c 3e 0d  ABLE</b>:..<ul>.
01b0: 0a 3c 6c 69 3e 3c 62 3e 41 4c 54 45 52 20 54 41  .<li><b>ALTER TA
01c0: 42 4c 45 20 3c 69 3e 6f 6c 64 5f 6e 61 6d 65 3c  BLE <i>old_name<
01d0: 2f 69 3e 20 52 45 4e 41 4d 45 20 54 4f 20 3c 69  /i> RENAME TO <i
01e0: 3e 6e 65 77 5f 6e 61 6d 65 3c 2f 69 3e 3c 2f 62  >new_name</i></b
01f0: 3e 20 77 61 73 20 65 66 66 65 63 74 69 76 65 6c  > was effectivel
0200: 79 20 73 75 70 70 6f 72 74 65 64 2c 20 62 75 74  y supported, but
0210: 20 74 68 65 20 6e 61 6d 65 20 63 68 61 6e 67 65   the name change
0220: 20 73 69 6d 70 6c 79 20 61 70 70 6c 69 65 64 20   simply applied 
0230: 74 6f 20 74 68 65 20 74 61 72 67 65 74 20 54 61  to the target Ta
0240: 62 6c 65 20 69 74 73 65 6c 66 2e 3c 62 72 3e 0d  ble itself.<br>.
0250: 0a 49 74 20 64 69 64 6e 27 74 20 70 72 6f 70 61  .It didn't propa
0260: 67 61 74 65 20 74 6f 20 61 6c 6c 20 64 65 70 65  gate to all depe
0270: 6e 64 69 6e 67 20 46 6f 72 65 69 67 6e 20 4b 65  nding Foreign Ke
0280: 79 73 2c 20 54 72 69 67 67 65 72 73 20 61 6e 64  ys, Triggers and
0290: 20 56 69 65 77 73 2c 20 74 68 75 73 20 65 61 73   Views, thus eas
02a0: 69 6c 79 20 6c 65 61 64 69 6e 67 20 74 6f 20 61  ily leading to a
02b0: 6e 20 69 6e 63 6f 6e 73 69 73 74 65 6e 74 20 61  n inconsistent a
02c0: 6e 64 20 62 75 67 67 79 20 44 42 20 6c 61 79 6f  nd buggy DB layo
02d0: 75 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62  ut.</li>..<li><b
02e0: 3e 41 4c 54 45 52 20 54 41 42 4c 45 20 3c 69 3e  >ALTER TABLE <i>
02f0: 74 62 6c 5f 6e 61 6d 65 3c 2f 69 3e 20 52 45 4e  tbl_name</i> REN
0300: 41 4d 45 20 43 4f 4c 55 4d 4e 20 3c 69 3e 6f 6c  AME COLUMN <i>ol
0310: 64 5f 63 6f 6c 3c 2f 69 3e 20 54 4f 20 3c 69 3e  d_col</i> TO <i>
0320: 6e 65 77 5f 63 6f 6c 3c 2f 69 3e 3c 2f 62 3e 20  new_col</i></b> 
0330: 77 61 73 6e 27 74 20 73 75 70 70 6f 72 74 65 64  wasn't supported
0340: 20 61 74 20 61 6c 6c 2e 3c 2f 6c 69 3e 0d 0a 3c   at all.</li>..<
0350: 2f 75 6c 3e 0d 0a 41 6c 6c 20 74 68 69 73 20 77  /ul>..All this w
0360: 61 73 20 69 6e 63 6f 6e 73 69 73 74 65 6e 74 20  as inconsistent 
0370: 66 72 6f 6d 20 74 68 65 20 75 73 75 61 6c 20 62  from the usual b
0380: 65 68 61 76 69 6f 72 20 6f 66 20 6f 74 68 65 72  ehavior of other
0390: 20 53 51 4c 20 44 42 4d 53 65 73 2c 20 61 6e 64   SQL DBMSes, and
03a0: 20 77 61 73 20 65 61 73 69 6c 79 20 70 65 72 63   was easily perc
03b0: 65 69 76 65 64 20 62 79 20 6d 61 6e 79 20 64 65  eived by many de
03c0: 76 65 6c 6f 70 65 72 73 20 61 6e 64 20 75 73 65  velopers and use
03d0: 72 73 20 61 73 20 61 20 6e 61 73 74 79 20 61 6e  rs as a nasty an
03e0: 64 20 75 6e 70 6c 65 61 73 61 6e 74 20 6c 69 6d  d unpleasant lim
03f0: 69 74 61 74 69 6f 6e 2e 3c 62 72 3e 3c 62 72 3e  itation.<br><br>
0400: 0d 0a 54 68 65 20 73 69 74 75 61 74 69 6f 6e 20  ..The situation 
0410: 68 61 73 20 72 61 64 69 63 61 6c 6c 79 20 63 68  has radically ch
0420: 61 6e 67 65 64 20 73 69 6e 63 65 20 74 68 65 20  anged since the 
0430: 72 65 6c 65 61 73 65 64 20 76 65 72 73 69 6f 6e  released version
0440: 20 3c 62 3e 33 2e 32 35 2e 30 3c 2f 62 3e 20 6f   <b>3.25.0</b> o
0450: 66 20 3c 62 3e 3c 69 3e 32 30 31 38 2d 30 39 2d  f <b><i>2018-09-
0460: 31 35 3c 2f 69 3e 3c 2f 62 3e 2e 3c 62 72 3e 0d  15</i></b>.<br>.
0470: 0a 53 51 4c 69 74 65 33 20 6e 6f 77 20 66 75 6c  .SQLite3 now ful
0480: 6c 79 20 73 75 70 70 6f 72 74 73 20 62 6f 74 68  ly supports both
0490: 20 6f 66 20 74 68 65 20 61 62 6f 76 65 20 66 6f   of the above fo
04a0: 72 6d 73 20 6f 66 20 3c 62 3e 41 4c 54 45 52 20  rms of <b>ALTER 
04b0: 54 41 42 4c 45 3c 2f 62 3e 20 61 6e 64 20 74 68  TABLE</b> and th
04c0: 69 73 2c 20 6c 6f 6e 67 6c 79 20 61 77 61 69 74  is, longly await
04d0: 65 64 2c 20 67 6f 6f 64 20 6e 65 77 73 20 6d 65  ed, good news me
04e0: 61 6e 73 20 74 68 61 74 20 53 51 4c 69 74 65 33  ans that SQLite3
04f0: 20 6e 6f 77 20 62 65 68 61 76 65 73 20 69 6e 20   now behaves in 
0500: 74 68 65 20 73 61 6d 65 20 77 61 79 20 61 73 20  the same way as 
0510: 61 6e 79 20 6f 74 68 65 72 20 44 42 4d 53 20 6f  any other DBMS o
0520: 6e 20 74 68 65 20 6d 61 72 6b 65 74 2e 3c 62 72  n the market.<br
0530: 3e 3c 62 72 3e 0d 0a 53 65 65 6e 20 66 72 6f 6d  ><br>..Seen from
0540: 20 74 68 65 20 53 70 61 74 69 61 4c 69 74 65 20   the SpatiaLite 
0550: 70 65 72 73 70 65 63 74 69 76 65 2c 20 70 72 6f  perspective, pro
0560: 62 6c 65 6d 73 20 61 72 69 73 65 20 74 68 61 74  blems arise that
0570: 20 6e 65 65 64 20 74 6f 20 62 65 20 61 64 64 72   need to be addr
0580: 65 73 73 65 64 2e 3c 75 6c 3e 0d 0a 20 3c 6c 69  essed.<ul>.. <li
0590: 3e 41 73 20 61 20 67 65 6e 65 72 61 6c 20 72 75  >As a general ru
05a0: 6c 65 3a 20 61 6c 77 61 79 73 20 61 73 73 75 6d  le: always assum
05b0: 65 20 74 68 61 74 20 3c 62 3e 53 51 4c 69 74 65  e that <b>SQLite
05c0: 33 3c 2f 62 3e 20 64 6f 65 73 20 6e 6f 74 20 6b  3</b> does not k
05d0: 6e 6f 77 20 28 3c 69 3e 6e 6f 72 20 63 61 72 65  now (<i>nor care
05e0: 3c 2f 69 3e 29 20 61 62 6f 75 74 20 41 64 6d 69  </i>) about Admi
05f0: 6e 69 73 74 72 61 74 69 6f 6e 20 54 41 42 4c 45  nistration TABLE
0600: 20 75 73 65 64 20 62 79 20 61 6e 79 20 3c 62 3e   used by any <b>
0610: 65 78 74 65 6e 73 69 6f 6e 73 3c 2f 62 3e 20 28  extensions</b> (
0620: 73 75 63 68 20 61 73 20 3c 62 3e 53 70 61 74 69  such as <b>Spati
0630: 61 4c 69 74 65 3c 2f 62 3e 20 6f 72 20 3c 62 3e  aLite</b> or <b>
0640: 47 65 6f 50 61 63 6b 61 67 65 3c 2f 62 3e 29 2e  GeoPackage</b>).
0650: 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 54 68  </li>..</ul>..Th
0660: 65 72 65 66 6f 72 65 20 61 6e 79 20 75 73 65 20  erefore any use 
0670: 6f 66 20 3c 62 3e 41 4c 54 45 52 20 54 41 42 4c  of <b>ALTER TABL
0680: 45 3c 2f 62 3e 20 6f 6e 20 61 6e 79 20 53 70 61  E</b> on any Spa
0690: 74 69 61 6c 20 54 61 62 6c 65 20 6f 72 20 43 6f  tial Table or Co
06a0: 6c 75 6d 6e 20 77 69 6c 6c 20 68 61 76 65 20 3c  lumn will have <
06b0: 62 3e 3c 69 3e 6e 6f 20 65 66 66 65 63 74 3c 2f  b><i>no effect</
06c0: 69 3e 3c 2f 62 3e 20 6f 6e 20 61 6e 79 20 41 64  i></b> on any Ad
06d0: 6d 69 6e 69 73 74 72 61 74 69 6f 6e 20 54 41 42  ministration TAB
06e0: 4c 45 2c 20 63 61 75 73 69 6e 67 20 74 68 65 20  LE, causing the 
06f0: 63 72 65 61 74 69 6f 6e 20 6f 66 20 61 6e 20 69  creation of an i
0700: 6e 76 61 6c 69 64 20 44 42 20 6c 61 79 6f 75 74  nvalid DB layout
0710: 0d 0a 3c 75 6c 3e 0d 0a 20 3c 6c 69 3e 63 61 75  ..<ul>.. <li>cau
0720: 73 65 64 20 62 79 20 3c 62 3e 62 72 6f 6b 65 6e  sed by <b>broken
0730: 20 6c 69 6e 6b 73 3c 2f 62 3e 20 74 6f 20 61 6c   links</b> to al
0740: 6c 20 75 73 65 64 20 4d 65 74 61 64 61 74 61 20  l used Metadata 
0750: 54 61 62 6c 65 73 20 65 6e 74 72 69 65 73 20 61  Tables entries a
0760: 6e 64 20 53 70 61 74 69 61 6c 20 49 6e 64 69 63  nd Spatial Indic
0770: 65 73 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a  es</li>..</ul>..
0780: 3c 62 72 3e 3c 62 72 3e 0d 0a 54 6f 20 72 65 73  <br><br>..To res
0790: 6f 6c 76 65 20 74 68 69 73 20 69 73 73 75 65 2c  olve this issue,
07a0: 20 61 20 63 6f 6d 70 6c 65 74 65 20 73 65 74 20   a complete set 
07b0: 6f 66 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67  of corresponding
07c0: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 68   SQL functions h
07d0: 61 76 65 20 62 65 65 6e 20 69 6e 74 72 6f 64 75  ave been introdu
07e0: 63 65 64 20 69 6e 20 76 65 72 73 69 6f 6e 20 3c  ced in version <
07f0: 62 3e 35 2e 30 2e 30 3c 2f 62 3e 20 74 6f 20 69  b>5.0.0</b> to i
0800: 6e 73 75 72 65 20 74 68 61 74 20 61 6e 79 20 41  nsure that any A
0810: 64 6d 69 6e 69 73 74 72 61 74 69 6f 6e 20 74 61  dministration ta
0820: 73 6b 73 20 6e 65 65 64 65 64 20 61 72 65 20 64  sks needed are d
0830: 6f 6e 65 20 63 6f 72 72 65 63 74 6c 79 2e 0d 0a  one correctly...
0840: 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 44 72 6f  <ul>..<li><b>Dro
0850: 70 54 61 62 6c 65 28 29 3c 2f 62 3e 3a 20 63 61  pTable()</b>: ca
0860: 6e 20 73 61 66 65 6c 79 20 64 72 6f 70 20 61 20  n safely drop a 
0870: 53 70 61 74 69 61 6c 20 54 61 62 6c 65 2c 20 53  Spatial Table, S
0880: 70 61 74 69 61 6c 20 56 69 65 77 20 6f 72 20 53  patial View or S
0890: 70 61 74 69 61 6c 20 56 69 72 74 75 61 6c 54 61  patial VirtualTa
08a0: 62 6c 65 2e 3c 62 72 3e 0d 0a 41 6e 79 20 64 65  ble.<br>..Any de
08b0: 70 65 6e 64 65 6e 74 20 54 72 69 67 67 65 72 73  pendent Triggers
08c0: 2c 20 53 70 61 74 69 61 6c 20 20 56 69 65 77 73  , Spatial  Views
08d0: 2c 20 53 70 61 74 69 61 6c 20 49 6e 64 65 78 65  , Spatial Indexe
08e0: 73 2c 20 4d 65 74 61 64 61 74 61 20 61 6e 64 20  s, Metadata and 
08f0: 53 74 61 74 69 73 74 69 63 73 20 77 69 6c 6c 20  Statistics will 
0900: 62 65 20 70 72 6f 70 65 72 6c 79 20 72 65 6d 6f  be properly remo
0910: 76 65 64 20 66 75 6c 6c 79 20 70 72 65 73 65 72  ved fully preser
0920: 76 69 6e 67 20 74 68 65 20 44 42 20 6c 61 79 6f  ving the DB layo
0930: 75 74 20 63 6f 6e 73 69 73 74 65 6e 63 79 2e 3c  ut consistency.<
0940: 62 72 3e 0d 0a 54 68 69 73 20 77 69 6c 6c 20 61  br>..This will a
0950: 6c 73 6f 20 77 6f 72 6b 20 6f 6e 20 61 6e 79 20  lso work on any 
0960: 6f 72 64 69 6e 61 72 79 20 28 6e 6f 6e 20 53 70  ordinary (non Sp
0970: 61 74 69 61 6c 29 20 20 54 61 62 6c 65 2c 20 52  atial)  Table, R
0980: 61 73 74 65 72 4c 69 74 65 32 20 52 61 73 74 65  asterLite2 Raste
0990: 72 20 43 6f 76 65 72 61 67 65 2c 20 56 69 72 74  r Coverage, Virt
09a0: 75 61 6c 54 61 62 6c 65 2c 20 47 65 6f 50 61 63  ualTable, GeoPac
09b0: 6b 61 67 65 20 28 56 65 63 74 6f 72 20 2f 20 52  kage (Vector / R
09c0: 61 73 74 65 72 20 54 61 62 6c 65 29 20 61 6e 64  aster Table) and
09d0: 20 4f 47 52 2f 46 44 4f 20 54 61 62 6c 65 2e 3c   OGR/FDO Table.<
09e0: 62 72 3e 0d 0a 3c 69 3e 3c 75 3e 4e 6f 74 65 3c  br>..<i><u>Note<
09f0: 2f 75 3e 3c 2f 69 3e 3a 20 74 68 69 73 20 66 75  /u></i>: this fu
0a00: 6e 63 74 69 6f 6e 20 69 73 20 6e 6f 74 20 64 69  nction is not di
0a10: 72 65 63 74 6c 79 20 72 65 6c 61 74 65 64 20 74  rectly related t
0a20: 6f 20 74 68 65 20 72 65 63 65 6e 74 20 63 68 61  o the recent cha
0a30: 6e 67 65 73 20 69 6e 74 72 6f 64 75 63 65 64 20  nges introduced 
0a40: 62 79 20 53 51 4c 69 74 65 33 0d 0a 3c 75 6c 3e  by SQLite3..<ul>
0a50: 0d 0a 20 3c 6c 69 3e 62 75 74 20 62 65 69 6e 67  .. <li>but being
0a60: 20 63 6c 6f 73 65 6c 79 20 72 65 6c 61 74 65 64   closely related
0a70: 20 74 6f 20 74 68 65 20 61 64 6d 69 6e 69 73 74   to the administ
0a80: 72 61 74 69 6f 6e 20 74 61 73 6b 73 20 66 6f 72  ration tasks for
0a90: 20 53 70 61 74 69 61 6c 20 54 61 62 6c 65 73 2f   Spatial Tables/
0aa0: 56 69 65 77 73 20 68 61 73 20 62 65 65 6e 20 61  Views has been a
0ab0: 64 61 70 74 65 64 2c 20 72 65 70 6c 61 63 69 6e  dapted, replacin
0ac0: 67 20 74 68 65 20 3c 69 3e 64 65 70 72 65 63 61  g the <i>depreca
0ad0: 74 65 64 3c 2f 69 3e 20 3c 62 3e 44 72 6f 70 47  ted</i> <b>DropG
0ae0: 65 6f 54 61 62 6c 65 28 29 3c 2f 62 3e 20 66 75  eoTable()</b> fu
0af0: 6e 63 74 69 6f 6e 20 69 6e 20 66 75 6c 6c 2e 3c  nction in full.<
0b00: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e  /li>..</ul></li>
0b10: 0d 0a 3c 6c 69 3e 3c 62 3e 52 65 6e 61 6d 65 54  ..<li><b>RenameT
0b20: 61 62 6c 65 28 29 3c 2f 62 3e 3a 20 63 61 6e 20  able()</b>: can 
0b30: 73 61 66 65 6c 79 20 72 65 6e 61 6d 65 20 61 20  safely rename a 
0b40: 53 70 61 74 69 61 6c 20 28 6f 72 20 6e 6f 6e 2d  Spatial (or non-
0b50: 53 70 61 74 69 61 6c 29 20 54 61 62 6c 65 2c 20  Spatial) Table, 
0b60: 62 75 74 20 3c 62 3e 63 61 6e 6e 6f 74 20 62 65  but <b>cannot be
0b70: 20 75 73 65 64 3c 2f 62 3e 20 66 6f 72 20 61 6e   used</b> for an
0b80: 79 20 6b 69 6e 64 20 6f 66 20 56 69 65 77 20 6f  y kind of View o
0b90: 72 20 56 69 72 74 75 61 6c 54 61 62 6c 65 2e 3c  r VirtualTable.<
0ba0: 62 72 3e 0d 0a 41 6e 79 20 64 65 70 65 6e 64 65  br>..Any depende
0bb0: 6e 74 20 54 72 69 67 67 65 72 73 2c 20 56 69 65  nt Triggers, Vie
0bc0: 77 73 2c 20 53 70 61 74 69 61 6c 20 49 6e 64 65  ws, Spatial Inde
0bd0: 78 65 73 2c 20 4d 65 74 61 64 61 74 61 20 61 6e  xes, Metadata an
0be0: 64 20 53 74 61 74 69 73 74 69 63 73 20 77 69 6c  d Statistics wil
0bf0: 6c 20 62 65 20 70 72 6f 70 65 72 6c 79 20 75 70  l be properly up
0c00: 64 61 74 65 64 20 66 75 6c 6c 79 20 70 72 65 73  dated fully pres
0c10: 65 72 76 69 6e 67 20 74 68 65 20 44 42 20 6c 61  erving the DB la
0c20: 79 6f 75 74 20 63 6f 6e 73 69 73 74 65 6e 63 79  yout consistency
0c30: 2e 0d 0a 3c 75 6c 3e 0d 0a 20 3c 6c 69 3e 3c 62  ...<ul>.. <li><b
0c40: 3e 56 49 45 57 73 3c 2f 62 3e 3a 20 6f 6e 6c 79  >VIEWs</b>: only
0c50: 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65   the name of the
0c60: 20 3c 62 3e 75 6e 64 65 72 6c 61 79 69 6e 67 3c   <b>underlaying<
0c70: 2f 62 3e 20 54 41 42 4c 45 20 75 73 65 64 20 62  /b> TABLE used b
0c80: 79 20 74 68 65 20 56 49 45 57 20 77 69 6c 6c 20  y the VIEW will 
0c90: 62 65 20 72 65 6e 61 6d 65 64 2e 3c 2f 6c 69 3e  be renamed.</li>
0ca0: 0d 0a 3c 2f 75 6c 3e 0d 0a 54 68 69 73 20 77 69  ..</ul>..This wi
0cb0: 6c 6c 20 61 6c 73 6f 20 77 6f 72 6b 20 6f 6e 20  ll also work on 
0cc0: 61 6e 79 20 6f 72 64 69 6e 61 72 79 20 28 6e 6f  any ordinary (no
0cd0: 6e 20 53 70 61 74 69 61 6c 29 20 54 61 62 6c 65  n Spatial) Table
0ce0: 2c 20 52 61 73 74 65 72 4c 69 74 65 32 20 52 61  , RasterLite2 Ra
0cf0: 73 74 65 72 20 43 6f 76 65 72 61 67 65 2c 20 47  ster Coverage, G
0d00: 65 6f 50 61 63 6b 61 67 65 20 61 6e 64 20 4f 47  eoPackage and OG
0d10: 52 2f 46 44 4f 20 54 61 62 6c 65 2e 3c 2f 6c 69  R/FDO Table.</li
0d20: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 52 65 6e 61 6d 65  >..<li><b>Rename
0d30: 43 6f 6c 75 6d 6e 28 29 3c 2f 62 3e 3a 20 63 61  Column()</b>: ca
0d40: 6e 20 73 61 66 65 6c 79 20 72 65 6e 61 6d 65 20  n safely rename 
0d50: 61 20 53 70 61 74 69 61 6c 20 28 6f 72 20 6e 6f  a Spatial (or no
0d60: 6e 2d 53 70 61 74 69 61 6c 29 2c 20 62 75 74 20  n-Spatial), but 
0d70: 3c 62 3e 63 61 6e 6e 6f 74 20 62 65 20 75 73 65  <b>cannot be use
0d80: 64 3c 2f 62 3e 20 66 6f 72 20 61 6e 79 20 6b 69  d</b> for any ki
0d90: 6e 64 20 6f 66 20 56 69 65 77 20 6f 72 20 56 69  nd of View or Vi
0da0: 72 74 75 61 6c 54 61 62 6c 65 2e 3c 62 72 3e 0d  rtualTable.<br>.
0db0: 0a 41 6e 79 20 64 65 70 65 6e 64 69 6e 67 20 54  .Any depending T
0dc0: 72 69 67 67 65 72 2c 20 56 69 65 77 2c 20 53 70  rigger, View, Sp
0dd0: 61 74 69 61 6c 20 49 6e 64 65 78 2c 20 4d 65 74  atial Index, Met
0de0: 61 64 61 74 61 20 61 6e 64 20 53 74 61 74 69 73  adata and Statis
0df0: 74 69 63 73 20 77 69 6c 6c 20 62 65 20 70 72 6f  tics will be pro
0e00: 70 65 72 6c 79 20 75 70 64 61 74 65 64 20 66 75  perly updated fu
0e10: 6c 6c 79 20 70 72 65 73 65 72 76 69 6e 67 20 74  lly preserving t
0e20: 68 65 20 44 42 20 6c 61 79 6f 75 74 20 63 6f 6e  he DB layout con
0e30: 73 69 73 74 65 6e 63 79 2e 0d 0a 3c 75 6c 3e 0d  sistency...<ul>.
0e40: 0a 20 3c 6c 69 3e 3c 62 3e 56 49 45 57 73 3c 2f  . <li><b>VIEWs</
0e50: 62 3e 3a 20 20 6f 6e 6c 79 20 74 68 65 20 43 6f  b>:  only the Co
0e60: 6c 75 6d 6e 2d 6e 61 6d 65 20 6f 66 20 74 68 65  lumn-name of the
0e70: 20 3c 62 3e 75 6e 64 65 72 6c 61 79 69 6e 67 3c   <b>underlaying<
0e80: 2f 62 3e 20 54 41 42 4c 45 20 75 73 65 64 20 62  /b> TABLE used b
0e90: 79 20 74 68 65 20 56 49 45 57 20 77 69 6c 6c 20  y the VIEW will 
0ea0: 62 65 20 72 65 6e 61 6d 65 64 2e 3c 2f 6c 69 3e  be renamed.</li>
0eb0: 0d 0a 3c 2f 75 6c 3e 0d 0a 57 69 6c 6c 20 61 6c  ..</ul>..Will al
0ec0: 73 6f 20 77 6f 72 6b 20 6f 6e 20 6f 72 64 69 6e  so work on ordin
0ed0: 61 72 79 20 28 6e 6f 6e 20 53 70 61 74 69 61 6c  ary (non Spatial
0ee0: 29 20 43 6f 6c 75 6d 6e 73 2c 20 47 65 6f 50 61  ) Columns, GeoPa
0ef0: 63 6b 61 67 65 20 61 6e 64 20 4f 47 52 2f 46 44  ckage and OGR/FD
0f00: 4f 20 47 65 6f 6d 65 74 72 69 65 73 2e 3c 2f 6c  O Geometries.</l
0f10: 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 53 70 65 63 69  i>..<li><b>Speci
0f20: 61 6c 20 4e 6f 74 65 3c 2f 62 3e 3a 20 53 51 4c  al Note</b>: SQL
0f30: 69 74 65 20 3c 62 3e 43 52 45 41 54 45 20 56 49  ite <b>CREATE VI
0f40: 45 57 3c 2f 62 3e 20 73 79 6e 74 61 78 20 65 78  EW</b> syntax ex
0f50: 70 6c 69 63 69 74 6c 79 20 64 65 63 6c 61 72 69  plicitly declari
0f60: 6e 67 20 63 6f 6c 75 6d 6e 73 3a 0d 0a 3c 75 6c  ng columns:..<ul
0f70: 3e 0d 0a 20 3c 6c 69 3e 54 68 65 20 3c 62 3e 65  >.. <li>The <b>e
0f80: 78 70 6c 69 63 69 74 3c 2f 62 3e 20 64 65 63 6c  xplicit</b> decl
0f90: 61 72 61 74 69 6f 6e 20 6f 66 20 43 6f 6c 75 6d  aration of Colum
0fa0: 6e 73 20 69 6e 20 74 68 65 20 3c 62 3e 43 52 45  ns in the <b>CRE
0fb0: 41 54 45 20 56 49 45 57 3c 2f 62 3e 20 69 73 20  ATE VIEW</b> is 
0fc0: 28 6f 66 66 69 63 69 61 6c 6c 79 29 20 6f 70 74  (officially) opt
0fd0: 69 6f 6e 61 6c 2e 3c 2f 6c 69 3e 0d 0a 20 3c 6c  ional.</li>.. <l
0fe0: 69 3e 55 6e 6f 66 66 69 63 69 61 6c 6c 79 2c 20  i>Unofficially, 
0ff0: 61 6e 79 20 43 6f 6c 75 6d 6e 20 6e 6f 74 20 3c  any Column not <
1000: 62 3e 65 78 70 6c 69 63 69 74 6c 79 3c 2f 62 3e  b>explicitly</b>
1010: 20 64 65 66 69 6e 65 64 20 69 73 20 63 6f 6e 73   defined is cons
1020: 69 64 65 72 65 64 20 3c 69 3e 75 6e 64 65 66 69  idered <i>undefi
1030: 6e 65 64 3c 2f 69 3e 20 61 6e 64 20 53 51 4c 69  ned</i> and SQLi
1040: 74 65 20 77 69 6c 6c 20 61 74 74 65 6d 70 74 20  te will attempt 
1050: 74 6f 20 72 65 73 6f 6c 76 65 20 74 68 65 20 3c  to resolve the <
1060: 62 3e 6f 6c 64 3c 2f 62 3e 20 6e 61 6d 65 20 62  b>old</b> name b
1070: 79 20 6c 6f 6f 6b 69 6e 67 20 69 6e 73 69 64 65  y looking inside
1080: 20 74 68 65 20 75 6e 64 65 72 6c 61 79 69 6e 67   the underlaying
1090: 20 3c 62 3e 54 41 42 4c 45 3c 2f 62 3e 3c 2f 6c   <b>TABLE</b></l
10a0: 69 3e 0d 0a 20 3c 6c 69 3e 4d 6f 72 65 20 69 6e  i>.. <li>More in
10b0: 66 6f 72 6d 61 74 69 6f 6e 20 61 6e 64 20 70 72  formation and pr
10c0: 61 63 74 69 63 61 6c 20 73 61 6d 70 6c 65 73 20  actical samples 
10d0: 6f 6e 20 68 6f 77 20 74 6f 20 3c 62 3e 65 78 70  on how to <b>exp
10e0: 6c 69 63 69 74 6c 79 3c 2f 62 3e 20 64 65 66 69  licitly</b> defi
10f0: 6e 65 20 63 6f 6c 75 6d 6e 73 20 63 61 6e 20 62  ne columns can b
1100: 65 20 66 6f 75 6e 64 20 68 65 72 65 3a 20 3c 61  e found here: <a
1110: 20 68 72 65 66 3d 22 68 74 74 70 73 3a 2f 2f 77   href="https://w
1120: 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f 67  ww.gaia-gis.it/g
1130: 61 69 61 2d 73 69 6e 73 2f 73 70 61 74 69 61 6c  aia-sins/spatial
1140: 69 74 65 2d 63 6f 6f 6b 62 6f 6f 6b 2d 35 2f 63  ite-cookbook-5/c
1150: 6f 6f 6b 62 6f 6f 6b 5f 74 6f 70 69 63 73 2e 61  ookbook_topics.a
1160: 64 6d 69 6e 73 74 72 61 74 69 6f 6e 2e 68 74 6d  dminstration.htm
1170: 6c 23 74 6f 70 69 63 5f 41 64 6d 69 6e 73 74 72  l#topic_Adminstr
1180: 61 74 69 6f 6e 5f 43 52 45 41 54 45 3a 56 49 45  ation_CREATE:VIE
1190: 57 5f 43 4f 4c 55 4d 4e 53 22 3e 3c 62 3e 53 51  W_COLUMNS"><b>SQ
11a0: 4c 69 74 65 3c 2f 62 3e 3a 20 3c 62 3e 43 52 45  Lite</b>: <b>CRE
11b0: 41 54 45 20 56 49 45 57 3c 2f 62 3e 20 73 79 6e  ATE VIEW</b> syn
11c0: 74 61 78 20 3c 62 3e 65 78 70 6c 69 63 69 74 6c  tax <b>explicitl
11d0: 79 3c 2f 62 3e 20 64 65 63 6c 61 72 69 6e 67 20  y</b> declaring 
11e0: 63 6f 6c 75 6d 6e 73 3c 2f 61 3e 3c 2f 6c 69 3e  columns</a></li>
11f0: 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 2f  ..</ul></li>..</
1200: 75 6c 3e 0d 0a 3c 62 72 3e 0d 0a 4c 65 74 27 73  ul>..<br>..Let's
1210: 20 6e 6f 77 20 73 65 65 20 65 61 63 68 20 73 69   now see each si
1220: 6e 67 6c 65 20 53 51 4c 20 66 75 6e 63 74 69 6f  ngle SQL functio
1230: 6e 20 69 6e 20 66 75 6c 6c 20 64 65 74 61 69 6c  n in full detail
1240: 73 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e  s.<br><br>..<hr>
1250: 0d 0a 3c 74 61 62 6c 65 20 63 65 6c 6c 73 70 61  ..<table cellspa
1260: 63 69 6e 67 3d 22 38 22 20 63 65 6c 6c 70 61 64  cing="8" cellpad
1270: 64 69 6e 67 3d 22 38 22 20 62 67 63 6f 6c 6f 72  ding="8" bgcolor
1280: 3d 22 23 66 66 66 66 39 30 22 3e 3c 74 72 3e 3c  ="#ffff90"><tr><
1290: 74 64 3e 0d 0a 3c 68 33 3e 57 61 72 6e 69 6e 67  td>..<h3>Warning
12a0: 3c 2f 68 33 3e 0d 0a 42 6f 74 68 20 3c 62 3e 52  </h3>..Both <b>R
12b0: 65 6e 61 6d 65 54 61 62 6c 65 28 29 3c 2f 62 3e  enameTable()</b>
12c0: 20 61 6e 64 20 3c 62 3e 52 65 6e 61 6d 65 43 6f   and <b>RenameCo
12d0: 6c 75 6d 6e 28 29 3c 2f 62 3e 20 73 74 72 69 63  lumn()</b> stric
12e0: 74 6c 79 20 72 65 71 75 69 72 65 20 53 51 4c 69  tly require SQLi
12f0: 74 65 33 20 76 65 72 73 69 6f 6e 20 3c 62 3e 33  te3 version <b>3
1300: 2e 32 35 2e 30 3c 2f 62 3e 20 28 6f 72 20 67 72  .25.0</b> (or gr
1310: 65 61 74 65 72 29 2e 3c 62 72 3e 0d 0a 49 66 20  eater).<br>..If 
1320: 53 70 61 74 69 61 4c 69 74 65 20 69 73 20 72 75  SpatiaLite is ru
1330: 6e 6e 69 6e 67 20 61 67 61 69 6e 73 74 20 61 6e  nning against an
1340: 20 65 61 72 6c 69 65 72 20 76 65 72 73 69 6f 6e   earlier version
1350: 20 62 6f 74 68 20 66 75 6e 63 74 69 6f 6e 73 20   both functions 
1360: 77 69 6c 6c 20 61 6c 77 61 79 73 20 72 61 69 73  will always rais
1370: 65 20 61 6e 20 3c 62 3e 45 78 63 65 70 74 69 6f  e an <b>Exceptio
1380: 6e 3c 2f 62 3e 20 63 6f 6d 70 6c 61 69 6e 69 6e  n</b> complainin
1390: 67 20 61 62 6f 75 74 20 74 68 65 20 6d 69 73 6d  g about the mism
13a0: 61 74 63 68 69 6e 67 20 6c 69 62 72 61 72 79 20  atching library 
13b0: 76 65 72 73 69 6f 6e 2e 0d 0a 3c 2f 74 64 3e 3c  version...</td><
13c0: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 68  /tr></table>..<h
13d0: 72 3e 0d 0a 3c 68 32 3e 44 72 6f 70 54 61 62 6c  r>..<h2>DropTabl
13e0: 65 28 29 3c 2f 68 32 3e 0d 0a 3c 76 65 72 62 61  e()</h2>..<verba
13f0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 44 72 6f  tim>..SELECT Dro
1400: 70 54 61 62 6c 65 28 27 73 6f 6d 65 5f 64 62 27  pTable('some_db'
1410: 2c 20 27 73 6f 6d 65 5f 74 61 62 6c 65 27 29 3b  , 'some_table');
1420: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..--------------
1430: 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 0d 0a 0d 0a 53  --------..1....S
1440: 45 4c 45 43 54 20 44 72 6f 70 54 61 62 6c 65 28  ELECT DropTable(
1450: 4e 55 4c 4c 2c 20 27 69 6e 65 78 69 73 74 65 6e  NULL, 'inexisten
1460: 74 5f 74 61 62 6c 65 27 29 3b 0d 0a 2d 2d 2d 2d  t_table');..----
1470: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1480: 2d 2d 0d 0a 44 72 6f 70 54 61 62 6c 65 20 65 78  --..DropTable ex
1490: 63 65 70 74 69 6f 6e 20 2d 20 6e 6f 74 20 65 78  ception - not ex
14a0: 69 73 74 69 6e 67 20 74 61 62 6c 65 20 5b 6d 61  isting table [ma
14b0: 69 6e 2e 69 6e 65 78 69 73 74 65 6e 74 5f 74 61  in.inexistent_ta
14c0: 62 6c 65 5d 0d 0a 0d 0a 53 45 4c 45 43 54 20 44  ble]....SELECT D
14d0: 72 6f 70 54 61 62 6c 65 28 4e 55 4c 4c 2c 20 27  ropTable(NULL, '
14e0: 69 6e 65 78 69 73 74 65 6e 74 5f 74 61 62 6c 65  inexistent_table
14f0: 27 2c 20 31 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d  ', 1);..--------
1500: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a  --------------..
1510: 30 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  0..</verbatim>..
1520: 53 75 70 70 6f 72 74 65 64 20 61 72 67 75 6d 65  Supported argume
1530: 6e 74 73 20 77 69 74 68 20 74 68 65 69 72 20 69  nts with their i
1540: 6e 74 65 72 70 72 65 74 61 74 69 6f 6e 3a 0d 0a  nterpretation:..
1550: 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 64 62 2d  <ul>..<li><b>db-
1560: 70 72 65 66 69 78 3c 2f 62 3e 3a 20 74 68 69 73  prefix</b>: this
1570: 20 66 69 72 73 74 20 6d 61 6e 64 61 74 6f 72 79   first mandatory
1580: 20 61 72 67 75 6d 65 6e 74 2c 20 6f 66 20 74 68   argument, of th
1590: 65 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 74 79  e <b>TEXT</b> ty
15a0: 70 65 2c 20 6d 75 73 74 20 63 6f 6e 74 61 69 6e  pe, must contain
15b0: 20 74 68 65 20 70 72 65 66 69 78 20 69 64 65 6e   the prefix iden
15c0: 74 69 66 79 69 6e 67 20 74 68 65 20 3c 69 3e 61  tifying the <i>a
15d0: 74 74 61 63 68 65 64 20 44 42 3c 2f 69 3e 20 77  ttached DB</i> w
15e0: 68 65 72 65 20 74 68 65 20 54 61 62 6c 65 20 6f  here the Table o
15f0: 72 20 56 69 65 77 20 74 6f 20 62 65 20 64 72 6f  r View to be dro
1600: 70 70 65 64 20 69 73 20 65 78 70 65 63 74 65 64  pped is expected
1610: 20 74 6f 20 62 65 2e 3c 62 72 3e 0d 0a 57 68 65   to be.<br>..Whe
1620: 6e 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 20 69 73  n <b>NULL</b> is
1630: 20 75 73 65 64 3a 20 3c 62 3e 27 4d 41 49 4e 27   used: <b>'MAIN'
1640: 3c 2f 62 3e 20 44 42 20 77 69 6c 6c 20 62 65 20  </b> DB will be 
1650: 69 6d 70 6c 69 63 69 74 6c 79 20 61 73 73 75 6d  implicitly assum
1660: 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62  ed.</li>..<li><b
1670: 3e 6e 61 6d 65 3c 2f 62 3e 3a 20 74 68 69 73 20  >name</b>: this 
1680: 73 65 63 6f 6e 64 20 6d 61 6e 64 61 74 6f 72 79  second mandatory
1690: 20 61 72 67 75 6d 65 6e 74 2c 20 6f 66 20 74 68   argument, of th
16a0: 65 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 74 79  e <b>TEXT</b> ty
16b0: 70 65 2c 20 6d 75 73 74 20 63 6f 6e 74 61 69 6e  pe, must contain
16c0: 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65   the name of the
16d0: 20 54 61 62 6c 65 20 28 6f 72 20 56 69 65 77 29   Table (or View)
16e0: 20 74 6f 20 62 65 20 64 72 6f 70 70 65 64 2e 3c   to be dropped.<
16f0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 70 65 72  /li>..<li><b>per
1700: 6d 69 73 73 69 76 65 3c 2f 62 3e 3a 20 74 68 69  missive</b>: thi
1710: 73 20 74 68 69 72 64 20 6f 70 74 69 6f 6e 61 6c  s third optional
1720: 20 61 72 67 75 6d 65 6e 74 2c 20 6f 66 20 74 68   argument, of th
1730: 65 20 3c 62 3e 42 4f 4f 4c 45 41 4e 3c 2f 62 3e  e <b>BOOLEAN</b>
1740: 20 74 79 70 65 2c 20 63 61 6e 20 62 65 20 61 70   type, can be ap
1750: 70 72 6f 70 72 69 61 74 65 6c 79 20 73 65 74 20  propriately set 
1760: 69 6e 20 6f 72 64 65 72 20 74 6f 20 64 65 74 65  in order to dete
1770: 72 6d 69 6e 65 20 74 68 65 20 65 78 70 65 63 74  rmine the expect
1780: 65 64 20 62 65 68 61 76 69 6f 72 20 69 6e 20 74  ed behavior in t
1790: 68 65 20 63 61 73 65 20 6f 66 20 66 61 69 6c 75  he case of failu
17a0: 72 65 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 69  re:..<ul>..<li>i
17b0: 66 20 3c 62 3e 70 65 72 6d 69 73 73 69 76 65 3d  f <b>permissive=
17c0: 46 41 4c 53 45 3c 2f 62 3e 20 61 6e 79 20 65 72  FALSE</b> any er
17d0: 72 6f 72 20 28 62 6f 74 68 20 69 6e 76 61 6c 69  ror (both invali
17e0: 64 20 61 72 67 75 6d 65 6e 74 73 20 6f 72 20 66  d arguments or f
17f0: 61 69 6c 75 72 65 20 64 75 65 20 65 2e 67 2e 20  ailure due e.g. 
1800: 74 6f 20 73 70 65 63 69 66 79 69 6e 67 20 61 20  to specifying a 
1810: 6e 6f 6e 20 65 78 69 73 74 69 6e 67 20 54 61 62  non existing Tab
1820: 6c 65 29 20 77 69 6c 6c 20 72 61 69 73 65 20 61  le) will raise a
1830: 6e 20 3c 62 3e 53 51 4c 20 45 78 63 65 70 74 69  n <b>SQL Excepti
1840: 6f 6e 3c 2f 62 3e 2c 20 74 68 75 73 20 69 6d 6d  on</b>, thus imm
1850: 65 64 69 61 74 65 6c 79 20 73 74 6f 70 70 69 6e  ediately stoppin
1860: 67 20 74 68 65 20 65 78 65 63 75 74 69 6f 6e 20  g the execution 
1870: 6f 66 20 61 6e 79 20 66 6f 6c 6c 6f 77 69 6e 67  of any following
1880: 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 2e 3c   SQL statement.<
1890: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 69 66 20 3c 62 3e  /li>..<li>if <b>
18a0: 70 65 72 6d 69 73 73 69 76 65 3d 54 52 55 45 3c  permissive=TRUE<
18b0: 2f 62 3e 20 6f 6e 6c 79 20 74 68 65 20 65 72 72  /b> only the err
18c0: 6f 72 73 20 63 61 75 73 65 64 20 62 79 20 69 6e  ors caused by in
18d0: 76 61 6c 69 64 20 61 72 67 75 6d 65 6e 74 73 20  valid arguments 
18e0: 77 69 6c 6c 20 72 61 69 73 65 20 61 6e 20 45 78  will raise an Ex
18f0: 63 65 70 74 69 6f 6e 2e 3c 62 72 3e 0d 0a 46 61  ception.<br>..Fa
1900: 69 6c 75 72 65 73 20 64 75 65 20 65 2e 67 2e 20  ilures due e.g. 
1910: 74 6f 20 73 70 65 63 69 66 79 69 6e 67 20 61 20  to specifying a 
1920: 6e 6f 6e 20 65 78 69 73 74 69 6e 67 20 54 61 62  non existing Tab
1930: 6c 65 20 77 69 6c 6c 20 6a 75 73 74 20 72 65 74  le will just ret
1940: 75 72 6e 20 61 6e 20 65 72 72 6f 72 20 63 6f 64  urn an error cod
1950: 65 2c 20 62 75 74 20 74 68 65 20 65 78 65 63 75  e, but the execu
1960: 74 69 6f 6e 20 6f 66 20 66 6f 6c 6c 6f 77 69 6e  tion of followin
1970: 67 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 73  g SQL statements
1980: 20 77 69 6c 6c 20 63 6f 6e 74 69 6e 75 65 20 75   will continue u
1990: 6e 61 66 66 65 63 74 65 64 2e 3c 62 72 3e 0d 0a  naffected.<br>..
19a0: 53 69 6d 70 6c 79 20 73 74 61 74 65 64 2c 20 3c  Simply stated, <
19b0: 62 3e 3c 69 3e 70 65 72 6d 69 73 73 69 76 65 2d  b><i>permissive-
19c0: 6d 6f 64 65 3c 2f 69 3e 3c 2f 62 3e 20 69 73 20  mode</i></b> is 
19d0: 6d 6f 72 65 20 6f 72 20 6c 65 73 73 20 74 68 65  more or less the
19e0: 20 73 61 6d 65 20 74 68 65 6e 20 73 70 65 63 69   same then speci
19f0: 66 79 69 6e 67 20 61 20 73 74 61 6e 64 61 72 64  fying a standard
1a00: 20 53 51 4c 20 3c 62 3e 49 46 20 45 58 49 53 54   SQL <b>IF EXIST
1a10: 53 3c 2f 62 3e 20 63 6c 61 75 73 65 2e 3c 2f 6c  S</b> clause.</l
1a20: 69 3e 0d 0a 3c 6c 69 3e 3c 69 3e 3c 75 3e 4e 6f  i>..<li><i><u>No
1a30: 74 65 3c 2f 75 3e 3c 2f 69 3e 3a 20 74 68 65 20  te</u></i>: the 
1a40: 64 65 66 61 75 6c 74 20 73 65 74 74 69 6e 67 20  default setting 
1a50: 69 73 20 3c 62 3e 70 65 72 6d 69 73 73 69 76 65  is <b>permissive
1a60: 3d 46 41 4c 53 45 3c 2f 62 3e 2e 20 28 69 2e 65  =FALSE</b>. (i.e
1a70: 2e 20 74 68 65 20 54 41 42 4c 45 20 3c 62 3e 6d  . the TABLE <b>m
1a80: 75 73 74 3c 2f 62 3e 20 65 78 69 73 74 29 2e 3c  ust</b> exist).<
1a90: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 69 3e 3c 75 3e  /li>..<li><i><u>
1aa0: 48 69 6e 74 3c 2f 75 3e 3c 2f 69 3e 3a 20 6f 70  Hint</u></i>: op
1ab0: 74 69 6e 67 20 66 6f 72 20 74 68 65 20 3c 62 3e  ting for the <b>
1ac0: 3c 69 3e 6e 6f 6e 2d 70 65 72 6d 69 73 73 69 76  <i>non-permissiv
1ad0: 65 3c 2f 69 3e 3c 2f 62 3e 20 6d 6f 64 65 20 69  e</i></b> mode i
1ae0: 73 20 62 65 73 74 20 66 69 74 20 77 68 65 6e 20  s best fit when 
1af0: 69 6e 74 65 72 61 63 74 69 76 65 6c 79 20 74 79  interactively ty
1b00: 70 69 6e 67 20 53 51 4c 20 73 74 61 74 65 6d 65  ping SQL stateme
1b10: 6e 74 73 20 6f 6e 20 74 68 65 20 6b 65 79 62 6f  nts on the keybo
1b20: 61 72 64 2c 20 62 65 63 61 75 73 65 20 74 68 69  ard, because thi
1b30: 73 20 77 61 79 20 61 6e 79 20 70 6f 73 73 69 62  s way any possib
1b40: 6c 65 20 65 72 72 6f 72 20 77 69 6c 6c 20 62 65  le error will be
1b50: 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 72 65 70   immediately rep
1b60: 6f 72 74 65 64 20 69 6e 20 66 75 6c 6c 20 64 65  orted in full de
1b70: 74 61 69 6c 73 2e 3c 62 72 3e 0d 0a 4f 6e 20 74  tails.<br>..On t
1b80: 68 65 20 6f 74 68 65 72 20 68 61 6e 64 20 77 68  he other hand wh
1b90: 65 6e 20 65 78 65 63 75 74 69 6e 67 20 73 6f 6d  en executing som
1ba0: 65 20 6d 6f 72 65 20 6f 72 20 6c 65 73 73 20 63  e more or less c
1bb0: 6f 6d 70 6c 65 78 20 53 51 4c 20 53 63 72 69 70  omplex SQL Scrip
1bc0: 74 20 3c 62 3e 3c 69 3e 70 65 72 6d 69 73 73 69  t <b><i>permissi
1bd0: 76 65 3c 2f 69 3e 3c 2f 62 3e 20 6d 6f 64 65 20  ve</i></b> mode 
1be0: 69 73 20 6f 66 74 65 6e 20 6d 6f 72 65 20 75 73  is often more us
1bf0: 65 66 75 6c 2c 20 62 65 63 61 75 73 65 20 74 72  eful, because tr
1c00: 69 76 69 61 6c 20 61 6e 64 20 66 6f 72 67 69 76  ivial and forgiv
1c10: 61 62 6c 65 20 65 72 72 6f 72 73 20 28 73 75 63  able errors (suc
1c20: 68 20 61 73 20 61 74 74 65 6d 70 74 69 6e 67 20  h as attempting 
1c30: 74 6f 20 64 72 6f 70 20 61 20 6e 6f 6e 20 65 78  to drop a non ex
1c40: 69 73 74 69 6e 67 20 74 61 62 6c 65 29 20 77 69  isting table) wi
1c50: 6c 6c 20 6e 6f 74 20 62 6c 6f 63 6b 20 74 68 65  ll not block the
1c60: 20 65 78 65 63 75 74 69 6f 6e 20 6f 66 20 74 68   execution of th
1c70: 65 20 73 63 72 69 70 74 2e 0d 0a 3c 2f 75 6c 3e  e script...</ul>
1c80: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 68 65 20 3c  </li>..<li>the <
1c90: 62 3e 72 65 74 75 72 6e 20 76 61 6c 75 65 3c 2f  b>return value</
1ca0: 62 3e 20 69 73 20 6f 66 20 74 68 65 20 3c 62 3e  b> is of the <b>
1cb0: 42 4f 4f 4c 45 41 4e 3c 2f 62 3e 20 74 79 70 65  BOOLEAN</b> type
1cc0: 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e  :..<ul>..<li><b>
1cd0: 54 52 55 45 3c 2f 62 3e 20 69 6e 20 74 68 65 20  TRUE</b> in the 
1ce0: 63 61 73 65 20 6f 66 20 73 75 63 63 65 73 73 2e  case of success.
1cf0: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 46 41  </li>..<li><b>FA
1d00: 4c 53 45 3c 2f 62 3e 20 28 6f 72 20 61 6e 20 3c  LSE</b> (or an <
1d10: 62 3e 45 78 63 65 70 74 69 6f 6e 3c 2f 62 3e 29  b>Exception</b>)
1d20: 20 69 6e 20 74 68 65 20 63 61 73 65 20 6f 66 20   in the case of 
1d30: 69 6e 76 61 6c 69 64 20 61 72 67 75 6d 65 6e 74  invalid argument
1d40: 73 20 6f 72 20 66 61 69 6c 75 72 65 2e 3c 2f 6c  s or failure.</l
1d50: 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a  i>..</ul></li>..
1d60: 3c 6c 69 3e 3c 62 3e 4e 6f 74 65 3c 2f 62 3e 3a  <li><b>Note</b>:
1d70: 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 63   this function c
1d80: 61 72 65 66 75 6c 6c 79 20 63 68 65 63 6b 73 20  arefully checks 
1d90: 74 6f 20 69 6e 73 75 72 65 20 74 68 61 74 20 74  to insure that t
1da0: 68 65 20 64 72 6f 70 70 69 6e 67 20 6f 66 20 61  he dropping of a
1db0: 6e 79 20 53 79 73 74 65 6d 20 6f 72 20 4d 65 74  ny System or Met
1dc0: 61 64 61 74 61 20 54 61 62 6c 65 73 20 69 6e 74  adata Tables int
1dd0: 65 72 6e 61 6c 6c 79 20 72 65 71 75 69 72 65 64  ernally required
1de0: 20 62 79 20 65 69 74 68 65 72 20 53 51 4c 69 74   by either SQLit
1df0: 65 33 2c 20 53 70 61 74 69 61 4c 69 74 65 2c 20  e3, SpatiaLite, 
1e00: 52 61 73 74 65 72 4c 69 74 65 32 2c 20 47 65 6f  RasterLite2, Geo
1e10: 50 61 63 6b 61 67 65 20 6f 72 20 46 44 4f 20 69  Package or FDO i
1e20: 73 20 70 72 65 76 65 6e 74 65 64 2e 3c 2f 6c 69  s prevented.</li
1e30: 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 62 72 3e 0d 0a  >..</ul>..<br>..
1e40: 3c 74 61 62 6c 65 20 63 65 6c 6c 73 70 61 63 69  <table cellspaci
1e50: 6e 67 3d 22 38 22 20 63 65 6c 6c 70 61 64 64 69  ng="8" cellpaddi
1e60: 6e 67 3d 22 38 22 20 62 67 63 6f 6c 6f 72 3d 22  ng="8" bgcolor="
1e70: 23 66 66 66 66 39 30 22 3e 3c 74 72 3e 3c 74 64  #ffff90"><tr><td
1e80: 3e 0d 0a 3c 68 33 3e 43 61 76 65 61 74 3c 2f 68  >..<h3>Caveat</h
1e90: 33 3e 0d 0a 41 20 73 69 6d 69 6c 61 72 20 66 75  3>..A similar fu
1ea0: 6e 63 74 69 6f 6e 20 6e 61 6d 65 64 20 3c 62 3e  nction named <b>
1eb0: 44 72 6f 70 47 65 6f 54 61 62 6c 65 28 29 3c 2f  DropGeoTable()</
1ec0: 62 3e 20 77 61 73 20 73 75 70 70 6f 72 74 65 64  b> was supported
1ed0: 20 62 79 20 70 72 65 76 69 6f 75 73 20 76 65 72   by previous ver
1ee0: 73 69 6f 6e 73 20 6f 66 20 53 70 61 74 69 61 4c  sions of SpatiaL
1ef0: 69 74 65 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 62  ite.<br><br>..<b
1f00: 3e 44 72 6f 70 47 65 6f 54 61 62 6c 65 28 29 3c  >DropGeoTable()<
1f10: 2f 62 3e 20 69 73 20 6e 6f 77 20 3c 62 3e 44 45  /b> is now <b>DE
1f20: 50 52 45 43 41 54 45 44 3c 2f 62 3e 2c 20 61 6e  PRECATED</b>, an
1f30: 64 20 77 69 6c 6c 20 72 65 6d 61 69 6e 20 74 6f  d will remain to
1f40: 20 61 76 6f 69 64 20 62 72 65 61 6b 69 6e 67 20   avoid breaking 
1f50: 65 78 69 73 74 69 6e 67 20 61 70 70 6c 69 63 61  existing applica
1f60: 74 69 6f 6e 73 20 61 6e 64 20 73 63 72 69 70 74  tions and script
1f70: 73 2e 3c 62 72 3e 0d 0a 49 74 20 69 73 20 73 74  s.<br>..It is st
1f80: 72 6f 6e 67 6c 79 20 72 65 63 6f 6d 6d 65 6e 64  rongly recommend
1f90: 65 64 20 75 73 65 20 3c 62 3e 44 72 6f 70 54 61  ed use <b>DropTa
1fa0: 62 6c 65 28 29 3c 2f 62 3e 20 66 6f 72 20 61 6e  ble()</b> for an
1fb0: 79 20 6e 65 77 20 64 65 76 65 6c 6f 70 6d 65 6e  y new developmen
1fc0: 74 20 61 73 20 66 75 6c 6c 20 61 6e 64 20 6d 6f  t as full and mo
1fd0: 72 65 20 72 65 6c 69 61 62 6c 65 20 72 65 70 6c  re reliable repl
1fe0: 61 63 65 6d 65 6e 74 2e 0d 0a 3c 2f 74 64 3e 3c  acement...</td><
1ff0: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62  /tr></table>..<b
2000: 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 32 3e 52 65  r>..<hr>..<h2>Re
2010: 6e 61 6d 65 54 61 62 6c 65 28 29 3c 2f 68 32 3e  nameTable()</h2>
2020: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45  ..<verbatim>..SE
2030: 4c 45 43 54 20 52 65 6e 61 6d 65 54 61 62 6c 65  LECT RenameTable
2040: 28 27 73 6f 6d 65 5f 64 62 27 2c 20 27 6f 6c 64  ('some_db', 'old
2050: 5f 74 61 62 6c 65 27 2c 20 27 6e 65 77 5f 74 61  _table', 'new_ta
2060: 62 6c 65 27 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d  ble');..--------
2070: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a  --------------..
2080: 31 0d 0a 0d 0a 53 45 4c 45 43 54 20 52 65 6e 61  1....SELECT Rena
2090: 6d 65 54 61 62 6c 65 28 4e 55 4c 4c 2c 20 27 6f  meTable(NULL, 'o
20a0: 6c 64 5f 74 61 62 6c 65 27 2c 20 27 65 78 69 73  ld_table', 'exis
20b0: 74 69 6e 67 5f 6e 65 77 5f 74 61 62 6c 65 27 29  ting_new_table')
20c0: 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ;..-------------
20d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 52 65 6e 61 6d  ---------..Renam
20e0: 65 54 61 62 6c 65 20 65 78 63 65 70 74 69 6f 6e  eTable exception
20f0: 20 2d 20 61 6c 72 65 61 64 79 20 65 78 69 73 74   - already exist
2100: 69 6e 67 20 74 61 62 6c 65 20 5b 6d 61 69 6e 2e  ing table [main.
2110: 65 78 69 73 74 69 6e 67 5f 6e 65 77 5f 74 61 62  existing_new_tab
2120: 6c 65 5d 0d 0a 0d 0a 53 45 4c 45 43 54 20 52 65  le]....SELECT Re
2130: 6e 61 6d 65 54 61 62 6c 65 28 4e 55 4c 4c 2c 20  nameTable(NULL, 
2140: 27 6f 6c 64 5f 74 61 62 6c 65 27 2c 20 27 65 78  'old_table', 'ex
2150: 69 73 74 69 6e 67 5f 6e 65 77 5f 74 61 62 6c 65  isting_new_table
2160: 27 2c 20 31 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d  ', 1);..--------
2170: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a  --------------..
2180: 30 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  0..</verbatim>..
2190: 53 75 70 70 6f 72 74 65 64 20 61 72 67 75 6d 65  Supported argume
21a0: 6e 74 73 20 77 69 74 68 20 74 68 65 69 72 20 69  nts with their i
21b0: 6e 74 65 72 70 72 65 74 61 74 69 6f 6e 3a 0d 0a  nterpretation:..
21c0: 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 64 62 2d  <ul>..<li><b>db-
21d0: 70 72 65 66 69 78 3c 2f 62 3e 3a 20 74 68 69 73  prefix</b>: this
21e0: 20 66 69 72 73 74 20 6d 61 6e 64 61 74 6f 72 79   first mandatory
21f0: 20 61 72 67 75 6d 65 6e 74 2c 20 6f 66 20 74 68   argument, of th
2200: 65 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 74 79  e <b>TEXT</b> ty
2210: 70 65 2c 20 6d 75 73 74 20 63 6f 6e 74 61 69 6e  pe, must contain
2220: 20 74 68 65 20 70 72 65 66 69 78 20 69 64 65 6e   the prefix iden
2230: 74 69 66 79 69 6e 67 20 74 68 65 20 3c 69 3e 61  tifying the <i>a
2240: 74 74 61 63 68 65 64 20 44 42 3c 2f 69 3e 20 77  ttached DB</i> w
2250: 68 65 72 65 20 74 68 65 20 54 61 62 6c 65 20 74  here the Table t
2260: 6f 20 62 65 20 72 65 6e 61 6d 65 64 20 69 73 20  o be renamed is 
2270: 65 78 70 65 63 74 65 64 20 74 6f 20 62 65 2e 3c  expected to be.<
2280: 62 72 3e 0d 0a 57 68 65 6e 20 3c 62 3e 4e 55 4c  br>..When <b>NUL
2290: 4c 3c 2f 62 3e 20 69 73 20 75 73 65 64 3a 20 3c  L</b> is used: <
22a0: 62 3e 27 4d 41 49 4e 27 3c 2f 62 3e 20 44 42 20  b>'MAIN'</b> DB 
22b0: 77 69 6c 6c 20 62 65 20 69 6d 70 6c 69 63 69 74  will be implicit
22c0: 6c 79 20 61 73 73 75 6d 65 64 2e 3c 2f 6c 69 3e  ly assumed.</li>
22d0: 0d 0a 3c 6c 69 3e 3c 62 3e 6f 6c 64 5f 6e 61 6d  ..<li><b>old_nam
22e0: 65 3c 2f 62 3e 3a 20 74 68 69 73 20 73 65 63 6f  e</b>: this seco
22f0: 6e 64 20 6d 61 6e 64 61 74 6f 72 79 20 61 72 67  nd mandatory arg
2300: 75 6d 65 6e 74 2c 20 6f 66 20 74 68 65 20 3c 62  ument, of the <b
2310: 3e 54 45 58 54 3c 2f 62 3e 20 74 79 70 65 2c 20  >TEXT</b> type, 
2320: 6d 75 73 74 20 63 6f 6e 74 61 69 6e 20 74 68 65  must contain the
2330: 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 54 61 62   name of the Tab
2340: 6c 65 20 74 6f 20 62 65 20 72 65 6e 61 6d 65 64  le to be renamed
2350: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 6e  .</li>..<li><b>n
2360: 65 77 5f 6e 61 6d 65 3c 2f 62 3e 3a 20 74 68 69  ew_name</b>: thi
2370: 73 20 74 68 69 72 64 20 6d 61 6e 64 61 74 6f 72  s third mandator
2380: 79 20 61 72 67 75 6d 65 6e 74 2c 20 6f 66 20 74  y argument, of t
2390: 68 65 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 74  he <b>TEXT</b> t
23a0: 79 70 65 2c 20 6d 75 73 74 20 63 6f 6e 74 61 69  ype, must contai
23b0: 6e 20 74 68 65 20 6e 65 77 20 6e 61 6d 65 20 74  n the new name t
23c0: 6f 20 62 65 20 61 73 73 69 67 6e 65 64 20 74 6f  o be assigned to
23d0: 20 74 68 65 20 54 61 62 6c 65 2e 3c 2f 6c 69 3e   the Table.</li>
23e0: 0d 0a 3c 6c 69 3e 3c 62 3e 70 65 72 6d 69 73 73  ..<li><b>permiss
23f0: 69 76 65 3c 2f 62 3e 3a 20 74 68 69 73 20 66 6f  ive</b>: this fo
2400: 75 72 74 68 20 6f 70 74 69 6f 6e 61 6c 20 61 72  urth optional ar
2410: 67 75 6d 65 6e 74 2c 20 6f 66 20 74 68 65 20 3c  gument, of the <
2420: 62 3e 42 4f 4f 4c 45 41 4e 3c 2f 62 3e 20 74 79  b>BOOLEAN</b> ty
2430: 70 65 2c 20 63 61 6e 20 62 65 20 61 70 70 72 6f  pe, can be appro
2440: 70 72 69 61 74 65 6c 79 20 73 65 74 20 69 6e 20  priately set in 
2450: 6f 72 64 65 72 20 74 6f 20 64 65 74 65 72 6d 69  order to determi
2460: 6e 65 20 74 68 65 20 65 78 70 65 63 74 65 64 20  ne the expected 
2470: 62 65 68 61 76 69 6f 72 20 69 6e 20 74 68 65 20  behavior in the 
2480: 63 61 73 65 20 6f 66 20 66 61 69 6c 75 72 65 2e  case of failure.
2490: 3c 62 72 3e 0d 0a 54 68 65 20 69 6e 74 65 72 70  <br>..The interp
24a0: 72 65 74 61 74 69 6f 6e 20 69 73 20 65 78 61 63  retation is exac
24b0: 74 6c 79 20 74 68 65 20 73 61 6d 65 20 61 73 20  tly the same as 
24c0: 69 6e 20 3c 62 3e 44 72 6f 70 54 61 62 6c 65 28  in <b>DropTable(
24d0: 29 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  )</b>.</li>..<li
24e0: 3e 74 68 65 20 3c 62 3e 72 65 74 75 72 6e 20 76  >the <b>return v
24f0: 61 6c 75 65 3c 2f 62 3e 20 69 73 20 6f 66 20 74  alue</b> is of t
2500: 68 65 20 3c 62 3e 42 4f 4f 4c 45 41 4e 3c 2f 62  he <b>BOOLEAN</b
2510: 3e 20 74 79 70 65 3a 0d 0a 3c 75 6c 3e 0d 0a 3c  > type:..<ul>..<
2520: 6c 69 3e 3c 62 3e 54 52 55 45 3c 2f 62 3e 20 69  li><b>TRUE</b> i
2530: 6e 20 74 68 65 20 63 61 73 65 20 6f 66 20 73 75  n the case of su
2540: 63 63 65 73 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  ccess.</li>..<li
2550: 3e 3c 62 3e 46 41 4c 53 45 3c 2f 62 3e 20 28 6f  ><b>FALSE</b> (o
2560: 72 20 61 6e 20 3c 62 3e 45 78 63 65 70 74 69 6f  r an <b>Exceptio
2570: 6e 3c 2f 62 3e 29 20 69 6e 20 74 68 65 20 63 61  n</b>) in the ca
2580: 73 65 20 6f 66 20 69 6e 76 61 6c 69 64 20 61 72  se of invalid ar
2590: 67 75 6d 65 6e 74 73 20 6f 72 20 66 61 69 6c 75  guments or failu
25a0: 72 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c  re.</li>..</ul><
25b0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 4e 6f 74  /li>..<li><b>Not
25c0: 65 3c 2f 62 3e 3a 20 74 68 69 73 20 66 75 6e 63  e</b>: this func
25d0: 74 69 6f 6e 20 63 61 72 65 66 75 6c 6c 79 20 63  tion carefully c
25e0: 68 65 63 6b 73 20 74 6f 20 69 6e 73 75 72 65 20  hecks to insure 
25f0: 74 68 61 74 20 74 68 65 20 72 65 6e 61 6d 69 6e  that the renamin
2600: 67 20 6f 66 20 61 6e 79 20 53 79 73 74 65 6d 20  g of any System 
2610: 6f 72 20 4d 65 74 61 64 61 74 61 20 54 61 62 6c  or Metadata Tabl
2620: 65 73 20 69 6e 74 65 72 6e 61 6c 6c 79 20 72 65  es internally re
2630: 71 75 69 72 65 64 20 62 79 20 65 69 74 68 65 72  quired by either
2640: 20 53 51 4c 69 74 65 33 2c 20 53 70 61 74 69 61   SQLite3, Spatia
2650: 4c 69 74 65 2c 20 52 61 73 74 65 72 4c 69 74 65  Lite, RasterLite
2660: 32 2c 20 47 65 6f 50 61 63 6b 61 67 65 20 6f 72  2, GeoPackage or
2670: 20 46 44 4f 20 69 73 20 70 72 65 76 65 6e 74 65   FDO is prevente
2680: 64 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a  d.</li>..</ul>..
2690: 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 63 65 6c  <br>..<table cel
26a0: 6c 73 70 61 63 69 6e 67 3d 22 38 22 20 63 65 6c  lspacing="8" cel
26b0: 6c 70 61 64 64 69 6e 67 3d 22 38 22 20 62 67 63  lpadding="8" bgc
26c0: 6f 6c 6f 72 3d 22 23 66 66 66 66 39 30 22 3e 3c  olor="#ffff90"><
26d0: 74 72 3e 3c 74 64 3e 0d 0a 3c 68 33 3e 42 65 20  tr><td>..<h3>Be 
26e0: 61 77 61 72 65 3c 2f 68 33 3e 0d 0a 53 51 4c 69  aware</h3>..SQLi
26f0: 74 65 33 20 63 61 6e 20 6e 65 76 65 72 20 72 65  te3 can never re
2700: 6e 61 6d 65 20 61 20 3c 62 3e 56 69 65 77 3c 2f  name a <b>View</
2710: 62 3e 20 6f 72 20 3c 62 3e 56 69 72 74 75 61 6c  b> or <b>Virtual
2720: 54 61 62 6c 65 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a  Table</b>.<br>..
2730: 49 66 20 79 6f 75 20 61 62 73 6f 6c 75 74 65 6c  If you absolutel
2740: 79 20 6e 65 65 64 20 74 6f 20 63 68 61 6e 67 65  y need to change
2750: 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 61 6e 79   the name of any
2760: 20 56 69 65 77 20 6f 72 20 56 69 72 74 75 61 6c   View or Virtual
2770: 54 61 62 6c 65 20 61 66 74 65 72 20 69 74 27 73  Table after it's
2780: 20 63 72 65 61 74 69 6f 6e 2c 20 79 6f 75 20 6d   creation, you m
2790: 75 73 74 20 66 69 72 73 74 20 64 72 6f 70 20 69  ust first drop i
27a0: 74 2c 20 61 6e 64 20 74 68 65 6e 20 72 65 63 72  t, and then recr
27b0: 65 61 74 65 20 69 74 20 77 69 74 68 20 74 68 65  eate it with the
27c0: 20 6e 65 77 20 6e 61 6d 65 2e 0d 0a 3c 2f 74 64   new name...</td
27d0: 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a  ></tr></table>..
27e0: 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 32 3e  <br>..<hr>..<h2>
27f0: 52 65 6e 61 6d 65 43 6f 6c 75 6d 6e 28 29 3c 2f  RenameColumn()</
2800: 68 32 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  h2>..<verbatim>.
2810: 0a 53 45 4c 45 43 54 20 52 65 6e 61 6d 65 43 6f  .SELECT RenameCo
2820: 6c 75 6d 6e 28 27 73 6f 6d 65 5f 64 62 27 2c 20  lumn('some_db', 
2830: 27 74 61 62 6c 65 5f 6e 61 6d 65 27 2c 20 27 6f  'table_name', 'o
2840: 6c 64 5f 63 6f 6c 75 6d 6e 27 2c 20 27 6e 65 77  ld_column', 'new
2850: 5f 63 6f 6c 75 6d 6e 27 29 3b 0d 0a 2d 2d 2d 2d  _column');..----
2860: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2870: 2d 2d 0d 0a 31 0d 0a 0d 0a 53 45 4c 45 43 54 20  --..1....SELECT 
2880: 52 65 6e 61 6d 65 43 6f 6c 75 6d 6e 28 4e 55 4c  RenameColumn(NUL
2890: 4c 2c 20 27 74 61 62 6c 65 5f 6e 61 6d 65 27 2c  L, 'table_name',
28a0: 20 27 6f 6c 64 5f 63 6f 6c 75 6d 6e 27 2c 20 27   'old_column', '
28b0: 65 78 69 73 74 69 6e 67 5f 63 6f 6c 75 6d 6e 27  existing_column'
28c0: 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  );..------------
28d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 52 65 6e 61  ----------..Rena
28e0: 6d 65 43 6f 6c 75 6d 6e 20 65 78 63 65 70 74 69  meColumn excepti
28f0: 6f 6e 20 2d 20 63 6f 6c 75 6d 6e 20 61 6c 72 65  on - column alre
2900: 61 64 79 20 64 65 66 69 6e 65 64 20 5b 6d 61 69  ady defined [mai
2910: 6e 2e 74 61 62 6c 65 5f 6e 61 6d 65 5d 20 65 78  n.table_name] ex
2920: 69 73 74 69 6e 67 5f 63 6f 6c 75 6d 6e 0d 0a 0d  isting_column...
2930: 0a 53 45 4c 45 43 54 20 52 65 6e 61 6d 65 43 6f  .SELECT RenameCo
2940: 6c 75 6d 6e 28 4e 55 4c 4c 2c 20 27 74 61 62 6c  lumn(NULL, 'tabl
2950: 65 5f 6e 61 6d 65 27 2c 20 27 6f 6c 64 5f 63 6f  e_name', 'old_co
2960: 6c 75 6d 6e 27 2c 20 27 65 78 69 73 74 69 6e 67  lumn', 'existing
2970: 5f 63 6f 6c 75 6d 6e 27 2c 20 31 29 3b 0d 0a 2d  _column', 1);..-
2980: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2990: 2d 2d 2d 2d 2d 0d 0a 30 0d 0a 3c 2f 76 65 72 62  -----..0..</verb
29a0: 61 74 69 6d 3e 0d 0a 53 75 70 70 6f 72 74 65 64  atim>..Supported
29b0: 20 61 72 67 75 6d 65 6e 74 73 20 77 69 74 68 20   arguments with 
29c0: 74 68 65 69 72 20 69 6e 74 65 72 70 72 65 74 61  their interpreta
29d0: 74 69 6f 6e 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69  tion:..<ul>..<li
29e0: 3e 3c 62 3e 64 62 2d 70 72 65 66 69 78 3c 2f 62  ><b>db-prefix</b
29f0: 3e 3a 20 74 68 69 73 20 66 69 72 73 74 20 6d 61  >: this first ma
2a00: 6e 64 61 74 6f 72 79 20 61 72 67 75 6d 65 6e 74  ndatory argument
2a10: 2c 20 6f 66 20 74 68 65 20 3c 62 3e 54 45 58 54  , of the <b>TEXT
2a20: 3c 2f 62 3e 20 74 79 70 65 2c 20 6d 75 73 74 20  </b> type, must 
2a30: 63 6f 6e 74 61 69 6e 20 74 68 65 20 70 72 65 66  contain the pref
2a40: 69 78 20 69 64 65 6e 74 69 66 79 69 6e 67 20 74  ix identifying t
2a50: 68 65 20 3c 69 3e 61 74 74 61 63 68 65 64 20 44  he <i>attached D
2a60: 42 3c 2f 69 3e 20 77 68 65 72 65 20 74 68 65 20  B</i> where the 
2a70: 54 61 62 6c 65 20 63 6f 6e 74 61 69 6e 69 6e 67  Table containing
2a80: 20 74 68 20 43 6f 6c 75 6d 6e 20 74 6f 20 62 65   th Column to be
2a90: 20 72 65 6e 61 6d 65 64 20 69 73 20 65 78 70 65   renamed is expe
2aa0: 63 74 65 64 20 74 6f 20 62 65 2e 3c 62 72 3e 0d  cted to be.<br>.
2ab0: 0a 57 68 65 6e 20 3c 62 3e 4e 55 4c 4c 3c 2f 62  .When <b>NULL</b
2ac0: 3e 20 69 73 20 75 73 65 64 3a 20 3c 62 3e 27 4d  > is used: <b>'M
2ad0: 41 49 4e 27 3c 2f 62 3e 20 44 42 20 77 69 6c 6c  AIN'</b> DB will
2ae0: 20 62 65 20 69 6d 70 6c 69 63 69 74 6c 79 20 61   be implicitly a
2af0: 73 73 75 6d 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  ssumed.</li>..<l
2b00: 69 3e 3c 62 3e 74 61 62 6c 65 5f 6e 61 6d 65 3c  i><b>table_name<
2b10: 2f 62 3e 3a 20 74 68 69 73 20 73 65 63 6f 6e 64  /b>: this second
2b20: 20 6d 61 6e 64 61 74 6f 72 79 20 61 72 67 75 6d   mandatory argum
2b30: 65 6e 74 2c 20 6f 66 20 74 68 65 20 3c 62 3e 54  ent, of the <b>T
2b40: 45 58 54 3c 2f 62 3e 20 74 79 70 65 2c 20 6d 75  EXT</b> type, mu
2b50: 73 74 20 63 6f 6e 74 61 69 6e 20 74 68 65 20 6e  st contain the n
2b60: 61 6d 65 20 6f 66 20 74 68 65 20 54 61 62 6c 65  ame of the Table
2b70: 20 74 6f 20 77 68 69 63 68 20 62 65 6c 6f 6e 67   to which belong
2b80: 73 20 74 6f 20 43 6f 6c 75 6d 6e 20 74 6f 20 62  s to Column to b
2b90: 65 20 72 65 6e 61 6d 65 64 2e 3c 2f 6c 69 3e 0d  e renamed.</li>.
2ba0: 0a 3c 6c 69 3e 3c 62 3e 6f 6c 64 5f 6e 61 6d 65  .<li><b>old_name
2bb0: 3c 2f 62 3e 3a 20 74 68 69 73 20 74 68 69 72 64  </b>: this third
2bc0: 20 6d 61 6e 64 61 74 6f 72 79 20 61 72 67 75 6d   mandatory argum
2bd0: 65 6e 74 2c 20 6f 66 20 74 68 65 20 3c 62 3e 54  ent, of the <b>T
2be0: 45 58 54 3c 2f 62 3e 20 74 79 70 65 2c 20 6d 75  EXT</b> type, mu
2bf0: 73 74 20 63 6f 6e 74 61 69 6e 20 74 68 65 20 6e  st contain the n
2c00: 61 6d 65 20 6f 66 20 74 68 65 20 43 6f 6c 75 6d  ame of the Colum
2c10: 6e 20 74 6f 20 62 65 20 72 65 6e 61 6d 65 64 2e  n to be renamed.
2c20: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 6e 65  </li>..<li><b>ne
2c30: 77 5f 6e 61 6d 65 3c 2f 62 3e 3a 20 74 68 69 73  w_name</b>: this
2c40: 20 66 6f 75 72 74 68 20 6d 61 6e 64 61 74 6f 72   fourth mandator
2c50: 79 20 61 72 67 75 6d 65 6e 74 2c 20 6f 66 20 74  y argument, of t
2c60: 68 65 20 3c 62 3e 54 45 58 54 3c 2f 62 3e 20 74  he <b>TEXT</b> t
2c70: 79 70 65 2c 20 6d 75 73 74 20 63 6f 6e 74 61 69  ype, must contai
2c80: 6e 20 74 68 65 20 6e 65 77 20 6e 61 6d 65 20 74  n the new name t
2c90: 6f 20 62 65 20 61 73 73 69 67 6e 65 64 20 74 6f  o be assigned to
2ca0: 20 74 68 65 20 43 6f 6c 75 6d 6e 2e 3c 2f 6c 69   the Column.</li
2cb0: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 70 65 72 6d 69 73  >..<li><b>permis
2cc0: 73 69 76 65 3c 2f 62 3e 3a 20 74 68 69 73 20 66  sive</b>: this f
2cd0: 69 66 74 68 20 6f 70 74 69 6f 6e 61 6c 20 61 72  ifth optional ar
2ce0: 67 75 6d 65 6e 74 2c 20 6f 66 20 74 68 65 20 3c  gument, of the <
2cf0: 62 3e 42 4f 4f 4c 45 41 4e 3c 2f 62 3e 20 74 79  b>BOOLEAN</b> ty
2d00: 70 65 2c 20 63 61 6e 20 62 65 20 61 70 70 72 6f  pe, can be appro
2d10: 70 72 69 61 74 65 6c 79 20 73 65 74 20 69 6e 20  priately set in 
2d20: 6f 72 64 65 72 20 74 6f 20 64 65 74 65 72 6d 69  order to determi
2d30: 6e 65 20 74 68 65 20 65 78 70 65 63 74 65 64 20  ne the expected 
2d40: 62 65 68 61 76 69 6f 72 20 69 6e 20 74 68 65 20  behavior in the 
2d50: 63 61 73 65 20 6f 66 20 66 61 69 6c 75 72 65 2e  case of failure.
2d60: 3c 62 72 3e 0d 0a 54 68 65 20 69 6e 74 65 72 70  <br>..The interp
2d70: 72 65 74 61 74 69 6f 6e 20 69 73 20 65 78 61 63  retation is exac
2d80: 74 6c 79 20 74 68 65 20 73 61 6d 65 20 61 73 20  tly the same as 
2d90: 69 6e 20 3c 62 3e 44 72 6f 70 54 61 62 6c 65 28  in <b>DropTable(
2da0: 29 3c 2f 62 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  )</b>.</li>..<li
2db0: 3e 74 68 65 20 3c 62 3e 72 65 74 75 72 6e 20 76  >the <b>return v
2dc0: 61 6c 75 65 3c 2f 62 3e 20 69 73 20 6f 66 20 74  alue</b> is of t
2dd0: 68 65 20 3c 62 3e 42 4f 4f 4c 45 41 4e 3c 2f 62  he <b>BOOLEAN</b
2de0: 3e 20 74 79 70 65 3a 0d 0a 3c 75 6c 3e 0d 0a 3c  > type:..<ul>..<
2df0: 6c 69 3e 3c 62 3e 54 52 55 45 3c 2f 62 3e 20 69  li><b>TRUE</b> i
2e00: 6e 20 74 68 65 20 63 61 73 65 20 6f 66 20 73 75  n the case of su
2e10: 63 63 65 73 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  ccess.</li>..<li
2e20: 3e 3c 62 3e 46 41 4c 53 45 3c 2f 62 3e 20 28 6f  ><b>FALSE</b> (o
2e30: 72 20 61 6e 20 3c 62 3e 45 78 63 65 70 74 69 6f  r an <b>Exceptio
2e40: 6e 3c 2f 62 3e 29 20 69 6e 20 74 68 65 20 63 61  n</b>) in the ca
2e50: 73 65 20 6f 66 20 69 6e 76 61 6c 69 64 20 61 72  se of invalid ar
2e60: 67 75 6d 65 6e 74 73 20 6f 72 20 66 61 69 6c 75  guments or failu
2e70: 72 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c  re.</li>..</ul><
2e80: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 4e 6f 74  /li>..<li><b>Not
2e90: 65 3c 2f 62 3e 3a 20 74 68 69 73 20 66 75 6e 63  e</b>: this func
2ea0: 74 69 6f 6e 20 63 61 72 65 66 75 6c 6c 79 20 63  tion carefully c
2eb0: 68 65 63 6b 73 20 74 6f 20 69 6e 73 75 72 65 20  hecks to insure 
2ec0: 74 68 61 74 20 74 68 65 20 72 65 6e 61 6d 69 6e  that the renamin
2ed0: 67 20 6f 66 20 61 6e 79 20 43 6f 6c 75 6d 6e 73  g of any Columns
2ee0: 20 62 65 6c 6f 6e 67 69 6e 67 20 74 6f 20 53 79   belonging to Sy
2ef0: 73 74 65 6d 20 6f 72 20 4d 65 74 61 64 61 74 61  stem or Metadata
2f00: 20 54 61 62 6c 65 73 20 69 6e 74 65 72 6e 61 6c   Tables internal
2f10: 6c 79 20 72 65 71 75 69 72 65 64 20 62 79 20 65  ly required by e
2f20: 69 74 68 65 72 20 53 51 4c 69 74 65 33 2c 20 53  ither SQLite3, S
2f30: 70 61 74 69 61 4c 69 74 65 2c 20 52 61 73 74 65  patiaLite, Raste
2f40: 72 4c 69 74 65 32 2c 20 47 65 6f 50 61 63 6b 61  rLite2, GeoPacka
2f50: 67 65 20 6f 72 20 46 44 4f 20 69 73 20 70 72 65  ge or FDO is pre
2f60: 76 65 6e 74 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 2f  vented.</li>..</
2f70: 75 6c 3e 0d 0a 3c 62 72 3e 0d 0a 3c 74 61 62 6c  ul>..<br>..<tabl
2f80: 65 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 38  e cellspacing="8
2f90: 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 38  " cellpadding="8
2fa0: 22 20 62 67 63 6f 6c 6f 72 3d 22 23 66 66 66 66  " bgcolor="#ffff
2fb0: 39 30 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 68  90"><tr><td>..<h
2fc0: 33 3e 42 65 20 61 77 61 72 65 3c 2f 68 33 3e 0d  3>Be aware</h3>.
2fd0: 0a 53 51 4c 69 74 65 33 20 63 61 6e 20 6e 65 76  .SQLite3 can nev
2fe0: 65 72 20 72 65 6e 61 6d 65 20 43 6f 6c 75 6d 6e  er rename Column
2ff0: 73 20 62 65 6c 6f 6e 67 69 6e 67 20 74 6f 20 61  s belonging to a
3000: 20 3c 62 3e 56 69 65 77 3c 2f 62 3e 20 6f 72 20   <b>View</b> or 
3010: 3c 62 3e 56 69 72 74 75 61 6c 54 61 62 6c 65 3c  <b>VirtualTable<
3020: 2f 62 3e 2e 3c 62 72 3e 0d 0a 49 66 20 79 6f 75  /b>.<br>..If you
3030: 20 61 62 73 6f 6c 75 74 65 6c 79 20 6e 65 65 64   absolutely need
3040: 20 74 6f 20 63 68 61 6e 67 65 20 74 68 65 20 6e   to change the n
3050: 61 6d 65 20 6f 66 20 61 6e 79 20 43 6f 6c 75 6d  ame of any Colum
3060: 6e 73 20 69 6e 20 61 20 56 69 65 77 20 6f 72 20  ns in a View or 
3070: 56 69 72 74 75 61 6c 54 61 62 6c 65 20 61 66 74  VirtualTable aft
3080: 65 72 20 69 74 27 73 20 63 72 65 61 74 69 6f 6e  er it's creation
3090: 2c 20 79 6f 75 20 6d 75 73 74 20 66 69 72 73 74  , you must first
30a0: 20 64 72 6f 70 20 69 74 2c 20 61 6e 64 20 74 68   drop it, and th
30b0: 65 6e 20 72 65 63 72 65 61 74 65 20 69 74 20 77  en recreate it w
30c0: 69 74 68 20 74 68 65 20 6e 65 77 20 43 6f 6c 75  ith the new Colu
30d0: 6d 6e 20 6e 61 6d 65 2e 0d 0a 3c 2f 74 64 3e 3c  mn name...</td><
30e0: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62  /tr></table>..<b
30f0: 72 3e 0d 0a 3c 68 72 3e 3c 62 72 3e 0d 0a 42 61  r>..<hr><br>..Ba
3100: 63 6b 20 74 6f 20 3c 61 20 68 72 65 66 3d 22 68  ck to <a href="h
3110: 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d  ttps://www.gaia-
3120: 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c 69  gis.it/fossil/li
3130: 62 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b 69  bspatialite/wiki
3140: 3f 6e 61 6d 65 3d 35 2e 30 2e 30 2d 64 6f 63 22  ?name=5.0.0-doc"
3150: 3e 35 2e 30 2e 30 2d 64 6f 63 20 6d 61 69 6e 20  >5.0.0-doc main 
3160: 70 61 67 65 3c 2f 61 3e 0a 5a 20 31 32 61 33 33  page</a>.Z 12a33
3170: 39 39 62 63 36 65 35 35 39 34 62 63 63 38 39 36  99bc6e5594bcc896
3180: 35 39 62 34 32 33 30 30 35 30 37 0a              59b42300507.