I’m working on a local and a remote SQL Server instance with SSMS. I create a tiny function like:
create function ufnTestFunc ()
returns int
begin
return 1
end
When I try to ‘modify’ it, or choose ‘script function as -> alter’, I get an error like:
Script failed for UserDefinedFunction ‘dbo.ufnTestFunc’.
(Microsoft.SqlServer.Smo)– Syntax error in TextHeader of UserDefinedFunction ‘ufnTestFunc’.
(Microsoft.SqlServer.Smo)
This also happens on already existing functions. What may be the reason?
Notes:
- All the functions work as intended
- I can script the function as ‘create’ with no problem.
- It’s not related with comments, as there are no comments in the test function
- Same happens with different DBs on the remote server
Local Server:
Microsoft SQL Server Express Edition (64-bit) – 10.50.2500.0
Remote Server:
Microsoft SQL Server Web Edition (64-bit) – 10.50.1600.1
SSMS:
Microsoft SQL Server Management Studio 10.50.2500.0
Microsoft Data Access Components (MDAC) 6.1.7601.17514
Microsoft MSXML 3.0 6.0
Microsoft .NET Framework 2.0.50727.5448
Ok like someone mentioned before, but with a little difference.
The problem is the
ASkeyword. Although theASkeyword before the function content is optional, SSMS can’t handle functions without it. They work, but make trouble. It’s a bug and not mentioned anywhere in the BOL.I normally use the
ASkeyword, but this time the DB is from a previous coder, who didn’t use it. In my test function I also didn’t use it to make the function as small as possible.