官方解释如下,我到现在都还没有搞清楚是为什么,我没有像下面所讲的那样执行两个同样的SELECT INTO语句,还是报这个错,而且我用第一种方法改了过后,只有第一次测试通过了,后面又出现这个问题,后来换成第二种方式,测试了几遍,到目前为止,还没有出现错误。另外,我是用JDBC来执行的SQL语句,我把没有使用第一种和第二种的SQL语句(原始SQL)放到SQL SERVER自带的查询分析器里面执行, 是不会报这个错的,请高手指点一下http://support.microsoft.com/kb/323586/en-us
A SELECT INTO query may return the following error message
- You run the same SELECT INTO query twice and separately.
- In between the two executions, you perform an operation that causes SQL Server to recompile the second SELECT INTO query.
To work around this problem, add the option KEEP PLAN after the second SELECT INTO statement, or change the current database to the target database before you run SELECT INTO statements.
For example, you can add the KEEP PLAN option, or specify the target database before you run the SELECT INTO statement:
Example:
Instead of using the following:
select * into test2..t2 from test1..t1
select * into test2..t2 from test1..t1 option (keep plan)
use test2
go
select * into test2..t2 from test1..t1