首页 数据库 mysql教程 SQLite数据库操作实践

SQLite数据库操作实践

Jun 07, 2016 pm 04:19 PM
sqlite 实践 操作 数据库

SQLite数据库操作实践 SQLite存储类型 null - 空值 integer - 有符号整数,自增列定义 id integer primary key autoincrement real - 浮点数,存储为8-byte IEEE浮点数 text - 文本字符串 使用数据库编码(UTF-8, UTF-16BE 或 UTF-16LE)进行存储 blob - 二进

 SQLite数据库操作实践
SQLite存储类型
null - 空值 
integer - 有符号整数,自增列定义 id integer primary key autoincrement
real - 浮点数,存储为8-byte IEEE浮点数 
text - 文本字符串 使用数据库编码(UTF-8, UTF-16BE 或 UTF-16LE)进行存储
blob - 二进制数据,如图片、声音等等 
也可以接受其它数据类型例如datetime,varchar,nvarchar,decimal,float,double,bigint 等等

Last login: Tue Jan 7 19:05:33 2014 from 192.168.10.1
[myth@host10 ~]$ su
Password: 
[root@host10 myth]# pwd //显示当前工作目录

/home/myth

进入SQLite命令行创建数据库并且打开数据库

[root@host10 myth]# sqlite3 bookstore.db 
SQLite version 3.6.20
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .databases
seq name file 
--- --------------- ----------------------------------------------------------
0 main /home/myth/bookstore.db 
sqlite> 
sqlite> .quit //退出SQLite命令行环境

[root@host10 myth]#

打开数据库

[root@host10 myth]# sqlite3 bookstore.db //如果数据库已经存在了,则打开数据库
SQLite version 3.6.20
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .help //查看帮助信息
.backup ?DB? FILE Backup DB (default "main") to FILE
.bail ON|OFF Stop after hitting an error. Default OFF
.databases List names and files of attached databases
.dump ?TABLE? ... Dump the database in an SQL text format
If TABLE specified, only dump tables matching
LIKE pattern TABLE.
.echo ON|OFF Turn command echo on or off
.exit Exit this program
.explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
.genfkey ?OPTIONS? Options are:
--no-drop: Do not drop old fkey triggers.
--ignore-errors: Ignore tables with fkey errors
--exec: Execute generated SQL immediately
See file tool/genfkey.README in the source 
distribution for further information.
.header(s) ON|OFF Turn display of headers on or off
.help Show this message
.import FILE TABLE Import data from FILE into TABLE
.indices ?TABLE? Show names of all indices
If TABLE specified, only show indices for tables
matching LIKE pattern TABLE.
.load FILE ?ENTRY? Load an extension library
.mode MODE ?TABLE? Set output mode where MODE is one of:
csv Comma-separated values
column Left-aligned columns. (See .width)
html HTML

code
insert SQL insert statements for TABLE
line One value per line
list Values delimited by .separator string
tabs Tab-separated values
tcl TCL list elements
.nullvalue STRING Print STRING in place of NULL values
.output FILENAME Send output to FILENAME
.output stdout Send output to the screen
.prompt MAIN CONTINUE Replace the standard prompts
.quit Exit this program
.read FILENAME Execute SQL in FILENAME
.restore ?DB? FILE Restore content of DB (default "main") from FILE
.schema ?TABLE? Show the CREATE statements
If TABLE specified, only show tables matching
LIKE pattern TABLE.
.separator STRING Change separator used by output mode and .import
.show Show the current values for various settings
.tables ?TABLE? List names of tables
If TABLE specified, only list tables matching
LIKE pattern TABLE.
.timeout MS Try opening locked tables for MS milliseconds
.width NUM NUM ... Set column widths for "column" mode
.timer ON|OFF Turn the CPU timer measurement on or off

sqlite>

创建表

sqlite> create table books(id integer primary key, title nvarchar(50),pubdate datetime); 
sqlite> create table publishers(id integer primary key, name varchar(20)); 
sqlite> .tables //查看数据库中存在的表
books publishers
sqlite> .schema books //显示表结构
CREATE TABLE books(id integer primary key, title nvarchar(50),pubdate datetime);
sqlite> 
sqlite> alter table books add column publisher text not null default '' collate nocase; //增加表字段
sqlite> .schema books //显示表结构
CREATE TABLE books(id integer primary key, title nvarchar(50),pubdate datetime, publisher text not null default '' collate nocase);
sqlite> 
sqlite> alter table publishers rename to authors; //修改表名
sqlite> .tables //查看数据库中存在的表
authors books 

sqlite>

修改字段名称

//修改字段名称和数据类型(删除字段也类似),更简单的做法:如果没有重要数据,可以直接删除表重新创建

sqlite> alter table authors rename to authorsOld;
sqlite> create table authors (id integer primary key, author nvarchar(20));
sqlite> insert into authors select id, name from authorsOld;
sqlite> drop table authorsOld;
sqlite> .schema authors
CREATE TABLE authors (id integer primary key, author nvarchar(20));

