How can I see the structure of a table in SQLite?

3

In MySQL, we can use the DESC <table> command to discover the structure of a table.

What about SQLite? How could I do that?

    
asked by anonymous 04.01.2017 / 12:08

2 answers

5

Something closer to the MySql% command%:

PRAGMA table_info([tabela]);

If you want something more detailed:

.schema [tabela]

You can also get everything by invoking only DESCRIBE [tabela] without specifying a table.

.schema

Additionally, it is also interesting to know the equivalent of .schema

The command is SHOW TABLES; or .tables




obs: [table] is an illustrative scope. You must enter the table name without the brackets. ex:

PRAGMA table_info(minha_tabela);

.schema minha_tabela
    
04.01.2017 / 12:14
6

If you are the interpreter, just use .schema nome_da_tabela . It will show the query that cranked it up for you. It does not have a specific mechanism.

You can also call a function that gives this information . This is done with PRAGMA schema.table_info('nome_da_tabela')

But in your application you will probably want to do different and query the structures table:

SELECT sql FROM sqlite_master WHERE type='nome_da_tabela';

In SQLite 3.16 you can do:

SELECT * FROM pragma_table_info('nome_da_tabela');

Remembering that SQLite has a dynamic typing database.

    
04.01.2017 / 12:19