-2

I'm trying to use a certificate to sign a user-defined function in SQL server (2016). My code is as follows:

CREATE FUNCTION myfunction()  
RETURNS TABLE  
AS  
RETURN  
 SELECT col1, col2 FROM sometable;

GO

ADD SIGNATURE TO myfunction
BY CERTIFICATE [mycertificate] 

WITH PASSWORD = 'mypassword';

GO

The error message I'm getting is

Msg 15560, Level 16, State 1, Line 1 Cannot add or drop a signature on 'myfunction' because only modules can be signed.

Can anyone tell me what I'm doing wrong?

***** Edit ***** It worked when I rewrote the function so that it wasn't in inline format:

CREATE FUNCTION myfunction()
  RETURNS @tableVariable TABLE (
  col1 int NOT NULL,
  col2 varchar(255) NOT NULL
  )
WITH EXECUTE AS OWNER
AS
BEGIN
   INSERT INTO @tableVariable (col1, col2)
   SELECT s.col1, s.col2
   FROM sometable s
   RETURN;
END;
2

The documentation calls out that

Inline table-valued functions cannot be signed

1
  • 2
    Unless you print them out... Nov 18 '17 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.