欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)文章

  • mysql 8.0 錯誤The server requested authentication method unknown to the client解決方法

    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
  • MySQL下載安裝配置詳細(xì)教程?附下載資源

    MySQL下載安裝配置詳細(xì)教程?附下載資源

    這篇文章主要介紹了MySQL下載安裝配置詳細(xì)教程?附下載資源,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-09-09
  • 簡單談?wù)凪ySQL的半同步復(fù)制

    簡單談?wù)凪ySQL的半同步復(fù)制

    從MySQL5.5開始,MySQL以插件的形式支持半同步復(fù)制。如何理解半同步呢?今天我們就來詳細(xì)講解下,希望大家能夠喜歡。
    2017-03-03
  • Linux如何添加mysql系統(tǒng)環(huán)境變量

    Linux如何添加mysql系統(tǒng)環(huán)境變量

    這篇文章主要介紹了Linux如何添加mysql系統(tǒng)環(huán)境變量問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • 最新評論