mysql常用语句

基本语句

DescriptionCodeRemarks
dos进入数据库mysql -uroot -p配置本机环境变量
显示所有数据库show databases;
创建数据库create database dbName;
删除数据库drop database dbName;
判断数据库是否存在
(获取数据库详情)
select * from information_schema.SCHEMATA where SCHEMA_NAME = “dbName”;
进入数据库use dbName;
显示所有表show tables;
查看表结构describe 表名;
查看表详细定义show create tables tableName;
创建表create table 表名 (字段名 类型 约束, 字段名 类型 约束,设置外键 …)
约束primary key / auto_increment / unique / not null / default ‘张三’主键和自动增长一起使用
设置外键foreign key (当前表外键名) references fkTbaleName(primaryKey)
设置外键(定外键名)constraint fkName foreign key (当前表外键名) references fkTbaleName(primaryKey)
删除外键约束alter table tableName drop foreign key fkName
删除表drop table 表名
如果表存在则删除drop table if exists class
插入数据insert into 表名(字段,…) values (数据,…);
清空数据delete from tableName有日志
清空数据truncate table tableName无日志
修改表名alter table tableName rename newTbaleName
修改字段名alter table tableName change oldFiledName newFiledName 类型 [约束]
修改字段类型/约束alter table tableName modify filedName 类型 [约束]
增加字段alter table tableName add filedName type [constraint] [first or after filedName]first–>首位 after filedName–>某字段后面
删除字段alter table tableName drop filedName
修改字段排序位置alter table tableName modify filedName type [constraint] first [or after filedName]
查询数据select * from tableName
todo 复杂查询

发布于CSDN

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值