「SQLite」テーブルの構造を確認する方法
使用例1
全てのテーブルの構造を取得
sqlite> .mode line
sqlite> select * from sqlite_master;
type = table
name = usertbl
tbl_name = usertbl
rootpage = 2
sql = CREATE TABLE usertbl(userid,name,addr)
type = table
name = emptbl
tbl_name = emptbl
rootpage = 3
sql = CREATE TABLE emptbl(empid integer,empname text,depname text)
type = table
name = student
tbl_name = student
rootpage = 4
sql = CREATE TABLE student(name text not null,hometown text,addr text)
sqlite>
sqlite> .mode line
sqlite> select * from sqlite_master;
type = table
name = usertbl
tbl_name = usertbl
rootpage = 2
sql = CREATE TABLE usertbl(userid,name,addr)
type = table
name = emptbl
tbl_name = emptbl
rootpage = 3
sql = CREATE TABLE emptbl(empid integer,empname text,depname text)
type = table
name = student
tbl_name = student
rootpage = 4
sql = CREATE TABLE student(name text not null,hometown text,addr text)
sqlite>
sqlite> .mode line sqlite> select * from sqlite_master; type = table name = usertbl tbl_name = usertbl rootpage = 2 sql = CREATE TABLE usertbl(userid,name,addr) type = table name = emptbl tbl_name = emptbl rootpage = 3 sql = CREATE TABLE emptbl(empid integer,empname text,depname text) type = table name = student tbl_name = student rootpage = 4 sql = CREATE TABLE student(name text not null,hometown text,addr text) sqlite>
使用例2
構文
select * from sqlite_master where type=’table’ and name ="xx"
特定のテーブルの構造を確認
sqlite> select * from sqlite_master where type='table' and name='student';
type = table
name = student
tbl_name = student
rootpage = 4
sql = CREATE TABLE student(name text not null,hometown text,addr text)
sqlite> select * from sqlite_master where type='table' and name='student';
type = table
name = student
tbl_name = student
rootpage = 4
sql = CREATE TABLE student(name text not null,hometown text,addr text)
sqlite> select * from sqlite_master where type='table' and name='student'; type = table name = student tbl_name = student rootpage = 4 sql = CREATE TABLE student(name text not null,hometown text,addr text)