| Property | Value |
|---|---|
| Name | sp_renamediagram |
| ID | 1655676946 |
| Schema | dbo |
| Owner | dbo |
| Type | SQL STORED PROCEDURE |
| Execute As | dbo |
| Encrypted |
|
| ANSI NULLS |
|
| Uses Quoted Identifier |
|
| Published |
|
| Schema Published |
|
| Execution Replicated |
|
| Replication Serializable Only |
|
| Skips Replication Constraints |
|
| Is Recompiled |
|
| Uses Database Collation |
|
| Null on Null Input |
|
| MS Shipped |
|
| Modify Date | 6/20/2011 3:16:00 PM |
| Create Date | 6/20/2011 3:16:00 PM |
| Permission | Grantor | Grant | With Grant Option | Deny |
|---|---|---|---|---|
| Alter | ||||
| Control | ||||
| Execute | dbo |
|
||
| Take Ownership | ||||
| View Definition |
| Permission | Grantor | Grant | With Grant Option | Deny |
|---|---|---|---|---|
| Alter | ||||
| Control | ||||
| Execute | dbo |
|
||
| Take Ownership | ||||
| View Definition |
| Parameter Name | Datatype | Output | Cursor Ref | Readonly | Has Default Value | Default Value | Xml Collection Name | Description |
|---|---|---|---|---|---|---|---|---|
| @diagramname | sysname |
|
|
|
|
|||
| @owner_id | int |
|
|
|
|
|||
| @new_diagramname | sysname |
|
|
|
|
| Script |
|---|
| SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON CREATE PROCEDURE dbo.sp_renamediagram ( @diagramname sysname, @owner_id int = null, @new_diagramname sysname ) WITH EXECUTE AS 'dbo' AS BEGIN set nocount on declare @theId int declare @IsDbo int declare @UIDFound int declare @DiagId int declare @DiagIdTarg int declare @u_name sysname if((@diagramname is null) or (@new_diagramname is null)) begin RAISERROR ('Invalid value', 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 @u_name = USER_NAME(@owner_id) 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 @UIDFound <> @theId)) begin RAISERROR ('Diagram does not exist or you do not have permission.', 16, 1) return -3 end -- if((@u_name is not null) and (@new_diagramname = @diagramname)) -- nothing will change -- return 0; if(@u_name is null) select @DiagIdTarg = diagram_id from dbo.sysdiagrams where principal_id = @theId and name = @new_diagramname else select @DiagIdTarg = diagram_id from dbo.sysdiagrams where principal_id = @owner_id and name = @new_diagramname if((@DiagIdTarg is not null) and @DiagId <> @DiagIdTarg) begin RAISERROR ('The name is already used.', 16, 1); return -2 end if(@u_name is null) update dbo.sysdiagrams set [name] = @new_diagramname, principal_id = @theId where diagram_id = @DiagId else update dbo.sysdiagrams set [name] = @new_diagramname 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_renamediagram' |