数据库,表以及表内文件的一些简单操作

此下都是一些基本操作 对于初学者用处还是很大的 里面所有代码建议都使用大写 本人小白一名 写小写方便他人观看不是一个好的习惯

数据库

create databases if not exists 数据库名称 character set 编码;

drop database exists 数据库名称;

alter database 数据库名称 character set 编码;

show databases;

create table 表名(列名1 类型,……….name varchar(24容纳字符串数));

drop table exists表名称;

a.改表名–>alter table 原名 rename to 新名;
b.改字符集–>alter table 表名 character set 编码;
c.改列名 –>alter table 表名 change 旧列名 新列名 新的数据类型;
d.增一列–>alter table 表名 add 列名 数据类型;
e.删一列–>alter table 表名 drop 列名;

show tables;

操作表

添加指定列 –>insert into 表名 (列名1,….) values (值1,….);
添加所有列 –>insert into 表名 values(值1,….);

truncate table 表名; –(先删表再建表效率高)

update 表名 set 列名1=值1,…..[where 条件]; – 后面的where条件不要就是改所有的

多字段查询–>select 列名1,…from 表名;
1.去重查询

select distinct 列名 from 表名称;

2.四则运算

select ifnull (列名1,0) + 列名2 from 表名称;

3.起别名

select 列名1 as 别名1,列名2 别名2 from表名称;

条件查询

A->and–>select * from 表名称 where 列名>条件1 and 列名<条件2;
and 或者&&
B->select * from 表名称where 列名 between 条件1 AND 条件2;
C.or–>select * from 表名称where 列名=条件1 or 列名=条件2;
or或者||
D.is null–>select * from 表名称 where 列名 is null;
E.is not null–>select * from 表名称 where 列名 is not null;

模糊查询(以王举例)

查姓王–>select*from hero where name like”王%”;– ‘%’表示多个字符
姓王名字两个字–>select*from hero where name like “王“; – ‘‘表示一个字符
第二个字是王–>select*from hero where name like “_王%”;
带王的–>select*from hero where name like “%王%”;

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值