SQLite语句

SQLite 语句可以以任何关键字开始,以分号;结束

ANALYZE 语句

1
2
3
4
5
ANALYZE;
or
ANALYZE database_name;
or
ANALYZE database_name.table_name;

AND/OR 子句

1
2
3
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION-1 {AND|OR} CONDITION-2;

ALTER TABLE 语句

1
ALTER TABLE table_name ADD COLUMN column_def...;

ALTER TABLE 语句(Rename)

1
ALTER TABLE table_name RENAME TO new_table_name;

ATTACH DATABASE 语句

1
ATTACH DATABASE 'DatabaseName' As 'Alias-Name';

BEGIN TRANSACTION 语句

1
2
3
BEGIN;
or
BEGIN EXCLUSIVE TRANSACTION;

BETWEEN 子句

1
2
3
SELECT column1, column2....columnN
FROM table_name
WHERE column_name BETWEEN val-1 AND val-2;

COMMIT 语句

1
COMMIT;

CREATE INDEX 语句

1
2
CREATE INDEX index_name
ON table_name ( column_name COLLATE NOCASE );

CREATE UNIQUE INDEX 语句

1
2
CREATE UNIQUE INDEX index_name
ON table_name ( column1, column2,...columnN);

CREATE TABLE 语句

1
2
3
4
5
6
7
8
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);

CREATE TRIGGER 语句

1
2
3
4
5
6
7
CREATE TRIGGER database_name.trigger_name
BEFORE INSERT ON table_name FOR EACH ROW
BEGIN
stmt1;
stmt2;
....
END;

CREATE VIEW 语句

1
2
CREATE VIEW database_name.view_name AS
SELECT statement....;

CREATE VIRTUAL TABLE 语句

1
2
3
CREATE VIRTUAL TABLE database_name.table_name USING weblog( access.log );
or
CREATE VIRTUAL TABLE database_name.table_name USING fts3( );

COMMIT TRANSACTION 语句

1
COMMIT;

COUNT 子句

1
2
3
SELECT COUNT(column_name)
FROM table_name
WHERE CONDITION;

DELETE 语句

1
2
DELETE FROM table_name
WHERE {CONDITION};

DETACH DATABASE 语句

1
DETACH DATABASE 'Alias-Name';

DISTINCT 子句

1
2
SELECT DISTINCT column1, column2....columnN
FROM table_name;

DROP INDEX 语句

1
DROP INDEX database_name.index_name;

DROP TABLE 语句

1
DROP TABLE database_name.table_name;

DROP VIEW 语句

1
DROP VIEW view_name;

DROP TRIGGER 语句

1
DROP TRIGGER trigger_name

EXISTS 子句

1
2
3
SELECT column1, column2....columnN
FROM table_name
WHERE column_name EXISTS (SELECT * FROM table_name );

EXPLAIN 语句

1
2
3
EXPLAIN INSERT statement...;
or
EXPLAIN QUERY PLAN SELECT statement...;

GLOB 子句

1
2
3
SELECT column1, column2....columnN
FROM table_name
WHERE column_name GLOB { PATTERN };

GROUP BY 子句

1
2
3
4
SELECT SUM(column_name)
FROM table_name
WHERE CONDITION
GROUP BY column_name;

HAVING 子句

1
2
3
4
5
SELECT SUM(column_name)
FROM table_name
WHERE CONDITION
GROUP BY column_name
HAVING (arithematic function condition);

INSERT INTO 语句

1
2
INSERT INTO table_name( column1, column2....columnN)
VALUES ( value1, value2....valueN);

IN 子句

1
2
3
SELECT column1, column2....columnN
FROM table_name
WHERE column_name IN (val-1, val-2,...val-N);

Like 子句

1
2
3
SELECT column1, column2....columnN
FROM table_name
WHERE column_name LIKE { PATTERN };

NOT IN 子句

1
2
3
SELECT column1, column2....columnN
FROM table_name
WHERE column_name NOT IN (val-1, val-2,...val-N);

ORDER BY 子句

1
2
3
4
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION
ORDER BY column_name {ASC|DESC};

PRAGMA 语句

1
2
3
4
5
6
7
PRAGMA pragma_name;
e.g.:
PRAGMA page_size;
PRAGMA cache_size = 1024;
PRAGMA table_info(table_name);

RELEASE SAVEPOINT 语句

1
RELEASE savepoint_name;

REINDEX 语句

1
2
3
REINDEX collation_name;
REINDEX database_name.index_name;
REINDEX database_name.table_name;

ROLLBACK 语句

1
2
3
ROLLBACK;
or
ROLLBACK TO SAVEPOINT savepoint_name;

SAVEPOINT 语句

1
SAVEPOINT savepoint_name;

SELECT 语句

1
2
SELECT column1, column2....columnN
FROM table_name;

UPDATE 语句

1
2
3
UPDATE table_name
SET column1 = value1, column2 = value2....columnN=valueN
[ WHERE CONDITION ];

VACUUM 语句

1
VACUUM;

WHERE 子句

1
2
3
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION;

参考 : http://www.runoob.com/sqlite/