我们知道,在SQL Server数据库中查询数据时需要用到SELECT……FROM语句结合WHERE条件来实现的,其实SQLite数据库查询数据的方式也是这样的,本文通过一个实例来介绍这一过程,希望能给大家带来收获。
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比平乡网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式平乡网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖平乡地区。费用合理售后完善,十载实体公司更值得信赖。
首先将下面的SQL 语句保存到 data.sql 文件中(为了以后的练习使用):
- BEGIN TRANSACTION;
- CREATE TABLE Cars(Id integer PRIMARY KEY, Name text, Cost integer);
- INSERT INTO Cars VALUES(1,'Audi',52642);
- INSERT INTO Cars VALUES(2,'Mercedes',57127);
- INSERT INTO Cars VALUES(3,'Skoda',9000);
- INSERT INTO Cars VALUES(4,'Volvo',29000);
- INSERT INTO Cars VALUES(5,'Bentley',350000);
- INSERT INTO Cars VALUES(6,'Citroen',21000);
- INSERT INTO Cars VALUES(7,'Hummer',41400);
- INSERT INTO Cars VALUES(8,'Volkswagen',21600);
- COMMIT;
- BEGIN TRANSACTION;
- CREATE TABLE Orders(Id integer PRIMARY KEY, OrderPrice integer CHECK(OrderPrice>0),
- Customer text);
- INSERT INTO Orders(OrderPrice, Customer) VALUES(1200, "Williamson");
- INSERT INTO Orders(OrderPrice, Customer) VALUES(200, "Robertson");
- INSERT INTO Orders(OrderPrice, Customer) VALUES(40, "Robertson");
- INSERT INTO Orders(OrderPrice, Customer) VALUES(1640, "Smith");
- INSERT INTO Orders(OrderPrice, Customer) VALUES(100, "Robertson");
- INSERT INTO Orders(OrderPrice, Customer) VALUES(50, "Williamson");
- INSERT INTO Orders(OrderPrice, Customer) VALUES(150, "Smith");
- INSERT INTO Orders(OrderPrice, Customer) VALUES(250, "Smith");
- INSERT INTO Orders(OrderPrice, Customer) VALUES(840, "Brown");
- INSERT INTO Orders(OrderPrice, Customer) VALUES(440, "Black");
- INSERT INTO Orders(OrderPrice, Customer) VALUES(20, "Brown");
- COMMIT;
然后在在终端执行命令 .read data.sql,将数据导入到数据库中:
- sqlite>
- sqlite> .tables
- Friends
- sqlite> .read data.sql
- sqlite> .tables
- Cars Orders Teachers
- sqlite>
可以看到,Cars 表和 Orders 表已经导入到数据库中,现在可以查询了:
- sqlite>
- sqlite> SELECT * FROM Cars;
- Id Name Cost
- ---- --------------- ---------------
- 1 Audi 52642
- 2 Mercedes 57127
- 3 Skoda 9000
- 4 Volvo 29000
- 5 Bentley 350000
- 6 Citroen 21000
- 7 Hummer 41400
- 8 Volkswagen 21600
- sqlite> SELECT * FROM Orders;
- Id OrderPrice Customer
- ---- --------------- ---------------
- 1 1200 Williamson
- 2 200 Robertson
- 3 40 Robertson
- 4 1640 Smith
- 5 100 Robertson
- 6 50 Williamson
- 7 150 Smith
- 8 250 Smith
- 9 840 Brown
- 10 440 Black
- 11 20 Brown
- sqlite>
关于SQLite数据库查找数据的知识就介绍到这里,我们还会在以后的文章里继续介绍,谢谢各位一直以来的支持!
【编辑推荐】
当前名称:一个SQLite数据库查询数据的代码实例
新闻来源:http://www.stwzsj.com/qtweb/news47/3647.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联