MySQL經常使用SQL語句

MySQL經常使用的SQL語句:orm

1.輸出全部信息it

show full fields from '表名稱'; io

2.改表名table

ALTER  TABLE table_name RENAME TO new_table_nameform

或 RENAME TABLE table_name TO new_table_nametest

3.查看註釋[轉自:]select

建立表的時候寫註釋方法

create table test1im

(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})

相關文章
相關標籤/搜索