mysql 命令总结

创建数据库:create database 数据库名;


修改数据库:alter database 数据库名


           character set 字符集名


           collate 字符校对规则;


删除数据库:drop database 数据库名;


创建表: create table 表名


       (列名 列的数据类型 列的约束, ...);


修改表: alter table 表名


      1.添加列: add 列名 列的数据类型 列的约束


      2.修改列的数据类型: modify 列名 新数据类型 新约束


      3.修改列的默认值:alter  列名  set default 默认值| drop default


      4.修改列的名字:change 旧列名 新列名 列定义


      5.删除列:drop 列名


      6.将字符集转换为二进制:convert to character set 字符集名字 ;


删除表:drop table 表名;


重命名表:1、alter table 旧表名


            rename 新表名;


         2、rename table 旧表名 to 新表名;


向表中插入数据:insert into 表名(列名,...) values(值,...);


修改表中的数据:update 表名 set 列名=新的列值 where 更新条件;


删除表中的数据:delete from 表名 where 删除条件;


查询数据:select [distinct(去除重复行)] 结果列,...结果列 as 新列名


         from  表1,表2,....


         where 条件(查询条件,连接条件)


         group by 分组的列名 asc | desc


         with rollup


         having 分组以后筛选的条件


         order by 要排序的关键字1,关键字2 asc |desc


         limit n| n,m ;


多个select语句链接使用:union


创建视图:create view 视图名 as select查询语句 with check option;


更新视图:       insert 视图名    (同表的操作)


(对视图当中的   update 视图名


 数据进行操作)  delete 视图名


修改视图:alter view 视图名 as select查询语句 with check option;


删除视图:drop view 视图名;

创建索引:1、create index 索引名 [using 索引类型]


            on 表名(列名(长度),...);


         2、create table 表名(列定义,.. index 索引名 [using 索引类型](列名));


         3、alter table 表名

            add index 索引名 using 索引类型(列名);


删除索引:1、drop  index  索引名 on 表名;


         2、alter table 表名


            drop index 索引名;

创建约束 1、create table 表名(列名,烈的数据类型 列的约束)


2、alter table 表名


add constraint 约束名 约束类型(列名);


删除约束:alter table 表名


drop 约束类型|约束名


约束类型:主键约束 primary key 


替代建约束 unique


外键约束 foreign key(列名) references 被参照表(主键列)


检查约束 check(检查条件)


 实体完整性 参照完整性 检查完整性














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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值