結構定義
|
CREATE TABLE
|
創建新表。
語法:
sql-command ::=
|
CREATE [TEMP | TEMPORARY] TABLE table-name ( column-def [, column-def]* [, constraint]* )
|
sql-command ::=
|
CREATE [TEMP | TEMPORARY] TABLE [database-name.] table-name AS select-statement
|
column-def ::=
|
name [type] [[CONSTRAINT name] column-constraint]*
|
type ::=
|
typename | typename ( number ) | typename ( number , number )
|
column-constraint ::=
|
NOT NULL [ conflict-clause ] | PRIMARY KEY [sort-order] [ conflict-clause ] | UNIQUE [ conflict-clause ] | CHECK ( expr ) [ conflict-clause ] | DEFAULT value | COLLATE collation-name
|
constraint ::=
|
PRIMARY KEY ( column-list ) [ conflict-clause ] | UNIQUE ( column-list ) [ conflict-clause ] | CHECK ( expr ) [ conflict-clause ]
|
conflict-clause ::=
|
ON CONFLICT conflict-algorithm
|
|
CREATE VIEW
|
創建一個視圖(虛擬表),該表以另一種方式表示一個或多個表中的資料。
語法:
sql-command ::=
|
CREATE [TEMP | TEMPORARY] VIEW [database-name.] view-name AS select-statement
|
例子: CREATE VIEW master_view AS SELECT * FROM sqlite_master WHERE type='view'; 說明: 創建一個名為master_view的視圖,其中包括sqlite_master這個表中的所有視圖表。
|
CREATE TRIGGER
|
創建觸發器,觸發器是一種特殊的存儲過程,在使用者試圖對指定的表執行指定的資料修改語句時自動執行。
語法:
sql-statement ::=
|
CREATE [TEMP | TEMPORARY] TRIGGER trigger-name [ BEFORE | AFTER ] database-event ON [database-name .] table-name trigger-action
|
sql-statement ::=
|
CREATE [TEMP | TEMPORARY] TRIGGER trigger-name INSTEAD OF database-event ON [database-name .] view-name trigger-action
|
database-event ::=
|
DELETE | INSERT | UPDATE | UPDATE OF column-list
|
trigger-action ::=
|
[ FOR EACH ROW | FOR EACH STATEMENT ] [ WHEN expression ] BEGIN trigger-step ; [ trigger-step ; ]* END
|
trigger-step ::=
|
update-statement | insert-statement | delete-statement | select-statement
|
例子: CREATE TRIGGER update_customer_address UPDATE OF address ON customers BEGIN UPDATE orders SET address = new.address WHERE customer_name = old.name; END; 說明: 創建了一個名為update_customer_address的觸發器,當用戶更新customers表中的address欄位時,將觸發並更新orders表中的address欄位為新的值。 比如執行如下一條語句: UPDATE customers SET address = '1 Main St.' WHERE name = 'Jack Jones'; 資料庫將自動執行如下語句: UPDATE orders SET address = '1 Main St.' WHERE customer_name = 'Jack Jones';
|
CREATE INDEX
|
為給定表或視圖創建索引。
語法:
sql-statement ::=
|
CREATE [UNIQUE] INDEX index-name ON [database-name .] table-name ( column-name [, column-name]* ) [ ON CONFLICT conflict-algorithm ]
|
column-name ::=
|
name [ COLLATE collation-name] [ ASC | DESC ]
|
例子: CREATE INDEX idx_email ON customers (email); 說明: 為customers表中的email創建一個名為idx_email的欄位。
|
結構刪除
|
DROP TABLE
|
刪除表定義及該表的所有索引。
語法:
sql-command ::=
|
DROP TABLE [database-name.] table-name
|
例子: DROP TABLE customers;
|
DROP VIEW
|
刪除一個視圖。
語法:
sql-command ::=
|
DROP VIEW view-name
|
例子: DROP VIEW master_view;
|
DROP TRIGGER
|
刪除一個觸發器。
語法:
sql-statement ::=
|
DROP TRIGGER [database-name .] trigger-name
|
例子: DROP TRIGGER update_customer_address;
|
DROP INDEX
|
刪除一個索引。
語法:
sql-command ::=
|
DROP INDEX [database-name .] index-name
|
例子: DROP INDEX idx_email;
|
資料操作
|
INSERT
|
將新行插入到表。
語法:
sql-statement ::=
|
INSERT [OR conflict-algorithm] INTO [database-name .] table-name [(column-list)] VALUES(value-list) | INSERT [OR conflict-algorithm] INTO [database-name .] table-name [(column-list)] select-statement
|
|
UPDATE
|
更新表中的現有資料。
語法:
sql-statement ::=
|
UPDATE [ OR conflict-algorithm ] [database-name .] table-name SET assignment [, assignment]* [WHERE expr]
|
assignment ::=
|
column-name = expr
|
|
DELETE
|
從表中刪除行。
語法:
sql-statement ::=
|
DELETE FROM [database-name .] table-name [WHERE expr]
|
|
SELECT
|
從表中檢索資料。
語法:
sql-statement ::=
|
SELECT [ALL | DISTINCT] result [FROM table-list] [WHERE expr] [GROUP BY expr-list] [HAVING expr] [compound-op select]* [ORDER BY sort-expr-list] [LIMIT integer [( OFFSET | , ) integer]]
|
result ::=
|
result-column [, result-column]*
|
result-column ::=
|
* | table-name . * | expr [ [AS] string ]
|
table-list ::=
|
table [join-op table join-args]*
|
table ::=
|
table-name [AS alias] | ( select ) [AS alias]
|
join-op ::=
|
, | [NATURAL] [LEFT | RIGHT | FULL] [OUTER | INNER | CROSS] JOIN
|
join-args ::=
|
[ON expr] [USING ( id-list )]
|
sort-expr-list ::=
|
expr [sort-order] [, expr [sort-order]]*
|
sort-order ::=
|
[ COLLATE collation-name ] [ ASC | DESC ]
|
compound_op ::=
|
UNION | UNION ALL | INTERSECT | EXCEPT
|
|
REPLACE
|
類似INSERT
語法:
sql-statement ::=
|
REPLACE INTO [database-name .] table-name [( column-list )] VALUES ( value-list ) | REPLACE INTO [database-name .] table-name [( column-list )] select-statement
|
|
交易處理
|
BEGIN TRANSACTION
|
標記一個事務的起始點。
語法:
sql-statement ::=
|
BEGIN [TRANSACTION [name]]
|
|
END TRANSACTION
|
標記一個事務的終止。
語法:
sql-statement ::=
|
END [TRANSACTION [name]]
|
|
COMMIT TRANSACTION
|
標誌一個事務的結束。
語法:
sql-statement ::=
|
COMMIT [TRANSACTION [name]]
|
|
ROLLBACK TRANSACTION
|
將交易復原到事務的起點。
語法:
sql-statement ::=
|
ROLLBACK [TRANSACTION [name]]
|
|
其他操作
|
COPY
|
主要用於導入大量的資料。
語法:
sql-statement ::=
|
COPY [ OR conflict-algorithm ] [database-name .] table-name FROM filename [ USING DELIMITERS delim ]
|
例子: COPY customers FROM customers.csv;
|
EXPLAIN
|
語法:
sql-statement ::=
|
EXPLAIN sql-statement
|
|
PRAGMA
|
語法:
sql-statement ::=
|
PRAGMA name [= value] | PRAGMA function(arg)
|
|
VACUUM
|
語法:
sql-statement ::=
|
VACUUM [index-or-table-name]
|
|
ATTACH DATABASE
|
附加一個資料庫到當前的資料庫連接。
語法:
sql-statement ::=
|
ATTACH [DATABASE] database-filename AS database-name
|
|
DETTACH DATABASE
|
從當前的資料庫分離一個使用ATTACH DATABASE附加的資料庫。
語法:
sql-command ::=
|
DETACH [DATABASE] database-name
|
|
留言列表