mysql数据表操作常用sql语句

显示全部表

show tables;

创建数据表

create table stu(
	id int unsigned primary key not null auto_increment, 
	name varchar(20), 
	age tinyint unsigned default 0,
	gender enum("male", "female", "unknow") default "unknow" 
	class_id int unsigned
);

显示表的结构

desc 表名

向表中插入数据

insert into stu values(1, "赵佶", 24, "male", 1603);

查询表中全部数据

select * from stu;

修改表结构-添加字段

alter table stu add birthday datetime;

修改表结构-修改字段(不重命名版)

alter table stu modify birthday date;

修改表结构-修改字段(重命名版)

alter table stu change birthday birth date default "1990-01-01";

修改表结构-删除字段

alter table stu drop birth;

删除表

drop table 表名;

多行数据插入

insert into stu values(5,"John",21,"male",1603,"1996-01-21"),(6,"Ann",20,"female",1603,"1996-01-20");

多行部分字段数据插入

insert into stu (id, name) values(3, "Bob"),(4,"Alice");

修改某行记录的某个字段的数据

update stu set age=20 where name="Bob";

指定条件查询

select * from stu where name="Bob";

指定字段查询

select name, age from stu;

指定字段起别名查询

select name as 姓名, age as 年龄 from stu;

物理删除数据表中的全部数据

delete from stu;

逻辑删除数据表中的全部数据

alter table stu add is_delete bit default 0;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值