日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > MAC >内容正文

MAC

mysql之查找所有数据库中没有主键的表问题

發布時間:2023/11/24 MAC 36 博士
生活随笔 收集整理的這篇文章主要介紹了 mysql之查找所有数据库中没有主键的表问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
  • 查找所有數據庫中沒有主鍵的表
  • 修改mysql數據表主鍵
  • 總結

查找所有數據庫中沒有主鍵的表

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' --排除系統庫
);

修改mysql數據表主鍵

這里以網上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 '創建時間',
? ? 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;

總結

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持電腦知識網www.pcxun.com。

總結

以上是生活随笔為你收集整理的mysql之查找所有数据库中没有主键的表问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。