title: How I should use BIT in SQL Server 2005
body: <p>Regarding to SQL performance.</p>
  
  <p>I have a scalar valued function for checking some specific condition in base, it returns BIT value for True or False.</p>
  
  <p>I now do not know how I should fill @BIT parameter </p>
  
  <p>If I write.</p>
  
  <pre><code>set @bit = convert(bit,1)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>set @bit = 1
  </code></pre>
  
  <p>or </p>
  
  <pre><code>set @bit='true'
  </code></pre>
  
  <p>function will work anyway but I do not know which method is recommended for daily use.</p>
  
  <p>Another question, I have table in my base with around 4 million records, daily insert is about 4K records in that table.</p>
  
  <p>Now I want to add CONSTRAINT on that table with scalar valued function that I mentioned already</p>
  
  <p>Something like this</p>
  
  <pre><code>ALTER TABLE fin_stavke
  ADD CONSTRAINT fin_stavke_knjizenje CHECK ( dbo.fn_ado_chk_fin(id)=convert(bit,1))
  </code></pre>
  
  <p>where "id" is the primary key of table fin_stavke and dbo.fn_ado_chk_fin looks like</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Will this type and method of checking constraint will affect badly performance on my table and SQL at all ?</p>
  
  <p>If there is also better way to add control on this table please let me know.</p>