数据库的增删改查和使用流程

本文介绍了SQL基础操作,包括创建表、删除表、插入数据、查询数据及数据库操作,详细解释了每一步的语法和用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建表                      列名 类型,
1...create table Student (id integer , name text, sex text, age  integer)

2…create table  if not exists Student  (id integer , name text default '张三' , sex text not null, age  integer)

删除表       表名
drop table Student

插入
所有列插入       表名              值               
insert into Student values (1, ‘张三’, ’男’, 18)
部分列插入
insert into Student (name, sex) values ( 'lisi', 'nv')

主键 (唯一, 不能反复)
create table Student (id integer primary key,name text, age integer, sex text )

查询
全部数据
select * from Student
查询姓名这一列 / 两列
select name from Student
select name, sex from Student
条件查询
select * from Student where age > 10
select * from Student where age > 10 and sex = 'nv'
select * from Student where age between 15 and 20

升序/降序
select * from Student order by id sac / desc
仅仅要前 5 条
select * from Student order by id asc limit 5

改动
1列
update Student set age = 18 where sex = ‘男’
多列(勿忘逗号分隔)
update Student set age = 16 , sex = '男'  where age < 19

删除
数据
delete from Student where sex = ‘男'
所有
delete from Student

使用sqlite
1.打开数据库
2.运行sql,做出数据处理
3.关闭数据库

操作
1.打开数据库
2.创建一个数据操作指针 stmt
3.运行sql 语句
4.处理结果

转载于:https://www.cnblogs.com/yxwkf/p/4025066.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值