我正在添加一个列作为不能为 NULL 的外键,因此需要有一个 DEFAULT 值。
ALTER TABLE location
ADD [retailer_brand_id] INT NOT NULL DEFAULT (SELECT retailer_id from retailer),
FOREIGN KEY(retailer_brand_id) REFERENCES retailer_brand(retailer_brand_id);
我想要实现的是,获取retailer_id
from SELECT retailer_id from retailer
,如果它等于 12 则将其设置为 0,否则设置为retailer_id
select 查询返回的值。
当我使用上述查询时,我收到一条错误消息
在这种情况下不允许子查询。只允许标量表达式。