sqlite的系統表sqlite master

2022-03-06 20:02:38 字數 956 閱讀 9963

sqlite資料庫中乙個特殊的名叫 sqlite_master 上執行乙個select查詢以獲得所有表的索引。每乙個 sqlite 資料庫都有乙個叫 sqlite_master 的表, 它定義資料庫的模式。 sqlite_master 表看起來如下:

create table sqlite_master ( 

type text, 

name text, 

tbl_name text, 

rootpage integer, 

sql text 

); 對於表來說,type 字段永遠是 『table』,name 字段永遠是表的名字。所以,要獲得資料庫中所有表的列表, 使用下列select語句:

select name from sqlite_master 

where type=』table』 

order by name; 

對於索引,type 等於 『index』, name 則是索引的名字,tbl_name 是該索引所屬的表的名字。 不管是表還是索引,sql 欄位是原先用 create table 或 create index 語句建立它們時的命令文字。對於自動建立的索引(用來實現 primary key 或 unique 約束),sql欄位為null。

臨時表不會出現在 sqlite_master 表中。臨時表及其索引和觸發器存放在另外乙個叫 sqlite_temp_master 的表中。sqlite_temp_master 跟 sqlite_master 差不多, 但它只是對於建立那些臨時表的應用可見。如果要獲得所有表的列表, 不管是永久的還是臨時的,可以使用類似下面的命令:

select name from 

(select * from sqlite_master union all 

select * from sqlite_temp_master) 

where type=』table』 

order by name

sqlite的系統表sqlite master介紹

sqlite資料庫中乙個特殊的名叫 sqlite master 上執行乙個select查詢以獲得所有表的索引。每乙個 sqlite 資料庫都有乙個叫 sqlite master 的表,它定義資料庫的模式。sqlite master 表看起來如下 create table sqlite master ...

關於sqlite中系統表sqlite master

create table sqlite master type text name text tbl name text rootpage integer sql text 表 對於表來說,type字段永遠是 table name字段永遠是表的名字。所以,要獲得資料庫中所有表的列表,使用下列sele...

Sqlite系統命令

size medium color orange bail on off stop after hitting an error.default off databases list names and files of attached databases 檢視目前掛的資料庫 dump table...