mysql之查找所有数据库中没有主键的表问题
作者:ailo555 时间:2024-01-12 15:27:19
查找所有数据库中没有主键的表
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;
来源:https://blog.csdn.net/ailo555/article/details/82706756
标签:mysql,查找,数据库,主键表
0
投稿
猜你喜欢
2020史上最全IDEA插件总结(推荐收藏)
2023-11-13 07:13:41
页面上存在多个FckEditor编辑器的验证方法
2022-07-29 07:00:49
如何处理包含JavaScript语句时的间隔符?
2009-11-14 20:39:00
详解MySQL双活同步复制四种解决方案
2024-01-13 04:39:47
Express实现Session身份认证的示例代码
2024-05-08 09:38:21
javascript对象概念大全
2009-05-22 18:24:00
自然语言处理之文本热词提取(含有《源码》和《数据》)
2021-11-26 11:14:58
Python 列表(List)操作方法详解
2023-06-15 10:10:04
Docker安装MySQL8的方法步骤
2024-01-21 12:26:40
python字典进行运算原理及实例分享
2023-02-16 14:17:14
python实现网页录音效果
2022-03-19 08:07:15
Python通过PIL获取图片主要颜色并和颜色库进行对比的方法
2022-06-05 13:51:35
浅谈python数据类型及类型转换
2023-08-28 15:25:32
通过实例了解JS 连续赋值
2024-05-02 16:15:14
Python判断三段线能否构成三角形的代码
2023-01-21 19:44:25
go语言实现mqtt协议的实践
2024-04-23 09:34:38
django+js+ajax实现刷新页面的方法
2021-04-19 05:22:20
试试把xml和javascript写到同一个文件里面
2009-10-02 16:53:00
ACCESS的参数化查询 附ASP和C#(ASP.NET)函数
2008-01-10 12:18:00
python数据结构leetcode338比特位计数算法
2023-05-06 21:24:33