UISenior 进阶 数据库

1.创建表

create table 表名 (字段1 约束1 约束2,字段2 约束1 约束2);

//上面的sql语句的含义是:第一次创建表,第二次如果再执行这个sql语句就会报错

create table if not exists 表名(字段1 约束1 约束2,字段2 约束1 约束2);

//实例

需求:创建一个student表,表中的字段有学号,姓名,年龄,学号的约束条件;作为主键,自增,不能为空,姓名默认为'无名氏';年龄大于16岁

create table student (s_id integer primary key autoincrement not null,s_name text default'无名氏',s_age interger check (s_age > 16));

2.插入数据

语法:

insert into 表名 (字段1,字段2,字段3)values (值1,值2,值3);

//事例:插入学生姓名,年龄

insert into student (s_name,s_age)values('小强',60);

3.更新数据

语法:

update 表名 set 字段名1 = 修改值1,字段名2 = 修改值2 where 条件;

事例:

update student set s_age = 25 where s_age = 18;

4.删除数据

语法:

delete from 表名 where 条件

需求:删除年龄为10岁的学生

delete from student where s_age = 10

5.查询数据

语法:

select 要查询的字段 from 表名 where 条件

//查询姓名为芳芳女神经的所有信息

select *from student where s_name = '芳芳女神经';

原文地址:https://www.cnblogs.com/mingjieLove00/p/5458186.html