ObjectProperty and sp_rename Change the description of the object name _mssql

Source: Internet
Author: User

Related OBJECTPROPERTY may refer to: http://msdn.microsoft.com/en-us/library/ms176105.aspx

Mistakes are unavoidable in the development process. In order to correct errors and normalization. You can use MS SQL Server's system stored procedures sp_rename and OBJECTPROPERTY to change the rename.

Instance one, change the table name:

Copy Code code as follows:

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 '



instance two, change the field name:

Copy Code code as follows:

EXECUTE sp_rename ' member. [EmployeeName] ', ' Name ', ' COLUMN '



instance three, change the primary key:

Copy Code code as follows:

IF EXISTS (SELECT top 1 1 sysobjects WHERE id = object_id (N ' [pk__employee__b00879c509746778] ')
and OBJECTPROPERTY (ID, N ' isprimarykey ') = 1)
EXECUTE sp_rename ' pk__employee__b00879c509746778 ', ' pk_member ', ' OBJECT '



instance four, change the stored procedure name:

Copy Code code as follows:

IF EXISTS (SELECT top 1 1 sysobjects WHERE id = object_id (N ' [Usp_employee_import] ')
and OBJECTPROPERTY (ID, N ' isprocedure ') = 1)
EXECUTE sp_rename ' usp_employee_import ', ' MEMBERINSSP '



After successful execution, you will receive a message:

Caution:changing any part of the object name could break scripts and stored procedures.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.