我有三个表格——
file (
file_id int primary key
filename text not null
etc...
)
product (
product_id int primary key
etc....
)
product_attachment (
product_id references product
file_id references file
)
我希望当这些数据进行自然连接时,product_id + filename是唯一的。
目前我想到最好的解决方案是将filename添加到product_attachment表中,但我想知道是否有避免这种方法的方式。
for update
会获取表级别锁,但是像你提到的那样显式地锁定表可能更清晰、更安全。顺便说一下,如果有可能更新filename
,你可能需要在file
表上添加类似的约束条件。 - FuzzyTree