sqlite不是严格的类型匹配,数据类型和定义的时候不一样也是可以的
一、sqlite命令行操作
有两种命令
一种是以 . 开头的,是系统命令
.help 帮助
.quit 退出
.exit 退出
.schema 查看表的结构
.table 查看当前数据库下有的表格
一种是不以 . 开头,以;结尾的,是sqlite命令
创建一张数据表
create table stu(id Integer,name char , sorce Interge);
create table+表格名字 (字段名字 字段类型,);
插入完整的数据(所有字段都有插入)
insert into stu values(1001,"zhangsan,80");
插入不完整的数据(部分字段插入)
insert into stu (name,score)values("zhangsan",90);
查询记录
select * from stu; //查询所有字段
select name from stu; // 查看部分字段
select name,score from stu;// 查询部分字段
select * from stu where score=80; //查找score等于80分的
select * from stu where score=80 and name=‘zhangsan’;//and可以换成or
删除
delete from stu where name='wangwu'; // 不加where就删除stu整个表格
更新
update stu set name='wangwu' where id=1001; // 将id=1001的学生名字改成wangwu
update stu set name='wangwu' ,score=80 where id=1001;
二、删除或者插入指定了列
添加一列
alter table stu add column address char; // 添加一列名为address,类型是char的列
然后通过updata更新address的值就好了
删除一列
sqlite不知处直接删除一列,需要分为以下几个步骤来实现
1--创建一张新表 创建新的元素,并将复制旧表的数据
create table stu1 as select id,name ,score from stu;
2--删除原有的表
drop table stu;
3--将新的表名字改成原有的旧表的名字
alter table stu1 rename to stu;
三、将一个字段设置为自增
//先将id设置为主键,并且自增
create table [stu]([id] INTEGER PRIMARY KEY AUTOINCREMENT,[name] char);
然后用insert插入数据就可以了,id会自动编号自增