插入多行,但对于每行检查是否尚不存在
如果目标表中存在,我希望插入多行。但是我不确定如何处理以下代码:
INSERT INTO sales.promotions(
promotion_name,
discount,
start_date,
expired_date
)
VALUES
('2019 Summer Promotion', 0.15, '20190601', '20190901'),
('2019 Fall Promotion', 0.20, '20191001', '20191101'),
('2019 Winter Promotion', 0.25, '20191201', '20200101');
因为不存在
条款将适用于所有行,而我需要行进行行:
WHERE NOT EXISTS (SELECT * FROM sales.promotions
WHERE promotion_name = 'Winter Promotion');
对不起,如果这很明显,不是太擅长SQL,我不确定如何为适当的研究介绍这个问题。
I am looking to insert multiple rows if they don't EXIST
in the target table. But I'm not sure how do this with the following code:
INSERT INTO sales.promotions(
promotion_name,
discount,
start_date,
expired_date
)
VALUES
('2019 Summer Promotion', 0.15, '20190601', '20190901'),
('2019 Fall Promotion', 0.20, '20191001', '20191101'),
('2019 Winter Promotion', 0.25, '20191201', '20200101');
Because the WHERE NOT EXIST
clause would apply to ALL rows whereas I need to do it row by row:
WHERE NOT EXISTS (SELECT * FROM sales.promotions
WHERE promotion_name = 'Winter Promotion');
Sorry if this is painfully obvious, not too good at SQL and I'm not really sure how to word this question for proper research.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用表值构造函数带有
的存在
:It is possible to use table value constructor with
exists
: