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'
Functionwill 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 ?
, , .