tybro0103
tybro0103

Reputation: 49693

sqlite3 explain table_name

In mysql you can view a table's structure via explain tablename; What is the equivalent for sqlite3?

Upvotes: 1

Views: 442

Answers (3)

unode
unode

Reputation: 9581

This was already answered in a more generic way here.

Edit:

Note that .schema will also give you INDEXES that match the same name.

Example:

CREATE TABLE job (
    id INTEGER PRIMARY KEY,
    data VARCHAR
);
CREATE TABLE job_name (
    id INTEGER PRIMARY KEY,
    name VARCHAR
);
CREATE INDEX job_idx on job(data);

Note the differences between:

sqlite> SELECT sql FROM SQLITE_MASTER WHERE type = 'table' AND name = 'job';
CREATE TABLE job (
        id INTEGER PRIMARY KEY,
        data VARCHAR
    )
sqlite> SELECT sql FROM SQLITE_MASTER WHERE name = 'job_idx';
CREATE INDEX job_idx on job(data)

and

sqlite> .schema job
CREATE TABLE job (
        id INTEGER PRIMARY KEY,
        data VARCHAR
    );
CREATE INDEX job_idx on job(data);

Including the semi-colon at the end of the queries.

Upvotes: 2

user180804
user180804

Reputation:

I believe ".schema tablename" is what you're looking for.

Upvotes: 2

McStretch
McStretch

Reputation: 20645

You can use .schema in the Command Line Shell:

With no arguments, the ".schema" command shows the original CREATE TABLE and CREATE INDEX statements that were used to build the current database. If you give the name of a table to ".schema", it shows the original CREATE statement used to make that table and all if its indices.

Upvotes: 2

Related Questions