So, I added a default value for a column in my table. the default value is the result of a function. for example:
--drop table t2
create table t2
(
id datetime2 default(dbo.idDT()),
v nvarchar(50)
)
It's ok. But, if I need to use the same funcion in a another db? If I try to add the db, SQL gives me error.
--drop table t2
create table t2
(
id datetime2 default(database.dbo.idDT()),
v nvarchar(50)
)
The trick I used is create a function that recall the function in the db like this:
CREATE FUNCTION [dbo].[idDT2]()
RETURNS datetime2
AS
BEGIN
return dbo.iddt()
END
and then:
--drop table t2
create table t2
(
id datetime2 default(dbo.idDT2()),
v nvarchar(50)
)
but performance are not good (at least 2x slow). There is a better trick??
or, could be be possible to improve the preformance calling function?