Sqlite3 commands (Part 1)

Source: Internet
Author: User
Tags sqlite database

Article Reference: www.sqlite.org/sqlite.html Sqlite3 We can manually manage the SQLite database. Common 2 sqlite3 On a computer, it is located in Android-SDK-Windows \ tools \ sqlite3.exe for managing SQLite databases on a computer; and on an Android system (on a mobile phone ), it is used to manage SQLite databases on the Android system. For the latter, you need to use ADB
Shell. Sometimes we do not want to directly operate the SQLite database on the Android system. In this case, we can copy it to a computer for operations. However, you must note that the former is the window system, and the latter is the Linux system. They indicate different paths. After the sqlite3 command, specify the database file to be opened or created with a parameter. If the specified database file does not exist, a new database is created with this parameter as the file name. Sqlite3 on the Android system must be run through its shell. If you want to create a database, you need the root permission. You can type "Su" in the shell to obtain the root permission. For Android sqlite3Program(Run through shell), you can press Ctrl + d, then press enter to exit the program and return to shell, or press Ctrl + C to exit the shell directly, if it is sqlite3 on the computer, you can press Ctrl + C to directly exit the sqlite3 program. The following is an example of creating an SQLite database named "ex1" that contains a table named "tbl1. Example 1 : $ Sqlite3 ex1 SQLite version 3.3.10 Enter ". Help" for instructions SQLite> Create Table tbl1 (one varchar (10), two smallint ); SQLite> insert into tbl1 values ('Hello! ', 10 ); SQLite> insert into tbl1 values ('Goodbye ', 20 ); SQLite> select * From tbl1; Hello! | 10 Goodbye | 20 SQLite> Sqlite3 supports two types of commands: SQL commands, non-SQL commands, and non-SQL commands prefixed with ".", such as ". Tables" commands. You can use ". help "command to view all its non-SQL commands. all ". "SQL statements with the prefix will be interpreted. At that time, you must add a semicolon to the end of the SQL statement"; "to indicate that the SQL statement input is complete, the command you entered starts to be executed in the SQL language. For example , Example 2: SQLite> Create Table tbl2 ( ...> F1 varchar (30) primary key, ...> F2 text, ...> F3 real ...> ); SQLite> The schema of the database is stored in a table named sqlite_master. Although you cannot perform drop table, update, insert or delete operations on it, but it can be queried like a normal table. For example , Example 3: Sqlite3/data/COM. Android. providers. Settings/databases/settings. DB SQLite version 3.6.22 Enter ". Help" for instructions Enter SQL statements terminated with ";" SQLite> . Tables . Tables Android_metadata bookmarks System Bluetooth_devices secure SQLite> Select * From sqlite_master; Select * From sqlite_master; Table | android_metadata | 3 | create table android_metadata (locale Text) Table | system | 4 | create table System (_ id integer primary key autoincrement , Name text unique on conflict replace, value text) Index | sqlite_autoindex_system_1 | system | 5 | Table | sqlite_sequence | 6 | create table sqlite_sequence (name, SEQ) Index | systemindex1 | system | 7 | create index systemindex1 on system (name) Table | secure | 8 | create table secure (_ id integer primary key autoincrement , Name text unique on conflict replace, value text) Index | sqlite_autoindex_secure_1 | secure | 9 | Index | secureindex1 | secure | 10 | create index secureindex1 on secure (name) Table | incluth_devices | 11 | create table incluth_devices (_ id Integer primary key, Name text, ADDR text, channel integer, type Integer) Table | bookmarks | 12 | create table bookmarks (_ id integer primary key, tit Le text, folder text, intent text, shortcut integer, ordering integer) Index | bookmarksindex1 | bookmarks | 13 | create index bookmarksindex1 on bookmarks (fo Lder) Index | bookmarksindex2 | bookmarks | 14 | create index bookmarksindex2 on bookmarks (SH Ortcut) SQLite> The schema of temporary tables is not saved in the "sqlite_master" table, because the temporary table is only visible to Applications created for it. the schema of temporary tables is stored in another table named "sqlite_temp_master. the "sqlite_temp_master" table is temporary itself.

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.