码迷,mamicode.com
首页 > 数据库 > 详细

关于数据库一些指令的简单操作

时间:2019-04-19 00:56:46      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:指令   查询   update   char   设置   特定   ike   hang   database   

这里的所有指令都试过,就没贴图了 ,因为挺简单的

?

?

create database student ; ? ? ? ? 创建一个数据库 ?名为student
use student; ?使用这个数据库
create table stu(name char(10),id int(10) primary key,sex char(10)); 创建表明,并设置属性分别有姓名,ID,性别,并且将ID设为主键。
insert into stu values("yuanyao","20160865112","male"); ?为新创建的数据库插入数据。
select * from stu ; 查看我的数据表 ?此时可以看见有一组数据了

update stu set name = ‘tian‘ while name = ‘yuanyao‘ ; 更新数据表中的数据,将yuanyao更新为tian

alter table stu add country char(10) ; ?为数据表stu增加一个属性 ,属性名字为country
alter table stu change country country1 char(10); 修改数据表中的属性,将country修改为country1
alter table stu modify country1 char(5) ; 修改属性country1的大小
alter table stu drop country1 ; ? 将country1的属性删除。

show databases ; 显示所有数据库的名称
show tables ;显示数据表
show tables from database ;显示当前数据库的所有数据表

drop database student ; 删除数据库
drop table stu ; 删除数据表

删除数据:
delete from stu where id = 20160865112 ; ?将删除ID为20160865112的一整行数据

清空数据:
truncate table stu; 将清除stu的一整张表的所有数据

distinct: 让在同一个属性的值只出现一次
select distinct sex from stu ; ? 显示结果,数据表stu的sex属性只会出现male和female。

like : 透过部分字符串的查询动作,可以搭配以下两个字原使用,‘%’,‘_’;
select * from stu where name like ‘%y‘ ; ? ?模糊查询,将返回所有带y的数据
select * from stu where name like ‘_y‘ ; ?查找最早出现y的数据,并返回,只返回一条数据

order by : 功能 就是将数据由大到小或者由小到大排序
select * from stu order by name asc ; 数据将按name的升幂排序,比如(原来的数据为yy,y,yyyyyy三种数据,使用指令后,将变为y,yy,yyyyyy);
select * from stu order by name desc;数据将按name的降幂排序

where:用于查找自己想要的数据
语法 select * from 表格名 ?where 条件式 ;
?select * from stu where stu.name = ‘yuanyao‘ ; 查询结果将返回name为yuanyao 的那一条数据

between: 找出属性值介于两者之间的所有属性
语法:select 属性 from 表格名 where 属性 between 值一 and 值二
select id from stu where id between 1 and 10 ; 结果将返回为ID从1到10的所有数据

and/or 当有多重条件式的时候可以使用
语法:select 属性 from 表名 where 简单条件 {and|or 简单条件} (属性可以不是同一个属性,比如 sex为male ,ID>10)
select id from stu where id > 10 and id < 20 ; 结果将返回ID大于10 且小于20的所有数据

in 当只想看到某些特定的值时可以使用
语法:select 属性 from 表名 where 属性 in (‘值一‘,‘值二‘)
select id from stu where id in(10,12,15) ; 结果将返回ID为10,12,15的所有数据。
?

关于数据库一些指令的简单操作

标签:指令   查询   update   char   设置   特定   ike   hang   database   

原文地址:https://www.cnblogs.com/ai2050/p/10733308.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!