首页 > 学院 > 开发设计 > 正文

mysql常用的sql语句

2019-11-06 06:49:14
字体:
来源:转载
供稿:网友

一、简单描述表结构,字段类型

desc tabl_name;

显示表结构,字段类型,主键,是否为空等属性,但不显示外键。

二、查询表中列的注释信息

select * from information_schema.columns

where table_schema = 'db'  #表所在数据库

and table_name = 'tablename' ; #你要查的表

三、只查询列名和注释

select  column_name, column_comment from information_schema.columns where table_schema ='db'  and table_name = 'tablename' ;

四、#查看表的注释

select table_name,table_comment from information_schema.tables  where table_schema = 'db' and table_name ='tablename'

ps:二~四是在元数据表中查看,我在实际操作中,常常不灵光,不知为什么,有了解的大侠请留印。

五、查看表生成的DDL 

show create table table_name;

这个命令虽然显示起来不是太容易看, 这个不是问题可以用/G来结尾,使得结果容易阅读;该命令把创建表的DDL显示出来,于是表结构、类型,外键,备注全部显示出来了。我比较喜欢这个命令:输入简单,显示结果全面。

六 MySQL 查看所有用户

select * from mysql.user

select user from mysql.user

  七  mysql 查看当前登录用户    select user();

  八    增加字段        mysql> ALTER TABLE table_name ADD field_name field_type;

    删除字段       MySQL ALTER TABLE table_name DROP field_name;

   修改原字段名称及类型     mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表