create table customers_payment_method (
customer_id int not null,
payment_method varbinary(8),
customer_id_cashapp int as
(case payment_method when 'cashapp' then customer_id end) stored,
customer_id_paypal int as
(case payment_method when 'paypal' then customer_id end) stored,
constraint cidcashapp foreign key (customer_id_cashapp) references customers_cashapp(customer_id),
constraint cidpaypal foreign key (customer_id_paypal) references customers_paypal(customer_id)
);
1条答案
按热度按时间jv4diomz1#
我不清楚您打算如何使用带有fk约束的表,但看起来您很可能可以用更好的方式设计数据库。也就是说,您可以在生成的列上使用约束来实现这一点:
fiddle