//还可以把数据导出成insert语句,然后删除表,重新创建表,执行所有insert语句添加数据

显示数据库所有表名称

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

Go语言如何实现数据库的增删改查操作? Go语言如何实现数据库的增删改查操作? Mar 27, 2024 pm 09:39 PM

Go语言是一种高效、简洁且易于学习的编程语言,因其在并发编程和网络编程方面的优势而备受开发者青睐。在实际开发中,数据库操作是不可或缺的一部分,本文将介绍如何使用Go语言实现数据库的增删改查操作。在Go语言中,我们通常使用第三方库来操作数据库,比如常用的sql包、gorm等。这里以sql包为例介绍如何实现数据库的增删改查操作。假设我们使用的是MySQL数据库。

PHP编码实践:拒绝使用goto语句的替代方案 PHP编码实践:拒绝使用goto语句的替代方案 Mar 28, 2024 pm 09:24 PM

PHP编码实践:拒绝使用goto语句的替代方案近年来,随着编程语言的不断更新和迭代,程序员们开始更加注重编码规范和最佳实践。在PHP编程中,goto语句作为一种控制流语句存在已久,但在实际应用中往往会导致代码的可读性和可维护性下降。本文将分享一些替代方案,帮助开发人员拒绝使用goto语句,提高代码质量。一、为什么拒绝使用goto语句?首先,让我们来思考一下为

在PHP中使用MySQLi建立数据库连接的详尽教程 在PHP中使用MySQLi建立数据库连接的详尽教程 Jun 04, 2024 pm 01:42 PM

如何在PHP中使用MySQLi建立数据库连接:包含MySQLi扩展(require_once)创建连接函数(functionconnect_to_db)调用连接函数($conn=connect_to_db())执行查询($result=$conn->query())关闭连接($conn->close())

Hibernate 如何实现多态映射? Hibernate 如何实现多态映射? Apr 17, 2024 pm 12:09 PM

Hibernate多态映射可映射继承类到数据库,提供以下映射类型:joined-subclass:为子类创建单独表,包含父类所有列。table-per-class:为子类创建单独表,仅包含子类特有列。union-subclass:类似joined-subclass,但父类表联合所有子类列。

iOS 18 新增'已恢复”相册功能 可找回丢失或损坏的照片 iOS 18 新增'已恢复”相册功能 可找回丢失或损坏的照片 Jul 18, 2024 am 05:48 AM

苹果公司最新发布的iOS18、iPadOS18以及macOSSequoia系统为Photos应用增添了一项重要功能,旨在帮助用户轻松恢复因各种原因丢失或损坏的照片和视频。这项新功能在Photos应用的"工具"部分引入了一个名为"已恢复"的相册,当用户设备中存在未纳入其照片库的图片或视频时,该相册将自动显示。"已恢复"相册的出现为因数据库损坏、相机应用未正确保存至照片库或第三方应用管理照片库时照片和视频丢失提供了解决方案。用户只需简单几步

饿了么绑定微信怎么操作 饿了么绑定微信怎么操作 Apr 01, 2024 pm 03:46 PM

饿了么这款软件里面汇集了各种不同的美食,大家可以在线挑选下单,商家接单后就会立即进行制作,用户们可以通过软件来绑定微信,想要了解具体的操作方法的话,记得来PHP中文网看看哦。饿了么绑定微信方法说明1、首先打开饿了么软件,进入到首页中后我们点击右下角的【我的】;2、然后在我的页面中我们需要点击左上角的【账号】;3、接着来到个人资料的页面中我们可以绑定手机、微信、支付宝、淘宝,在这里我们点击【微信】;4、最后点击过后在微信授权的页面中选好需要绑定的微信号之后点击【允许】即可;

深入解析HTML如何读取数据库 深入解析HTML如何读取数据库 Apr 09, 2024 pm 12:36 PM

HTML无法直接读取数据库,但可以通过JavaScript和AJAX实现。其步骤包括建立数据库连接、发送查询、处理响应和更新页面。本文提供了利用JavaScript、AJAX和PHP来从MySQL数据库读取数据的实战示例,展示了如何在HTML页面中动态显示查询结果。该示例使用XMLHttpRequest建立数据库连接,发送查询并处理响应,从而将数据填充到页面元素中,实现了HTML读取数据库的功能。

Go 语言实战指南:删除字符串操作详解 Go 语言实战指南:删除字符串操作详解 Mar 27, 2024 am 10:54 AM

Go语言作为一种新兴的程序设计语言,广泛应用于云计算、网络编程等领域。在Go语言的字符串操作中,删除字符串是一个常见的需求。本文将深入探讨如何在Go语言中进行字符串的删除操作,逐步解析相关方法和实现原理,并提供详细的代码示例。在Go语言中,我们可以使用strings包来提供一些常用的字符串处理函数。其中,删除字符串的操作可以通过strin

See all articles