1

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

1

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

2

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.

1 Comment

It was indeed. My question is a little more specific though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.