相關(guān)的OBJECTPROPERTY可參考:http://msdn.microsoft.com/en-us/library/ms176105.aspx
開發(fā)過程中,錯誤免不了。為了糾正錯誤與規(guī)范化??梢允褂肕S SQL Server的系統(tǒng)存儲過程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'
執(zhí)行成功之后,你會收到一條信息:
Caution: Changing any part of an object name could break scripts and stored procedures.
您可能感興趣的文章:- Windows Server 2007四月CTP發(fā)布 下載
- SQL Server 2016 CTP2.3 的關(guān)鍵特性總結(jié)