summaryrefslogtreecommitdiff
path: root/doc/note/sqlite/sqlite.txt
blob: 3805e071756e990f74e927026f676e85c9be4643 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


## How to merge two DBs with same schema

BEGIN TRANSACTION;
ATTACH 'gugus.db' AS other;
INSERT INTO "Foo" SELECT * FROM "other"."Foo";
INSERT INTO "Bar" SELECT * FROM "other"."Bar";
COMMIT;
DETACH other;


ATTACH 'bekb-2023.db' AS other;
INSERT INTO "Account" SELECT * FROM "other"."Account";
INSERT INTO "Currency" SELECT * FROM "other"."Currency";
INSERT INTO "AccountType" SELECT * FROM "other"."AccountType";
INSERT INTO "Transaction" SELECT * FROM "other"."Transaction";


## import CSV

csv Example (no headrow):
  1;foo
  2;bar

  sqlite3 foo.db -bail -cmd '.mode csv' -cmd '.separator ;' -cmd '.import foo.csv FooTable'


## Drop Column

  ALTER TABLE table DROP COLUMN column;


## Add Column

  ALTER TABLE table ADD COLUMN column NOT NULL DEFAULT 'gugus';


## Refs

[drop column TODO vote](https://stackoverflow.com/a/66399224/4415884)