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 768717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:13:25+00:00 2026-05-14T18:13:25+00:00

Regarding to SQL performance. I have a scalar valued function for checking some specific

  • 0

Regarding to SQL performance.

I have a scalar valued function for checking some specific condition in base, it returns BIT value for True or False.

I now do not know how I should fill @BIT parameter

If I write.

set @bit = convert(bit,1)

or

set @bit = 1

or

set @bit='true'

function will work anyway but I do not know which method is recommended for daily use.

Another question, I have table in my base with around 4 million records, daily insert is about 4K records in that table.

Now I want to add CONSTRAINT on that table with scalar valued function that I mentioned already

Something like this

ALTER TABLE fin_stavke
ADD CONSTRAINT fin_stavke_knjizenje CHECK ( dbo.fn_ado_chk_fin(id)=convert(bit,1))

where “id” is the primary key of table fin_stavke and dbo.fn_ado_chk_fin looks like

create FUNCTION fn_ado_chk_fin
(
    @stavka_id int
)
RETURNS bit
AS
BEGIN
declare @bit bit

if exists (select * from fin_stavke where id=@stavka_id and doc_id is null and protocol_id is null)
        begin
            set @bit=0


        end
    else
        begin
            set @bit=1
        end
return @bit;
END
GO

Will this type and method of checking constraint will affect badly performance on my table and SQL at all ?

If there is also better way to add control on this table please let me know.

  • 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-14T18:13:25+00:00Added an answer on May 14, 2026 at 6:13 pm

    I might be wrong but from the looks of it, it seems you only want to check that not both doc_id and protocol_id are NULL?

    You can add a table constraint to achieve this.

    ALTER TABLE fin_stavke
    ADD CONSTRAINT fin_stavke_knjizenje CHECK ( doc_id IS NOT NULL OR protocol_id IS NOT NULL)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When reading about SQL Injection and XSS i was wondering if you guys have
After reading a couple of answers and comments on some SQL questions here, and
I was reading about refactoring a large slow SQL Query over here , and
I am reading in CSV file and translating it to an SQL Table. The
I'm reading data from a table( from a MySQL Database) with Hibernate SQL Query.
Regarding the same program as my question a few minutes ago ... I added
Regarding cross-site request forgery (CSRF) attacks, if cookies are most used authentication method, why
Question regarding how to setup dbase relationships (newbie, this may be trivial) Followed the
Recently Jeff has posted regarding his trouble with database deadlocks related to reading. Multiversion
Following my question regarding a .NET YAML Library ... as there doesn't seem to

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.