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