MYSQL常用增删改查命令

MYSQL常用增删改查命令

– 数据库的操作

-- 数据库的链接
	1.mysql -uroot -p
	2.mysql -uroot -p123456
	
-- 数据库的退出
	1.quit/exit/ctrl+d
	
-- 查看数据库
	show databases;
	
-- 查看数据库版本
	select version();
	
-- 显示时间
	show now();
	
-- 创建数据库
	create database name;
	# 如果没有指定编码,会默认使用拉丁文
	# 指定编码的方法
	create database charset = utf8;
	
	
-- 查看创建数据库的语句
	show create database python01;

-- 删除数据库
    # 物理删除
	
	drop database python01
	-- 删除数据表
	delete from students;
	# 逻辑删除
		--  alter table students add is_delete bit default 0;
			updata students set is_delete=1 where id=11;
			
			
	
-- 使用数据库
	use python01;
-- 查看当前数据库中所有表
	show tables
-- 创建数据表
	create tables;
	
 #  create table students(id int unsigned primary key not null auto_increment,
	name varchar(30),
	age tinyint unsigned,
	high decimal(5,2),
	gender enum("男“,"女","中性","保密") default "保密",
	cls_id
	);
	
	-- 插入数据--
	insert into students values(1,"老王","18","188.88","男",0)
	
	insert into students (name,cls_id) values("老陈",1)
		-- 多行插入
			insert into students values(1,"老王","18","188.88","男",0),(1,"老李","18","188.88","女",0);
			
	
	-- 查询数据
	select * from classes;
	
	-- 修改数据
	updata students set gender=1 #(把所有的gender都修改了一遍)
	
	updata students set gender=1 where name="老王";
	
	updata students set gender=1 where id=3; # (单独修改了id=3的数据)
	
	updata students set gender=1 where
-- 查看表
desc xxxx;


select name,gender from students; # (只看nmae和gender列)


select * from students;
select * from students where id<3;#(查询id<3的所有信息)
select * from students where name="小李飞刀"; #(查询name为小李飞刀的所有信息)

select id as 序号,gender as 性别,name as 姓名 from students;


-- 查看表的创建方式

	show create table students;



-- 修改表的结构

	-- 添加字段
		alter table students add birthday datatime;
		
	-- 删除字段
		alter table students drop high;
		
	-- 修改字段
		-- 不修改字段,修改类型和约束
		alter table students modify birthday data;
		
		-- 修改字段
		alter table students change birthday birth data default "2008-1-1";
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值