Database Use of SQLite

Source: Internet
Author: User
Tags sqlite sqlite database

The database is widely used and can be applied to all major operating systems, such as Java, Android, IOS, windows, etc.

Although SQLite is a lightweight small engine, but can support up to 2TB size of the database, as a single file, in the form of B-TREE data structure stored in the disk, with lightweight, independent, isolation, cross-platform, multi-language and interface, security and so on.

Multiple processes can then read data from the consolidated database in a unified time, but only one can write data

About SQLite data types: SQLite supports null (NULL), INTEGER (shaped value), REAL (floating-point value), TEXT (string value), and BLOB (binary object) data type

Dynamic Data type (weak reference): When a value is inserted into the database, SQLite checks its type, and if the type does not match the associated column, SQLite attempts to convert the value to the type of the column, and if it cannot, the value is stored as its own type

Database: Equivalent to Excel file, is a carrier of several data tables, internal can exist several data tables

Data table (table): equivalent to a worksheet in an Excel file for storing data

column/Field (column): a vertical row

Row: That is, a horizontal

English: Design: Designed, unique: Unique, execute: Execute, insert: INSERT, into: To ... Inside, delete: delete, auto: Auto, increment: Grow/increase, primary: primary, PRIMARY key: Primary key, Version: edition

SQL statements are a series of fixed statements that are formatted to implement all the contents of a database.


Next is the use of SQLite

There are two main classes of SQLite: 1.SQLiteDatabase 2.SQLiteOpenHelper

1.SQLiteDatabase: Provides a number of ways to manage SQLite database classes, provide create, delete, modify, execute SQL commands, and perform other common database administration tasks

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/85/AC/wKioL1esGzLBX8gfAAESx-t1t9g046.png-wh_500x0-wm_3 -wmp_4-s_729274968.png "style=" Float:none; "title=" Sql1.png "alt=" Wkiol1esgzlbx8gfaaesx-t1t9g046.png-wh_50 "/>

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/85/AE/wKiom1esGzPDFRX9AACbfd-3sc4528.png-wh_500x0-wm_3 -wmp_4-s_2046027021.png "style=" Float:none; "title=" Sql2.png "alt=" Wkiom1esgzpdfrx9aacbfd-3sc4528.png-wh_50 "/>


650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/85/DB/wKiom1esWdDyWPm7AACwEPpaNbo819.png-wh_500x0-wm_3 -wmp_4-s_1468303480.png "title=" Sql3.png "alt=" Wkiom1eswddywpm7aacweppanbo819.png-wh_50 "/>

These are the main additions and deletions of the change statement.

"Create data Table"

Syntax: CREATE TABLE table name (field design list)

Field Design list Syntax: Field name fields data Type field constraint

Separate the fields with a comma in English

Example: CREATE TABLE teachers (name varchar (8) NOT NULL unique, tel varchar (+), email varchar (50))//number in parentheses to limit input maximum word count

Note that there must be a space between each property and property

"Add Data"

Syntax: INSERT into table name (field list) VALUES (Value list)

Example:

INSERT into teachers (name, tel, email) VALUES (' Harry ', ' 13800138001 ', ' [email protected] ')

INSERT into teachers (email, name, tel) values (' [email protected] ', ' John Doe ', ' 13800138006 ')

INSERT into teachers (name) VALUES (' Zhang San ')

"Delete Data"

Syntax: delete from table name [WHERE clause]

Syntax for the WHERE clause: where field condition operator value [relational operator field condition operator value]

Conditional operators: = <> >= <=

Relational operators: and Or not

Example:

Delete from teachers//delete all data in teacher table

Delete from teachers where Name= ' Zhang San '//delete data for the Name field with the value ' Zhang San '

Delete from teachers where tel= ' 010-66778899 '//delete data for the Tel field with a value of ' 010-66778899 '

Delete from teacher where name= ' John Doe ' and tel= ' 10086 '//Remove the value of the name character as ' constant ', and the value of the Tel field is ' 10086 ' data, the above 2 conditions must satisfy both

Delete from teachers where name= ' John Doe ' or tel= ' 13800138007 '//Remove the value of the name character as ' John Doe ', or the value of the Tel field is ' 13800138007 ' data, The above 2 conditions satisfy any of these 1 articles can be

"Modify Data"

Syntax: Update table name set field Assignment list [WHERE clause]

Field Assignment list: Field name = field value

Example:

Update teachers set tel= ' 010-66778899 '//Set the value of the Tel field for each piece of data to ' 010-66778899 '

Update teachers set email= ' [email protected] ' where Name= ' Zhang San '//Set the value of the Name field to ' Zhang San ' the value of the email field is ' [email protected] '



2.SQLiteOpenHelper: is a Sqlitedatabase helper class for managing database creation and version updates, typically establishing a class to inherit from it, and overriding the OnCreate () and Onupgrade () methods

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/85/DB/wKiom1esXyHjt9MaAAD9UxPFpHE119.png-wh_500x0-wm_3 -wmp_4-s_867092353.png "title=" Sql4.png "alt=" Wkiom1esxyhjt9maaad9uxpfphe119.png-wh_50 "/>

is the main method of Sqliteopenhelper.


Works best when combined with 1 and 2

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/85/DB/wKioL1esYkKzLRctAAC8hPOCs1A118.png-wh_500x0-wm_3 -wmp_4-s_1045471634.png "style=" Float:none; "title=" Sql5.png "alt=" Wkiol1esykkzlrctaac8hpocs1a118.png-wh_50 "/>

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/85/DB/wKiom1esYkTBRoVXAAE0t-yPNt8263.png-wh_500x0-wm_3 -wmp_4-s_275012774.png "style=" Float:none; "title=" Sql6.png "alt=" Wkiom1esyktbrovxaae0t-ypnt8263.png-wh_50 "/>

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/85/DB/wKioL1esYkWBUZXfAAD-0Ck8S5I717.png-wh_500x0-wm_3 -wmp_4-s_1028802133.png "style=" Float:none; "title=" Sql7.png "alt=" Wkiol1esykwbuzxfaad-0ck8s5i717.png-wh_50 "/>

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/85/DB/wKioL1esYkfygKfWAAC4uLFKqrw608.png-wh_500x0-wm_3 -wmp_4-s_3235060306.png "style=" Float:none; "title=" Sql8.png "alt=" Wkiol1esykfygkfwaac4ulfkqrw608.png-wh_50 "/>



This article is from the "11828641" blog, please be sure to keep this source http://11838641.blog.51cto.com/11828641/1837047

Database Use of SQLite

Related Article

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.