Home >Database >Mysql Tutorial >OBJECTPROPERTY与sp_rename更改对象名称的介绍

OBJECTPROPERTY与sp_rename更改对象名称的介绍

WBOY
WBOYOriginal
2016-06-07 18:04:401189browse

开发过程中,错误免不了。为了纠正错误与规范化。可以使用MS SQL Server的系统存储过程sp_rename与OBJECTPROPERTY来更改重命名

相关的OBJECTPROPERTY可参考:

开发过程中,错误免不了。为了纠正错误与规范化。可以使用MS SQL Server的系统存储过程sp_rename与OBJECTPROPERTY来更改重命名。

实例一,更改表名:
代码如下:
IF EXISTS(SELECT TOP 1 1 FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[Employee]')
AND OBJECTPROPERTY(id, N'IsUserTable') = 1
)
EXECUTE sp_rename 'Employee', 'Member'



实例二,更改字段名:

代码如下:
EXECUTE sp_rename 'Member.[EmployeeName]', 'Name', 'COLUMN'



实例三,更改主键:

代码如下:
IF EXISTS(SELECT TOP 1 1 FROM sysobjects WHERE id = OBJECT_ID(N'[PK__Employee__B00879C509746778]')
AND OBJECTPROPERTY(id, N'IsPrimaryKey') = 1)
EXECUTE sp_rename 'PK__Employee__B00879C509746778', 'PK_Member', 'OBJECT'



实例四,更改存储过程名:

代码如下:
IF EXISTS(SELECT TOP 1 1 FROM sysobjects WHERE id = OBJECT_ID(N'[usp_Employee_Import]')
AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
EXECUTE sp_rename 'usp_Employee_Import', 'MemberInsSp'



执行成功之后,你会收到一条信息:

Caution: Changing any part of an object name could break scripts and stored procedures.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn