python sqlite3查看數據庫所有表(table)


#coding:utf-8

import sqlite3

'''
sqlite3存在系統表sqlite_master,結構如下:
sqlite_master(
    type TEXT,      #類型:table-表,index-索引,view-視圖
    name TEXT,      #名稱:表名,索引名,視圖名
    tbl_name TEXT,
    rootpage INTEGER,
    sql TEXT
    )
'''
#查看某數據庫中所有表
def GetTables(db_file = 'main.db'):
    try:
        conn = sqlite3.connect(db_file)
        cur = conn.cursor()
        cur.execute("select name from sqlite_master where type='table' order by name")
        print cur.fetchall()
    except sqlite3.Error, e:
            print e
'''
#查看表結構
cur.execute("PRAGMA table_info(T_Person)")
print cur.fetchall()
'''

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM