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.