1

Looks kind a stupid question but I have been stuck here for an hour.

I create a user defined function from Query window in SQL Server Management Studio with following statement:

CREATE  FUNCTION fnTest()
RETURNS int
AS
BEGIN
    return 123;

END

Function creates successfully and I can see it in SQL object browser as here:

enter image description here

But function isn't available for use in that database.

enter image description here Interestingly when I try to Alter function by right clicking the function, function script loads with error message:

enter image description here

Can somebody give me an idea what I am missing here?

EDIT: It really turned to be a stupid question. There is no error in function name, script, execution or Alter script. Everything is fine. Only SQL Editor is incorrectly showing error and I was confused by the editor error message. I apologies to everybody who spent time.

WSK
  • 5,949
  • 8
  • 49
  • 74

1 Answers1

2

Why didn't you specify dbo. when you created the function? My guess is that, because you didn't do so, the function was created in your default schema, which is not dbo.

The only other possibility I can think of is that you are trying to execute the code in the context of the wrong database.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490