概述转自:http://www.sqlite.com.cn/POParticle/6/11.Html SQLite内建
语法表 结构定义 CREATE TABLE 创建新表。 语法: sql-command ::= CREATE [TEMP | TEMPORARY] TABLE table-name ( column-def [, column-def]* [, constraint]
转自:http://www.sqlite.com.cn/POParticle/6/11.Html@H_403_1@
sqlite内建语法表@H_403_1@
@H_403_1@
结构定义 |
CREATE table | 创建新表。@H_403_1@ 语法: @H_403_1@ 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 | 创建一个视图(虚拟表),该表以另一种方式表示一个或多个表中的数据。@H_403_1@ 语法: @H_403_1@ 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 | 创建触发器,触发器是一种特殊的存储过程,在用户试图对指定的表执行指定的数据修改语句时自动执行。@H_403_1@ 语法: @H_403_1@ 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';@H_403_1@ |
CREATE INDEX | 为给定表或视图创建索引。@H_403_1@ 语法: @H_403_1@ 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 INDEXIDx_email ON customers (email); 说明: 为customers表中的email创建一个名为IDx_email的字段。@H_403_1@ |
结构删除 |
DROP table | 删除表定义及该表的所有索引。@H_403_1@ 语法: @H_403_1@ sql-command::= | DROP table [database-name.] table-name | 例子: DROP table customers; |
DROP VIEW | 删除一个视图。@H_403_1@ 语法: @H_403_1@ sql-command::= | DROP VIEW vIEw-name | 例子: DROP VIEW master_vIEw;@H_403_1@ |
DROP TRIGGER | 删除一个触发器。@H_403_1@ 语法: @H_403_1@ sql-statement::= | DROP TRIGGER [database-name .] trigger-name | 例子: DROP TRIGGER update_customer_address;@H_403_1@ |
DROP INDEX | 删除一个索引。@H_403_1@ 语法: @H_403_1@ sql-command::= | DROP INDEX [database-name .] index-name | 例子: DROP INDEX IDx_email;@H_403_1@ |
数据 *** 作 |
INSERT | 将新行插入到表。@H_403_1@ 语法: @H_403_1@ 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 | 更新表中的现有数据。@H_403_1@ 语法: @H_403_1@ sql-statement::= | UPDATE [ OR conflict-algorithm ] [database-name .] table-name SET assignment [, assignment]* [WHERE expr] | assignment::= | column-name = expr | |
DELETE | 从表中删除行。@H_403_1@ 语法: @H_403_1@ sql-statement::= | DELETE FROM [database-name .] table-name [WHERE expr] | |
SELECT | 从表中检索数据。@H_403_1@ 语法: @H_403_1@ 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@H_403_1@ 语法: @H_403_1@ 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 | 标记一个事务的起始点。@H_403_1@ 语法: @H_403_1@ sql-statement::= | BEGIN [TRANSACTION [name]] | |
END TRANSACTION | 标记一个事务的终止。@H_403_1@ 语法: @H_403_1@ sql-statement::= | END [TRANSACTION [name]] | |
COMMIT TRANSACTION | 标志一个事务的结束。@H_403_1@ 语法: @H_403_1@ sql-statement::= | COMMIT [TRANSACTION [name]] | |
RolLBACK TRANSACTION | 将事务回滚到事务的起点。@H_403_1@ 语法: @H_403_1@ sql-statement::= | RolLBACK [TRANSACTION [name]] | |
其他 *** 作 |
copY | 主要用于导入大量的数据。@H_403_1@ 语法: @H_403_1@ sql-statement::= | copY [ OR conflict-algorithm ] [database-name .] table-name FROM filename [ USING DEliMITERS delim ] | 例子: copYcustomers FROM customers.csv; |
EXPLAIN | 语法: @H_403_1@ sql-statement::= | EXPLAIN sql-statement | |
PRAGMA | 语法: @H_403_1@ sql-statement::= | PRAGMA name [= value] | PRAGMA function(arg) | |
VACUUM | 语法: @H_403_1@ sql-statement::= | VACUUM [index-or-table-name] | |
ATTACH DATABASE | 附加一个数据库到当前的数据库连接。@H_403_1@ 语法: @H_403_1@ sql-statement::= | ATTACH [DATABASE] database-filename AS database-name | |
DETTACH DATABASE | 从当前的数据库分离一个使用ATTACH DATABASE附加的数据库。@H_403_1@ 语法: @H_403_1@ sql-command::= | DETACH [DATABASE] database-name | |
sqlite内建函数表@H_403_1@
@H_403_1@
算术函数 |
abs(X) | 返回给定数字表达式的绝对值。 |
max(X,Y[,...]) | 返回表达式的最大值。 |
min(X,...]) | 返回表达式的最小值。 |
random(*) | 返回随机数。 |
round(X[,Y]) | 返回数字表达式并四舍五入为指定的长度或精度。 |
字符处理函数 |
length(X) | 返回给定字符串表达式的字符个数。 |
lower(X) | 将大写字符数据转换为小写字符数据后返回字符表达式。 |
upper(X) | 返回将小写字符数据转换为大写的字符表达式。 |
substr(X,Y,Z) | 返回表达式的一部分。 |
randstr() | |
quote(A) | |
like(A,B) | 确定给定的字符串是否与指定的模式匹配。 |
glob(A,B) | |
条件判断函数 |
coalesce(X,...]) | |
ifnull(X,Y) | |
nullif(X,Y) | |
集合函数 |
avg(X) | 返回组中值的平均值。 |
count(X) | 返回组中项目的数量。 |
max(X) | 返回组中值的最大值。 |
min(X) | 返回组中值的最小值。 |
sum(X) | 返回表达式中所有值的和。 |
其他函数 |
typeof(X) | 返回数据的类型。 |
last_insert_rowID() | 返回最后插入的数据的ID。 |
sqlite_version(*) | 返回sqlite的版本。 |
change_count() | 返回受上一语句影响的行数。 |
last_statement_change_count() |
总结
以上是内存溢出为你收集整理的SQLite内建语法表 [转]全部内容,希望文章能够帮你解决SQLite内建语法表 [转]所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)