数据库:存放数据的仓库
1、关系型数据库:用二维的表格来存放数据。有行、列之分。一个关系就是一张表格,一个数据库有若干个表格。
(1)MySQL、Oracle —— 甲骨文公司
(2)DB2、ACCESS
2、非关系型数据库:NoSQL数据库。以文档的方式管理数据
MongoDB、sitesql
3、MySQL数据库:
(1)创建数据库:
(2)创建表
varchar:字符串
主键:唯一标识表格中一行记录的列称为主键列(值不能重复)
使用Navicat软件创建数据库以及studentinfo表
4、SQL:结构化查询语言(Structure Query Language),是关系型数据库的标准查询语言
(1)查询语句:
select 列名1、列名2,... from 表名[where 条件 ]
--查询studentinfo表的所有记录: *是通配符代表所有列
select * fromstudentinfo;
--查询student表中id、name、address列
select id,name,address from studentinfo;
select id,name,address from studentinfo;
--条件查询:带where子句的查询
--查询所有性别为'男'的记录
select * from studentinfo where sex='男';
--查询所有性别为'男',年龄大于19的记录
select * from studentinfo where sex='男' and age > 19;
--查询所有性别为'男',年龄大于19的记录
select * from studentinfo where sex='男' or age >= 19;
--查询年龄在18-22岁之间的记录
select * from studentinfo where age between 18 and 22;
--查询地址是西安的学生
select * from studentinfo where address = '西安';
--查询地址是西安、渭南、咸阳的学生信息
select * from studentinfo where address in ('西安','渭南','咸阳');
--查询地址不是西安、渭南、咸阳的学生信息
select * from studentinfo where address not in ('西安','渭南','咸阳');
--模糊查询 使用like关键字 ,%通配符表示0到多个字符,_表示个字符
--查询小开头的学生
select * from studentinfo where name like '大%';
--查询姓大、名字2个字的学生记录
select * from studentinfo where name like '大_';
--查询名字有3个字,最后一个字是'黄'的学生记录
select * from studentinfo where name like '_黄';
(2)插入语句:向数据表中插入记录
insert into 表名(列名1,列名2...)values(值1,值2......)
insert into studentinfo(id,name,sex) values('1017','大白','女');
insert into studentinfo(id,name,sex) values('1018','小风','男');
(3)删除语句:删除表中的记录 注:使用删除需要使用where子句 否则就会删除整张表的数据
delete from 表名 [where 条件]
--删除id为1013的学生记录
delete from studentinfo where id = '1013';
--删除address为'渭南'的学生记录
delete from studentinfo where address = '渭南';
(4)更新语句:更新表中的记录 修改
update 表名 set 列名1=值1,列名2=值2...[where 条件]
--更新id为1017的学生的'age'与 'address'
update studentinfo set age = 19, address = '四川' where id = '1017';