AUTO INCREMENT を使う場合は "INTEGER NOT NULL PRIMARY KEY" でフィールドを定義して、データ登録の時は NULL を指定する。
実行結果
> a.exe test.db "CREATE TABLE test_tbl(ID INTEGER PRIMARY KEY, NAME TEXT NOT NULL);" > a.exe test.db "INSERT INTO test_tbl(ID, NAME) VALUES (NULL, '1st');" > a.exe test.db "INSERT INTO test_tbl(ID, NAME) VALUES (NULL, '2nd');" > a.exe test.db "INSERT INTO test_tbl(ID, NAME) VALUES (NULL, '3rd');" > a.exe test.db "SELECT * from test_tbl;" ID = 1 NAME = 1st ID = 2 NAME = 2nd ID = 3 NAME = 3rd
sqlite3.exe の場合
sqlite> CREATE TABLE tbl3 (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL); sqlite> INSERT INTO tbl3 VALUES (NULL, 'Tokyo'); sqlite> INSERT INTO tbl3 VALUES (NULL, 'Osaka'); sqlite> INSERT INTO tbl3 VALUES (NULL, 'Nagoya'); sqlite> SELECT * FROM tbl3; 1|Tokyo 2|Osaka 3|Nagoya
0 件のコメント:
コメントを投稿