MySQL数据库的CRUD基本操作

MySQL数据库的CRUD基本操作! ! ! !

首先登录数据库服务器:

mysql -uroot -p

打开创建好的数据库 及表

desc t_haha

MySQL数据库的CRUD基本操作:

一:增! ! ! ! !

 查看一下表内容 发现原来没有内容,然后我们来添加

二: 更! ! ! ! !

将表中原有数据修改为我们需要的数据

update t_name set 字段1 = 新值, 字段2 = 新值 … where 条件

三:删! ! ! ! !

delete from tablename where 条件

四:改!!!!!!

表结构的修改:alter table |-- 增加新的字段 ALTER TABLE 表名 ADD 列名 列类型 约束条件; alter
table t_hero add address varchar(255); |-- 修改字段的类型 ALTER TABLE 表名
MODIFY 列名 列类型; alter table t_hero modify id bigint; |– 修改字段名称 ALTER
TABLE 表名 CHANGE 旧列名 新列名 列类型; alter table t_hero change id hero_id
int; |-- 修改表名称 ALTER TABLE 表名 RENAME 新表名; alter table t_hero rename
hero; – 第二种写法 rename table hero to t_hero;

五:查!!!!!

1.查询一张表: select * from 表名;

2.查询指定字段: select 字段1,字段2,字段3….from 表名;

3.where条件查询:select 字段1,字段2,字段3 frome 表名 where 条件表达式;

例:select * from t_studect where id=1;
select * from t_student where age>22;

4.带in关键字查询: select 字段1,字段2 frome 表名 where 字段 [not]in(元素1,元素2);

例: select * from t_student where age in (21,23);
select * from t_student where age not in (21,23);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值