MySQL常用SQL語句

2022-08-12 18:36:22 字數 1274 閱讀 9905

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

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

或select * from table_a where id=(select max(id) from table_a where id < )

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

或select * from table_a where id=(select min(id) from table_a where id > )

MySql 常用SQL語句

create database kali use kali show tables create table students sno varchar 10 primary key,sname varchar 10 not null,varchar 2 check in 男 女 age varcha...

常用sql語句(mysql)

給表新增列 sql alter table table name add column col name varchar 255 not null default default value 增加表列,指定格式 sql alter table table name add col name bool...

MySQL常用SQL語句

查詢一張表中的所有資料 sql view plain copy select from table name 查詢一張表中的指定列資料 sql view plain copy select column a,column b from table name 按條件查詢一張表中的所有資料 sql vi...