I am using SQL Server 2005 and in one of the tables i have a column that stores stored proc name. While inserting values in that column I want to ensure that a stored proc of that name exists in the database.
ALTER TABLE MyTable WITH CHECK
ADD CONSTRAINT [CK_MyTable_MyColumn] CHECK ((SELECT COUNT(*) FROM sys.sysobjects WHERE id = object_id(MyColumn) AND OBJECTPROPERTY(id, N'IsProcedure')=1) = 1)
but this gives the following error
Subqueries are not allowed in this
context. Only scalar expressions are
allowed.
How can I do this.
Functions are allowed: