您好,登錄后才能下訂單哦!
今天小編給大家分享一下mysql查找所有數(shù)據(jù)庫中沒有主鍵的表問題怎么解決的相關(guān)知識點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
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)庫 );
這里以網(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;
以上就是“mysql查找所有數(shù)據(jù)庫中沒有主鍵的表問題怎么解決”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學(xué)習(xí)更多的知識,請關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。