Mysql中返回一個數據庫的所有表名,列名數據類型備注
更新時間:2010年04月28日 22:52:02 作者:
在Mysql中怎樣返回一個數據庫的所有表名,列名數據類型備注
desc 表名;
show columns from 表名;
describe 表名;
show create table 表名;
use information_schema
select * from columns where table_name='表名';
順便記下:
show databases;
也可以這樣
use information_schema
select table_schema,table_name from tables where table_schema='數據庫名'
use 數據庫名;
show tables;
原有一unique索引AK_PAS_Name(PAC_Name)在表tb_webparamcounter中,
執(zhí)行以下sql修改索引
alter table tb_webparamcounter drop index AK_PAS_Name;
alter table tb_webparamcounter add UNIQUE AK_PAS_Name(PC_ID,PAC_Name);
若發(fā)現索引的邏輯不對,還需要再加一個字段進去,執(zhí)行
alter table tb_webparamcounter drop index AK_PAS_Name;
alter table tb_webparamcounter add UNIQUE AK_PAS_Name(PC_ID,PAC_Name,PAC_Value);
注意:這時的PC_ID,PAC_Name,PAC_Value三個字段不是FOREIGN KEY
否則必需先drop FOREIGN KEY,再重做上一步才行
獲取列名數據類型備注
SELECT COLUMN_NAME, DATA_TYPE, COLUMN_COMMENT FROM information_schema.columns WHERE table_name = ?
show columns from 表名;
describe 表名;
show create table 表名;
use information_schema
select * from columns where table_name='表名';
順便記下:
show databases;
也可以這樣
use information_schema
select table_schema,table_name from tables where table_schema='數據庫名'
use 數據庫名;
show tables;
原有一unique索引AK_PAS_Name(PAC_Name)在表tb_webparamcounter中,
執(zhí)行以下sql修改索引
alter table tb_webparamcounter drop index AK_PAS_Name;
alter table tb_webparamcounter add UNIQUE AK_PAS_Name(PC_ID,PAC_Name);
若發(fā)現索引的邏輯不對,還需要再加一個字段進去,執(zhí)行
alter table tb_webparamcounter drop index AK_PAS_Name;
alter table tb_webparamcounter add UNIQUE AK_PAS_Name(PC_ID,PAC_Name,PAC_Value);
注意:這時的PC_ID,PAC_Name,PAC_Value三個字段不是FOREIGN KEY
否則必需先drop FOREIGN KEY,再重做上一步才行
獲取列名數據類型備注
SELECT COLUMN_NAME, DATA_TYPE, COLUMN_COMMENT FROM information_schema.columns WHERE table_name = ?
相關文章
MySQL報錯Failed to open the referenced&nbs
在數據庫操作中,嘗試刪除外鍵約束表'master_role'時遇到錯誤碼3730,因其被'user_role'表中的外鍵'fk_user_role'引用,解決方法包括關閉外鍵檢查和刪除外鍵,阿里巴巴開發(fā)手冊和知乎回答指出,外鍵雖能維護數據一致性2024-11-11Ubuntu下啟動、停止、重啟MySQL,查看錯誤日志命令大全
這篇文章主要介紹了Ubuntu下啟動、停止、重啟MySQL,查看錯誤日志命令大全,需要的朋友可以參考下2014-06-06mysql 8.0.15 winx64壓縮包安裝配置方法圖文教程
這篇文章主要為大家詳細介紹了mysql 8.0.15 winx64壓縮包安裝配置方法圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-05-05