SQLite3语法(转)
转自:http://hi.baidu.com/ylxiit/blog/item/53011c858b124220c75cc325.html SQL的指令格式 建立资料表 create table film(title,length,year,starring);
这个create table指令的语法为: create table table_name(field1,field2,field3,...);
建立索引 create index film_title_index on film(title);
create index index_name on table_name(field_to_be_indexed);
加入一笔资料 insert into table_name values(data1,data2,data3,...);
insert into film values ('Silence of the Lambs,The',118,1991,'Jodie Foster');
查询资料 select columns from table_name where expression;
select * from film;
select * from film limit 10;
select * from film order by year limit 10;
select * from film order by year desc limit 10;
select title,year from film order by year desc limit 10;
select * from film where starring='Jodie Foster';
select * from film where starring like 'Jodie%';
select title,year from film where starring like 'Jodie%' and year >= 1985 order by year desc limit 10;
select count(*) from film;
select count(*) from film where year >= 1985;
如何更改或删除资料 例如有一笔资料的名字打错了: update film set starring='Jodie Foster' where starring='Jodee Foster';
delete from film where year < 1970;
将结果写到文件 默认情况下,sqlite3会将结果发送到标准输出,你可以使用 ".output" 来改变,只是将输出到的文件名作为参数传递给 .output,所有后面的查询结果都会写到文件里。开头使用 ".output stdout" 会再次写到标准输出,例如: sqlite> .mode list 其他sqlite的特别用法 sqlite3 film.db "select * from film;"
sqlite3 -html film.db "select * from film;"
sqlite3 film.db ".dump" > output.sql
sqlite3 film.db < output.sql
begin; 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ieclipse/archive/2010/05/07/5567113.aspx (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |