How should I use BIT in SQL Server 2005

Regarding SQL performance.

I have a scalar value function to check some specific conditions in the database, it returns a BIT value for True or False.

Now I do not know how I should fill the @BIT parameter

If I write.

set @bit = convert(bit,1)

or

set @bit = 1

or

set @bit='true'
Function

will work anyway, but I donโ€™t know which method is recommended for daily use.

Another question: I have a table in my database with about 4 million records, daily insertion is about 4K records in this table.

Now I want to add CONSTRAINT to this table with a scalar function that I already mentioned

Something like that

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 the fin_stavke table, 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

SQL ?

, , .

+5
4

, , - , , doc_id protocol_id NULL?

, .

ALTER TABLE fin_stavke
ADD CONSTRAINT fin_stavke_knjizenje CHECK ( doc_id IS NOT NULL OR protocol_id IS NOT NULL)
+4

 set @bit = 1

( true ) .

+2

, 1 0. . , .

, , . , , , .

+1

โ€‹โ€‹ :

set @bit = 1

, , :

set @bit = cast(1 as bit)

, , , . .

+1

All Articles