An execution error occurs when the table variable name '[]' is added to the SQL server stored procedure.

Source: Internet
Author: User

Write the Stored Procedure (SQL Server 2005) in the previous work, declare a table variable, In the select... when using the from Table variable name, press ENTER plug-in SQL prompt 4 to automatically add [] brackets to the table variable name. At that time, I was not aware of any problems, if you press F5 to alter the stored procedure, no compilation error is prompted. An error occurred while executing the stored procedure:

 

Message 208, level 16, status 1, process Test2, 9th rows
The object name '@ temp_id' is invalid.

The stored procedure is as follows:

Code Set ansi_nulls on
Go
Set quoted_identifier on
Go
Create proc [DBO]. [Test2]
As
Declare @ temp_id table
(
[ID] [varchar] (18) not null
Primary Key
)

Begin try
Select *
From [@ temp_id]
End try
Begin catch
Print 'error occurred'
End catch

It is strange that SQL server does not report an error during the create or alter stored procedure. An error occurs when the stored procedure is executed. Moreover, this error cannot be caught by the try... Catch Block. What is the principle? I wonder if the cool guys in the yard can explain it?

Therefore, after creating and modifying the stored procedure, you can try to execute it and see if there is any error.

 

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.