sqliteHow do I format an SQLite database with version 3?
SQLite version 3 is a popular open source relational database system. Formatting an SQLite database with version 3 can be done using the SQL commands CREATE TABLE and INSERT INTO. The following example code block creates a database called 'mydb' and a table called 'mytable' with columns 'name' and 'age':
sqlite3 mydb.db
CREATE TABLE mytable (name TEXT, age INT);
INSERT INTO mytable (name, age) VALUES ('John', 25);
INSERT INTO mytable (name, age) VALUES ('Jane', 30);
The output of the above code should be:
sqlite> CREATE TABLE mytable (name TEXT, age INT);
sqlite> INSERT INTO mytable (name, age) VALUES ('John', 25);
sqlite> INSERT INTO mytable (name, age) VALUES ('Jane', 30);
Code explanation
sqlite3 mydb.db
: This command creates the database file 'mydb.db'.CREATE TABLE mytable (name TEXT, age INT)
: This command creates a table called 'mytable' with two columns, 'name' and 'age'.INSERT INTO mytable (name, age) VALUES ('John', 25)
: This command inserts a row into the table with the values 'John' and 25 for the 'name' and 'age' columns, respectively.INSERT INTO mytable (name, age) VALUES ('Jane', 30)
: This command inserts a row into the table with the values 'Jane' and 30 for the 'name' and 'age' columns, respectively.
Helpful links
More of Sqlite
- How do I use SQLite to retrieve data from a specific year?
- How do I use SQLite with Visual Studio?
- How can SQLite and ZFS be used together for software development?
- How do I use the SQLite ZIP VFS to compress a database?
- How to configure SQLite with XAMPP on Windows?
- How can I use SQLite with Zabbix?
- How do I use SQLite transactions?
- How do I call sqlitepcl.raw.setprovider() when using SQLite?
- How can I use an upsert statement to update data in a SQLite database?
- How do I use the SQLite SUBSTRING function?
See more codes...