SQLite classic ...LOGIN
SQLite classic tutorial
author:php.cn  update time:2022-04-13 17:05:02

SQLite creates database


SQLite’s sqlite3 command is used to create a new SQLite database. You don't need any special permissions to create one.

Syntax

The basic syntax of the sqlite3 command is as follows:

$sqlite3 DatabaseName.db

Normally, the database name is in Should be unique within the RDBMS.

Example

If you want to create a new database <testDB.db>, the SQLITE3 statement is as follows:

$sqlite3 testDB.db
SQLite version 3.7.15.2 2013-01-09 11:53:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>

The above command will create a file testDB.db in the current directory. This file will be used as a database by the SQLite engine. If you have noticed that the sqlite3 command will provide a sqlite> prompt after successfully creating the database file.

Once the database is created, you can use SQLite's .databases command to check whether it is in the database list, as follows:

sqlite> .databases
seq name                                                                                                                                                                                                                                                                                               . -
0 main /home/sqlite/testDB.db
You can use the SQLite

.quit command to exit the sqlite prompt, as shown below:

sqlite>.quit
$
.dump command

You can use the SQLite

.dump point command in the command prompt to Export the complete database in a text file as follows:

$sqlite3 testDB.db .dump > testDB.sql
The above command will convert the entire

testDB.db Convert the contents of the database into SQLite statements and dump them into the ASCII text file testDB.sql. You can restore from the generated testDB.sql in a simple way as follows:

$sqlite3 testDB.db < testDB.sql
The database at this time is empty, once you have the table and data in the database you can try the above two procedures. Now, let's move on to the next chapter.