2014年07月15日

SQLite3 AUTOINCREMENT

create table TEST_NO_1 (seq_id INTEGER PRIMARY KEY AUTOINCREMENT, di integer);
create table TEST_NO_2 (seq_id INTEGER PRIMARY KEY AUTOINCREMENT, di integer);
create table TEST_NO_3 (seq_id INTEGER PRIMARY KEY AUTOINCREMENT, di integer);

insert into TEST_NO_1 (di) values (1);

insert into TEST_NO_2 (di) values (1);
insert into TEST_NO_2 (di) values (1);

insert into TEST_NO_3 (di) values (1);
insert into TEST_NO_3 (di) values (1);
insert into TEST_NO_3 (di) values (1);

.mode colum
select * from sqlite_sequence;

update sqlite_sequence set seq = 22 where name = 'TEST_NO_3';

select seq_id from TEST_NO_3 order by seq_id desc;

select ROWID from TEST_NO_3;
select ROWID+1 from TEST_NO_3;
select (ROWID+1) As NextVal from TEST_NO_3;
select ROWID,* from TEST_NO_3;


posted by a23 at 13:29| Comment(0) | SQLite

2014年07月14日

SQLite3 テーブルの存在チェック

create table test_tbl (id integer, name text, price real);

select tbl_name from sqlite_master where type='table' and name='テーブル名';
select sql from sqlite_master where type='table' and name='テーブル名';
select * from sqlite_master where type='table' and name='テーブル名';

select count(*) from sqlite_master where type='table' and name='テーブル名';


posted by a23 at 15:34| Comment(0) | SQLite