all groups > sql server programming > march 2004 >
You're in the

sql server programming

group:

Invalid cursor state


Invalid cursor state Dean Slindee
3/13/2004 10:18:39 PM
sql server programming:
I get the following message when attempting to insert a new column into a
table in design mode:
- Unable to modify table.
ODBC error: [Microsoft][ODBC SQL Server Driver]Invalid cursor state

Only SQL Server 2000 is connected to the database.
What does this mean and how does one fix it?

Thanks,
Dean Slindee

Re: Invalid cursor state Aaron Bertrand [MVP]
3/14/2004 11:12:26 AM
Use ALTER TABLE from Query Analyzer.

Also see http://www.aspfaq.com/2515

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/




[quoted text, click to view]

Re: Invalid cursor state Dean Slindee
3/14/2004 2:42:02 PM
Thanks for your reply.

After fiddling with it some more, the problem occurs when trying to insert a
column
between other columns, but does not occur when appending the column at the
end
of the table. I dealt with it by creating an empty table the way it wanted
it arranged,
and inserting from the legacy table, and deleting the old table and renaming
the new table. Problem bypassed.

Dean Slindee

[quoted text, click to view]

Re: Invalid cursor state Erland Sommarskog
3/14/2004 4:32:11 PM
Dean Slindee (slindee@mindspring.com) writes:
[quoted text, click to view]

I say that this is a bug in Enterprise Manager. The user should never
see any error like this.

I have no idea what may have happened, but did you try to close down
EM, and start anew?

Myself, and many other experience SQL professionals, prefer to use
SQL statements to change tables. Here is an example of the syntax for
adding column to a table is:

ALTER TABLE tbl ADD col int NULL


--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
Re: Invalid cursor state Aaron Bertrand [MVP]
3/14/2004 5:29:39 PM
Now, why does column order matter? Or is this just a cosmetic thing?

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


[quoted text, click to view]

Re: Invalid cursor state Erland Sommarskog
3/14/2004 11:13:12 PM
Aaron Bertrand [MVP] (aaron@TRASHaspfaq.com) writes:
[quoted text, click to view]

Column does matter, yes. No, it does not affect performance, neither
does it affect how queries are carried out.

But there are several other reasons:

o While SELECT * is not to be used in actual code, it is great when
debugging and looking at data in support situations. Then having
the columns in some sort of logical order makes it easier to find
the data. This is particularly important if you have tables with
20-30 columns or more.

o Again, when doing sp_help or looking at the table in a data model,
be that Visual Designer or something else, it helps developers if
columns are in order.

o If you have several instances of the same database schema, and
want to bulk data from one table to another, it is immensly easier
if column order is the same everywhere, as you don't need to write
any format file.



--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
Re: Invalid cursor state Erland Sommarskog
3/14/2004 11:17:23 PM
Dean Slindee (slindee@mindspring.com) writes:
[quoted text, click to view]

The difference between the two cases is that when adding a column at the
end of the table, EM performs an ALTER TABLE (I assume), but when you're
inserting a column in the middle, it performs the same roundtrip that
you did yourself. Apparently it lost track of itself there.

I did a quick test, and I was not able to repeat the error. Are you running
SP3? It might be a bug that has been fixed.

Keep in mind when you run this manually, that you need to copy foreign
keys, triggers and indexes as well.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
Re: Invalid cursor state Martin Lingl
3/15/2004 5:22:43 PM
In addition to Erland's comments (which I second), ANSI SQL-92 says the
following about tables:
A table is a multiset of rows. A row is a nonempty sequence of
values. Every row of the same table has the same cardinality and
contains a value of every column of that table. The i-th value in
every row of a table is a value of the i-th column of that table.
The row is the smallest unit of data that can be inserted into a
table and deleted from a table.

To me this clearly indicates that the columns of a table are ordered in any
ANSI SQL-92 compliant database, not just in SQL server, or else there would
not be an i-th value. I have read opposite opinions on this board many
times.

Martin


[quoted text, click to view]

Re: Invalid cursor state Tibor Karaszi
3/15/2004 5:33:37 PM
It is correct that the ANSI SQL standard parts from the relational model
regarding column ordering. Column are ordered in ANSI SQL (just look at an
INSERT statement without a column name list, or SELECT *).

Personally, I don't write production code which is dependent on column
ordering. I do agree with Erland's comments regarding "niceness" in database
diagrams, when you do ad-how queries and things like that.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp


[quoted text, click to view]

AddThis Social Bookmark Button