Sub queries in check constraint
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have table designed in SQL-Server 2008 R2. I have a column in that table which needs to be checked against another table when data is inserting. ALTER TABLE Table1 WITH CHECK ADD CONSTRAINT CK_Code CHECK (MyField in (Select Field From Table2)) This cause an error Sub-queries are not allowed in this context. Only scalar expressions are allowed. I have looked at this question about Check Constraint - Subqueries are not allowed in this context . Is there any way of achieving this without using a trigger? 回答1: Note, what you really want is a