我有一个名为“ supported_languages”的表,如下所示:
-----------------------------------------------------------
language_ref | language _name | language_active |
-----------------------------------------------------------
en | English | Y |
-----------------------------------------------------------
es | Espanol | Y |
-----------------------------------------------------------
fr | Francias | Y |
-----------------------------------------------------------
he | hebrew | NULL |
-----------------------------------------------------------
我想创建一个查询,该查询将仅将英语设置为有效。仅当以下三种语言-en,es,fr处于活动状态(Y)并且“ he”语言为空时(与提供的表格相同)。仅在这种情况下-将“ language_active”下的所有内容更改为N,并使英语成为唯一有效的语言。
有什么帮助吗?
谢谢!
答案 0 :(得分:0)
您需要将类似的内容放入更新触发器中。
if exists (select * from supported_languages where language_ref = 'en' and language_active = 'Y')
and exists (select * from supported_languages where language_ref = 'es' and language_active = 'Y')
and exists (select * from supported_languages where language_ref = 'fr' and language_active = 'Y')
and exists (select * from supported_languages where language_ref = 'he' and language_active = 'N')
update supported_languages set language_active = 'N'
where language_ref = 'es' or language_ref = 'fr'