mysql之查找所有數(shù)據(jù)庫中沒有主鍵的表問題
更新時間:2023年03月23日 09:41:19 作者:ailo555
這篇文章主要介紹了mysql之查找所有數(shù)據(jù)庫中沒有主鍵的表問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
查找所有數(shù)據(jù)庫中沒有主鍵的表
select table_schema,table_name from information_schema.tables where (table_schema,table_name) not in( select distinct table_schema,table_name from information_schema.columns where COLUMN_KEY='PRI' ) and table_schema not in ( 'sys','mysql','information_schema','performance_schema' --排除系統(tǒng)庫 );
修改mysql數(shù)據(jù)表主鍵
這里以網(wǎng)上copy的建表語句為例
create table users ( ? ? name ? ? ?varchar(50) ? ? ? ? ? ? ? ? ? ? ? ? null, ? ? salt ? ? ?char(4) ? ? ? ? ? ? ? ? ? ? ? ? ? ? null comment '鹽', ? ? password ?varchar(255) ? ? ? ? ? ? ? ? ? ? ? ?null comment '密碼', ? ? create_at timestamp default CURRENT_TIMESTAMP null comment '創(chuàng)建時間', ? ? update_at timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '修改時間', ? ? tid ? ? ? int unsigned auto_increment ? ? ? ? primary key ) ? ? charset = utf8;
mysql的版本是8,這里要把主鍵tid改為id。需改自增主鍵需要三步驟
先刪除掉自增
alter table ?users modify tid int not null;
再刪除主鍵
alter table ?users drop primary key;
修改名稱
alter table ?users change tid id int unsigned auto_increment primary key;
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Linux系統(tǒng)利用crontab定時備份Mysql數(shù)據(jù)庫方法
本文教你如果快速利用系統(tǒng)crontab來定時執(zhí)行備份文件,按日期對備份結(jié)果進(jìn)行保存2021-09-09MySQL性能優(yōu)化之Open_Table配置參數(shù)的合理配置建議
這篇文章主要介紹了MySQL性能優(yōu)化之Open_Table配置參數(shù)的合理配置建議,在MySQL數(shù)據(jù)庫中,Opened_tables表示打開過的表數(shù)量,需要的朋友可以參考下2014-07-07

mysql 8.0 錯誤The server requested authentication method unkno
在本篇文章里小編給大家整理的是關(guān)于mysql 8.0 錯誤The server requested authentication method unknown to the client解決方法,有此需要的朋友們可以學(xué)習(xí)下。
2019-08-08 
Linux如何添加mysql系統(tǒng)環(huán)境變量
這篇文章主要介紹了Linux如何添加mysql系統(tǒng)環(huán)境變量問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
2023-04-04