sqlite数据库基本语句集合



//数据库一般以二维表的形式存储
//一行算一条数据,一条中有多列,叫字段


//Tables,创建的表
//Views,组织数据(组织多个数据库的数据,结合起来返回)
//indexs,索引,优化,用于大数据库中(索引不能随便加,加错了影响性能)
//triggers,触发器,每一次执行都会触发,如某人删了数据会有记录


//不区分字母大小写,最好小写




//数据类型
//text,大文本,用于存储大量文本
//varchar,字符串,2000单词或字符串以内。
//blob,二进制形式,存储大图片等大数据
//timestamp,时间戳
//integer,整形
//float
//double
//boonlean




//是什么类型的数据,就要录入什么类型的数据,否则在大数据库中后果严重,数据丢失




几个限定词
//prikey,主键,唯一标识,不能重复(大数据库中有联合主键,多个主键联合起来唯一)(默认不会重复,不需要加uinque)
//        主键一般要选中notnull(主键默认不重复,自增)
//unique,唯一,限定不能重复。
//
//notnull,不为空,(主键可以为空,但是不合理,主键为空,没法查到)
//
//autoinc,自增,不输入数据时,自动增加(有的数据库只有主键能自增,一般自增的都是主键)(主键默认从1开始自增)
//
//deaultvalue,不输入时,就是这个默认值








//query :查询数据






//SQ语句
//一 表操作
// 1 创建表
create table if not exists t_class(
                     class_id integer primary key autoincrement,//(主键的notnull可以不写)
                     class_name varchar,
                     person_count integer default 0)


// 2 删除表
drop table if exists t_person




//二 数据操作
// 2 插入数据==== (增)
insert into t_class(class_name,person_count) values('    class1  ',10)//字符类型的放在单引号中


// 3 删除数据==== (删)
delete from t_class//删除所有行(再增加的时候是从删除前的最大的id后边开始增的)
delete from  t_class2 where class_id=5//删除一条


// 4 修改数据==== (改)
update t_class set class_name='oldclassname' ,person_count=20//所有行全改
update t_class set class_name='oldclassname' ,person_count=20   where class_id=7// 改一条


// 5 查询数据==== (查)
select * from t_class// 查询所有,(全查加星号,不建议,大数据库中不推荐,慢,建议写上全部的字段)
select * from t_class where class_name = 'class'//查一条


//查一条中的某几列数据
select class_id,person_count from t_class where class_name='oldclassname'


//几个关键字 and, or, betwee, in, not in, like
select class_id,person_count from t_class where class_id =7 and person_count=20// (一般用在不同字段,同时成立)
select class_id,person_count from t_class where class_id =7 or person_count=20
select class_id,person_count from t_class where class_id between 7 and 20
select class_id,person_count from t_class where class_name  in ('  oldclassname','newclassnamenew'// in效率高
select * from t_class where class_name like '%new'//以new结尾// %占位符
select * from t_class where class_name like 'new%'//以new开头
select * from t_class where class_name like '%class%'//含有new


















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值