mysql之查找所有数据库中没有主键的表问题
生活随笔
收集整理的這篇文章主要介紹了
mysql之查找所有数据库中没有主键的表问题
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
- 查找所有數(shù)據(jù)庫中沒有主鍵的表
- 修改mysql數(shù)據(jù)表主鍵
- 總結(jié)
查找所有數(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)驗,希望能給大家一個參考,也希望大家多多支持電腦知識網(wǎng)www.pcxun.com。
總結(jié)
以上是生活随笔為你收集整理的mysql之查找所有数据库中没有主键的表问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 查一次left join没有走索引以及原
- 下一篇: “欲得身心俱静好”下一句是什么