如何操作sqlite数据库

前端之家收集整理的这篇文章主要介绍了如何操作sqlite数据库前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

安装Django的时候会自动sqlite数据库安装上,下面介绍如何操作sqlite数据库

1 进入你创建的目录,在终端运行 sqlite3 DBname.db

2 进入后输入.help可以查看帮助文档

3 .tables 可以要看sqlite3中有哪些表

select * from tablename; 查看数据

具体操作命令:

  1. [root@10 src]# cd rietveld
  2. [root@10 rietveld]# ls
  3. apache.conf.example dev.db Makefile README settings.pyc TODO upload.py.orig
  4. codereview __init__.py manage.py rietveld_helper static UPDATES
  5. codereview.wsgi.example __init__.pyc patches settings.py templates upload.py
  6. [root@10 rietveld]# sqlite3 dev.db
  7. sqlite version 3.6.20
  8. Enter ".help" for instructions
  9. Enter sql statements terminated with a ";"
  10. sqlite> .tables
  11. auth_group codereview_issue
  12. auth_group_permissions codereview_message
  13. auth_message codereview_patch
  14. auth_permission codereview_patchset
  15. auth_user codereview_repository
  16. auth_user_groups django_admin_log
  17. auth_user_user_permissions django_content_type
  18. codereview_account django_session
  19. codereview_branch django_site
  20. codereview_bucket gae2django_reftestmodel
  21. codereview_comment gae2django_regressiontestmodel
  22. codereview_content
  23. sqlite> select * from auth_user;
  24. 1|root|||root@root.com|sha1$dac64$c7c81d89f0ff8f8cedefc95ad59a3849cf705f12|1|1|1|2012-09-20 23:43:39.161264|2012-09-20 03:54:33.257231
  25. 2|tao.lu|||tao.lu@autonvai.com|sha1$fff77$7b4c631f4a6bf2b216dab658d853b3ef98d81906|0|1|0|2012-09-20 22:21:14|2012-09-20 22:20:56
  26. sqlite> .help
  27. .backup ?DB? FILE Backup DB (default "main") to FILE
  28. .bail ON|OFF Stop after hitting an error. Default OFF
  29. .databases List names and files of attached databases
  30. .dump ?TABLE? ... Dump the database in an sql text format
  31. If TABLE specified,only dump tables matching
  32. LIKE pattern TABLE.
  33. .echo ON|OFF Turn command echo on or off
  34. .exit Exit this program
  35. .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
  36. .genfkey ?OPTIONS? Options are:
  37. --no-drop: Do not drop old fkey triggers.
  38. --ignore-errors: Ignore tables with fkey errors
  39. --exec: Execute generated sql immediately
  40. See file tool/genfkey.README in the source
  41. distribution for further information.
  42. .header(s) ON|OFF Turn display of headers on or off
  43. .help Show this message
  44. .import FILE TABLE Import data from FILE into TABLE
  45. .indices ?TABLE? Show names of all indices
  46. If TABLE specified,only show indices for tables
  47. matching LIKE pattern TABLE.
  48. .load FILE ?ENTRY? Load an extension library
  49. .mode MODE ?TABLE? Set output mode where MODE is one of:
  50. csv Comma-separated values
  51. column Left-aligned columns. (See .width)
  52. html HTML <table> code
  53. insert sql insert statements for TABLE
  54. line One value per line
  55. list Values delimited by .separator string
  56. tabs Tab-separated values
  57. tcl TCL list elements
  58. .nullvalue STRING Print STRING in place of NULL values
  59. .output FILENAME Send output to FILENAME
  60. .output stdout Send output to the screen
  61. .prompt MAIN CONTINUE Replace the standard prompts
  62. .quit Exit this program
  63. .read FILENAME Execute sql in FILENAME
  64. .restore ?DB? FILE Restore content of DB (default "main") from FILE
  65. .schema ?TABLE? Show the CREATE statements
  66. If TABLE specified,only show tables matching
  67. LIKE pattern TABLE.
  68. .separator STRING Change separator used by output mode and .import
  69. .show Show the current values for varIoUs settings
  70. .tables ?TABLE? List names of tables
  71. If TABLE specified,only list tables matching
  72. LIKE pattern TABLE.
  73. .timeout MS Try opening locked tables for MS milliseconds
  74. .width NUM NUM ... Set column widths for "column" mode
  75. .timer ON|OFF Turn the cpu timer measurement on or off
  76. sqlite>

猜你在找的Sqlite相关文章