Mysql之檢視表名和列名 yellowcong

2021-08-14 19:48:27 字數 1593 閱讀 5439

在命令列裡面,可以直接通過show databases;show tables;以及desc sys_user來檢視表,但是在程式中,不能直接通過這種方法來獲取,解決辦法如下

-- 登入yellowcong 資料庫

mysql -uroot -proot yellowcong

-- 檢視當前資料庫

select

database()

-- 檢視資料庫裡面的表

--table_schema 當前的資料庫

--table_type='base table' 表示基礎的普通表

select table_name from information_schema.tables where table_schema='yellowcong'

and table_type='base table';

-- 查詢指定資料庫中指定表的所有欄位名column_name

-- 檢視列的名稱

select column_name from information_schema.columns where table_schema='yellowcong'

and table_name='sys_user';

登入,並檢視當前資料庫

檢視當前資料據庫額表

檢視表sys_user的列名稱

-- 檢視資料庫

show databases;

-- 模糊查詢包含y的資料庫

show databases like

'%y%';

-- 檢視表

show tables;

--模糊查詢包含user的表

show tables like

'%user%';

-- 檢視列, 檢視sys_user表資訊

desc sys_user;

檢視資料庫

檢視表

檢視某張表資訊

庫和表的模糊查詢

mysql 命令下檢視表名等簡單操作

建立表 create table 表名 欄位1名 varchar 255 not null default 欄位2名 varchar 255 not null default 檢視表結構 desc 表名 show columns from 表名 describe 表名 insert insert i...

MySQL 新增和檢視表注釋 字段注釋

建立表的時候寫注釋 create table student name varchar 20 comment 欄位的注釋 age int comment 欄位的注釋 comment 表的注釋 修改表的注釋 alter table student comment 修改後的表的注釋 修改欄位的注釋 al...

mysql檢視表注釋和字段注釋的方法

1 取字段注釋 select column name 列名,data type 字段型別,column comment 字段注釋 from information schema.columns where table name companies 表名 and table schema testhu...