简单数据库命令记忆

mysql -h 主机名 -u 用户名 -p

h,u,p三个参数 注意没有;


create database 数据库名;

use 数据库名;

drop database 数据库名;


下面是针对表的操作!

create table 表名称(列声明);

create table students
	(
		id int unsigned not null auto_increment primary key,
		name char(8) not null,
		sex char(4) not null,
		age tinyint unsigned not null,
		tel char(13) null default "-"
	);

alter table 表名 rename 新表名;

drop table 表名;


下面是针对表的列操作!

alter table 表名 add 列名 列数据类型 [after 插入位置];

alter table 表名 change 列名称 列新名称 新数据类型;

alter table 表名 drop 列名称;



 
 
 
下面是数据操作
select 列名称 from 表名称 [查询条件];
select * from students;
条件:select 列名称 from 表名称 where 条件;
条件实例:

 
 

查询年龄在21岁以上的所有人信息: select * from students where age > 21;

查询名字中带有 "王" 字的所有人信息: select * from students where name like "%王%";

查询id小于5且年龄大于20的所有人信息: select * from students where id<5 and age>20;

insert [into] 表名 [(列名1, 列名2, 列名3, ...)] values (值1, 值2, 值3, ...);

insert into students values(NULL, "王刚", "男", 20, "13811371377");

部分数据

insert into students (name, sex, age) values("孙丽华", "女", 21); 
delete from 表名称 where 删除条件;
上面三个总体上来说是对行操作!
而下面这个是二维的
update 表名称 set 列名称=新值 where 更新条件;








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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值