Sqlite3 database command operation

Source: Internet
Author: User
Tags import database

SQLiteA database is a lightweight, self-contained DBMS,It is portable, easy to use, small, efficient, and reliable.

SQLite is embedded into applications that use it.ProgramThey share the same process space, rather than a separate process. From the external perspective, it is not like an RDBMS, but inside the process, it is complete, self-contained database engine.

One of the major advantages of an embedded database is that you do not need network configuration or management in your program.Because the client and server run in the same process space.

SQLite database permissions only depend on the file system, without the concept of user accounts. SQLite has database-level locking and no network server. It requires memory usage, but other expenses are very small. It is suitable for embedded devices. All you need to do is compile it correctly into your program.


Create a database using SQLite

SQLite is very convenient to use. You only need to enter the name of the SQLite database"Sqlite3"Command. If the file does not exist, a new (database) file is created. ThenSqlite3The program prompts you to enter SQL. The SQL statement is ended with a semicolon (;). After you press the Enter key, the SQL statement is executed. For example, create an SQLite database that contains the "user" table "TBL.

CREATE command:

Create Database User

Sqlite3 user

Create Table TBL

Create Table TBL (name char (10), age smallint, score float );

Query a table

. Table

Insert data

Insert into TBL values ('hangzhou', 24, 98 );

Insert into TBL values ('sunboys', 20, 78.5 );

Query data

Select * From TBL;

Modify Display Mode

. Mode Column

Procedure:


Its operations are not much different from common relational databases, so it is convenient to add, delete, modify, and query data.

SQLite can display the query results in eight ways, which greatly facilitates data processing. The sqlite3 program can display the query results in eight different formats:

. Mode mode? Table? Set output mode where mode is one of:
CSV comma-separated values
Column left-aligned columns. (See. width)
HTML






Code insert SQL insert statements for table line one value per line list values delimited. separator string tabs tab-separated values

TCL list elements

Usage:. Mode column (switch the output format to row mode, for example)

Sqlite3 Import and Export Database

Export Database

SQLite>. Databases(Display database)
SQLite>. Backup main. User. SQL(Backup database main)
SQLite>. Backup. user2. SQL(Backup default database main)

Export table

SQLite>. Output user_tbl. SQL
SQLite>. Dump TBL

Procedure:

Import Database

Yanggang @ doodlemobile :~ $Sqlite3 user2. SQL

Recommendation reference:

Official SQLite website

SQLite Data Type

Sqlite3 Embedded Database

Http://blog.csdn.net/xing_hao/article/details/6660589

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.