mysql操作相关

@Mysql语句
命令
show databases —显示当前服务下的所有数据库
use 数据库名—使用该数据库
show tables —显示该数据库下的所有数据表
desc 表名 —查看表的数据结构
** 数据库命令**
create database 数据库名—创建数据库
drop database 数据库名 —删除数据库
alter database 数据库名 character set utf8 —修改数据库配置
select database()—查看正在使用的数据库
show create database 数据库名—查看数据库定义信息
drop databases 数据库名称—删除数据库
数据库表操作

CREATE TABLE table_name(
column_name data_type [default default_value] [column_constaint] [comment 'comment_content'],
……
[table_constaint]
)[engine=engine_type] [default charset=charset_type];`

说明:

  1. table_name:表名;
  2. column_name:字段名,字段名一般由字母和下划线构成,多个单词时,单词与单词之间使用下划线间隔;同
    一个表中字段名不允许重复;
  3. data_type:字段类型;
  4. default default_value:设置默认值;
  5. column_constaint:设置字段级约束;
  6. comment ‘comment_content‘:设置注释;
  7. table_constaint:设置表级约束;
  8. engine:设置存储引擎 https://blog.csdn.net/gaohuanjie/article/details/50944782
  9. charset:设置编码,一般为uft8;
    添加字段:
alter table table_name 
add column_name data_type [default default_value] [column_constaint] [after 字段名] [comment 
'comment_content’];

修改字段:

alter table table_name
modify column_name data_type [default default_value] ;

删除字段:

alter table table_name
drop column_name

重命名表:

rename 旧名字 to 新名字

截断表:

truncate table 表名

注意:
截断表后数据清除,保留表的结构
删除表:

drop table 表名

修改数据
添加数据:
第一种

insert into 表名(字段) values(值)

第二种

create table new_student(
	id char(36) primary key,
	name varchar(8) not null,
	mobile char(11),
	address varchar(150)
)
insert into new_student select id,name,mobile,address from student

删除数据:

delete from 表名 [where ......]

修改数据:

update table_name select  字段=value [where......]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值