Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Unexecutable sequence

Author  Topic 

tomino79
Starting Member

13 Posts

Posted - 2005-09-12 : 10:31:21
Hi, try to write this to your SQL Query Analyzer and you will get an error message:

create table aaa ( i int)
insert into aaa ( i ) values ( 2 )
alter table aaa add j int
insert into aaa ( i,j ) values ( 2,3 )

The first time you execute the query you get Unknown column "j". Then when you execute every step everything is ok. (I know maybe it cannot be in one batch because when the select is preparing he doesnt know that the i will be there, but why ???) BUT HTE PROBLEM IS:
When you then drop the table and try to execute the whole sequence as a batch, there is NO ERROR. (Is SQL Server remembering something about table aaa???) And then you can execute the sequence as many times as you wish, you will not get any error messages.
It is very strange, and I couldnt find any explanation for it on MSDN.
Can anybody help me with that ?

Tomas.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-09-12 : 10:33:15
put "go" between statements

Go with the flow & have fun! Else fight the flow
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-12 : 10:34:33
After Alter statement use Go

alter table aaa add j int
Go
insert into aaa ( i,j ) values ( 2,3 )


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

tomino79
Starting Member

13 Posts

Posted - 2005-09-12 : 10:48:47
But I cant put directly GO to the sequence, because GO is only a SQL Query Analyzer Statement.I am executing this query through ADO Command.

But anyway, that is not important, because after the separate execution (with go) you can simply remove go and it will work..
You know what is strange in this case.. That the SQLSrv acts different in the first time then the other. Because after executing it with go, you can remove GO, and execute it as a whole sequence.

Tom.

Thanks for help, I was looking for some theoretical explanation (cache ? has SQL Server cached that aaa will have i and j columns so in the step of generating execution plan it will not raise an error ? )

Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-09-13 : 05:17:35
GO is a job seperator...not a T-SQL command. The code fails without the GO, because at 'plan generation stage', the 'J' column doesn't exist. Basically you're hitting a problem because you're adding columns on the fly....."don't" is the best advice.
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2005-09-13 : 05:26:26
Wow! That was a long post to ask for the statement terminator in ADO. That would be the humble semi-colon ;.
Works in the SqlClient classes too.

DavidM

A front-end is something that tries to violate a back-end.
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2005-09-13 : 08:23:56
Creating and Altering tables from ADO? *shudder*

Help us help YOU!
Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

*need more coffee*
SELECT * FROM Users WHERE CLUE > 0
(0 row(s) affected)
Go to Top of Page
   

- Advertisement -