1、什么是关系型数据库? 答:依据关系模型创建的数据库,把数据保存在不同的表中, 表与表存在着 某些关系。 2、什么是非关系型数据库? 答:非关系型数据库也叫nosql数据库,全称not only sql。 通常数据以对象 的形式存储在数据库中,不固定结构, 例如列模型,键值对模型 关系型数据库特点? 1.安全 2.保持数据的一致性 3.实现对表与表进行复杂的数据查询 非关系型数据库特点? 1.效率高 2.容易扩展 3.使用更加灵活 关系型数据库有哪些? 1.db2 2.oracle 3.mysql 4.sql server 非关系型数据库有哪些? 1.hbase(列模型) 2.redis(键值对模型) 3.mongodb(文档类模型) Mysql特点 1.体积小,安装简单,维护成本低 2.开源,免费 3.使用C++编写 4.支持多系统1、create database +数据库名称, 创建数据库 create table +表名(字段1名称,数据类型,约束,字段2名称,数据类型,约束 ) 创建表 2、drop database +数据库名称 删除数据库 drop table +表名 删除表 3、use +数据库名称 进入数据库 4、show tables 查询数据库中的表 5、show database 查询数据库 6、desc +表名称; 查询表结构 7、改表名称:alter table dcs rename xiaoqian;(把表dcs名称改为xiaoqian) 8、改表字段名称:alter table dcs change id s_id int(4);(把dcs表中的id字段名称改为s_id名称) 9、增加单个字段:alter table dcs add class int(4);(给dcs增加一个表字段class默认放在末尾) 10、增加多个字段 alter table 表名称 add (字段1,字段2); 11、增加字段放在最前面:alter table xiaoqian add id int(4)first;
12、增加字段放在某个字段的后面:alter table xiaoqian add sex char(2)after age; 13、alter table 表名称 drop 字段 删除单个字段 14、alter table 表名称 drop 字段,drop 字段, 删除多个字段 15、创建表增加主键和自增长约束 create table dcs68(id int(4)primary key auto_increment,name char(10),scroeint(4)); 16、给没有主键的表增加主键和自增长 alter table xiaoqian change id idint(5)primary key;
alter table xiaoqian change id idint(5)auto_increment; 17、删除主键和自增长 alter table xiaoqian change id id int(5);删除id中的自增长 alter table xiaoqian drop primary key;删除主键 18、insert into stu(id,name,age,scroe)values(1,'zhang',20,89); #增加一行数据 19、delete from stu;删除整个表中的所有数据 20、delete from stu where 条件 21、update 表名称 set 修改的值 where 条件指定 22、select * from 表名称; 23、select * from stu;查询stu表中的所有内容 24、通过条件查询某个条件的值: select * from 表名称 where 条件; 通过条件查询满足几个条件的内容: select * from 表名称where 条件 and 条件; select * from stu where name='qian' andage=20;查询满足姓名是qian年纪是20的数据 大于> select * from stu where scroe>60; 大于60分所有信息 小于> select * from stu where scroe<60;小于60分所有信息 等于= select * from stu where scroe=60;等于60分所有信息 大于等于>= select * from stu where scroe>=60;大于等于60分所有信息 小于等于<= select * from stu where scroe<=60;小于等于60分所有信息 不等于!= select * from stu where scroe !=60;不包含60分的所有信息 in指定具体的值
select * from stu where scroe in(60,88,99);指定的值有就显示,没有就不显示
|