MySQL常用SQL语句

MySQL常用的SQL语句:

1.输出所有信息

show full fields from '表名称'; 

2.改表名

ALTER  TABLE table_name RENAME TO new_table_name

或 RENAME TABLE table_name TO new_table_name

3.查看注释[转自:]

创建表的时候写注释

create table test1

(field_name int comment '字段的注释'

)comment='表的注释';

修改表的注释

alter table test1 comment '修改后的表的注释';

修改字段的注释

alter table test1 modify column field_name int comment '修改后的字段注释';

--注意:字段名和字段类型照写就行

查看表注释的方法

--在生成的SQL语句中看

show create table table_name; //可以看到: 表的结构, ENGINE, DEFAULT CHARSET, COMMENT

--在元数据的表里面看

use information_schema;

select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' \G

查看字段注释的方法

--show

show full columns from test1;

--在元数据的表里面看

select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' \G

4.查询当前数据上一条和下一条记录

查询上一条:

select * from table_a where id=(select id from table_a where id < {$id} order by id desc limit 1)

select * from table_a where id=(select max(id) from table_a where id < {$id})

查询下一条:

select * from table_a where id=(select id from table_a where id > {$id} order by id asc limit 1)

 或

select * from table_a where id=(select min(id) from table_a where id > {$id})

posted @ 2015-10-13 10:08  wen_php  阅读(239)  评论(0编辑  收藏  举报