Inline Table Valued Functions in Check Constraints

  • I know you can use UDFs in Check Constraints but could you use an Inline Table valued Function in a CHeck constraint like:

    (Column in (select * from fnTableData))

  • What did SQL Server tell you when you tried?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • So far I've gotten this:

    Subqueries are not supported in CHECK constraints

  • I would say that your answer is NO then. Check Constraints do not support the use of inline table valued functions.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • John,

    I would say that your answer of NO is probably correct. Although I am no SQL master so maybe there is a way around it...

  • In this case, not by using a CHECK Constraint (that I know of). You are limited to using a trigger to validate your data or add the checking logic to your INSERT/UPDATE stored procedures if you are using SPs exclusively to handle INSERT/UPDATEs.

    Why not use a foreign key relation to your other table? Wouldn't that serve the same purpose?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • AVB (12/7/2007)


    John,

    I would say that your answer of NO is probably correct. Although I am no SQL master so maybe there is a way around it...

    Simple scalar function which returns 1 if parameter is in the range, 0 if it's not.

    Constraint will look like this:

    dbo.CheckFunction (CheckedColumn) = 1

    _____________
    Code for TallyGenerator

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply