SQLite

How to Use the Schema Command to Show Table Structure in SQLite

The SQLite database has multiple commands that are used to perform different operations, such as the “.schema” command that is used to display the structure of the available tables. Users need to follow this particular procedure if they require an effect of the table at any time. Moreover, it describes the table implies printing information about each column, like column name, data type, and size.

This guide will describe the usage of the schema command in SQLite.

How to Use the Schema Command to Show Table Structure in SQLite?

To show table structure in SQLite by using the “.schema” command, check out the following instructions:

  • Open the Windows terminal and switch to the SQLite folder.
  • List all the databases and navigate to one of them.
  • View the existing tables and choose the desired one.
  • Run the “.schema <table-name>” command to show the table structure.

Step 1: Launch Windows Terminal

Search “Command Prompt” with the help of the “Startup” menu and open it:

Step 2: Navigate to SQLite Directory

Then, execute the “cd” command along with the “sqlite” folder name and navigate to it:

cd sqlite

Step 3: Display Existing Databases

Now, display all the available SQLite databases by running the “.databases” command:

.databases

According to the given output, only one database exists named “mydatadb.db”:

Step 4: Navigate to Database

Execute the “.open” command along with the database name and navigate to it:

.open mydatadb.db

Step 5: View Database Table

Next, list the available database tables by using the “.table” command:

.table

As you can see, the current working database contains two tables and we have selected the “employees_info” table for further process:

Step 6: Show Table Structure

Lastly, execute the “.schema” command along with the previously selected table name:

.schema employees_info

It can be seen that the structure of the “employees_info” table has been displayed which contains:

  • emID” column name that has “INT” data type.
  • empName”, “empDesigination”, and “empAddress” columns which have the “CHAR” data type:

You have learned the easiest way to show the table structure in SQLite using the “.schema” command.

Conclusion

To view the table structure in SQLite, the “.schema” command can be used. For that purpose, first, open the Windows terminal and switch to the SQLite folder. Then, list the databases and navigate to one of them. Next, view the existing tables, select the desired one, and execute the “.schema <table-name>” command. In this guide, we have illustrated the method of displaying the table structure in SQLite.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.