ALTER TABLE [TABLE NAME}
ADD CONSTRAINT [NAME OF THE CHECK CONSTRAINT)
CHECK(dbo.<Name of the Function> (<Key Column Name>) = 1)
CREATE FUNCTION [dbo].[fnCheckTable01]
(@Table01ID int)
RETURNS bit
AS
BEGIN
IF EXISTS(SELECT * FROM Table01 (NOLOCK) WHERE Table01ID = @Table01ID)
RETURN 1
RETURN 0
END
GO
Comments