Problems with SQL Server calling stored procedures sp_rename

Source: Internet
Author: User
Tags table name

Environment: SQL Server 2008 R2

Problem: When calling stored procedure sp_rename "parameter @objname ambiguous or declared @objtype (column) is incorrect".

Solve:

Look at the following commands, if you first execute the first two sentences, and then execute the third sentence what will happen?

Use test;--the database  
sp_rename ' D_s_t.avg_grade ', ' avg_g ', ' column ';--d_s_t is the table name, Avg_grade is the original column name, and Avg_g is the new column name  
exec Sp_rename ' D_s_t.avg_grade ', ' avg_g ', ' column ';

Yes, you're right. will report the error as described above.

Since you executed the second sentence, your original column has changed the name, and you can't find it again with the original column.

If the third sentence is to be further implemented, it can be changed to read:

exec sp_rename ' d_s_t. 

Avg_g ', ' avg_g_new ', ' column ';

PS: Oh, this error is due to their carelessness, so the programmer must have a meticulous heart.

Related Article

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.