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

Asked

Viewed 3,075 times

4

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

And in Sqlite? How could I do that?

  • Who gave the negative, could explain the reason? What could be improved in the question?

  • It wasn’t me. But I think it’s .schema <table>

2 answers

6

If you are the interpreter just use .schema nome_da_tabela. He will show the query that Grou this for you. It does not have a specific mechanism.

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

But in its application will probably want to do different and consult the table of structures:

SELECT sql FROM sqlite_master WHERE type='nome_da_tabela';

In Sqlite 3.16 you can already do:

SELECT * FROM pragma_table_info('nome_da_tabela');

I put in the Github for future reference.

Remembering that Sqlite has is a dynamic typing database.

5


Something closer to command DESCRIBE [tabela] mysql:

PRAGMA table_info([tabela]);

If you want something more detailed:

.schema [tabela]

You can also get everything by calling only .schema without specifying a table.

.schema

Additionally, it is also interesting to know the equivalent of SHOW TABLES;

The command is .tables or .ta




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

PRAGMA table_info(minha_tabela);

.schema minha_tabela
  • Great, I think the PRAGMA table_info([table]) was the closest to DESCRIBLE [table] +1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.