Allan
asked on
Check and Create UDF
HI Experts,
This should be easy. How to check if udf exist, if not then create a blank udf.
IF NOT EXISTS (select name
from sysobjects
where type in ('FN', 'IF', 'TF')
and name = 'Some_udf')
EXEC('CREATE FUNCTION dbo.Some_udf AS RETURN 0')
GO
-- The Alter Statement goes here
ALTER FUNCTION [dbo].Some_udf
(
@blah01 CHAR(13),
@blah02 CHAR(2)
)
RETURNS CHAR(2)
AS
BEGIN
END
RETURN ....
This should be easy. How to check if udf exist, if not then create a blank udf.
IF NOT EXISTS (select name
from sysobjects
where type in ('FN', 'IF', 'TF')
and name = 'Some_udf')
EXEC('CREATE FUNCTION dbo.Some_udf AS RETURN 0')
GO
-- The Alter Statement goes here
ALTER FUNCTION [dbo].Some_udf
(
@blah01 CHAR(13),
@blah02 CHAR(2)
)
RETURNS CHAR(2)
AS
BEGIN
END
RETURN ....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Correct, so you can check for non-existence and create as you were but then you would have to explicitly GRANT permissions in that case; therefore, you can always drop and then after creation add GRANT statements you need.
ASKER
THanks. Seems that's more work than using Alter -- permission is set once and you don't have to deal with it.
ASKER
Thanks for all your help!
ASKER
splitting points ..
ASKER
correct me if i'm wrong; one reason why i don't want to drop is because the object will lose it's permission if dropped.