mysql之查找所有數(shù)據(jù)庫(kù)中沒(méi)有主鍵的表問(wèn)題
查找所有數(shù)據(jù)庫(kù)中沒(méi)有主鍵的表
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)庫(kù)
);修改mysql數(shù)據(jù)表主鍵
這里以網(wǎng)上copy的建表語(yǔ)句為例
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)建時(shí)間', ? ? update_at timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '修改時(shí)間', ? ? 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;
修改名稱(chēng)
alter table ?users change tid id int unsigned auto_increment primary key;
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Navicat連接MySQL出現(xiàn)2059錯(cuò)誤的解決方案
當(dāng)使用Navicat連接MySQL時(shí),如果出現(xiàn)錯(cuò)誤代碼2059,表示MySQL服務(wù)器不接受Navicat提供的加密插件,解決方法主要有兩種:一是修改MySQL用戶(hù)的認(rèn)證插件為mysql_native_password,二是升級(jí)Navicat到最新版本以支持MySQL8.0及其默認(rèn)的caching_sha2_password認(rèn)證插件2024-10-10
MySQL 利用frm文件和ibd文件恢復(fù)表數(shù)據(jù)
這篇文章主要介紹了MySQL 利用frm文件和ibd文件恢復(fù)表數(shù)據(jù),幫助大家更好的理解和學(xué)習(xí)使用MySQL,感興趣的朋友可以了解下2021-03-03
提升MYSQL查詢(xún)效率的10個(gè)SQL語(yǔ)句優(yōu)化技巧
MySQL數(shù)據(jù)庫(kù)執(zhí)行效率對(duì)程序的執(zhí)行速度有很大的影響,有效的處理優(yōu)化數(shù)據(jù)庫(kù)是非常有用的。尤其是大量數(shù)據(jù)需要處理的時(shí)候2018-03-03
MySQL安裝與創(chuàng)建用戶(hù)操作(新手入門(mén)指南)
這篇文章主要為大家介紹了MySQL安裝與創(chuàng)建用戶(hù)的使用講解是非常適合小白新手的入門(mén)學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05
MySql,MVCC實(shí)現(xiàn)及其機(jī)制,快照讀在RC,RR下的區(qū)別說(shuō)明
這篇文章主要介紹了MySql,MVCC實(shí)現(xiàn)及其機(jī)制,快照讀在RC,RR下的區(qū)別說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-04-04

