Sqlite简单例子
发布时间:2020-12-12 19:26:19 所属栏目:百科 来源:网络整理
导读:-- 1、创建数据库 -- 2、创建表 create table employee( _id integer primary key AUTOINCREMENT,name text,age integer,money integer ); -- 删除表 DROP TABLE 表名称 drop table employee; -- 3、插入数据 -- INSERT INTO 表名称 VALUES (值1,值2,....) i
-- 1、创建数据库 -- 2、创建表 create table employee( _id integer primary key AUTOINCREMENT,name text,age integer,money integer ); -- 删除表 DROP TABLE 表名称 drop table employee; -- 3、插入数据 -- INSERT INTO 表名称 VALUES (值1,值2,....) insert into employee values (1,'赵日天',28,10000); insert into employee values (2,'叶良辰',18,3000); insert into employee values (3,'龙傲天',15000); insert into employee values (4,'福尔康',48,11000); insert into employee (name,age,money) values ('赵日天',10000); insert into employee (name,money) values ('叶良辰',3000); insert into employee (name,money) values ('龙傲天',15000); insert into employee (name,money) values ('福尔康',11000); -- INSERT INTO table_name (列1,列2,...) VALUES (值1,....) insert into employee (name,money) values ('刘斩仙',38,8000) -- 4、删除数据 -- DELETE FROM 表名称 WHERE 列名称 = 值 -- 删除一行数据 where表示条件 delete from employee where name='刘斩仙'; --删除所有数据 DELETE FROM employee -- 5、修改数据 --UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值 -- 修改一行数据 把龙傲天改成38岁 update employee set age=38 where _id=3 --把龙傲天年龄加10岁 update employee set age=age+10 where _id=3 -- 修改多行数据 把龙傲天年龄加10岁,工资涨10000 update employee set age=age+10,money=money+10000 where _id=3 -- 修改所有数据 update employee set money=10000; -- 把赵日天和龙傲天的工资都改成20000 update employee set money=20000 where _id=1 or _id=3; -- 6、查询数据 -- SELECT 列名称 FROM 表名称 -- 只要name,money select name,money from employee; -- SELECT * FROM 表名称 *代表所有列 select * from employee; -- 只查询一行数据 select * from employee where _id=4; -- 7、修改表的结构 -- 向表中添加一列 ALTER TABLE table_name ADD column_name datatype alter table employee add card text; -- 8、分页 select image,title,content from employee limit 0,5; (0这个位置的意思是从哪个位置开始也称偏移量,5这个位置是查询多少条数量) -- 9、查询总共有多少行,返回的是所有列的行数最多的值(无论有几列或者有可能某一列是没有数据或者为空) select count(*) from employee; -- 10、查询某一列(元素)有多少行,在一个表格中假如有15行,但是这个列中有某一行是null,那么得到的值就是14 select count(image) from emplyee; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- React+NodeJS+Express 环境搭建与部署
- 数组 – AS3中的多维数组排序
- c# – 改进的噪声版本保持返回0
- objective-c – 使用SKAction colorizeWithColor使SKSprite
- Swift中闭包实现OC的block传值
- ruby-on-rails – ActionCable – 无法升级到WebSocket
- objective-c – iOS中的PngCrush是什么?
- SQLite入门与分析(一)---简介
- postgresql – Apache Spark:JDBC连接不起作用
- ruby-on-rails – Carrierwave / Fog – 参数错误,提供程序