TSQL函数和Check约束以确保表中存在父值
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TSQL函数和Check约束以确保表中存在父值相关的知识,希望对你有一定的参考价值。
If a "InReplyToID" is provided, it must be a valid MessageId
ALTER TABLE [dbo].[Message] WITH CHECK ADD CONSTRAINT [CK_Message] CHECK (([InReplyToId] IS NULL OR [dbo].[CheckInReplyToMessageId]([InReplyToId])>=(0))) GO ALTER TABLE [dbo].[Message] CHECK CONSTRAINT [CK_Message] CREATE FUNCTION [dbo].[CheckInReplyToMessageId] ( @MessageId BIGINT ) RETURNS bit AS BEGIN DECLARE @RetVal bit SET @RetVal = (SELECT MessageId FROM Message WHERE MessageId = @MessageId) RETURN isnull(@RetVal, 0) END
以上是关于TSQL函数和Check约束以确保表中存在父值的主要内容,如果未能解决你的问题,请参考以下文章