Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/altercons3.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / test / altercons3.test` 109 lines ยท 3276 bytes Raw Blame History 1 # 2026 July 8 2 # 3 # The author disclaims copyright to this source code. In place of 4 # a legal notice, here is a blessing: 5 # 6 # May you do good and not evil. 7 # May you find forgiveness for yourself and forgive others. 8 # May you share freely, never taking more than you give. 9 # 10 #************************************************************************* 11 # 12 13 set testdir [file dirname $argv0] 14 source $testdir/tester.tcl 15 set testprefix altercons3 16 17 # If SQLITE_OMIT_ALTERTABLE is defined, omit this file. 18 ifcapable !altertable { 19 finish_test 20 return 21 } 22 23 #------------------------------------------------------------------------- 24 do_execsql_test 1.0 { 25 CREATE TABLE p1(a PRIMARY KEY); 26 CREATE TABLE c1(b CONSTRAINT fk REFERENCES p1(a)); 27 } 28 do_execsql_test 1.1 { 29 ALTER TABLE c1 DROP CONSTRAINT fk; 30 SELECT sql FROM sqlite_schema WHERE name='c1'; 31 } {{CREATE TABLE c1(b)}} 32 33 34 #------------------------------------------------------------------------- 35 reset_db 36 do_execsql_test 2.0 { 37 CREATE TABLE p1(a PRIMARY KEY); 38 CREATE TABLE c1(b, CONSTRAINT fk FOREIGN KEY (b) REFERENCES p1(a)); 39 } 40 do_execsql_test 2.1 { 41 ALTER TABLE c1 DROP CONSTRAINT fk; 42 SELECT sql FROM sqlite_schema WHERE name='c1'; 43 } {{CREATE TABLE c1(b)}} 44 45 #------------------------------------------------------------------------- 46 reset_db 47 do_execsql_test 3.0 { 48 CREATE TABLE generated(a PRIMARY KEY); 49 CREATE TABLE c1(b CONSTRAINT fk REFERENCES generated(a)); 50 } 51 do_execsql_test 3.1 { 52 ALTER TABLE c1 DROP CONSTRAINT fk; 53 SELECT sql FROM sqlite_schema WHERE name='c1'; 54 } {{CREATE TABLE c1(b)}} 55 56 #-------------------------------------------------------------------------- 57 reset_db 58 59 foreach {tn before after} { 60 1 "CREATE TABLE c1(b CONSTRAINT fk REFERENCES p1(a))" 61 "CREATE TABLE c1(b)" 62 63 2 "CREATE TABLE c1(b, c, CONSTRAINT fk FOREIGN key (c, b) REFERENCES p1(o,t))" 64 "CREATE TABLE c1(b, c)" 65 66 3 "CREATE TABLE c1(b, generated, 67 CONSTRAINT fk FOREIGN key (generated) REFERENCES p1(o))" 68 "CREATE TABLE c1(b, generated)" 69 70 4 "CREATE TABLE c1(b, generated CONSTRAINT fk REFERENCES p1(o) NOT NULL)" 71 "CREATE TABLE c1(b, generated NOT NULL)" 72 73 5 "CREATE TABLE c1(b, generated CONSTRAINT fk REFERENCES x1)" 74 "CREATE TABLE c1(b, generated)" 75 76 6 "CREATE TABLE c1(x CONSTRAINT fk REFERENCES p(a) ON DELETE SET DEFAULT\ 77 ON UPDATE CASCADE, y)" 78 "CREATE TABLE c1(x, y)" 79 80 7 "CREATE TABLE c1(w REFERENCES p DEFERRABLE INITIALLY DEFERRED,\ 81 x CONSTRAINT fk REFERENCES p NOT DEFERRABLE)" 82 "CREATE TABLE c1(w REFERENCES p DEFERRABLE INITIALLY DEFERRED, x)" 83 84 } { 85 do_execsql_test 4.$tn.1 { DROP TABLE IF EXISTS c1 } 86 do_execsql_test 4.$tn.2 $before 87 do_execsql_test 4.$tn.3 { ALTER TABLE c1 DROP CONSTRAINT fk } 88 do_execsql_test 4.$tn.4 { 89 SELECT sql FROM sqlite_schema WHERE name='c1' 90 } [list $after] 91 } 92 93 #------------------------------------------------------------------------- 94 reset_db 95 do_execsql_test 5.0 { 96 CREATE TABLE x1(a, b CONSTRAINT ott REFERENCES x2); 97 PRAGMA writable_schema = 1; 98 UPDATE sqlite_schema SET sql='CREATE TABLE x1(a, b CONSTRAINT ott REFERENCES'; 99 } 100 101 do_execsql_test 5.1 { 102 ALTER TABLE x1 DROP CONSTRAINT ott; 103 } 104 105 do_execsql_test 5.2 { 106 SELECT sql FROM sqlite_schema 107 } {{CREATE TABLE x1(a, b }} 108 109 finish_test