「SQLite」テーブルの構造を確認する方法

2021年9月5日

使用例1
全てのテーブルの構造を取得

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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"
特定のテーブルの構造を確認

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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)

 

 

SQLite

Posted by arkgame