Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 223447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:13:20+00:00 2026-05-11T19:13:20+00:00

Does table constraints execute in the same transaction? I have a transaction with Read

  • 0

Does table constraints execute in the same transaction?

I have a transaction with Read Committed isolation level which inserts some rows in a table. The table has a constraint on it that calls a function which in turn selects some rows from the same table.

It looks like the function runs without knowing anything about the transaction and the select in the function returns rows in the table which were there prior to the transaction.

Is there a workaround or am I missing anything? Thanks.

Here are the codes for the transaction and the constraint:

insert into Treasury.DariaftPardakhtDarkhastFaktor
    (DarkhastFaktor, DariaftPardakht, Mablagh, CodeVazeiat, 
    ZamaneTakhsiseFaktor, MarkazPakhsh, ShomarehFaktor, User) 
values
    (@DarkhastFaktor, @DariaftPardakht, @Mablagh, @CodeVazeiat,
    @ZamaneTakhsiseFaktor, @MarkazPakhsh, @ShomarehFaktor, @User);


constraint expression (enforce for inserts and updates):
([Treasury].[ufnCheckDarkhastFaktorMablaghConstraint]([DarkhastFaktor])=(1))

ufnCheckDarkhastFaktorMablaghConstraint:

returns bit
as
begin
    declare @SumMablagh float
    declare @Mablagh    float

    select @SumMablagh = isnull(sum(Mablagh), 0)
    from Treasury.DariaftPardakhtDarkhastFaktor
    where DarkhastFaktor= @DarkhastFaktor

    select @Mablagh = isnull(MablaghKhalesFaktor, 0) 
    from Sales.DarkhastFaktor
    where DarkhastFaktor= @DarkhastFaktor

    if @Mablagh - @SumMablagh < -1
      return 0

    return 1
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:13:20+00:00Added an answer on May 11, 2026 at 7:13 pm

    Check constraints are not enforced for delete operations, see http://msdn.microsoft.com/en-us/library/ms188258.aspx

    CHECK constraints are not validated
    during DELETE statements. Therefore,
    executing DELETE statements on tables
    with certain types of check
    constraints may produce unexpected
    results.

    Edit – to answer your question on workaround, you can use a delete trigger to roll back if your function call shows an invariant is broken.

    Edit #2 – @reticent, if you are adding rows then the function called by the check constraint should in fact see the rows. If it didn’t, check constraints would be useless. Here is a simple example, you will find that the first 2 inserts succeed and the third fails as expected:

    create table t1 (id int)
    go
    create function t1_validateSingleton () 
    returns bit
    as
    begin
    declare @ret bit
    set @ret = 1
    if exists (
        select count(*)
        from t1
        group by id
        having count(*) > 1
    )
    begin
        set @ret = 0
    end
    return (@ret)
    end
    go
    alter table t1
    add constraint t1_singleton
        check (dbo.t1_validateSingleton()=1)
    go
    insert t1 values (1)
    insert t1 values (2)
    insert t1 values (1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Raw objects in AS3 (Object class, or things defined by… May 12, 2026 at 12:26 am
  • Editorial Team
    Editorial Team added an answer Start learning Asp.net MVC as soon as possible. Designers will… May 12, 2026 at 12:26 am
  • Editorial Team
    Editorial Team added an answer This is actually a much more challenging question than it… May 12, 2026 at 12:26 am

Related Questions

Environment I'm working on a C++ application that uses SQL Native Client 9.0 to
My primary question is which approach is faster. Some briefing I'm developing an application
I'm using a custom-built inhouse application that generates a standard set of reports on
Does anyone know of a good javascript menu using the prototype library. I need

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.