Skip to content

Conversation

@srutzky
Copy link
Contributor

@srutzky srutzky commented Jan 10, 2018

sys.sql_modules

Added link to OBJECT_DEFINITION page in the "Description" column for definition. Execute the following to see that OBJECT_DEFINITION is the source for the definition column:

EXEC sp_helptext N'sys.sql_modules';

But even if it wasn't the source, it still outputs the same value.

ALTER SCHEMA and sp_rename

  1. Added reference to OBJECT_DEFINITION function page for sp_rename.
  2. Changed "schema-contained" to be "schema-scoped" to be consistent with OBJECT_NAME and OBJECT_SCHEMA_NAME documentation (and most likely other pages)
  3. Copied two paragraphs of Remarks from sp_rename documentation and adjusted to pertain to this context
  4. Removed "or view" from SSMS instructions since first new Remarks paragraph recommends against using ALTER SCHEMA on views 😉
  5. Fixed IMPERSONATION permission (which doesn't exist) to be the actual IMPERSONATE permission
  6. Please see related blog post containing explanation and example code / proof:
    Stored Procedure / Function / View / Trigger Definitions Can Be Wrong, Even If sp_rename Was Never Used

ALTER SCHEMA

Relating to the advice about the need to manually update referenced objects that have been transferred / moved, please execute the following:

USE [tempdb];

GO
CREATE SCHEMA [TransferTest];
GO

CREATE TABLE [TransferTest].[MoveMe] ([Col1] INT);

GO
CREATE PROCEDURE [TransferTest].[SelectFromMoveMe]
AS
SET NOCOUNT ON;
SELECT [Col1] FROM [TransferTest].[MoveMe];
GO

EXEC [TransferTest].[SelectFromMoveMe];

ALTER SCHEMA [dbo] TRANSFER [TransferTest].[MoveMe];

SELECT * FROM [dbo].[MoveMe];

EXEC [TransferTest].[SelectFromMoveMe];
/*
Msg 208, Level 16, State 1, Procedure TransferTest.SelectFromMoveMe, Line X [Batch Start Line Y]
Invalid object name 'TransferTest.MoveMe'.
*/

`OBJECT_DEFINITION` is the actual source for the `definition` column here.
This function is the source of the `sys.sql_modules.definition` column anyway.
1. Changed "schema-contained" to be "schema-scoped" to be consistent with https://docs.microsoft.com/en-us/sql/t-sql/functions/object-name-transact-sql and https://docs.microsoft.com/en-us/sql/t-sql/functions/object-schema-name-transact-sql

2. Copied two paragraphs of remarks from https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-rename-transact-sql and adjusted to be appropriate in this context

3. Removed "or view" from SSMS instructions since first new "caution" paragraph recommends against using `ALTER SCHEMA` on views.

4. Fixed `IMPERSONATION` permission (which doesn't exist) to be the actual `IMPERSONATE` permission
@PRMerger3
Copy link
Contributor

@srutzky : Thanks for your contribution to the SQL documentation! The author, @edmacauley, has been notified to review your proposed change.

@edmacauley
Copy link
Contributor

Thanks @srutzky for your clarity edits. #sign-off

@PRMerger18
Copy link
Contributor

Only the author, @edmaca, can sign off on this pull request.

@craigg-msft
Copy link
Contributor

Thank you @srutzky and @edmacauley

@craigg-msft craigg-msft merged commit 23b60a4 into MicrosoftDocs:live Jan 17, 2018
@srutzky
Copy link
Contributor Author

srutzky commented Jan 18, 2018

@edmacauley and @craigg-msft : you are quite welcome 😄 .

@srutzky srutzky deleted the SRutzky-ImproveAlterSchema branch January 18, 2018 00:04
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.

5 participants