DEV Community

Danilsa Caraballo
Danilsa Caraballo

Posted on

SQLite: A tool that allows creating databases from the terminal

I had learned how to create a table for a new database using tools like Excel, Matlab, My sql and table plus.

Now, with SQLite I can create the databases in a very practical way, it is similar to Mysql, so today I a practical example, comparing Mysql with SQLite,

  1. We must be in the folder where we will create the database:

To SQLite

Alt Text

in the case of Mysql, you must find the location of the program to be able to execute it

brew search mysql
//or
./mysql -u root -p
Enter fullscreen mode Exit fullscreen mode
  1. Open the tool, giving name to database:

To SQLite

~ sqlite3 mydatabase
Enter fullscreen mode Exit fullscreen mode

in the case of Mysql

~ create database mydatabase
Enter fullscreen mode Exit fullscreen mode
  1. Create new table, taking into account the type of the column:

SQLite and Mysql are the same

~ use mydatabase
~ create table dataUsers(
          Id integer primary key,
          Name text,
          Last_name text,
          age integer,
          Cell integer 
)
Enter fullscreen mode Exit fullscreen mode
  1. insert the data:

SQLite andMysql are the same

insert into dataUsers(0001,'Ema','Garces', 21, 0573033333055 );

//or

insert into dataUsers( Name text,Last_name text, age real, Cell integer ) VALUES (0001,'Ema','Garces', 21, 0573033333055);
Enter fullscreen mode Exit fullscreen mode
  1. Show table:

To SQLite

~ .mode {mode of choice}
~ select * from dataUsers; 
Enter fullscreen mode Exit fullscreen mode

there are several view modes to display the table:
ascii, box, csv, column, html, insert, line, list, tabs, tcl, etc.

in the case of Mysql

~ show tables;
~ describe dataUsers;
~ select * from dataUsers; 
Enter fullscreen mode Exit fullscreen mode
  1. Bonus: Connect to database with table plus

6.1 open table plus:
Alt Text
6.2 create new connection:

Alt Text
Alt Text
6.3 name the connection and find the location of the database:

Alt Text

Top comments (0)