Improve company productivity with a Business Account.Sign Up
CREATE FUNCTION [dbo].[chk_ParentOrder](@DetID int) RETURNS int AS
if exists (
SELECT 1 FROM cons where ConID=DetID
SELECT 1 FROM coms where ComID=DetID
) return 1 else return 0;
Open in new window
ALTER TABLE [Order]
ADD CONSTRAINT chkParentItem CHECK (dbo.chk_ParentOrder(DetID) != 0 );
Be seen. Boost your question’s priority for more expert views and faster solutions
CREATE FUNCTION [dbo].[chk_ParentOrder](@RefNo Varchar(21)) RETURNS int AS
declare @result int =0;
set @result=sign ((SELECT count(1) FROM cons where ConID=@RefNo) + (SELECT count(1) FROM comm where ComID=@RefNo));
CREATE TRIGGER [dbo].[trg_DelCom] ON [dbo].[Comm] FOR DELETE AS
IF Exists (select 1 from [Order] where DetID in (select ComID from deleted))
RAISERROR( 'Children exists!', 16, 2 )
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.