table of Contents
A, SQLite grammar
1. Case Sensitivity
It is worth noting that the focus point, SQLite is not case sensitive , but some commands are case-sensitive, such as: GLOB and glob has different meanings in SQLite years.
2. Comment
SQLite notes and other annotations SQL language is the same, are additional notes. Comments can be added to increase the readability of SQL statements.
SQL comments begin with two consecutive "-" character starts with the content of the latter are annotated. It can be written in any place.
Or you can use the "/ *" Start "* /" end. Comment block.
-- select * from LinkMen;
select * from LinkMen; -- 在语句后面注释
/*这是注释
这也是*/ select * from LinkMen;
3. SQLite statement
So statements can begin with any keywords, such as SELECT, INSERT, UPDATE, DELETE, etc., so the statement in English semicolon ";" at the end.
-- 创建表
CREATE TABLE table_name(
column1 datatype,
.....
columnN datatype,
);
-- 创建索引
CREATE INDEX index_name ON table_name;
-- 创建触发器
CREATE TRIGGER trigger_name [BEFORE|AFTER] event_name
ON table_name
BEGIN
-- 触发器逻辑....
END;
-- 创建视图
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name, ...
WHERE [condition];
-- 提交 语句:
COMMIT;
-- 删除表
DROP TABLE database_name.table_name;
-- 删除索引
DROP INDEX database_name.index_name;
-- 删除视图
DROP VIEW view_name;
-- 插入数据
INSERT INTO table_name( column1, column2....columnN)
VALUES ( value1, value2....valueN);
-- 查询数据
SELECT column1, column2....columnN
FROM table_name;
-- 修改数据
UPDATE table_name
SET column1 = value1, ..., columnN=valueN
WHERE [condition];
-- 删除数据
DELETE FROM table_name
WHERE [condition];
-- GROUP BY分组
SELECT SUM(column_name)
FROM table_name
WHERE CONDITION
GROUP BY column_name;
-- HAVING对group by加条件过滤
SELECT SUM(column_name)
FROM table_name
WHERE CONDITION
GROUP BY column_name
HAVING (arithematic function condition);
-- IN
SELECT column1, column2....columnN
FROM table_name
WHERE column_name IN (val-1, val-2,...val-N);
-- LIKE
SELECT column1, column2....columnN
FROM table_name
WHERE column_name LIKE [ PATTERN ];
-- ORDER BY 排序
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION
ORDER BY column_name {ASC|DESC};
Two, SQLite data type
Data type is used to specify a data type attribute of any object. Each column, and each variable expression has an associated data type.
type of data | description |
---|---|
NULL | Value is a NULL value. |
INTEGER | Value is a signed integer, stored value in accordance with the size of 1,2,3,4,6 or 8 bytes. |
REAL | Value is a floating point value, stored as 8-byte IEEE floating-point numbers. |
TEXT | Value is a text string, using the database encoding (UTF-8, UTF-16BE or UTF-16LE) storage. |
BLOB | Value is a blob data, stored entirely in accordance with its input. |
1. Boolean data type
SQLite no separate Boolean storage class. Instead, the Boolean value is stored as an integer of 0 (false) and 1 (true).
2. Date and Time data type
No single SQLite for storing the date and / or time-based storage, but SQLite able to store the date and time as TEXT, REAL or INTEGER value.
type of data | Date Format |
---|---|
TEXT | Format "YYYY-MM-DD HH: MM: SS.SSS" date. |
REAL | The number of days from the beginning of noon 4714 BC November 24 Greenwich time counting. |
INTEGER | Counting the number of seconds from 1970-01-01 00:00:00 UTC. |