Skip to content

Conversation

@srutzky
Copy link
Contributor

@srutzky srutzky commented Feb 26, 2020

This PR fixes Issue #4219

Previous wording:

READONLY
Indicates that the parameter cannot be updated or modified within the definition of the function. If the parameter type is a user-defined table type, READONLY should be specified.

implied that the READONLY keyword:

  1. could be used by parameter types other than user-defined table types (TVPs)
  2. was optional (even if recommended) for user-defined table types (TVPs)

The following tests prove both implications are incorrect, and that READONLY is;

  1. not optional for user-defined table types
  2. not valid for other parameter types
USE [tempdb];

------------------------------------------

GO
CREATE PROCEDURE dbo.TestReadOnlyWithNonTVP
(
	@Param INT = 5 READONLY
)
AS

SELECT @Param;
GO
/*
Msg 346, Level 15, State 1, Procedure TestReadOnlyWithNonTVP, Line XX [Batch Start Line YY]
The parameter "@Param" can not be declared READONLY since it is not a table-valued parameter
*/

------------------------------------------

CREATE TYPE dbo.TestTableType AS TABLE
(
	Col INT
);


GO
CREATE PROCEDURE dbo.TestNoReadOnlyWithTVP
(
	@Param dbo.TestTableType
)
AS

SELECT * FROM @Param;
GO
/*
Msg 352, Level 15, State 1, Procedure TestNoReadOnlyWithTVP, Line XX [Batch Start Line YY]
The table-valued parameter "@Param" must be declared with the READONLY option.
*/

------------------------------------------

Take care,
Solomon...
https://SqlQuantumLift.com/
https://SqlQuantumLeap.com/
https://SQLsharp.com/

Previous wording implied that the `READONLY` keyword:

1. could be used by parameter types other than user-defined table types (TVPs)
2. was optional for user-defined table types (TVPs)
@PRMerger20
Copy link
Contributor

@srutzky : Thanks for your contribution! The author(s) have been notified to review your proposed change.

@ktoliver ktoliver added the aq-pr-triaged tracking label for the PR review team label Feb 26, 2020
@CarlRabeler CarlRabeler merged commit ec2dfd6 into MicrosoftDocs:live Feb 27, 2020
@srutzky srutzky deleted the patch-4 branch February 28, 2020 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants