Sqlite System Table sqlite_master

Source: Internet
Author: User
Keywords sqlite system tables sqlite_master sqlite system tables sqlite_master
Perform a SELECT query on a special name SQLITE_MASTER in the SQLite database to obtain the indexes of all tables. Every SQLite database has a table called SQLITE_MASTER, which defines the database schema. The SQLITE_MASTER table looks as follows:
Simple Application Server
USD1.00 New User Coupon
* Only 3,000 coupons available.
* Each new user can only get one coupon(except users from distributors).
* The coupon is valid for 30 days from the date of receipt.

CREATE TABLE sqlite_master (
type TEXT,
name TEXT,
tbl_name TEXT,
rootpage INTEGER,
sql TEXT
);

For tables, the type field is always ‘table’ and the name field is always the name of the table. So, to get a list of all tables in the database, use the following SELECT statement:

SELECT name FROM sqlite_master
WHERE type=’table’
ORDER BY name;

For an index, type is equal to ‘index’, name is the name of the index, and tbl_name is the name of the table to which the index belongs. Regardless of whether it is a table or an index, the sql field is the command text when they were originally created with the CREATE TABLE or CREATE INDEX statement. For automatically created indexes (used to implement PRIMARY KEY or UNIQUE constraints), the sql field is NULL.

Temporary tables will not appear in the SQLITE_MASTER table. Temporary tables and their indexes and triggers are stored in another table called SQLITE_TEMP_MASTER. SQLITE_TEMP_MASTER is similar to SQLITE_MASTER, but it is only visible to applications that create temporary tables. If you want to get a list of all tables, whether permanent or temporary, you can use a command similar to the following:

SELECT name FROM
(SELECT * FROM sqlite_master UNION ALL
SELECT * FROM sqlite_temp_master)
WHERE type=’table’
ORDER BY name
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.