gpt4 book ai didi

mysql - MySQL判断主键是否存在的方法

转载 作者:行者123 更新时间:2023-11-29 05:04:15 29 4
gpt4 key购买 nike

我已经尝试了几个 sql 脚本但都失败了。这是我接近的那个:

SELECT *
FROM INFORMATION_SCHEMA.STATISTICS
WHERE table_schema = schema()
AND table_name = 'my_table_name'
AND index_name = 'column_name';

最佳答案

我认为你需要以下声明

https://www.db-fiddle.com/f/jbdzXwpWkYichsBL1ib2Rj/2

select constraint_name
from information_schema.table_constraints
where table_name = 'mytable'
and table_schema = 'myschema'
and constraint_name = 'PRIMARY';

或以下 https://www.db-fiddle.com/f/jbdzXwpWkYichsBL1ib2Rj/3

SELECT EXISTS(
SELECT 1
FROM information_schema.columns
WHERE
table_name='messages'
and column_key = 'PRI'
) As HasPrimaryKey;

关于mysql - MySQL判断主键是否存在的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51713336/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com