procedures key icon Procedure: sp_alterdiagram

Properties

Property Value
Name sp_alterdiagram
ID 1671677003
Schema dbo
Owner dbo
Type SQL STORED PROCEDURE
Execute As dbo
Encrypted false
ANSI NULLS true
Uses Quoted Identifier true
Published false
Schema Published false
Execution Replicated false
Replication Serializable Only false
Skips Replication Constraints false
Is Recompiled false
Uses Database Collation false
Null on Null Input false
MS Shipped false
Modify Date 6/20/2011 3:16:00 PM
Create Date 6/20/2011 3:16:00 PM

Extended Properties

No extended properties defined.

Permissions

Permissions for: guest

Permission Grantor Grant With Grant Option Deny
Alter
Control
Execute dbo true
Take Ownership
View Definition

Permissions for: public

Permission Grantor Grant With Grant Option Deny
Alter
Control
Execute dbo true
Take Ownership
View Definition

Parameters

Parameter Name Datatype Output Cursor Ref Readonly Has Default Value Default Value Xml Collection Name Description
@diagramname sysname false false false false
@owner_id int false false false false
@version int false false false false
@definition varbinary(max) false false false false

Objects that depend on [sp_alterdiagram]

Objects on which [sp_alterdiagram] depends

SQL

Script
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE PROCEDURE dbo.sp_alterdiagram ( @diagramname sysname, @owner_id int = null, @version int, @definition varbinary(max) ) WITH EXECUTE AS 'dbo' AS BEGIN set nocount on declare @theId int declare @retval int declare @IsDbo int declare @UIDFound int declare @DiagId int declare @ShouldChangeUID int if(@diagramname is null) begin RAISERROR ('Invalid ARG', 16, 1) return -1 end execute as caller; select @theId = DATABASE_PRINCIPAL_ID(); select @IsDbo = IS_MEMBER(N'db_owner'); if(@owner_id is null) select @owner_id = @theId; revert; select @ShouldChangeUID = 0 select @DiagId = diagram_id, @UIDFound = principal_id from dbo.sysdiagrams where principal_id = @owner_id and name = @diagramname if(@DiagId IS NULL or (@IsDbo = 0 and @theId <> @UIDFound)) begin RAISERROR ('Diagram does not exist or you do not have permission.', 16, 1); return -3 end if(@IsDbo <> 0) begin if(@UIDFound is null or USER_NAME(@UIDFound) is null) -- invalid principal_id begin select @ShouldChangeUID = 1 ; end end -- update dds data update dbo.sysdiagrams set definition = @definition where diagram_id = @DiagId ; -- change owner if(@ShouldChangeUID = 1) update dbo.sysdiagrams set principal_id = @theId where diagram_id = @DiagId ; -- update dds version if(@version is not null) update dbo.sysdiagrams set version = @version where diagram_id = @DiagId ; return 0 END
EXEC sys.sp_addextendedproperty @name=N'microsoft_database_tools_support', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'PROCEDURE',@level1name=N'sp_alterdiagram'

See also

List of Procedures