热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

SQLite学习笔记二(数据库管理,命令行操作)

nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd

1.在下载一个windows下shell程序,下载地址:http://www.sqlite.com/sqlite-shell-win32-x86-3070900.zip

2.下载完成后解压得到sqlite3.exe,放置在任意目录;

3.使用方式:

a.打开数据库

[html]
  1. Microsoft Windows XP [版本 5.1.2600]  
  2. (C) 版权所有 1985-2001 Microsoft Corp.  
  3.   
  4. C:\Documents and Settings\socrates.WINXP-DUANYX>cd /d E:\tmp\sqlite_stduy\db  
  5.   
  6. E:\tmp\sqlite_stduy\db>sqlite3.exe sqlite_study.db  --参数为要打开的数据库名(存在目录时请带//访问)  
  7. SQLite version 3.7.9 2011-11-01 00:52:41  
  8. Enter ".help" for instructions  
  9. Enter SQL statements terminated with a ";"  
  10. sqlite>  

b. 查看命令行帮助:

[html]
  1. sqlite> .help  
  2. .backup ?DB? FILE      Backup DB (default "main") to FILE  
  3. .bail ON|OFF           Stop after hitting an error.  Default OFF  
  4. .databases             List names and files of attached databases  
  5. .dump ?TABLE? ...      Dump the database in an SQL text format  
  6.                          If TABLE specified, only dump tables matching  
  7.                          LIKE pattern TABLE.  
  8. .echo ON|OFF           Turn command echo on or off  
  9. .exit                  Exit this program  
  10. .explain ?ON|OFF?      Turn output mode suitable for EXPLAIN on or off.  
  11.                          With no args, it turns EXPLAIN on.  
  12. .header(s) ON|OFF      Turn display of headers on or off  
  13. .help                  Show this message  
  14. .import FILE TABLE     Import data from FILE into TABLE  
  15. .indices ?TABLE?       Show names of all indices  
  16.                          If TABLE specified, only show indices for tables  
  17.                          matching LIKE pattern TABLE.  
  18. .load FILE ?ENTRY?     Load an extension library  
  19. .log FILE|off          Turn logging on or off.  FILE can be stderr/stdout  
  20. .mode MODE ?TABLE?     Set output mode where MODE is one of:  
  21.                          csv      Comma-separated values  
  22.                          column   Left-aligned columns.  (See .width)  
  23.                          html     HTML <table> code  
  24.                          insert   SQL insert statements for TABLE  
  25.                          line     One value per line  
  26.                          list     Values delimited by .separator string  
  27.                          tabs     Tab-separated values  
  28.                          tcl      TCL list elements  
  29. .nullvalue STRING      Print STRING in place of NULL values  
  30. .output FILENAME       Send output to FILENAME  
  31. .output stdout         Send output to the screen  
  32. .prompt MAIN CONTINUE  Replace the standard prompts  
  33. .quit                  Exit this program  
  34. .read FILENAME         Execute SQL in FILENAME  
  35. .restore ?DB? FILE     Restore content of DB (default "main") from FILE  
  36. .schema ?TABLE?        Show the CREATE statements  
  37.                          If TABLE specified, only show tables matching  
  38.                          LIKE pattern TABLE.  
  39. .separator STRING      Change separator used by output mode and .import  
  40. .show                  Show the current values for various settings  
  41. .stats ON|OFF          Turn stats on or off  
  42. .tables ?TABLE?        List names of tables  
  43.                          If TABLE specified, only list tables matching  
  44.                          LIKE pattern TABLE.  
  45. .timeout MS            Try opening locked tables for MS milliseconds  
  46. .width NUM1 NUM2 ...   Set column widths for "column" mode  
  47. .timer ON|OFF          Turn the CPU timer measurement on or off  
  48. sqlite>  

c.参考以上命令行帮助即可操作数据库,举例如下:

[html]
  1. sqlite> .databases   --查看数据库的存放路径  
  2. seq  name             file  
  3.   
  4. ---  ---------------  ----------------------------------------------------------  
  5.   
  6. 0    main             E:\tmp\sqlite_stduy\db\sqlite_study.db  
  7.   
  8. sqlite> .tables  --查看当前数据库中的表  
  9. tbl_product   tbl_product1  tbl_product2  tbl_product3  
  10. sqlite> select * from tbl_product3;  --执行SQL语句  
  11. 1|iphone4s  
  12. sqlite> insert into tbl_product3 values('nokia'); --SQL语句出错提示  
  13. Error: table tbl_product3 has 2 columns but 1 values were supplied  
  14. sqlite> insert into tbl_product3 values(2, 'nokia');  
  15. sqlite> select * from tbl_product3;  
  16. 1|iphone4s  
  17. 2|nokia  
  18. sqlite>.mode tabs  --设置显示模式(以Tab键做为列间间隔符)  
  19. sqlite> select * from tbl_product3;  
  20. 1       iphone4s  
  21. 2       nokia  
  22. sqlite> .show  --查看当前shell的环境变量  
  23.      echo: off  
  24.   explain: off  
  25.   headers: off  
  26.      mode: list  
  27. nullvalue: ""  
  28.    output: stdout  
  29. separator: "\t"  
  30.     stats: off  
  31.     width:  
  32. sqlite>.quit  --退出数据库  
  33.   
  34. E:\tmp\sqlite_stduy\db>  

其他相关操作请参考.help进行。


推荐阅读
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文是一位90后程序员分享的职业发展经验,从年薪3w到30w的薪资增长过程。文章回顾了自己的青春时光,包括与朋友一起玩DOTA的回忆,并附上了一段纪念DOTA青春的视频链接。作者还提到了一些与程序员相关的名词和团队,如Pis、蛛丝马迹、B神、LGD、EHOME等。通过分享自己的经验,作者希望能够给其他程序员提供一些职业发展的思路和启示。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文详细介绍了在Centos7上部署安装zabbix5.0的步骤和注意事项,包括准备工作、获取所需的yum源、关闭防火墙和SELINUX等。提供了一步一步的操作指南,帮助读者顺利完成安装过程。 ... [详细]
  • 如何去除Win7快捷方式的箭头
    本文介绍了如何去除Win7快捷方式的箭头的方法,通过生成一个透明的ico图标并将其命名为Empty.ico,将图标复制到windows目录下,并导入注册表,即可去除箭头。这样做可以改善默认快捷方式的外观,提升桌面整洁度。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 本文由编程笔记小编整理,介绍了PHP中的MySQL函数库及其常用函数,包括mysql_connect、mysql_error、mysql_select_db、mysql_query、mysql_affected_row、mysql_close等。希望对读者有一定的参考价值。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文讨论了在数据库打开和关闭状态下,重新命名或移动数据文件和日志文件的情况。针对性能和维护原因,需要将数据库文件移动到不同的磁盘上或重新分配到新的磁盘上的情况,以及在操作系统级别移动或重命名数据文件但未在数据库层进行重命名导致报错的情况。通过三个方面进行讨论。 ... [详细]
  • 本文介绍了如何清除Eclipse中SVN用户的设置。首先需要查看使用的SVN接口,然后根据接口类型找到相应的目录并删除相关文件。最后使用SVN更新或提交来应用更改。 ... [详细]
author-avatar
泱泱大国吴
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有