gpt4 book ai didi

mysql - 如何在sql中为串行数据类型的列创建外键

转载 作者:行者123 更新时间:2023-11-30 22:52:17 24 4
gpt4 key购买 nike

我有一种情况需要在 mysql 中为序列类型列创建一个外键。

而且我还想知道,为串行类型列(这是主键)定义外键是否是一种好的做法/标准

表 1:

txn_id SERIAL,
txn_status integer

表 2:

txn_id integer foreign key (for table1.txn_id)
txn_error_code integer

最佳答案

由于 SERIALBIGINT UNSIGNED 的别名,您可以使用如下代码。

CREATE TABLE IF NOT EXISTS Table2(
txn_id BIGINT UNSIGNED,
txn_error_code integer,
FOREIGN KEY (txn_id) REFERENCES Table1 (txn_id))

关于mysql - 如何在sql中为串行数据类型的列创建外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27838598/

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