「SQLite3」sqlite_masterでテーブルスキーマを取得

環境
Windows10 64bit
SQLite3.37.0

書式
select * from sqlite_master;
select * from sqlite_master where type =’table’
and name =’xx’;

使用例1
sqlite_masterテーブルからスキーマを確認します

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 = user
tbl_name = user
rootpage = 2
sql = CREATE TABLE user(uid,uname)
type = table
name = usertbl
tbl_name = usertbl
rootpage = 3
sql = CREATE TABLE usertbl(uid, pwd)
type = table
name = depbl
tbl_name = depbl
rootpage = 4
sql = CREATE TABLE depbl(depid integer, pwd text)
sqlite> .mode line sqlite> select * from sqlite_master; type = table name = user tbl_name = user rootpage = 2 sql = CREATE TABLE user(uid,uname) type = table name = usertbl tbl_name = usertbl rootpage = 3 sql = CREATE TABLE usertbl(uid, pwd) type = table name = depbl tbl_name = depbl rootpage = 4 sql = CREATE TABLE depbl(depid integer, pwd text)
sqlite> .mode line
sqlite> select * from sqlite_master;
    type = table
    name = user
tbl_name = user
rootpage = 2
     sql = CREATE TABLE user(uid,uname)

    type = table
    name = usertbl
tbl_name = usertbl
rootpage = 3
     sql = CREATE TABLE usertbl(uid, pwd)

    type = table
    name = depbl
tbl_name = depbl
rootpage = 4
     sql = CREATE TABLE depbl(depid integer, pwd text)

使用例2
特定のテーブルの構造を確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sqlite> select * from sqlite_master where type='table' and name='depbl';
type = table
name = depbl
tbl_name = depbl
rootpage = 4
sql = CREATE TABLE depbl(depid integer, pwd text)
sqlite> select * from sqlite_master where type='table' and name='depbl'; type = table name = depbl tbl_name = depbl rootpage = 4 sql = CREATE TABLE depbl(depid integer, pwd text)
sqlite> select * from sqlite_master where type='table' and name='depbl';
    type = table
    name = depbl
tbl_name = depbl
rootpage = 4
     sql = CREATE TABLE depbl(depid integer, pwd text)

 

SQLite

Posted by arkgame