None of these commands alter the database. If you’re unfamiliar with SQL syntax, you can use and tweak the examples I’ll provide below to safely browse through the data. If you want to look at what’s inside these tables, you need to use SQL syntax. schema customersĬREATE TABLE customers( name text, age int) Code language: SQL (Structured Query Language) ( sql ) Browsing SQLite tables on the command lineĪt this point, we know which tables there are, and we even had a look a the schema behind those tables. You can print the schema for a specific table by supplying its name: sqlite>. When run without arguments, it will print the schema for all tables. schema command prints the CREATE statement that was used to create tables. tablesĬustomers Code language: SQL (Structured Query Language) ( sql ) SQLite. In our case, the output of this command looks like this: sqlite>. tables command show all available tables. databasesĬode language: SQL (Structured Query Language) ( sql ) SQLite. When entering this command, it will output something like this: sqlite>. You can in fact open multiple databases at once, and copy data from one to another or join data from tables that are in different databases. databases we can see which databases are attached to this session. tables ?TABLE? List names of tables matching LIKE pattern TABLEĬode language: plaintext ( plaintext ) SQLite. show Show the current values for various settings schema ?PATTERN? Show the CREATE statements matching PATTERN databases List names and files of attached databases In the extract below, I’ve snipped large parts of the output and only included the commands that are useful when using SQLite as a browser: sqlite>. help for usage hints, but it will output a large list of commands, most of which we don’t care about at this point. SQLite opens the database without much fanfare, but it does print a helpful message to the screen. Now we are all set up to browse our SQLite database! Useful SQLite commands Sqlite> Code language: plaintext ( plaintext ) We can open it with the sqlite3 command like this: C:\> sqlite3 customers.db We’ll work with our previous database called customers.db. Let’s start by opening this SQLite database in a file on the filesystem. Now we have an existing database to work with. If you inspect the filesystem, you’ll see that SQLite has created the customers.db file for us. To close the shell, press control+D, which sends the end-of-file character to your terminal, or type in the. Mary|53 Code language: SQL (Structured Query Language) ( sql ) We can see the results with a simple SELECT statement: sqlite> select * from customers Sqlite> insert into customers values( 'Mary', 53) Code language: SQL (Structured Query Language) ( sql ) Sqlite> insert into customers values( 'Erik', 40) Now create a table and insert some data by entering the following lines: sqlite> create table customers( name text, age int) db extension to clearly mark this as a database file. You can pick any filename you want though, but I recommend using the. We can directly give our database a name by giving it as the first argument: $ sqlite3 customers.db We need to start SQLite with the sqlite3 command again to get an SQLite shell. If you don’t have a database, let’s first create one from scratch so we have something to work with. Sqlite> Code language: Bash ( bash ) Create an SQLite database on Command Line If you already have a file-based SQLite database, however, it’s easier to directly open it like so: C:\> sqlite3 customers.db As SQLite points out to use, we can open a database by using the. When opening SQLite without any arguments, it will create an in-memory database. Use ".open FILENAME" to reopen on a persistent database. This works the same on all the operating systems (Windows, MacOS, Linux): C:\> sqlite3Ĭonnected to a transient in-memory database. To open the SQLite shell, we must enter the sqlite3 command in a terminal or command prompt. If you haven’t done so already, install SQLite first. We can use the SQLite shell to browse SQLite databases. Browsing SQLite tables on the command lineĬommand Line Browsing of SQLite databases.Create an SQLite database on Command Line. Command Line Browsing of SQLite databases.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |