Wiki page
[CloneTable] by
sandro
2014-08-28 16:02:55.
0000: 44 20 32 30 31 34 2d 30 38 2d 32 38 54 31 36 3a D 2014-08-28T16:
0010: 30 32 3a 35 35 2e 31 37 36 0a 4c 20 43 6c 6f 6e 02:55.176.L Clon
0020: 65 54 61 62 6c 65 0a 50 20 34 61 37 39 36 65 38 eTable.P 4a796e8
0030: 65 32 62 37 63 38 62 36 38 39 33 37 35 38 61 38 e2b7c8b6893758a8
0040: 66 34 61 66 39 66 64 38 65 63 34 33 61 30 32 35 f4af9fd8ec43a025
0050: 31 0a 55 20 73 61 6e 64 72 6f 0a 57 20 31 34 38 1.U sandro.W 148
0060: 38 36 0a 3c 68 32 3e 71 75 69 63 6b 20 68 6f 77 86.<h2>quick how
0070: 2d 74 6f 20 67 75 69 64 65 3a 20 75 73 69 6e 67 -to guide: using
0080: 20 43 6c 6f 6e 65 54 61 62 6c 65 28 29 3c 2f 68 CloneTable()</h
0090: 32 3e 0d 0a 53 74 61 72 74 69 6e 67 20 73 69 6e 2>..Starting sin
00a0: 63 65 20 76 65 72 73 69 6f 6e 20 3c 62 3e 34 2e ce version <b>4.
00b0: 32 2e 31 3c 2f 62 3e 20 61 20 6e 65 77 20 3c 62 2.1</b> a new <b
00c0: 3e 43 6c 6f 6e 65 54 61 62 6c 65 28 29 3c 2f 62 >CloneTable()</b
00d0: 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 69 > SQL function i
00e0: 73 20 6e 6f 77 20 61 76 61 69 6c 61 62 6c 65 3b s now available;
00f0: 20 74 68 69 73 20 6e 65 77 20 66 75 6e 63 74 69 this new functi
0100: 6f 6e 20 69 73 20 73 70 65 63 69 66 69 63 61 6c on is specifical
0110: 6c 79 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 73 ly intended to s
0120: 69 6d 70 6c 69 66 79 20 63 6f 70 79 69 6e 67 20 implify copying
0130: 64 61 74 61 20 62 65 74 77 65 65 6e 20 64 69 66 data between dif
0140: 66 65 72 65 6e 74 20 54 61 62 6c 65 73 20 61 6e ferent Tables an
0150: 64 20 28 6d 61 79 20 62 65 29 20 62 65 74 77 65 d (may be) betwe
0160: 65 6e 20 64 69 66 66 65 72 65 6e 74 20 44 42 2d en different DB-
0170: 66 69 6c 65 73 2e 0d 0a 53 65 76 65 72 61 6c 20 files...Several
0180: 61 64 76 61 6e 63 65 64 20 6f 70 74 69 6f 6e 20 advanced option
0190: 69 6e 74 65 6e 64 65 64 20 74 6f 20 73 75 70 70 intended to supp
01a0: 6f 72 74 20 66 6c 65 78 69 62 6c 65 20 62 65 68 ort flexible beh
01b0: 61 76 69 6f 72 73 20 61 72 65 20 73 75 70 70 6f aviors are suppo
01c0: 72 74 65 64 2c 20 73 6f 20 72 65 61 64 69 6e 67 rted, so reading
01d0: 20 74 68 69 73 20 71 75 69 63 6b 20 74 75 74 6f this quick tuto
01e0: 72 69 61 6c 20 69 73 20 73 74 72 6f 6e 67 6c 79 rial is strongly
01f0: 20 73 75 67 67 65 73 74 65 64 20 69 6e 20 6f 72 suggested in or
0200: 64 65 72 20 74 6f 20 63 6c 61 72 69 66 79 20 61 der to clarify a
0210: 6e 79 20 70 6f 73 73 69 62 6c 65 20 64 6f 75 62 ny possible doub
0220: 74 20 61 62 6f 75 74 20 3c 62 3e 43 6c 6f 6e 65 t about <b>Clone
0230: 54 61 62 6c 65 28 29 3c 2f 62 3e 2e 0d 0a 3c 68 Table()</b>...<h
0240: 34 3e 64 6f 77 6e 6c 6f 61 64 69 6e 67 20 74 68 4>downloading th
0250: 65 20 73 61 6d 70 6c 65 20 44 42 3c 2f 68 34 3e e sample DB</h4>
0260: 0d 0a 49 6e 20 74 68 69 73 20 74 75 74 6f 72 69 ..In this tutori
0270: 61 6c 20 77 65 27 6c 6c 20 75 73 65 20 61 20 73 al we'll use a s
0280: 61 6d 70 6c 65 20 44 42 20 61 76 61 69 6c 61 62 ample DB availab
0290: 6c 65 20 66 6f 72 20 3c 61 20 68 72 65 66 3d 22 le for <a href="
02a0: 68 74 74 70 3a 2f 2f 77 77 77 2e 67 61 69 61 2d http://www.gaia-
02b0: 67 69 73 2e 69 74 2f 67 61 69 61 2d 73 69 6e 73 gis.it/gaia-sins
02c0: 2f 63 6c 6f 6e 65 5f 74 61 62 6c 65 2f 63 6c 6f /clone_table/clo
02d0: 6e 65 5f 6f 72 69 67 69 6e 2e 7a 69 70 22 3e 64 ne_origin.zip">d
02e0: 6f 77 6e 6c 6f 61 64 3c 2f 61 3e 0d 0a 3c 68 34 ownload</a>..<h4
02f0: 3e 65 78 70 6c 6f 72 69 6e 67 20 74 68 65 20 73 >exploring the s
0300: 61 6d 70 6c 65 20 44 42 3c 2f 68 34 3e 0d 0a 41 ample DB</h4>..A
0310: 73 20 79 6f 75 20 63 61 6e 20 65 61 73 69 6c 79 s you can easily
0320: 20 63 68 65 63 6b 20 74 68 65 20 73 61 6d 70 6c check the sampl
0330: 65 20 44 42 20 63 6f 6e 74 61 69 6e 73 20 74 68 e DB contains th
0340: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 54 61 62 6c e following Tabl
0350: 65 73 3a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 es:<br><br>..<ta
0360: 62 6c 65 20 77 69 64 74 68 3d 22 31 30 30 25 22 ble width="100%"
0370: 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 32 22 cellspacing="2"
0380: 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22 cellpadding="6"
0390: 20 62 6f 72 64 65 72 3d 22 31 22 20 62 67 63 6f border="1" bgco
03a0: 6c 6f 72 3d 22 23 66 30 66 66 66 30 22 3e 0d 0a lor="#f0fff0">..
03b0: 3c 74 72 3e 3c 74 68 20 62 67 63 6f 6c 6f 72 3d <tr><th bgcolor=
03c0: 22 23 66 66 64 64 61 30 22 3e 54 61 62 6c 65 3c "#ffdda0">Table<
03d0: 2f 74 68 3e 3c 74 68 20 62 67 63 6f 6c 6f 72 3d /th><th bgcolor=
03e0: 22 23 66 66 64 64 61 30 22 3e 43 72 65 61 74 65 "#ffdda0">Create
03f0: 20 53 74 61 74 65 6d 65 6e 74 3c 2f 74 68 3e 3c Statement</th><
0400: 74 68 20 62 67 63 6f 6c 6f 72 3d 22 23 66 66 64 th bgcolor="#ffd
0410: 64 61 30 22 3e 47 65 6f 6d 65 74 72 79 20 43 6f da0">Geometry Co
0420: 6c 75 6d 6e 3c 2f 74 68 3e 3c 74 68 20 62 67 63 lumn</th><th bgc
0430: 6f 6c 6f 72 3d 22 23 66 66 64 64 61 30 22 3e 49 olor="#ffdda0">I
0440: 6e 64 65 78 3c 2f 74 68 3e 3c 74 68 20 62 67 63 ndex</th><th bgc
0450: 6f 6c 6f 72 3d 22 23 66 66 64 64 61 30 22 3e 54 olor="#ffdda0">T
0460: 72 69 67 67 65 72 3c 2f 74 68 3e 3c 2f 74 72 3e rigger</th></tr>
0470: 0d 0a 3c 74 72 3e 3c 74 64 3e 3c 62 3e 72 65 67 ..<tr><td><b>reg
0480: 69 6f 6e 73 3c 2f 62 3e 3c 2f 74 64 3e 0d 0a 3c ions</b></td>..<
0490: 74 64 3e 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43 td><verbatim>..C
04a0: 52 45 41 54 45 20 54 41 42 4c 45 20 72 65 67 69 REATE TABLE regi
04b0: 6f 6e 73 20 28 0d 0a 20 20 20 20 6d 61 63 72 6f ons (.. macro
04c0: 5f 72 65 67 69 6f 6e 20 54 45 58 54 20 4e 4f 54 _region TEXT NOT
04d0: 20 4e 55 4c 4c 2c 0d 0a 20 20 20 20 6e 75 74 73 NULL,.. nuts
04e0: 5f 31 20 54 45 58 54 20 4e 4f 54 20 4e 55 4c 4c _1 TEXT NOT NULL
04f0: 2c 0d 0a 20 20 20 20 6e 75 74 73 5f 32 20 54 45 ,.. nuts_2 TE
0500: 58 54 20 4e 4f 54 20 4e 55 4c 4c 20 50 52 49 4d XT NOT NULL PRIM
0510: 41 52 59 20 4b 45 59 2c 0d 0a 20 20 20 20 72 65 ARY KEY,.. re
0520: 67 69 6f 6e 20 54 45 58 54 20 4e 4f 54 20 4e 55 gion TEXT NOT NU
0530: 4c 4c 2c 20 0d 0a 20 20 20 20 70 6f 70 5f 32 30 LL, .. pop_20
0540: 31 31 20 49 4e 54 45 47 45 52 20 4e 4f 54 20 4e 11 INTEGER NOT N
0550: 55 4c 4c 2c 0d 0a 20 20 20 20 70 6f 70 5f 6d 5f ULL,.. pop_m_
0560: 32 30 31 31 20 49 4e 54 45 47 45 52 20 4e 4f 54 2011 INTEGER NOT
0570: 20 4e 55 4c 4c 2c 0d 0a 20 20 20 20 70 6f 70 5f NULL,.. pop_
0580: 66 5f 32 30 31 31 20 49 4e 54 45 47 45 52 20 4e f_2011 INTEGER N
0590: 4f 54 20 4e 55 4c 4c 0d 0a 29 3b 0d 0a 3c 2f 76 OT NULL..);..</v
05a0: 65 72 62 61 74 69 6d 3e 3c 2f 74 64 3e 3c 74 64 erbatim></td><td
05b0: 3e 3c 69 3e 6e 6f 6e 65 3c 2f 69 3e 3c 2f 74 64 ><i>none</i></td
05c0: 3e 3c 74 64 3e 3c 69 3e 6e 6f 6e 65 3c 2f 69 3e ><td><i>none</i>
05d0: 3c 2f 74 64 3e 3c 74 64 3e 3c 69 3e 6e 6f 6e 65 </td><td><i>none
05e0: 3c 2f 69 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a </i></td></tr>..
05f0: 3c 74 72 3e 3c 74 64 3e 3c 62 3e 70 72 6f 76 5f <tr><td><b>prov_
0600: 69 74 63 3c 2f 62 3e 3c 2f 74 64 3e 0d 0a 3c 74 itc</b></td>..<t
0610: 64 3e 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 d><verbatim>..CR
0620: 45 41 54 45 20 54 41 42 4c 45 20 70 72 6f 76 5f EATE TABLE prov_
0630: 69 74 63 20 28 0d 0a 20 20 20 20 69 64 20 49 4e itc (.. id IN
0640: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 TEGER PRIMARY KE
0650: 59 20 41 55 54 4f 49 4e 43 52 45 4d 45 4e 54 2c Y AUTOINCREMENT,
0660: 0d 0a 20 20 20 20 6e 75 74 73 5f 32 20 54 45 58 .. nuts_2 TEX
0670: 54 20 4e 4f 54 20 4e 55 4c 4c 2c 0d 0a 20 20 20 T NOT NULL,..
0680: 20 6e 75 74 73 5f 33 20 54 45 58 54 20 4e 4f 54 nuts_3 TEXT NOT
0690: 20 4e 55 4c 4c 2c 0d 0a 20 20 20 20 70 72 6f 76 NULL,.. prov
06a0: 69 6e 63 65 20 54 45 58 54 20 4e 4f 54 20 4e 55 ince TEXT NOT NU
06b0: 4c 4c 2c 0d 0a 20 20 20 20 63 6f 64 65 20 54 45 LL,.. code TE
06c0: 58 54 20 4e 4f 54 20 4e 55 4c 4c 2c 0d 0a 20 20 XT NOT NULL,..
06d0: 20 20 70 6f 70 5f 32 30 31 31 20 49 4e 54 45 47 pop_2011 INTEG
06e0: 45 52 20 44 45 46 41 55 4c 54 20 30 2c 0d 0a 20 ER DEFAULT 0,..
06f0: 20 20 20 70 6f 70 5f 6d 5f 32 30 31 31 20 49 4e pop_m_2011 IN
0700: 54 45 47 45 52 20 44 45 46 41 55 4c 54 20 30 2c TEGER DEFAULT 0,
0710: 0d 0a 20 20 20 20 70 6f 70 5f 66 5f 32 30 31 31 .. pop_f_2011
0720: 20 49 4e 54 45 47 45 52 20 44 45 46 41 55 4c 54 INTEGER DEFAULT
0730: 20 30 0d 0a 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 0..);..</verbat
0740: 69 6d 3e 3c 2f 74 64 3e 3c 74 64 3e 3c 62 3e 67 im></td><td><b>g
0750: 65 6f 6d 3c 2f 62 3e 3c 62 72 3e 3c 62 72 3e 73 eom</b><br><br>s
0760: 72 69 64 3d 3c 62 3e 33 32 36 33 32 3c 2f 62 3e rid=<b>32632</b>
0770: 3c 62 72 3e 3c 62 3e 4d 55 4c 54 49 50 4f 4c 59 <br><b>MULTIPOLY
0780: 47 4f 4e 3c 2f 62 3e 3c 62 72 3e 3c 62 72 3e 3c GON</b><br><br><
0790: 69 3e 6e 6f 20 53 70 61 74 69 61 6c 20 49 6e 64 i>no Spatial Ind
07a0: 65 78 3c 2f 69 3e 3c 2f 74 64 3e 0d 0a 3c 74 64 ex</i></td>..<td
07b0: 3e 3c 69 3e 6e 6f 6e 65 3c 2f 69 3e 3c 2f 74 64 ><i>none</i></td
07c0: 3e 3c 74 64 3e 3c 69 3e 6e 6f 6e 65 3c 2f 69 3e ><td><i>none</i>
07d0: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e </td></tr>..<tr>
07e0: 3c 74 64 3e 3c 62 3e 70 72 6f 76 5f 69 74 66 3c <td><b>prov_itf<
07f0: 2f 62 3e 3c 2f 74 64 3e 3c 74 64 20 63 6f 6c 73 /b></td><td cols
0800: 70 61 6e 3d 22 34 22 20 72 6f 77 73 70 61 6e 3d pan="4" rowspan=
0810: 22 34 22 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 "4" align="cente
0820: 72 22 3e 3c 69 3e 73 61 6d 65 20 61 73 20 3c 62 r"><i>same as <b
0830: 3e 70 72 6f 76 5f 69 74 63 3c 2f 62 3e 3c 2f 74 >prov_itc</b></t
0840: 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 d></tr>..<tr><td
0850: 3e 3c 62 3e 70 72 6f 76 5f 69 74 67 3c 2f 62 3e ><b>prov_itg</b>
0860: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e </td></tr>..<tr>
0870: 3c 74 64 3e 3c 62 3e 70 72 6f 76 5f 69 74 68 3c <td><b>prov_ith<
0880: 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c /b></td></tr>..<
0890: 74 72 3e 3c 74 64 3e 3c 62 3e 70 72 6f 76 5f 69 tr><td><b>prov_i
08a0: 74 69 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e ti</b></td></tr>
08b0: 0d 0a 3c 74 72 3e 3c 74 64 3e 3c 62 3e 70 72 6f ..<tr><td><b>pro
08c0: 76 69 6e 63 65 73 3c 2f 62 3e 3c 2f 74 64 3e 0d vinces</b></td>.
08d0: 0a 3c 74 64 3e 3c 76 65 72 62 61 74 69 6d 3e 0d .<td><verbatim>.
08e0: 0a 43 52 45 41 54 45 20 54 41 42 4c 45 20 70 72 .CREATE TABLE pr
08f0: 6f 76 69 6e 63 65 73 20 28 0d 0a 20 20 20 20 6e ovinces (.. n
0900: 75 74 73 5f 32 20 54 45 58 54 20 4e 4f 54 20 4e uts_2 TEXT NOT N
0910: 55 4c 4c 2c 0d 0a 20 20 20 20 6e 75 74 73 5f 33 ULL,.. nuts_3
0920: 20 54 45 58 54 20 4e 4f 54 20 4e 55 4c 4c 20 50 TEXT NOT NULL P
0930: 52 49 4d 41 52 59 20 4b 45 59 2c 0d 0a 20 20 20 RIMARY KEY,..
0940: 20 70 72 6f 76 69 6e 63 65 20 54 45 58 54 20 4e province TEXT N
0950: 4f 54 20 4e 55 4c 4c 2c 0d 0a 20 20 20 20 63 6f OT NULL,.. co
0960: 64 65 20 54 45 58 54 20 4e 4f 54 20 4e 55 4c 4c de TEXT NOT NULL
0970: 2c 0d 0a 20 20 20 20 70 6f 70 5f 32 30 31 31 20 ,.. pop_2011
0980: 49 4e 54 45 47 45 52 20 4e 4f 54 20 4e 55 4c 4c INTEGER NOT NULL
0990: 2c 0d 0a 20 20 20 20 70 6f 70 5f 6d 5f 32 30 31 ,.. pop_m_201
09a0: 31 20 49 4e 54 45 47 45 52 20 4e 4f 54 20 4e 55 1 INTEGER NOT NU
09b0: 4c 4c 2c 0d 0a 20 20 20 20 70 6f 70 5f 66 5f 32 LL,.. pop_f_2
09c0: 30 31 31 20 49 4e 54 45 47 45 52 20 4e 4f 54 20 011 INTEGER NOT
09d0: 4e 55 4c 4c 2c 0d 0a 20 20 20 20 43 4f 4e 53 54 NULL,.. CONST
09e0: 52 41 49 4e 54 20 66 6b 5f 70 72 6f 76 5f 72 65 RAINT fk_prov_re
09f0: 67 20 0d 0a 20 20 20 20 20 20 20 20 46 4f 52 45 g .. FORE
0a00: 49 47 4e 20 4b 45 59 20 28 6e 75 74 73 5f 32 29 IGN KEY (nuts_2)
0a10: 20 0d 0a 20 20 20 20 20 20 20 20 52 45 46 45 52 .. REFER
0a20: 45 4e 43 45 53 20 72 65 67 69 6f 6e 73 20 28 6e ENCES regions (n
0a30: 75 74 73 5f 32 29 29 3b 0d 0a 3c 2f 76 65 72 62 uts_2));..</verb
0a40: 61 74 69 6d 3e 3c 2f 74 64 3e 3c 74 64 3e 3c 62 atim></td><td><b
0a50: 3e 67 65 6f 6d 3c 2f 62 3e 3c 62 72 3e 3c 62 72 >geom</b><br><br
0a60: 3e 73 72 69 64 3d 3c 62 3e 33 32 36 33 32 3c 2f >srid=<b>32632</
0a70: 62 3e 3c 62 72 3e 3c 62 3e 4d 55 4c 54 49 50 4f b><br><b>MULTIPO
0a80: 4c 59 47 4f 4e 3c 2f 62 3e 3c 62 72 3e 3c 62 72 LYGON</b><br><br
0a90: 3e 3c 62 3e 53 70 61 74 69 61 6c 20 49 6e 64 65 ><b>Spatial Inde
0aa0: 78 3c 2f 62 3e 3c 2f 74 64 3e 0d 0a 3c 74 64 3e x</b></td>..<td>
0ab0: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 <verbatim>..CREA
0ac0: 54 45 20 49 4e 44 45 58 20 69 64 78 5f 70 72 6f TE INDEX idx_pro
0ad0: 76 5f 63 6f 64 65 20 0d 0a 20 20 20 20 4f 4e 20 v_code .. ON
0ae0: 70 72 6f 76 69 6e 63 65 73 20 28 63 6f 64 65 29 provinces (code)
0af0: 3b 0d 0a 43 52 45 41 54 45 20 49 4e 44 45 58 20 ;..CREATE INDEX
0b00: 69 64 78 5f 70 72 6f 76 5f 6e 61 6d 65 20 0d 0a idx_prov_name ..
0b10: 20 20 20 20 4f 4e 20 70 72 6f 76 69 6e 63 65 73 ON provinces
0b20: 20 28 6e 61 6d 65 29 3b 0d 0a 3c 2f 76 65 72 62 (name);..</verb
0b30: 61 74 69 6d 3e 3c 2f 74 64 3e 3c 74 64 3e 3c 76 atim></td><td><v
0b40: 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54 45 erbatim>..CREATE
0b50: 20 54 52 49 47 47 45 52 20 69 6e 73 5f 70 72 6f TRIGGER ins_pro
0b60: 76 20 0d 0a 20 20 20 20 41 46 54 45 52 20 49 4e v .. AFTER IN
0b70: 53 45 52 54 20 4f 4e 20 70 72 6f 76 69 6e 63 65 SERT ON province
0b80: 73 0d 0a 42 45 47 49 4e 0d 0a 20 20 55 50 44 41 s..BEGIN.. UPDA
0b90: 54 45 20 72 65 67 69 6f 6e 73 20 0d 0a 20 20 53 TE regions .. S
0ba0: 45 54 20 70 6f 70 5f 32 30 31 31 20 3d 20 70 6f ET pop_2011 = po
0bb0: 70 5f 32 30 31 31 20 2b 20 4e 45 57 2e 70 6f 70 p_2011 + NEW.pop
0bc0: 5f 32 30 31 31 2c 0d 0a 20 20 20 20 70 6f 70 5f _2011,.. pop_
0bd0: 6d 5f 32 30 31 31 20 3d 20 70 6f 70 5f 6d 5f 32 m_2011 = pop_m_2
0be0: 30 31 31 20 2b 20 4e 45 57 2e 70 6f 70 5f 6d 5f 011 + NEW.pop_m_
0bf0: 32 30 31 31 2c 0d 0a 20 20 20 20 70 6f 70 5f 66 2011,.. pop_f
0c00: 5f 32 30 31 31 20 3d 20 70 6f 70 5f 66 5f 32 30 _2011 = pop_f_20
0c10: 31 31 20 2b 20 4e 45 57 2e 70 6f 70 5f 66 5f 32 11 + NEW.pop_f_2
0c20: 30 31 31 0d 0a 20 20 57 48 45 52 45 20 6e 75 74 011.. WHERE nut
0c30: 73 5f 32 20 3d 20 4e 45 57 2e 6e 75 74 73 5f 32 s_2 = NEW.nuts_2
0c40: 3b 0d 0a 45 4e 44 3b 0d 0a 3c 2f 76 65 72 62 61 ;..END;..</verba
0c50: 74 69 6d 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a tim></td></tr>..
0c60: 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 </table><br>..Th
0c70: 65 20 73 61 6d 70 6c 65 20 44 42 20 69 73 20 66 e sample DB is f
0c80: 75 6c 6c 79 20 62 61 73 65 64 20 6f 6e 20 74 68 ully based on th
0c90: 65 20 32 30 31 31 20 49 74 61 6c 69 61 6e 20 43 e 2011 Italian C
0ca0: 65 6e 73 75 73 20 6b 69 6e 64 6c 79 20 72 65 6c ensus kindly rel
0cb0: 65 61 73 65 64 20 62 79 20 3c 61 20 68 72 65 66 eased by <a href
0cc0: 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 69 73 74 ="http://www.ist
0cd0: 61 74 2e 69 74 2f 69 74 2f 61 72 63 68 69 76 69 at.it/it/archivi
0ce0: 6f 2f 31 30 34 33 31 37 22 3e 49 53 54 41 54 3c o/104317">ISTAT<
0cf0: 2f 61 3e 20 75 6e 64 65 72 20 3c 61 20 68 72 65 /a> under <a hre
0d00: 66 3d 22 68 74 74 70 73 3a 2f 2f 63 72 65 61 74 f="https://creat
0d10: 69 76 65 63 6f 6d 6d 6f 6e 73 2e 6f 72 67 2f 6c ivecommons.org/l
0d20: 69 63 65 6e 73 65 73 2f 62 79 2f 33 2e 30 2f 22 icenses/by/3.0/"
0d30: 3e 43 43 2d 42 59 20 6c 69 63 65 6e 73 65 3c 2f >CC-BY license</
0d40: 61 3e 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 4a 75 73 a>.<br><br>..Jus
0d50: 74 20 66 65 77 20 6b 65 79 70 6f 69 6e 74 73 20 t few keypoints
0d60: 77 6f 72 74 68 20 74 6f 20 62 65 20 68 69 67 68 worth to be high
0d70: 6c 69 67 68 74 65 64 3a 0d 0a 3c 75 6c 3e 0d 0a lighted:..<ul>..
0d80: 3c 6c 69 3e 42 6f 74 68 20 52 65 67 69 6f 6e 73 <li>Both Regions
0d90: 20 61 6e 64 20 50 72 6f 76 69 6e 63 65 73 20 61 and Provinces a
0da0: 72 65 20 63 6f 64 65 64 20 61 63 63 6f 72 64 69 re coded accordi
0db0: 6e 67 6c 79 20 74 6f 20 3c 61 20 68 72 65 66 3d ngly to <a href=
0dc0: 22 68 74 74 70 3a 2f 2f 65 6e 2e 77 69 6b 69 70 "http://en.wikip
0dd0: 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 4e 6f edia.org/wiki/No
0de0: 6d 65 6e 63 6c 61 74 75 72 65 5f 6f 66 5f 54 65 menclature_of_Te
0df0: 72 72 69 74 6f 72 69 61 6c 5f 55 6e 69 74 73 5f rritorial_Units_
0e00: 66 6f 72 5f 53 74 61 74 69 73 74 69 63 73 22 3e for_Statistics">
0e10: 4e 55 54 53 3c 2f 61 3e 3c 62 72 3e 0d 0a 3c 62 NUTS</a><br>..<b
0e20: 3e 4e 55 54 53 20 6c 65 76 65 6c 2d 32 3c 2f 62 >NUTS level-2</b
0e30: 3e 20 61 6e 64 20 3c 62 3e 4e 55 54 53 20 6c 65 > and <b>NUTS le
0e40: 76 65 6c 2d 33 3c 2f 62 3e 20 63 6f 64 65 73 20 vel-3</b> codes
0e50: 63 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 61 20 correspond to a
0e60: 72 65 6c 61 74 69 6f 6e 61 6c 20 68 69 65 72 61 relational hiera
0e70: 72 63 68 79 20 72 65 66 6c 65 63 74 65 64 20 62 rchy reflected b
0e80: 79 20 74 68 65 20 3c 62 3e 50 72 69 6d 61 72 79 y the <b>Primary
0e90: 3c 2f 62 3e 20 2f 20 3c 62 3e 46 6f 72 65 69 67 </b> / <b>Foreig
0ea0: 6e 20 4b 65 79 3c 2f 62 3e 20 72 65 6c 61 74 69 n Key</b> relati
0eb0: 6f 6e 73 68 69 70 73 20 6a 6f 69 6e 69 6e 67 20 onships joining
0ec0: 74 68 65 20 3c 62 3e 72 65 67 69 6f 6e 73 3c 2f the <b>regions</
0ed0: 62 3e 20 61 6e 64 20 3c 62 3e 70 72 6f 76 69 6e b> and <b>provin
0ee0: 63 65 73 3c 2f 62 3e 20 54 61 62 6c 65 73 2e 3c ces</b> Tables.<
0ef0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 41 6c 6c 20 49 74 /li>..<li>All It
0f00: 61 6c 69 61 6e 20 50 72 6f 76 69 6e 63 65 73 20 alian Provinces
0f10: 61 72 65 20 63 6f 6e 74 61 69 6e 65 64 20 77 69 are contained wi
0f20: 74 68 69 6e 20 74 68 65 20 74 61 62 6c 65 73 20 thin the tables
0f30: 3c 62 3e 70 72 6f 76 5f 69 74 63 3c 2f 62 3e 2c <b>prov_itc</b>,
0f40: 20 3c 62 3e 70 72 6f 76 5f 69 74 66 3c 2f 62 3e <b>prov_itf</b>
0f50: 2c 20 3c 62 3e 70 72 6f 76 5f 69 74 67 3c 2f 62 , <b>prov_itg</b
0f60: 3e 2c 20 3c 62 3e 70 72 6f 76 5f 69 74 68 3c 2f >, <b>prov_ith</
0f70: 62 3e 20 61 6e 64 20 3c 62 3e 70 72 6f 76 5f 69 b> and <b>prov_i
0f80: 74 69 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 45 61 63 ti</b>.<br>..Eac
0f90: 68 20 73 69 6e 67 6c 65 20 54 61 62 6c 65 20 64 h single Table d
0fa0: 69 72 65 63 74 6c 79 20 63 6f 72 72 65 73 70 6f irectly correspo
0fb0: 6e 64 73 20 74 6f 20 61 20 3c 62 3e 4e 55 54 53 nds to a <b>NUTS
0fc0: 20 6c 65 76 65 6c 2d 31 3c 2f 62 3e 20 63 6f 64 level-1</b> cod
0fd0: 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 54 61 62 e.</li>..<li>Tab
0fe0: 6c 65 20 3c 62 3e 70 72 6f 76 69 6e 63 65 73 3c le <b>provinces<
0ff0: 2f 62 3e 20 28 77 68 6f 6c 65 20 49 74 61 6c 79 /b> (whole Italy
1000: 29 20 69 73 20 69 6e 73 74 65 61 64 20 63 6f 6d ) is instead com
1010: 70 6c 65 74 65 6c 79 20 65 6d 70 74 79 20 28 3c pletely empty (<
1020: 69 3e 77 65 27 6c 6c 20 73 65 65 20 6c 61 74 65 i>we'll see late
1030: 72 20 74 68 65 20 69 6e 74 65 6e 64 65 64 20 73 r the intended s
1040: 63 6f 70 65 20 6f 66 20 74 68 69 73 20 54 61 62 cope of this Tab
1050: 6c 65 3c 2f 69 3e 29 3a 0d 0a 3c 75 6c 3e 0d 0a le</i>):..<ul>..
1060: 3c 6c 69 3e 74 68 69 73 20 74 61 62 6c 65 20 69 <li>this table i
1070: 73 20 73 75 70 70 6f 72 74 65 64 20 62 79 20 74 s supported by t
1080: 77 6f 20 6f 72 64 69 6e 61 72 79 20 49 6e 64 69 wo ordinary Indi
1090: 63 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 ces.</li>..<li>t
10a0: 68 65 72 65 20 69 73 20 61 20 54 72 69 67 67 65 here is a Trigge
10b0: 72 20 66 69 72 69 6e 67 20 65 61 63 68 20 74 69 r firing each ti
10c0: 6d 65 20 74 68 61 74 20 61 20 6e 65 77 20 72 6f me that a new ro
10d0: 77 20 77 69 6c 6c 20 62 65 20 69 6e 73 65 72 74 w will be insert
10e0: 65 64 20 69 6e 74 6f 20 74 68 69 73 20 54 61 62 ed into this Tab
10f0: 6c 65 2e 3c 62 72 3e 0d 0a 54 68 65 20 69 6e 74 le.<br>..The int
1100: 65 6e 64 65 64 20 73 63 6f 70 65 20 6f 66 20 74 ended scope of t
1110: 68 69 73 20 54 72 69 67 67 65 72 20 69 73 20 74 his Trigger is t
1120: 6f 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 75 70 o immediately up
1130: 64 61 74 65 20 74 68 65 20 50 6f 70 75 6c 61 74 date the Populat
1140: 69 6f 6e 20 32 30 31 31 20 76 61 6c 75 65 73 20 ion 2011 values
1150: 73 74 6f 72 65 64 20 69 6e 74 6f 20 74 68 65 20 stored into the
1160: 3c 62 3e 72 65 67 69 6f 6e 73 3c 2f 62 3e 20 54 <b>regions</b> T
1170: 61 62 6c 65 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c able.</li>..</ul
1180: 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 ></li>..</ul><br
1190: 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 54 75 74 >..<hr>..<h3>Tut
11a0: 6f 72 69 61 6c 20 73 74 65 70 20 23 31 20 28 3c orial step #1 (<
11b0: 69 3e 62 61 73 69 63 20 6c 65 76 65 6c 3c 2f 69 i>basic level</i
11c0: 3e 29 3c 2f 68 33 3e 0d 0a 57 65 27 6c 6c 20 75 >)</h3>..We'll u
11d0: 73 65 20 74 68 65 20 3c 62 3e 73 71 6c 69 74 65 se the <b>sqlite
11e0: 33 3c 2f 62 3e 20 43 4c 49 20 66 72 6f 6e 74 2d 3</b> CLI front-
11f0: 65 6e 64 20 74 6f 6f 6c 20 69 6e 20 74 68 65 20 end tool in the
1200: 66 6f 6c 6c 6f 77 69 6e 67 20 65 78 61 6d 70 6c following exampl
1210: 65 73 2c 20 62 75 74 20 79 6f 75 20 63 6f 75 6c es, but you coul
1220: 64 20 65 76 65 6e 74 75 61 6c 6c 79 20 75 73 65 d eventually use
1230: 20 65 69 74 68 65 72 20 3c 62 3e 73 70 61 74 69 either <b>spati
1240: 61 6c 69 74 65 3c 2f 62 3e 20 6f 72 20 3c 62 3e alite</b> or <b>
1250: 73 70 61 74 69 61 6c 69 74 65 5f 67 75 69 3c 2f spatialite_gui</
1260: 62 3e 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d b>...<verbatim>.
1270: 0a 24 20 73 71 6c 69 74 65 33 20 74 65 73 74 31 .$ sqlite3 test1
1280: 2e 73 71 6c 69 74 65 0d 0a 53 51 4c 69 74 65 20 .sqlite..SQLite
1290: 76 65 72 73 69 6f 6e 20 33 2e 38 2e 36 20 32 30 version 3.8.6 20
12a0: 31 34 2d 30 38 2d 31 35 20 31 31 3a 34 36 3a 33 14-08-15 11:46:3
12b0: 33 0d 0a 45 6e 74 65 72 20 22 2e 68 65 6c 70 22 3..Enter ".help"
12c0: 20 66 6f 72 20 75 73 61 67 65 20 68 69 6e 74 73 for usage hints
12d0: 2e 0d 0a 73 71 6c 69 74 65 3e 20 53 45 4c 45 43 ...sqlite> SELEC
12e0: 54 20 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f 6e T load_extension
12f0: 28 27 6d 6f 64 5f 73 70 61 74 69 61 6c 69 74 65 ('mod_spatialite
1300: 27 29 3b 0d 0a 73 71 6c 69 74 65 3e 0d 0a 3c 2f ');..sqlite>..</
1310: 76 65 72 62 61 74 69 6d 3e 0d 0a 77 65 27 6c 6c verbatim>..we'll
1320: 20 73 74 61 72 74 20 62 79 20 63 72 65 61 74 69 start by creati
1330: 6e 67 20 61 20 6e 65 77 20 44 42 20 6e 61 6d 65 ng a new DB name
1340: 64 20 3c 62 3e 74 65 73 74 31 2e 73 71 6c 69 74 d <b>test1.sqlit
1350: 65 3c 2f 62 3e 20 61 6e 64 20 62 79 20 6c 6f 61 e</b> and by loa
1360: 64 69 6e 67 20 74 68 65 20 3c 62 3e 6d 6f 64 5f ding the <b>mod_
1370: 73 70 61 74 69 61 6c 69 74 65 3c 2f 62 3e 20 64 spatialite</b> d
1380: 79 6e 61 6d 69 63 20 65 78 74 65 6e 73 69 6f 6e ynamic extension
1390: 2e 3c 62 72 3e 0d 0a 3c 76 65 72 62 61 74 69 6d .<br>..<verbatim
13a0: 3e 0d 0a 73 71 6c 69 74 65 3e 20 53 45 4c 45 43 >..sqlite> SELEC
13b0: 54 20 49 6e 69 74 53 70 61 74 69 61 6c 4d 65 74 T InitSpatialMet
13c0: 61 64 61 74 61 28 31 29 3b 0d 0a 31 0d 0a 73 71 adata(1);..1..sq
13d0: 6c 69 74 65 3e 0d 0a 3c 2f 76 65 72 62 61 74 69 lite>..</verbati
13e0: 6d 3e 0d 0a 6e 6f 77 20 77 65 27 6c 6c 20 70 72 m>..now we'll pr
13f0: 6f 70 65 72 6c 79 20 69 6e 69 74 69 61 6c 69 7a operly initializ
1400: 65 20 74 68 65 20 6e 65 77 20 44 42 20 62 79 20 e the new DB by
1410: 63 72 65 61 74 69 6e 67 20 61 6e 79 20 72 65 71 creating any req
1420: 75 69 72 65 64 20 6d 61 74 61 74 61 62 6c 65 2e uired matatable.
1430: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 73 71 ..<verbatim>..sq
1440: 6c 69 74 65 3e 20 41 54 54 41 43 48 20 44 41 54 lite> ATTACH DAT
1450: 41 42 41 53 45 20 22 2e 2f 63 6c 6f 6e 65 5f 6f ABASE "./clone_o
1460: 72 69 67 69 6e 2e 73 71 6c 69 74 65 22 20 41 53 rigin.sqlite" AS
1470: 20 6f 72 69 67 69 6e 3b 0d 0a 73 71 6c 69 74 65 origin;..sqlite
1480: 3e 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a >..</verbatim>..
1490: 61 6e 64 20 66 69 6e 61 6c 6c 79 20 77 65 27 6c and finally we'l
14a0: 6c 20 61 74 74 61 63 68 20 74 68 65 20 3c 62 3e l attach the <b>
14b0: 63 6c 6f 6e 65 5f 6f 72 69 67 69 6e 2e 73 71 6c clone_origin.sql
14c0: 69 74 65 3c 2f 62 3e 20 73 61 6d 70 6c 65 20 44 ite</b> sample D
14d0: 42 3a 20 77 65 20 61 72 65 20 6e 6f 77 20 72 65 B: we are now re
14e0: 61 64 79 20 66 6f 72 20 63 6f 70 79 69 6e 67 20 ady for copying
14f0: 64 61 74 61 20 62 65 74 77 65 65 6e 20 74 68 65 data between the
1500: 20 74 77 6f 20 44 42 2d 66 69 6c 65 73 2e 0d 0a two DB-files...
1510: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 73 71 6c 69 <verbatim>..sqli
1520: 74 65 3e 20 53 45 4c 45 43 54 20 43 6c 6f 6e 65 te> SELECT Clone
1530: 54 61 62 6c 65 28 27 6f 72 69 67 69 6e 27 2c 20 Table('origin',
1540: 27 72 65 67 69 6f 6e 73 27 2c 20 27 72 65 67 69 'regions', 'regi
1550: 6f 6e 73 27 2c 20 31 29 3b 0d 0a 31 0d 0a 73 71 ons', 1);..1..sq
1560: 6c 69 74 65 3e 0d 0a 3c 2f 76 65 72 62 61 74 69 lite>..</verbati
1570: 6d 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 m>..<ul>..<li>th
1580: 65 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74 e first argument
1590: 20 3c 62 3e 27 6f 72 69 67 69 6e 27 3c 2f 62 3e <b>'origin'</b>
15a0: 20 69 64 65 6e 74 69 66 69 65 73 20 74 68 65 20 identifies the
15b0: 3c 62 3e 3c 69 3e 44 42 2d 70 72 65 66 69 78 3c <b><i>DB-prefix<
15c0: 2f 69 3e 3c 2f 62 3e 20 6f 66 20 74 68 65 20 69 /i></b> of the i
15d0: 6e 70 75 74 20 54 61 62 6c 65 2e 3c 62 72 3e 0d nput Table.<br>.
15e0: 0a 49 66 20 74 68 65 20 69 6e 70 75 74 20 54 61 .If the input Ta
15f0: 62 6c 65 20 69 73 20 6c 6f 63 61 74 65 64 20 6f ble is located o
1600: 6e 20 74 68 65 20 70 72 69 6d 61 72 79 20 44 42 n the primary DB
1610: 20 79 6f 75 20 73 69 6d 70 6c 79 20 68 61 76 65 you simply have
1620: 20 74 6f 20 73 70 65 63 69 66 79 20 74 68 65 20 to specify the
1630: 3c 62 3e 27 6d 61 69 6e 27 3c 2f 62 3e 20 63 6f <b>'main'</b> co
1640: 6e 76 65 6e 74 69 6f 6e 61 6c 20 44 42 2d 70 72 nventional DB-pr
1650: 65 66 69 78 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e efix.</li>..<li>
1660: 74 68 65 20 73 65 63 6f 6e 64 20 61 72 67 75 6d the second argum
1670: 65 6e 74 20 3c 62 3e 27 72 65 67 69 6f 6e 73 27 ent <b>'regions'
1680: 3c 2f 62 3e 20 69 64 65 6e 74 69 66 69 65 73 20 </b> identifies
1690: 74 68 65 20 3c 62 3e 3c 69 3e 69 6e 70 75 74 20 the <b><i>input
16a0: 54 61 62 6c 65 3c 2f 69 3e 3c 2f 62 3e 2e 3c 2f Table</i></b>.</
16b0: 6c 69 3e 0d 0a 3c 6c 69 3e 74 68 65 20 74 68 69 li>..<li>the thi
16c0: 72 64 20 61 72 67 75 6d 65 6e 74 20 3c 62 3e 27 rd argument <b>'
16d0: 72 65 67 69 6f 6e 73 27 3c 2f 62 3e 20 69 64 65 regions'</b> ide
16e0: 6e 74 69 66 69 65 73 20 74 68 65 20 3c 62 3e 3c ntifies the <b><
16f0: 69 3e 6f 75 74 70 75 74 20 54 61 62 6c 65 3c 2f i>output Table</
1700: 69 3e 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 3c 75 3e i></b>.<br>..<u>
1710: 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a Please note</u>:
1720: 20 74 68 65 20 6f 75 74 70 75 74 20 54 61 62 6c the output Tabl
1730: 65 20 69 73 20 61 6c 77 61 79 73 20 69 6e 74 65 e is always inte
1740: 6e 64 65 64 20 74 6f 20 62 65 20 6c 6f 63 61 74 nded to be locat
1750: 65 64 20 6f 6e 20 74 68 65 20 3c 62 3e 6d 61 69 ed on the <b>mai
1760: 6e 3c 2f 62 3e 20 44 42 2e 3c 2f 6c 69 3e 0d 0a n</b> DB.</li>..
1770: 3c 6c 69 3e 74 68 65 20 66 6f 75 72 74 68 20 61 <li>the fourth a
1780: 72 67 75 6d 65 6e 74 20 3c 62 3e 31 3c 2f 62 3e rgument <b>1</b>
1790: 20 73 69 6d 70 6c 79 20 64 65 63 6c 61 72 65 73 simply declares
17a0: 20 74 68 61 74 20 74 68 65 20 77 68 6f 6c 65 20 that the whole
17b0: 3c 75 3e 63 72 65 61 74 65 20 2f 20 63 6f 70 79 <u>create / copy
17c0: 3c 2f 75 3e 20 28 3c 69 3e 61 6b 61 3c 2f 69 3e </u> (<i>aka</i>
17d0: 20 3c 75 3e 63 6c 6f 6e 69 6e 67 3c 2f 75 3e 29 <u>cloning</u>)
17e0: 20 6f 70 65 72 61 74 69 6f 6e 20 68 61 73 20 74 operation has t
17f0: 6f 20 62 65 20 61 74 6f 6d 69 63 61 6c 6c 79 20 o be atomically
1800: 63 6f 6e 66 69 6e 65 64 20 77 69 74 68 69 6e 20 confined within
1810: 61 20 6d 6f 6e 6f 6c 69 74 68 69 63 20 53 51 4c a monolithic SQL
1820: 20 54 72 61 6e 73 61 63 74 69 6f 6e 2e 3c 2f 6c Transaction.</l
1830: 69 3e 20 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 76 65 72 i> ..</ul>..<ver
1840: 62 61 74 69 6d 3e 0d 0a 73 71 6c 69 74 65 3e 20 batim>..sqlite>
1850: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 72 65 SELECT * FROM re
1860: 67 69 6f 6e 73 3b 0d 0a 3c 2f 76 65 72 62 61 74 gions;..</verbat
1870: 69 6d 3e 0d 0a 61 73 20 79 6f 75 20 63 61 6e 20 im>..as you can
1880: 65 61 73 69 6c 79 20 63 68 65 63 6b 20 61 20 6e easily check a n
1890: 65 77 20 3c 62 3e 72 65 67 69 6f 6e 73 3c 2f 62 ew <b>regions</b
18a0: 3e 20 74 61 62 6c 65 20 68 61 73 20 62 65 65 6e > table has been
18b0: 20 63 72 65 61 74 65 64 20 28 65 78 61 63 74 6c created (exactl
18c0: 79 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 y corresponding
18d0: 74 6f 20 69 6e 70 75 74 20 64 65 66 69 6e 69 74 to input definit
18e0: 69 6f 6e 73 29 2c 20 61 6e 64 20 61 6c 6c 20 72 ions), and all r
18f0: 6f 77 73 20 68 61 76 65 20 62 65 65 6e 20 63 6f ows have been co
1900: 70 69 65 64 2e 0d 0a 3c 76 65 72 62 61 74 69 6d pied...<verbatim
1910: 3e 0d 0a 73 71 6c 69 74 65 3e 20 53 45 4c 45 43 >..sqlite> SELEC
1920: 54 20 43 6c 6f 6e 65 54 61 62 6c 65 28 27 6f 72 T CloneTable('or
1930: 69 67 69 6e 27 2c 20 27 70 72 6f 76 5f 69 74 63 igin', 'prov_itc
1940: 27 2c 20 27 70 72 6f 76 69 6e 63 65 73 27 2c 20 ', 'provinces',
1950: 31 2c 0d 0a 20 20 20 20 20 20 20 20 20 20 27 3a 1,.. ':
1960: 3a 72 65 73 65 71 75 65 6e 63 65 3a 3a 27 2c 20 :resequence::',
1970: 27 3a 3a 69 67 6e 6f 72 65 3a 3a 70 6f 70 5f 32 '::ignore::pop_2
1980: 30 31 31 27 2c 20 27 3a 3a 69 67 6e 6f 72 65 3a 011', '::ignore:
1990: 3a 70 6f 70 5f 6d 5f 32 30 31 31 27 2c 20 27 3a :pop_m_2011', ':
19a0: 3a 69 67 6e 6f 72 65 3a 3a 70 6f 70 5f 66 5f 32 :ignore::pop_f_2
19b0: 30 31 31 27 29 3b 0d 0a 31 0d 0a 73 71 6c 69 74 011');..1..sqlit
19c0: 65 3e 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d e>..</verbatim>.
19d0: 0a 6d 6f 72 65 20 6f 72 20 6c 65 73 73 20 74 68 .more or less th
19e0: 69 73 20 69 73 20 74 68 65 20 73 61 6d 65 20 61 is is the same a
19f0: 73 20 61 62 6f 76 65 3a 20 62 75 74 20 69 6e 20 s above: but in
1a00: 74 68 69 73 20 63 61 73 65 20 66 75 72 74 68 65 this case furthe
1a10: 72 20 3c 62 3e 6f 70 74 69 6f 6e 73 3c 2f 62 3e r <b>options</b>
1a20: 20 67 61 76 65 20 62 65 65 6e 20 73 70 65 63 69 gave been speci
1a30: 66 69 65 64 2e 3c 62 72 3e 0d 0a 54 68 65 20 3c fied.<br>..The <
1a40: 62 3e 43 6c 6f 6e 65 54 61 62 6c 65 28 29 3c 2f b>CloneTable()</
1a50: 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 b> SQL functions
1a60: 20 61 63 63 65 70 74 73 20 61 20 6d 61 78 69 6d accepts a maxim
1a70: 75 6d 20 6f 66 20 31 30 20 6f 70 74 69 6f 6e 73 um of 10 options
1a80: 20 61 6c 6c 20 70 72 65 73 65 6e 74 69 6e 67 20 all presenting
1a90: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 61 the following ca
1aa0: 6e 6f 6e 69 63 61 6c 20 66 6f 72 6d 3a 20 3c 62 nonical form: <b
1ab0: 3e 3a 3a 6f 70 74 69 6f 6e 5f 6e 61 6d 65 3a 3a >::option_name::
1ac0: 3c 2f 62 3e 3c 69 3e 63 6f 6c 75 6d 6e 5f 6e 61 </b><i>column_na
1ad0: 6d 65 3c 2f 69 3e 2e 3c 62 72 3e 0d 0a 54 68 65 me</i>.<br>..The
1ae0: 20 66 69 72 73 74 20 6f 70 74 69 6f 6e 20 63 6f first option co
1af0: 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 61 72 67 rresponds to arg
1b00: 75 6d 65 6e 74 20 23 35 20 61 6e 64 20 73 6f 20 ument #5 and so
1b10: 6f 6e 3a 20 62 61 64 6c 79 20 66 6f 72 6d 61 74 on: badly format
1b20: 74 65 64 20 6f 72 20 6d 65 61 6e 69 6e 67 6c 65 ted or meaningle
1b30: 73 73 20 2f 20 6e 6f 74 20 61 70 70 6c 69 63 61 ss / not applica
1b40: 62 6c 65 20 64 69 72 65 63 74 69 76 65 73 20 77 ble directives w
1b50: 69 6c 6c 20 62 65 20 73 69 6c 65 6e 74 6c 79 20 ill be silently
1b60: 64 69 73 63 61 72 64 65 64 20 77 69 74 68 6f 75 discarded withou
1b70: 74 20 61 6e 79 20 66 75 72 74 68 65 72 20 63 6f t any further co
1b80: 6e 73 65 71 75 65 6e 63 65 2e 0d 0a 3c 76 65 72 nsequence...<ver
1b90: 62 61 74 69 6d 3e 0d 0a 73 71 6c 69 74 65 3e 20 batim>..sqlite>
1ba0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 72 65 SELECT * FROM re
1bb0: 67 69 6f 6e 73 3b 0d 0a 3c 2f 76 65 72 62 61 74 gions;..</verbat
1bc0: 69 6d 3e 0d 0a 61 73 20 79 6f 75 20 63 61 6e 20 im>..as you can
1bd0: 64 69 72 65 63 74 6c 79 20 63 68 65 63 6b 3a 0d directly check:.
1be0: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 20 3c .<ul>..<li>the <
1bf0: 62 3e 3a 3a 72 65 73 65 71 75 65 6e 63 65 3a 3a b>::resequence::
1c00: 3c 2f 62 3e 20 6f 70 74 69 6f 6e 20 68 61 73 20 </b> option has
1c10: 63 61 75 73 65 64 20 74 68 61 74 20 50 72 69 6d caused that Prim
1c20: 61 72 79 20 4b 65 79 20 76 61 6c 75 65 73 20 68 ary Key values h
1c30: 61 76 65 20 62 65 65 6e 20 72 65 73 65 71 75 65 ave been reseque
1c40: 6e 63 65 64 20 73 74 61 72 74 69 6e 67 20 66 72 nced starting fr
1c50: 6f 6d 20 31 20 61 6e 64 20 61 76 6f 69 64 69 6e om 1 and avoidin
1c60: 67 20 61 6e 79 20 76 6f 69 64 20 69 6e 74 65 72 g any void inter
1c70: 76 61 6c 2e 3c 62 72 3e 0d 0a 3c 75 3e 50 6c 65 val.<br>..<u>Ple
1c80: 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20 69 74 ase note</u>: it
1c90: 20 73 69 6d 70 6c 79 20 77 6f 72 6b 73 20 66 6f simply works fo
1ca0: 72 20 50 72 69 6d 61 72 79 20 4b 65 79 73 20 62 r Primary Keys b
1cb0: 61 73 65 64 20 6f 6e 20 61 20 73 69 6e 67 6c 65 ased on a single
1cc0: 20 63 6f 6c 75 6d 6e 20 6f 66 20 74 68 65 20 3c column of the <
1cd0: 62 3e 49 4e 54 45 47 45 52 20 41 55 54 4f 49 4e b>INTEGER AUTOIN
1ce0: 43 52 45 4d 45 4e 54 3c 2f 62 3e 20 74 79 70 65 CREMENT</b> type
1cf0: 20 61 6e 64 20 77 69 6c 6c 20 62 65 20 69 67 6e and will be ign
1d00: 6f 72 65 64 20 6f 6e 20 61 6e 79 20 6f 74 68 65 ored on any othe
1d10: 72 20 63 61 73 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c r case.</li>..<l
1d20: 69 3e 65 61 63 68 20 3c 62 3e 3a 3a 69 67 6e 6f i>each <b>::igno
1d30: 72 65 3a 3a 3c 2f 62 3e 3c 69 3e 63 6f 6c 75 6d re::</b><i>colum
1d40: 6e 3c 2f 69 3e 20 6f 70 74 69 6f 6e 20 69 6e 73 n</i> option ins
1d50: 74 65 61 64 20 68 61 73 20 63 61 75 73 65 64 20 tead has caused
1d60: 74 68 61 74 20 20 3c 62 3e 70 6f 70 5f 32 30 31 that <b>pop_201
1d70: 31 3c 2f 62 3e 2c 20 3c 62 3e 70 6f 70 5f 6d 5f 1</b>, <b>pop_m_
1d80: 32 30 31 31 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 2011</b> and <b>
1d90: 70 6f 70 5f 66 5f 32 30 31 31 3c 2f 62 3e 20 63 pop_f_2011</b> c
1da0: 6f 6c 75 6d 6e 73 20 68 61 76 65 20 62 65 65 6e olumns have been
1db0: 20 63 6f 6d 70 6c 65 74 65 6c 79 20 69 67 6e 6f completely igno
1dc0: 72 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e red.</li>..</ul>
1dd0: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 73 71 ..<verbatim>..sq
1de0: 6c 69 74 65 3e 20 53 45 4c 45 43 54 20 43 6c 6f lite> SELECT Clo
1df0: 6e 65 54 61 62 6c 65 28 27 6f 72 69 67 69 6e 27 neTable('origin'
1e00: 2c 20 27 70 72 6f 76 5f 69 74 68 27 2c 20 27 70 , 'prov_ith', 'p
1e10: 72 6f 76 69 6e 63 65 73 27 2c 20 31 2c 20 0d 0a rovinces', 1, ..
1e20: 20 20 20 20 20 20 20 20 20 20 27 3a 3a 61 70 70 '::app
1e30: 65 6e 64 3a 3a 27 2c 20 27 3a 3a 69 67 6e 6f 72 end::', '::ignor
1e40: 65 3a 3a 70 6f 70 5f 32 30 31 31 27 2c 20 27 3a e::pop_2011', ':
1e50: 3a 69 67 6e 6f 72 65 3a 3a 70 6f 70 5f 6d 5f 32 :ignore::pop_m_2
1e60: 30 31 31 27 2c 20 27 3a 3a 69 67 6e 6f 72 65 3a 011', '::ignore:
1e70: 3a 70 6f 70 5f 66 5f 32 30 31 31 27 29 3b 0d 0a :pop_f_2011');..
1e80: 31 0d 0a 73 71 6c 69 74 65 3e 20 53 45 4c 45 43 1..sqlite> SELEC
1e90: 54 20 43 6c 6f 6e 65 54 61 62 6c 65 28 27 6f 72 T CloneTable('or
1ea0: 69 67 69 6e 27 2c 20 27 70 72 6f 76 5f 69 74 69 igin', 'prov_iti
1eb0: 27 2c 20 27 70 72 6f 76 69 6e 63 65 73 27 2c 20 ', 'provinces',
1ec0: 31 2c 20 0d 0a 20 20 20 20 20 20 20 20 20 20 27 1, .. '
1ed0: 3a 3a 61 70 70 65 6e 64 3a 3a 27 2c 20 27 3a 3a ::append::', '::
1ee0: 69 67 6e 6f 72 65 3a 3a 70 6f 70 5f 32 30 31 31 ignore::pop_2011
1ef0: 27 2c 20 27 3a 3a 69 67 6e 6f 72 65 3a 3a 70 6f ', '::ignore::po
1f00: 70 5f 6d 5f 32 30 31 31 27 2c 20 27 3a 3a 69 67 p_m_2011', '::ig
1f10: 6e 6f 72 65 3a 3a 70 6f 70 5f 66 5f 32 30 31 31 nore::pop_f_2011
1f20: 27 29 3b 0d 0a 31 0d 0a 73 71 6c 69 74 65 3e 20 ');..1..sqlite>
1f30: 53 45 4c 45 43 54 20 43 6c 6f 6e 65 54 61 62 6c SELECT CloneTabl
1f40: 65 28 27 6f 72 69 67 69 6e 27 2c 20 27 70 72 6f e('origin', 'pro
1f50: 76 5f 69 74 66 27 2c 20 27 70 72 6f 76 69 6e 63 v_itf', 'provinc
1f60: 65 73 27 2c 20 31 2c 20 0d 0a 20 20 20 20 20 20 es', 1, ..
1f70: 20 20 20 20 27 3a 3a 61 70 70 65 6e 64 3a 3a 27 '::append::'
1f80: 2c 20 27 3a 3a 69 67 6e 6f 72 65 3a 3a 70 6f 70 , '::ignore::pop
1f90: 5f 32 30 31 31 27 2c 20 27 3a 3a 69 67 6e 6f 72 _2011', '::ignor
1fa0: 65 3a 3a 70 6f 70 5f 6d 5f 32 30 31 31 27 2c 20 e::pop_m_2011',
1fb0: 27 3a 3a 69 67 6e 6f 72 65 3a 3a 70 6f 70 5f 66 '::ignore::pop_f
1fc0: 5f 32 30 31 31 27 29 3b 0d 0a 31 0d 0a 73 71 6c _2011');..1..sql
1fd0: 69 74 65 3e 0d 0a 3c 2f 76 65 72 62 61 74 69 6d ite>..</verbatim
1fe0: 3e 0d 0a 6d 6f 72 65 20 6f 72 20 6c 65 73 73 20 >..more or less
1ff0: 61 73 20 62 65 66 6f 72 65 3b 20 77 65 27 6c 6c as before; we'll
2000: 20 73 69 6d 70 6c 79 20 72 65 61 64 20 64 61 74 simply read dat
2010: 61 20 66 72 6f 6d 20 3c 62 3e 70 72 6f 76 5f 69 a from <b>prov_i
2020: 74 68 3c 2f 62 3e 2c 20 3c 62 3e 70 72 6f 76 5f th</b>, <b>prov_
2030: 69 74 69 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 70 iti</b> and <b>p
2040: 72 6f 76 5f 69 74 66 3c 2f 62 3e 20 69 6e 70 75 rov_itf</b> inpu
2050: 74 20 54 61 62 6c 65 73 20 73 74 69 6c 6c 20 63 t Tables still c
2060: 6f 6e 74 69 6e 75 69 6e 67 20 74 6f 20 75 73 65 ontinuing to use
2070: 20 74 68 65 20 3c 62 3e 70 72 6f 76 69 6e 63 65 the <b>province
2080: 73 3c 2f 62 3e 20 54 61 62 6c 65 20 61 73 20 74 s</b> Table as t
2090: 68 65 20 6f 75 74 70 75 74 20 74 61 72 67 65 74 he output target
20a0: 2e 3c 62 72 3e 0d 0a 41 6e 79 77 61 79 20 69 6e .<br>..Anyway in
20b0: 20 74 68 69 73 20 63 61 73 65 20 77 65 27 76 65 this case we've
20c0: 20 73 70 65 63 69 66 69 65 64 20 74 68 65 20 3c specified the <
20d0: 62 3e 3a 3a 61 70 70 65 6e 64 3a 3a 3c 2f 62 3e b>::append::</b>
20e0: 20 6f 70 74 69 6f 6e 3b 20 74 68 69 73 20 69 73 option; this is
20f0: 20 62 65 63 61 75 73 65 20 3c 62 3e 43 6c 6f 6e because <b>Clon
2100: 65 54 61 62 6c 65 28 29 3c 2f 62 3e 20 68 61 73 eTable()</b> has
2110: 20 74 68 65 20 63 61 70 61 62 69 6c 69 74 79 20 the capability
2120: 74 6f 20 61 70 70 65 6e 64 20 64 61 74 61 20 69 to append data i
2130: 6e 74 6f 20 61 6e 20 61 6c 72 65 61 64 79 20 65 nto an already e
2140: 78 69 73 74 69 6e 67 20 6f 75 74 70 75 74 20 74 xisting output t
2150: 61 62 6c 65 2c 20 62 75 74 20 73 74 72 69 63 74 able, but strict
2160: 6c 79 20 72 65 71 75 69 72 65 73 20 74 68 69 73 ly requires this
2170: 20 65 78 70 6c 69 63 69 74 20 61 75 74 68 6f 72 explicit author
2180: 69 7a 61 74 69 6f 6e 2e 3c 62 72 3e 0d 0a 3c 75 ization.<br>..<u
2190: 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f 75 3e >Please note</u>
21a0: 3a 20 3c 62 3e 3a 3a 61 70 70 65 6e 64 3a 3a 3c : <b>::append::<
21b0: 2f 62 3e 20 61 6c 77 61 79 73 20 69 6d 70 6c 69 /b> always impli
21c0: 65 73 20 3c 62 3e 3a 3a 72 65 73 65 71 75 65 6e es <b>::resequen
21d0: 63 65 3a 3a 3c 2f 62 3e 2c 20 73 6f 20 74 68 65 ce::</b>, so the
21e0: 72 65 20 69 73 20 6e 6f 20 6e 65 65 64 20 74 6f re is no need to
21f0: 20 73 70 65 63 69 66 79 20 74 68 69 73 20 73 65 specify this se
2200: 63 6f 6e 64 20 6f 70 74 69 6f 6e 2e 0d 0a 3c 76 cond option...<v
2210: 65 72 62 61 74 69 6d 3e 73 71 6c 69 74 65 3e 20 erbatim>sqlite>
2220: 53 45 4c 45 43 54 20 43 6c 6f 6e 65 54 61 62 6c SELECT CloneTabl
2230: 65 28 27 6f 72 69 67 69 6e 27 2c 20 27 70 72 6f e('origin', 'pro
2240: 76 5f 69 74 67 27 2c 20 27 70 72 6f 76 69 6e 63 v_itg', 'provinc
2250: 65 73 27 2c 20 31 2c 20 27 3a 3a 61 70 70 65 6e es', 1, '::appen
2260: 64 3a 3a 27 29 3b 0d 0a 31 0d 0a 73 71 6c 69 74 d::');..1..sqlit
2270: 65 3e 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d e>..</verbatim>.
2280: 0a 69 6e 20 74 68 69 73 20 6c 61 73 74 20 63 61 .in this last ca
2290: 6c 6c 20 74 6f 20 3c 62 3e 43 6c 6f 6e 65 54 61 ll to <b>CloneTa
22a0: 62 6c 65 28 29 3c 2f 62 3e 20 77 65 27 76 65 20 ble()</b> we've
22b0: 69 6e 74 65 6e 74 69 6f 6e 61 6c 6c 79 20 73 75 intentionally su
22c0: 70 70 72 65 73 73 65 64 20 61 6c 6c 20 74 68 65 ppressed all the
22d0: 20 3c 62 3e 3a 3a 69 67 6e 6f 72 65 3a 3a 3c 2f <b>::ignore::</
22e0: 62 3e 20 6f 70 74 69 6f 6e 73 2e 0d 0a 3c 76 65 b> options...<ve
22f0: 72 62 61 74 69 6d 3e 0d 0a 73 71 6c 69 74 65 3e rbatim>..sqlite>
2300: 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 72 SELECT * FROM r
2310: 65 67 69 6f 6e 73 3b 0d 0a 3c 2f 76 65 72 62 61 egions;..</verba
2320: 74 69 6d 3e 0d 0a 61 73 20 79 6f 75 20 63 61 6e tim>..as you can
2330: 20 64 69 72 65 63 74 6c 79 20 63 68 65 63 6b 20 directly check
2340: 3c 62 3e 43 6c 6f 6e 65 54 61 62 6c 65 28 29 3c <b>CloneTable()<
2350: 2f 62 3e 20 68 61 73 20 64 65 74 65 63 74 65 64 /b> has detected
2360: 20 74 68 61 74 20 74 68 65 20 6f 75 74 70 75 74 that the output
2370: 20 54 61 62 6c 65 20 6c 61 63 6b 65 64 20 73 6f Table lacked so
2380: 6d 65 20 6f 66 20 74 68 65 20 72 65 71 75 69 72 me of the requir
2390: 65 64 20 63 6f 6c 75 6d 6e 73 2c 20 61 6e 64 20 ed columns, and
23a0: 61 6c 6c 20 74 68 65 6d 20 68 61 76 65 20 62 65 all them have be
23b0: 65 6e 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 en automatically
23c0: 20 63 72 65 61 74 65 64 20 6f 6e 20 74 68 65 20 created on the
23d0: 66 6c 79 20 62 65 66 6f 72 65 20 63 6f 70 79 69 fly before copyi
23e0: 6e 67 20 61 6e 79 20 64 61 74 61 2e 0d 0a 3c 76 ng any data...<v
23f0: 65 72 62 61 74 69 6d 3e 0d 0a 73 71 6c 69 74 65 erbatim>..sqlite
2400: 3e 20 44 45 54 41 43 48 20 44 41 54 41 42 41 53 > DETACH DATABAS
2410: 45 20 6f 72 69 67 69 6e 3b 0d 0a 73 71 6c 69 74 E origin;..sqlit
2420: 65 3e 20 2e 71 75 69 74 0d 0a 24 0d 0a 3c 2f 76 e> .quit..$..</v
2430: 65 72 62 61 74 69 6d 3e 0d 0a 66 69 6e 69 73 68 erbatim>..finish
2440: 65 64 20 2e 2e 2e 20 74 68 69 73 20 66 69 72 73 ed ... this firs
2450: 74 20 74 75 74 6f 72 69 61 6c 20 73 74 6f 70 73 t tutorial stops
2460: 20 68 65 72 65 2e 0d 0a 3c 62 72 3e 3c 62 72 3e here...<br><br>
2470: 3c 68 72 3e 0d 0a 3c 68 33 3e 54 75 74 6f 72 69 <hr>..<h3>Tutori
2480: 61 6c 20 73 74 65 70 20 23 32 20 28 3c 69 3e 61 al step #2 (<i>a
2490: 64 76 61 6e 63 65 64 20 6c 65 76 65 6c 3c 2f 69 dvanced level</i
24a0: 3e 29 3c 2f 68 33 3e 0d 0a 54 68 69 73 20 73 65 >)</h3>..This se
24b0: 63 6f 6e 64 20 74 75 74 6f 72 69 61 6c 20 69 73 cond tutorial is
24c0: 20 76 65 72 79 20 73 69 6d 69 6c 61 72 20 74 6f very similar to
24d0: 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 6f 6e the previous on
24e0: 65 2c 20 62 75 74 20 69 73 20 69 6e 74 65 6e 64 e, but is intend
24f0: 65 64 20 74 6f 20 65 78 70 6c 6f 72 65 20 6d 6f ed to explore mo
2500: 72 65 20 63 6f 6d 70 6c 65 78 20 61 6e 64 20 73 re complex and s
2510: 6f 70 68 69 73 74 69 63 61 74 65 64 20 53 51 4c ophisticated SQL
2520: 20 66 65 61 74 75 72 65 73 2e 0d 0a 3c 76 65 72 features...<ver
2530: 62 61 74 69 6d 3e 0d 0a 24 20 73 71 6c 69 74 65 batim>..$ sqlite
2540: 33 20 74 65 73 74 32 2e 73 71 6c 69 74 65 0d 0a 3 test2.sqlite..
2550: 53 51 4c 69 74 65 20 76 65 72 73 69 6f 6e 20 33 SQLite version 3
2560: 2e 38 2e 36 20 32 30 31 34 2d 30 38 2d 31 35 20 .8.6 2014-08-15
2570: 31 31 3a 34 36 3a 33 33 0d 0a 45 6e 74 65 72 20 11:46:33..Enter
2580: 22 2e 68 65 6c 70 22 20 66 6f 72 20 75 73 61 67 ".help" for usag
2590: 65 20 68 69 6e 74 73 2e 0d 0a 73 71 6c 69 74 65 e hints...sqlite
25a0: 3e 20 53 45 4c 45 43 54 20 6c 6f 61 64 5f 65 78 > SELECT load_ex
25b0: 74 65 6e 73 69 6f 6e 28 27 6d 6f 64 5f 73 70 61 tension('mod_spa
25c0: 74 69 61 6c 69 74 65 27 29 3b 0d 0a 73 71 6c 69 tialite');..sqli
25d0: 74 65 3e 20 53 45 4c 45 43 54 20 49 6e 69 74 53 te> SELECT InitS
25e0: 70 61 74 69 61 6c 4d 65 74 61 64 61 74 61 28 31 patialMetadata(1
25f0: 29 3b 0d 0a 31 0d 0a 73 71 6c 69 74 65 3e 20 41 );..1..sqlite> A
2600: 54 54 41 43 48 20 44 41 54 41 42 41 53 45 20 22 TTACH DATABASE "
2610: 2e 2f 63 6c 6f 6e 65 5f 6f 72 69 67 69 6e 2e 73 ./clone_origin.s
2620: 71 6c 69 74 65 22 20 41 53 20 6f 72 69 67 69 6e qlite" AS origin
2630: 3b 0d 0a 73 71 6c 69 74 65 3e 0d 0a 3c 2f 76 65 ;..sqlite>..</ve
2640: 72 62 61 74 69 6d 3e 20 0d 0a 45 78 61 63 74 6c rbatim> ..Exactl
2650: 79 20 61 73 20 69 6e 20 74 68 65 20 70 72 65 76 y as in the prev
2660: 69 6f 75 73 20 74 75 74 6f 72 69 61 6c 20 77 65 ious tutorial we
2670: 27 6c 6c 20 73 74 61 72 74 20 62 79 20 63 72 65 'll start by cre
2680: 61 74 69 6e 67 20 61 6e 64 20 69 6e 69 74 69 61 ating and initia
2690: 6c 69 7a 69 6e 67 20 61 20 6e 65 77 20 65 6d 70 lizing a new emp
26a0: 74 79 20 44 42 20 3c 62 3e 74 65 73 74 32 2e 73 ty DB <b>test2.s
26b0: 71 6c 69 74 65 3c 2f 62 3e 20 28 6f 75 74 70 75 qlite</b> (outpu
26c0: 74 20 64 65 73 74 69 6e 61 74 69 6f 6e 29 20 74 t destination) t
26d0: 68 65 6e 20 61 74 74 61 63 68 69 6e 67 20 3c 62 hen attaching <b
26e0: 3e 63 6c 6f 6e 65 5f 6f 72 69 67 69 6e 2e 73 71 >clone_origin.sq
26f0: 6c 69 74 65 3c 2f 62 3e 20 28 69 6e 70 75 74 20 lite</b> (input
2700: 6f 72 69 67 69 6e 29 2e 0d 0a 3c 76 65 72 62 61 origin)...<verba
2710: 74 69 6d 3e 0d 0a 73 71 6c 69 74 65 3e 20 53 45 tim>..sqlite> SE
2720: 4c 45 43 54 20 43 6c 6f 6e 65 54 61 62 6c 65 28 LECT CloneTable(
2730: 27 6f 72 69 67 69 6e 27 2c 20 27 72 65 67 69 6f 'origin', 'regio
2740: 6e 73 27 2c 20 27 72 65 67 69 6f 6e 73 27 2c 20 ns', 'regions',
2750: 31 29 3b 0d 0a 31 0d 0a 73 71 6c 69 74 65 3e 0d 1);..1..sqlite>.
2760: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 66 69 .</verbatim>..fi
2770: 72 73 74 20 77 65 27 6c 6c 20 63 6c 6f 6e 65 20 rst we'll clone
2780: 74 68 65 20 3c 62 3e 72 65 67 69 6f 6e 73 3c 2f the <b>regions</
2790: 62 3e 20 54 61 62 6c 65 2e 0d 0a 3c 76 65 72 62 b> Table...<verb
27a0: 61 74 69 6d 3e 73 71 6c 69 74 65 3e 20 53 45 4c atim>sqlite> SEL
27b0: 45 43 54 20 43 6c 6f 6e 65 54 61 62 6c 65 28 27 ECT CloneTable('
27c0: 6f 72 69 67 69 6e 27 2c 20 27 70 72 6f 76 69 6e origin', 'provin
27d0: 63 65 73 27 2c 20 27 70 72 6f 76 69 6e 63 65 73 ces', 'provinces
27e0: 27 2c 20 31 2c 0d 0a 20 20 20 20 20 20 20 20 20 ', 1,..
27f0: 20 20 20 20 20 20 20 20 20 20 20 27 3a 3a 77 69 '::wi
2800: 74 68 2d 66 6f 72 65 69 67 6e 2d 6b 65 79 73 3a th-foreign-keys:
2810: 3a 27 2c 20 27 3a 3a 77 69 74 68 2d 74 72 69 67 :', '::with-trig
2820: 67 65 72 73 3a 3a 27 29 3b 0d 0a 73 71 6c 69 74 gers::');..sqlit
2830: 65 3e 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d e>..</verbatim>.
2840: 0a 74 68 65 6e 20 77 65 27 6c 6c 20 63 6c 6f 6e .then we'll clon
2850: 65 20 74 68 65 20 3c 62 3e 70 72 6f 76 69 6e 63 e the <b>provinc
2860: 65 73 3c 2f 62 3e 20 54 61 62 6c 65 2e 20 41 73 es</b> Table. As
2870: 20 79 6f 75 20 73 75 72 65 6c 79 20 72 65 6d 65 you surely reme
2880: 6d 62 65 72 20 74 68 69 73 20 54 61 62 6c 65 20 mber this Table
2890: 69 73 20 63 6f 6d 70 6c 65 74 65 6c 79 20 65 6d is completely em
28a0: 70 74 79 20 28 69 74 20 63 6f 6e 74 61 69 6e 73 pty (it contains
28b0: 20 6e 6f 20 72 6f 77 73 29 3b 20 62 75 74 20 69 no rows); but i
28c0: 74 27 73 20 69 6e 74 65 6e 64 65 64 20 73 63 6f t's intended sco
28d0: 70 65 20 69 73 20 74 68 65 20 6f 6e 65 20 74 6f pe is the one to
28e0: 20 61 63 74 20 61 73 20 6b 69 6e 64 20 6f 66 20 act as kind of
28f0: 3c 69 3e 3c 62 3e 74 65 6d 70 6c 61 74 65 3c 2f <i><b>template</
2900: 62 3e 3c 2f 69 3e 2c 20 73 6f 20 74 6f 20 65 6e b></i>, so to en
2910: 73 75 72 65 20 74 68 61 74 20 61 20 6e 65 77 20 sure that a new
2920: 54 61 62 6c 65 20 70 72 65 73 65 6e 74 69 6e 67 Table presenting
2930: 20 65 78 61 63 74 6c 79 20 74 68 65 20 73 61 6d exactly the sam
2940: 65 20 69 64 65 6e 74 69 63 61 6c 20 6c 61 79 6f e identical layo
2950: 75 74 20 77 69 6c 6c 20 62 65 20 63 72 65 61 74 ut will be creat
2960: 65 64 20 6f 6e 20 74 68 65 20 64 65 73 74 69 6e ed on the destin
2970: 61 74 69 6f 6e 20 73 69 64 65 2e 0d 0a 3c 75 6c ation side...<ul
2980: 3e 0d 0a 3c 6c 69 3e 74 68 65 20 3c 62 3e 3a 3a >..<li>the <b>::
2990: 77 69 74 68 2d 66 6f 72 65 69 67 6e 2d 6b 65 79 with-foreign-key
29a0: 73 3a 3a 3c 2f 62 3e 20 6f 70 74 69 6f 6e 20 73 s::</b> option s
29b0: 70 65 63 69 66 69 65 73 20 74 68 61 74 20 61 6e pecifies that an
29c0: 79 20 46 6f 72 65 69 67 6e 20 4b 65 79 20 64 65 y Foreign Key de
29d0: 66 69 6e 65 64 20 69 6e 20 74 68 65 20 6f 72 69 fined in the ori
29e0: 67 69 6e 20 77 69 6c 6c 20 62 65 20 72 65 63 72 gin will be recr
29f0: 65 61 74 65 64 20 6f 6e 20 74 68 65 20 64 65 73 eated on the des
2a00: 74 69 6e 61 74 69 6f 6e 2e 3c 62 72 3e 0d 0a 42 tination.<br>..B
2a10: 79 20 64 65 66 61 75 6c 74 20 3c 62 3e 43 6c 6f y default <b>Clo
2a20: 6e 65 54 61 62 6c 65 28 29 3c 2f 62 3e 20 6e 65 neTable()</b> ne
2a30: 76 65 72 20 61 74 74 65 6d 70 74 73 20 74 6f 20 ver attempts to
2a40: 72 65 63 72 65 61 74 65 20 46 6f 72 65 69 67 6e recreate Foreign
2a50: 20 4b 65 79 73 2c 20 62 65 63 61 75 73 65 20 74 Keys, because t
2a60: 68 65 79 20 63 6f 6d 70 6c 65 74 65 6c 79 20 72 hey completely r
2a70: 65 6c 69 65 73 20 75 70 6f 6e 20 6f 74 68 65 72 elies upon other
2a80: 20 54 61 62 6c 65 73 20 74 68 61 74 20 63 6f 75 Tables that cou
2a90: 6c 64 20 62 65 20 65 76 65 6e 74 75 61 6c 6c 79 ld be eventually
2aa0: 20 64 65 66 69 6e 65 64 20 6f 72 20 6e 6f 74 2e defined or not.
2ab0: 20 41 6e 79 77 61 79 20 79 6f 75 20 63 61 6e 20 Anyway you can
2ac0: 65 78 70 6c 69 63 69 74 6c 79 20 72 65 71 75 65 explicitly reque
2ad0: 73 74 20 66 6f 72 20 74 68 65 69 72 20 64 75 70 st for their dup
2ae0: 6c 69 63 61 74 69 6f 6e 20 77 68 65 6e 65 76 65 lication wheneve
2af0: 72 20 79 6f 75 20 74 68 69 6e 6b 20 74 68 69 73 r you think this
2b00: 20 69 73 20 61 6e 20 75 73 65 66 75 6c 20 61 6e is an useful an
2b10: 64 20 6c 65 67 69 74 69 6d 61 74 65 20 61 63 74 d legitimate act
2b20: 69 6f 6e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 ion.</li>..<li>t
2b30: 68 65 20 73 61 6d 65 20 63 6f 6e 73 69 64 65 72 he same consider
2b40: 61 74 69 6f 6e 20 61 70 70 6c 79 20 74 6f 20 54 ation apply to T
2b50: 72 69 67 67 65 72 73 3b 20 3c 62 3e 43 6c 6f 6e riggers; <b>Clon
2b60: 65 54 61 62 6c 65 28 29 3c 2f 62 3e 20 77 69 6c eTable()</b> wil
2b70: 6c 20 75 73 75 61 6c 6c 79 20 69 67 6e 6f 72 65 l usually ignore
2b80: 20 61 6e 79 20 54 72 69 67 67 65 72 20 64 65 66 any Trigger def
2b90: 69 6e 69 74 69 6f 6e 2c 20 62 75 74 20 79 6f 75 inition, but you
2ba0: 20 63 61 6e 20 61 6e 79 77 61 79 20 65 78 70 6c can anyway expl
2bb0: 69 63 69 74 20 72 65 71 75 65 73 74 20 66 6f 72 icit request for
2bc0: 20 74 68 65 69 72 20 64 75 70 6c 69 63 61 74 69 their duplicati
2bd0: 6f 6e 20 62 79 20 73 70 65 63 69 66 79 69 6e 67 on by specifying
2be0: 20 74 68 65 20 3c 62 3e 3a 3a 77 69 74 68 2d 74 the <b>::with-t
2bf0: 72 69 67 67 65 72 73 3a 3a 3c 2f 62 3e 20 6f 70 riggers::</b> op
2c00: 74 69 6f 6e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e tion.</li>..<li>
2c10: 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f <u>Please note</
2c20: 75 3e 3a 20 61 6e 79 20 49 6e 64 65 78 20 28 6f u>: any Index (o
2c30: 72 20 53 70 61 74 69 61 6c 20 49 6e 64 65 78 29 r Spatial Index)
2c40: 20 64 65 66 69 6e 65 64 20 62 79 20 74 68 65 20 defined by the
2c50: 6f 72 69 67 69 6e 20 77 69 6c 6c 20 61 6c 77 61 origin will alwa
2c60: 79 73 20 62 65 20 72 65 70 6c 69 63 61 74 65 64 ys be replicated
2c70: 20 69 6e 74 6f 20 74 68 65 20 64 65 73 74 69 6e into the destin
2c80: 61 74 69 6f 6e 20 62 65 63 61 75 73 65 20 74 68 ation because th
2c90: 69 73 20 64 6f 65 73 6e 27 74 20 69 6e 76 6f 6c is doesn't invol
2ca0: 76 65 73 20 61 6e 79 20 69 6e 74 65 72 61 63 74 ves any interact
2cb0: 69 6f 6e 20 77 69 74 68 20 64 69 66 66 65 72 65 ion with differe
2cc0: 6e 74 20 54 61 62 6c 65 73 2e 3c 2f 6c 69 3e 0d nt Tables.</li>.
2cd0: 0a 3c 2f 75 6c 3e 20 0d 0a 3c 76 65 72 62 61 74 .</ul> ..<verbat
2ce0: 69 6d 3e 73 71 6c 69 74 65 3e 20 53 45 4c 45 43 im>sqlite> SELEC
2cf0: 54 20 43 6c 6f 6e 65 54 61 62 6c 65 28 27 6f 72 T CloneTable('or
2d00: 69 67 69 6e 27 2c 20 27 70 72 6f 76 5f 69 74 63 igin', 'prov_itc
2d10: 27 2c 20 27 70 72 6f 76 69 6e 63 65 73 27 2c 20 ', 'provinces',
2d20: 31 2c 20 27 3a 3a 61 70 70 65 6e 64 3a 3a 27 29 1, '::append::')
2d30: 3b 0d 0a 31 0d 0a 3c 76 65 72 62 61 74 69 6d 3e ;..1..<verbatim>
2d40: 73 71 6c 69 74 65 3e 20 53 45 4c 45 43 54 20 43 sqlite> SELECT C
2d50: 6c 6f 6e 65 54 61 62 6c 65 28 27 6f 72 69 67 69 loneTable('origi
2d60: 6e 27 2c 20 27 70 72 6f 76 5f 69 74 68 27 2c 20 n', 'prov_ith',
2d70: 27 70 72 6f 76 69 6e 63 65 73 27 2c 20 31 2c 20 'provinces', 1,
2d80: 27 3a 3a 61 70 70 65 6e 64 3a 3a 27 29 3b 0d 0a '::append::');..
2d90: 31 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 73 71 6c 1..<verbatim>sql
2da0: 69 74 65 3e 20 53 45 4c 45 43 54 20 43 6c 6f 6e ite> SELECT Clon
2db0: 65 54 61 62 6c 65 28 27 6f 72 69 67 69 6e 27 2c eTable('origin',
2dc0: 20 27 70 72 6f 76 5f 69 74 69 27 2c 20 27 70 72 'prov_iti', 'pr
2dd0: 6f 76 69 6e 63 65 73 27 2c 20 31 2c 20 27 3a 3a ovinces', 1, '::
2de0: 61 70 70 65 6e 64 3a 3a 27 29 3b 0d 0a 31 0d 0a append::');..1..
2df0: 3c 76 65 72 62 61 74 69 6d 3e 73 71 6c 69 74 65 <verbatim>sqlite
2e00: 3e 20 53 45 4c 45 43 54 20 43 6c 6f 6e 65 54 61 > SELECT CloneTa
2e10: 62 6c 65 28 27 6f 72 69 67 69 6e 27 2c 20 27 70 ble('origin', 'p
2e20: 72 6f 76 5f 69 74 66 27 2c 20 27 70 72 6f 76 69 rov_itf', 'provi
2e30: 6e 63 65 73 27 2c 20 31 2c 20 27 3a 3a 61 70 70 nces', 1, '::app
2e40: 65 6e 64 3a 3a 27 29 3b 0d 0a 31 0d 0a 3c 76 65 end::');..1..<ve
2e50: 72 62 61 74 69 6d 3e 73 71 6c 69 74 65 3e 20 53 rbatim>sqlite> S
2e60: 45 4c 45 43 54 20 43 6c 6f 6e 65 54 61 62 6c 65 ELECT CloneTable
2e70: 28 27 6f 72 69 67 69 6e 27 2c 20 27 70 72 6f 76 ('origin', 'prov
2e80: 5f 69 74 67 27 2c 20 27 70 72 6f 76 69 6e 63 65 _itg', 'province
2e90: 73 27 2c 20 31 2c 20 27 3a 3a 61 70 70 65 6e 64 s', 1, '::append
2ea0: 3a 3a 27 29 3b 0d 0a 31 0d 0a 73 71 6c 69 74 65 ::');..1..sqlite
2eb0: 3e 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a >..</verbatim>..
2ec0: 74 68 69 73 20 66 69 6e 61 6c 20 73 65 72 69 65 this final serie
2ed0: 73 20 6f 66 20 3c 62 3e 43 6c 6f 6e 65 54 61 62 s of <b>CloneTab
2ee0: 6c 65 28 29 3c 2f 62 3e 20 63 61 6c 6c 73 20 77 le()</b> calls w
2ef0: 69 6c 6c 20 65 66 66 65 63 74 69 76 65 6c 79 20 ill effectively
2f00: 70 6f 70 75 6c 61 74 65 20 74 68 65 20 3c 62 3e populate the <b>
2f10: 70 72 6f 76 69 6e 63 65 73 3c 2f 62 3e 20 54 61 provinces</b> Ta
2f20: 62 6c 65 3b 20 70 61 73 73 69 6e 67 20 74 68 65 ble; passing the
2f30: 20 3c 62 3e 3a 3a 61 70 70 65 6e 64 3a 3a 3c 2f <b>::append::</
2f40: 62 3e 20 6f 70 74 69 6f 6e 20 69 73 20 61 20 6d b> option is a m
2f50: 61 6e 64 61 74 6f 72 79 20 72 65 71 75 69 73 69 andatory requisi
2f60: 74 65 2c 20 62 65 63 61 75 73 65 20 74 68 65 20 te, because the
2f70: 64 65 73 74 69 6e 61 74 69 6f 6e 20 54 61 62 6c destination Tabl
2f80: 65 20 77 61 73 20 62 65 65 6e 20 63 72 65 61 74 e was been creat
2f90: 65 64 20 69 6e 20 61 20 70 72 65 76 69 6f 75 73 ed in a previous
2fa0: 20 73 74 65 70 2e 0d 0a 3c 76 65 72 62 61 74 69 step...<verbati
2fb0: 6d 3e 0d 0a 73 71 6c 69 74 65 3e 20 53 45 4c 45 m>..sqlite> SELE
2fc0: 43 54 20 2a 20 46 52 4f 4d 20 72 65 67 69 6f 6e CT * FROM region
2fd0: 73 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d s;..</verbatim>.
2fe0: 0a 66 69 6e 61 6c 20 63 68 65 63 6b 3a 20 61 6c .final check: al
2ff0: 6c 20 32 30 31 31 20 50 6f 70 75 6c 61 74 69 6f l 2011 Populatio
3000: 6e 20 76 61 6c 75 65 73 20 61 72 65 20 6e 6f 77 n values are now
3010: 20 63 6f 72 72 65 63 74 6c 79 20 72 65 70 6f 72 correctly repor
3020: 74 65 64 20 66 6f 72 20 65 61 63 68 20 52 65 67 ted for each Reg
3030: 69 6f 6e 2e 20 54 68 65 20 54 72 69 67 67 65 72 ion. The Trigger
3040: 20 64 69 64 20 69 73 20 77 6f 72 6b 20 61 73 20 did is work as
3050: 65 78 70 65 63 74 65 64 2e 0d 0a 3c 76 65 72 62 expected...<verb
3060: 61 74 69 6d 3e 0d 0a 73 71 6c 69 74 65 3e 20 44 atim>..sqlite> D
3070: 45 54 41 43 48 20 44 41 54 41 42 41 53 45 20 6f ETACH DATABASE o
3080: 72 69 67 69 6e 3b 0d 0a 73 71 6c 69 74 65 3e 20 rigin;..sqlite>
3090: 2e 71 75 69 74 0d 0a 24 0d 0a 3c 2f 76 65 72 62 .quit..$..</verb
30a0: 61 74 69 6d 3e 0d 0a 66 69 6e 69 73 68 65 64 20 atim>..finished
30b0: 2e 2e 2e 20 63 6c 6f 73 65 20 61 6e 64 20 71 75 ... close and qu
30c0: 69 74 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 3c 68 72 it...<br><br><hr
30d0: 3e 0d 0a 3c 68 33 3e 6f 70 74 69 6f 6e 73 20 73 >..<h3>options s
30e0: 75 70 70 6f 72 74 65 64 20 62 79 20 43 6c 6f 6e upported by Clon
30f0: 65 54 61 62 6c 65 28 29 3c 2f 68 33 3e 0d 0a 3c eTable()</h3>..<
3100: 74 61 62 6c 65 20 77 69 64 74 68 3d 22 31 30 30 table width="100
3110: 25 22 20 62 6f 72 64 65 72 3d 22 31 22 20 63 65 %" border="1" ce
3120: 6c 6c 73 70 61 63 69 6e 67 3d 22 32 22 20 63 65 llspacing="2" ce
3130: 6c 6c 70 61 64 64 69 6e 67 3d 22 38 22 20 62 67 llpadding="8" bg
3140: 63 6f 6c 6f 72 3d 22 23 66 66 66 66 66 30 22 3e color="#fffff0">
3150: 0d 0a 3c 74 72 3e 3c 74 68 20 62 67 63 6f 6c 6f ..<tr><th bgcolo
3160: 72 3d 22 23 64 30 64 30 64 30 22 3e 6f 70 74 69 r="#d0d0d0">opti
3170: 6f 6e 20 6e 61 6d 65 3c 2f 62 3e 3c 2f 74 68 3e on name</b></th>
3180: 3c 74 68 20 62 67 63 6f 6c 6f 72 3d 22 23 64 30 <th bgcolor="#d0
3190: 64 30 64 30 22 20 77 69 64 74 68 3d 22 34 30 25 d0d0" width="40%
31a0: 22 3e 61 63 74 69 6f 6e 3c 2f 74 68 3e 3c 74 68 ">action</th><th
31b0: 20 62 67 63 6f 6c 6f 72 3d 22 23 64 30 64 30 64 bgcolor="#d0d0d
31c0: 30 22 20 77 69 64 74 68 3d 22 34 30 25 22 3e 6e 0" width="40%">n
31d0: 6f 74 65 73 3c 2f 74 68 3e 3c 2f 74 72 3e 0d 0a otes</th></tr>..
31e0: 3c 74 72 3e 3c 74 64 3e 3c 62 3e 3a 3a 77 69 74 <tr><td><b>::wit
31f0: 68 2d 66 6f 72 65 69 67 6e 2d 6b 65 79 73 3a 3a h-foreign-keys::
3200: 3c 2f 62 3e 3c 2f 74 64 3e 3c 74 64 3e 77 68 69 </b></td><td>whi
3210: 6c 65 20 63 72 65 61 74 69 6e 67 20 74 68 65 20 le creating the
3220: 64 65 73 74 69 6e 61 74 69 6f 6e 20 54 61 62 6c destination Tabl
3230: 65 20 61 6c 6c 20 46 6f 72 65 69 67 6e 20 4b 65 e all Foreign Ke
3240: 79 73 20 64 65 66 69 6e 65 64 20 62 79 20 74 68 ys defined by th
3250: 65 20 6f 72 69 67 69 6e 20 77 69 6c 6c 20 62 65 e origin will be
3260: 20 64 75 70 6c 69 63 61 74 65 64 2e 3c 62 72 3e duplicated.<br>
3270: 0d 0a 28 3c 69 3e 74 68 69 73 20 6d 61 79 20 65 ..(<i>this may e
3280: 76 65 6e 74 75 61 6c 6c 79 20 63 61 75 73 65 20 ventually cause
3290: 73 75 62 73 65 71 75 65 6e 74 20 66 61 69 6c 75 subsequent failu
32a0: 72 65 73 20 69 66 20 74 68 65 20 72 65 66 65 72 res if the refer
32b0: 65 6e 63 65 64 20 54 61 62 6c 65 20 64 6f 65 73 enced Table does
32c0: 6e 27 74 20 65 66 66 65 63 74 69 76 65 6c 79 20 n't effectively
32d0: 65 78 69 73 74 3c 2f 69 3e 29 2e 3c 2f 74 64 3e exist</i>).</td>
32e0: 3c 74 64 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a <td></td></tr>..
32f0: 3c 74 72 3e 3c 74 64 3e 3c 62 3e 3a 3a 77 69 74 <tr><td><b>::wit
3300: 68 2d 74 72 69 67 67 65 72 73 3a 3a 3c 2f 62 3e h-triggers::</b>
3310: 3c 2f 74 64 3e 3c 74 64 3e 77 68 69 6c 65 20 63 </td><td>while c
3320: 72 65 61 74 69 6e 67 20 74 68 65 20 64 65 73 74 reating the dest
3330: 69 6e 61 74 69 6f 6e 20 54 61 62 6c 65 20 61 6c ination Table al
3340: 6c 20 54 72 69 67 67 65 72 73 20 64 65 66 69 6e l Triggers defin
3350: 65 64 20 62 79 20 74 68 65 20 6f 72 69 67 69 6e ed by the origin
3360: 20 77 69 6c 6c 20 62 65 20 64 75 70 6c 69 63 61 will be duplica
3370: 74 65 64 2e 3c 62 72 3e 0d 0a 28 3c 69 3e 74 68 ted.<br>..(<i>th
3380: 69 73 20 6d 61 79 20 65 76 65 6e 74 75 61 6c 6c is may eventuall
3390: 79 20 63 61 75 73 65 20 73 75 62 73 65 71 75 65 y cause subseque
33a0: 6e 74 20 66 61 69 6c 75 72 65 73 20 69 66 20 74 nt failures if t
33b0: 68 65 20 54 72 69 67 67 65 72 27 73 20 61 63 74 he Trigger's act
33c0: 69 6f 6e 20 72 65 66 65 72 65 6e 63 65 73 20 73 ion references s
33d0: 6f 6d 65 20 6e 6f 74 20 65 78 69 73 74 69 6e 67 ome not existing
33e0: 20 54 61 62 6c 65 20 6f 72 20 43 6f 6c 75 6d 6e Table or Column
33f0: 3c 2f 69 3e 29 2e 3c 2f 74 64 3e 3c 74 64 3e 3c </i>).</td><td><
3400: 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c /td></tr>..<tr><
3410: 74 64 3e 3c 62 3e 3a 3a 61 70 70 65 6e 64 3a 3a td><b>::append::
3420: 3c 2f 62 3e 3c 2f 74 64 3e 3c 74 64 3e 61 73 73 </b></td><td>ass
3430: 75 6d 65 73 20 74 68 61 74 20 74 68 65 20 64 65 umes that the de
3440: 73 74 69 6e 61 74 69 6f 6e 20 54 61 62 6c 65 20 stination Table
3450: 68 61 73 20 62 65 65 6e 20 61 6c 72 65 61 64 79 has been already
3460: 20 63 72 65 61 74 65 64 20 69 6e 20 61 20 70 72 created in a pr
3470: 65 76 69 6f 75 73 20 73 74 65 70 2e 3c 62 72 3e evious step.<br>
3480: 0d 0a 41 64 64 69 74 69 6f 6e 61 6c 20 43 6f 6c ..Additional Col
3490: 75 6d 6e 73 20 6d 61 79 20 62 65 20 61 75 74 6f umns may be auto
34a0: 6d 61 74 69 63 61 6c 6c 79 20 61 64 64 65 64 20 matically added
34b0: 69 66 20 72 65 71 75 69 72 65 64 2e 3c 2f 74 64 if required.</td
34c0: 3e 0d 0a 3c 74 64 3e 4d 69 73 6d 61 74 63 68 69 >..<td>Mismatchi
34d0: 6e 67 20 63 6f 6c 75 6d 6e 20 64 65 63 6c 61 72 ng column declar
34e0: 61 74 69 6f 6e 73 20 6f 72 20 53 51 4c 20 63 6f ations or SQL co
34f0: 6e 73 74 72 61 69 6e 74 73 20 6d 61 79 20 6c 65 nstraints may le
3500: 61 64 20 74 6f 20 61 6e 20 65 76 65 6e 74 75 61 ad to an eventua
3510: 6c 20 66 61 69 6c 2e 3c 62 72 3e 0d 0a 65 2e 67 l fail.<br>..e.g
3520: 2e 20 74 68 69 73 20 77 69 6c 6c 20 75 73 75 61 . this will usua
3530: 6c 6c 79 20 68 61 70 70 65 6e 20 77 68 65 6e 20 lly happen when
3540: 61 6e 20 6f 72 64 69 6e 61 72 79 20 63 6f 6c 75 an ordinary colu
3550: 6d 6e 20 69 73 20 61 6c 72 65 61 64 79 20 64 65 mn is already de
3560: 66 69 6e 65 64 20 61 6e 64 20 63 72 65 61 74 69 fined and creati
3570: 6e 67 20 61 20 47 65 6f 6d 65 74 72 79 20 6f 66 ng a Geometry of
3580: 20 74 68 65 20 73 61 6d 65 20 69 64 65 6e 74 69 the same identi
3590: 63 61 6c 20 6e 61 6d 65 20 69 73 20 73 74 72 69 cal name is stri
35a0: 63 74 6c 79 20 72 65 71 75 69 72 65 64 2e 3c 2f ctly required.</
35b0: 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 td></tr>..<tr><t
35c0: 64 3e 3c 62 3e 3a 3a 72 65 73 65 71 75 65 6e 63 d><b>::resequenc
35d0: 65 3a 3a 3c 2f 62 3e 3c 2f 74 64 3e 3c 74 64 3e e::</b></td><td>
35e0: 72 65 73 65 74 73 20 66 72 6f 6d 20 62 65 67 69 resets from begi
35f0: 6e 6e 69 6e 67 20 74 68 65 20 73 65 71 75 65 6e nning the sequen
3600: 63 65 20 6f 66 20 76 61 6c 75 65 73 20 75 73 65 ce of values use
3610: 64 20 62 79 20 61 20 50 72 69 6d 61 72 79 20 4b d by a Primary K
3620: 65 79 20 6f 66 20 74 68 65 20 3c 62 3e 49 4e 54 ey of the <b>INT
3630: 45 47 45 52 20 41 55 54 4f 49 4e 43 52 45 4d 45 EGER AUTOINCREME
3640: 4e 54 3c 2f 62 3e 20 74 79 70 65 2e 3c 62 72 3e NT</b> type.<br>
3650: 0d 0a 41 6e 79 20 6f 74 68 65 72 20 64 69 66 66 ..Any other diff
3660: 65 72 65 6e 74 20 74 79 70 65 20 6f 66 20 50 72 erent type of Pr
3670: 69 6d 61 72 79 20 4b 65 79 20 6c 61 63 6b 69 6e imary Key lackin
3680: 67 20 74 68 65 20 3c 62 3e 41 55 54 4f 49 4e 43 g the <b>AUTOINC
3690: 52 45 4d 45 4e 54 3c 2f 62 3e 20 63 6c 61 75 73 REMENT</b> claus
36a0: 65 20 77 69 6c 6c 20 62 65 20 75 6e 61 66 66 65 e will be unaffe
36b0: 63 74 65 64 2e 3c 2f 74 64 3e 0d 0a 3c 74 64 3e cted.</td>..<td>
36c0: 70 6f 74 65 6e 74 69 61 6c 6c 79 20 68 61 72 6d potentially harm
36d0: 66 75 6c 20 6f 70 74 69 6f 6e 20 69 66 20 73 6f ful option if so
36e0: 6d 65 20 66 75 72 74 68 65 72 20 46 6f 72 65 69 me further Forei
36f0: 67 6e 20 4b 65 79 20 69 6e 73 69 73 74 73 20 6f gn Key insists o
3700: 6e 20 74 68 61 74 20 50 72 69 6d 61 72 79 20 4b n that Primary K
3710: 65 79 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 ey</td></tr>..<t
3720: 72 3e 3c 74 64 3e 3c 62 3e 3a 3a 69 67 6e 6f 72 r><td><b>::ignor
3730: 65 3a 3a 3c 2f 62 3e 3c 69 3e 63 6f 6c 75 6d 6e e::</b><i>column
3740: 5f 6e 61 6d 65 3c 2f 69 3e 3c 2f 74 64 3e 3c 74 _name</i></td><t
3750: 64 3e 53 68 61 64 6f 77 73 20 61 20 63 6f 6c 75 d>Shadows a colu
3760: 6d 6e 20 70 72 65 73 65 6e 74 20 69 6e 20 74 68 mn present in th
3770: 65 20 6f 72 69 67 69 6e 20 54 61 62 6c 65 20 61 e origin Table a
3780: 73 20 69 66 20 69 74 20 77 61 73 20 6e 6f 74 20 s if it was not
3790: 65 78 69 73 74 69 6e 67 2e 3c 2f 74 64 3e 0d 0a existing.</td>..
37a0: 3c 74 64 3e 74 68 69 73 20 6f 70 74 69 6f 6e 20 <td>this option
37b0: 77 69 6c 6c 20 62 65 20 61 6c 77 61 79 73 20 69 will be always i
37c0: 67 6e 6f 72 65 64 20 66 6f 72 20 61 6e 79 20 63 gnored for any c
37d0: 6f 6c 75 6d 6e 20 64 69 72 65 63 74 6c 79 20 72 olumn directly r
37e0: 65 66 65 72 65 6e 63 65 64 20 62 79 20 61 20 50 eferenced by a P
37f0: 72 69 6d 61 72 79 20 6f 72 20 46 6f 72 65 69 67 rimary or Foreig
3800: 6e 20 4b 65 79 20 6f 72 20 65 76 65 6e 20 62 79 n Key or even by
3810: 20 61 6e 20 49 6e 64 65 78 2e 3c 2f 74 64 3e 3c an Index.</td><
3820: 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 3c 62 3e tr>..<tr><td><b>
3830: 3a 3a 63 61 73 74 32 6d 75 6c 74 69 3a 3a 3c 2f ::cast2multi::</
3840: 62 3e 3c 69 3e 67 65 6f 6d 65 74 72 79 5f 6e 61 b><i>geometry_na
3850: 6d 65 3c 2f 69 3e 3c 2f 74 64 3e 3c 74 64 3e 46 me</i></td><td>F
3860: 6f 72 63 65 73 20 61 20 47 65 6f 6d 65 74 72 79 orces a Geometry
3870: 20 74 6f 20 62 65 20 70 72 6f 6d 6f 74 65 64 20 to be promoted
3880: 74 6f 20 69 74 73 20 3c 62 3e 4d 55 4c 54 49 2d to its <b>MULTI-
3890: 74 79 70 65 3c 2f 62 3e 20 65 71 75 69 76 61 6c type</b> equival
38a0: 65 6e 74 2e 3c 2f 74 64 3e 0d 0a 3c 74 64 3e 53 ent.</td>..<td>S
38b0: 65 65 20 74 68 65 20 64 6f 63 75 6d 65 6e 74 61 ee the documenta
38c0: 74 69 6f 6e 20 61 62 6f 75 74 20 74 68 65 20 3c tion about the <
38d0: 62 3e 43 61 73 74 54 6f 4d 75 6c 74 69 28 29 3c b>CastToMulti()<
38e0: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e /b> SQL function
38f0: 20 66 6f 72 20 6d 6f 72 65 20 64 65 74 61 69 6c for more detail
3900: 73 2e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f s.</td></tr>..</
3910: 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 3c 68 72 3e table><br>..<hr>
3920: 0d 0a 3c 68 33 3e 75 73 65 66 75 6c 20 68 69 6e ..<h3>useful hin
3930: 74 3a 20 63 69 72 63 75 6d 76 65 6e 74 69 6e 67 t: circumventing
3940: 20 74 68 65 20 3c 75 3e 41 4c 54 45 52 20 54 41 the <u>ALTER TA
3950: 42 4c 45 20 44 52 4f 50 20 43 4f 4c 55 4d 4e 3c BLE DROP COLUMN<
3960: 2f 75 3e 20 69 73 73 75 65 3c 2f 68 33 3e 0d 0a /u> issue</h3>..
3970: 53 51 4c 69 74 65 20 6e 6f 74 6f 72 69 6f 75 73 SQLite notorious
3980: 6c 79 20 64 6f 65 73 6e 27 74 20 73 75 70 70 6f ly doesn't suppo
3990: 72 74 20 74 68 65 20 3c 62 3e 41 4c 54 45 52 20 rt the <b>ALTER
39a0: 54 41 42 4c 45 20 44 52 4f 50 20 43 4f 4c 55 4d TABLE DROP COLUM
39b0: 4e 3c 2f 62 3e 20 73 74 61 74 65 6d 65 6e 74 3b N</b> statement;
39c0: 20 3c 62 3e 43 6c 6f 6e 65 54 61 62 6c 65 28 29 <b>CloneTable()
39d0: 3c 2f 62 3e 20 63 61 6e 20 62 65 20 65 61 73 69 </b> can be easi
39e0: 6c 79 20 75 73 65 64 20 69 6e 20 6f 72 64 65 72 ly used in order
39f0: 20 74 6f 20 63 69 72 63 75 6d 76 65 6e 74 20 74 to circumvent t
3a00: 68 69 73 20 6c 69 6d 69 74 61 74 69 6f 6e 2e 0d his limitation..
3a10: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
3a20: 45 43 54 20 43 6c 6f 6e 65 54 61 62 6c 65 28 27 ECT CloneTable('
3a30: 6d 61 69 6e 27 2c 20 27 6f 6c 64 5f 74 61 62 6c main', 'old_tabl
3a40: 65 27 2c 20 27 6e 65 77 5f 74 61 62 6c 65 27 2c e', 'new_table',
3a50: 20 31 2c 20 27 3a 3a 69 67 6e 6f 72 65 3a 3a 66 1, '::ignore::f
3a60: 6f 6f 27 29 3b 0d 0a 44 52 4f 50 20 54 41 42 4c oo');..DROP TABL
3a70: 45 20 6f 6c 64 5f 74 61 62 6c 65 3b 0d 0a 3c 2f E old_table;..</
3a80: 76 65 72 62 61 74 69 6d 3e 0a 5a 20 33 64 36 66 verbatim>.Z 3d6f
3a90: 32 65 32 37 30 33 33 34 30 39 34 36 35 35 33 39 2e27033409465539
3aa0: 33 38 65 63 32 64 36 62 31 38 61 34 0a 38ec2d6b18a4.