Microsoft SQL - "Invalid column name" after deleting column - sql

I am using Azure SQL in Microsoft SQL Management studio. I firstly renamed a column called ssma$rowid to ssmarowid, then I deleted this column using
ALTER TABLE "myCoolTable" DROP COLUMN "ssmarowid";
SQL management studio prompted me that the deletion was successful, but now that I try to run any UPDATE commands on my table in different columns, I get this error message:
Invalid column name 'ssma$rowid'.
If I try to edit a cell without scripting, by right-clicking my table, then Edit top 200, I get this error message:
The data in row xxx was not committed.
Error Source: .Net SqlClient Data Provider.
Error Message: Invalid column name 'ssma$rowid'
Invalid column name 'ssma$rowid'
Invalid column name 'ssma$rowid'
Correct the errors and retry or press ESC to cancel the change(s)
The column ssma$rowid does not appear in my table at all when I run a SELECT statement, and if I explicitly try to pull the column ssma$rowid or ssmarowid SQL tells me that they don't exist.
It appears that my column has been lost in the ether somewhere, where can I start searching to find my rogue column?

Ensure the ALTER TABLE states the column between brackets like this :
ALTER TABLE [myCoolTable] DROP COLUMN [ssmarowid];

Related

Invalid identifier coming in dblink procedure and it becomes invalid when i add column to table

I have 2 databases connected using a database link.
As soon as I add a column in my test table in both the databases
the procedures accessed via the database link become invalid.
A normal insert via a database link works, but as soon as I put it in a procedure it gives compilation errors.

Trying to add column of CLOB type to table in DB2

I need to add a column of type "CLOB" to the existing table in the database, so I am using the below query:
alter table foldet add("FOLDER_FIELD_VALUE_TWO" CLOB);
but I am getting the below error
Error starting at line : 5 in command -
alter table foldet add("FOLDER_FIELD_VALUE_TWO" CLOB)
Error report -
SQL Error: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=CLOB;DER_FIELD_VALUE_TWO";JOIN , DRIVER=3.63.75
How to add a column to the table?
You don't say what DB2 version or platform sends the error response, but the SQLSTATE/SQLCODE values should be consistent across essentially all of them. Looking up SQLSTATE 42501 in DB2 for i 7.2, the given reason is:
The authorization ID does not have the privilege to perform the
specified operation on the identified object.
IOW, you don't have sufficient authority to change the structure of the table when you connect with the userid that received the error.
SQLSTATE 42501 is from you latest comment. From your question, SQLSTATE 42601 is:
A character, token, or clause is invalid or missing.
Your comment describes how you cleared that up, and the answer from #SimeonVanov correctly addresses that.
ALTER TABLE table_name
ADD column_name datatype
This is the syntax for adding column to a table. So if you get rid of the brackets I think it should be ok.
You're getting the error (-551) because you don't have the ALTER authority on the table. It's all there in the error message, as shown in the manual.
SQL Error: SQLCODE=-551, SQLSTATE=42501, SQLERRMC=IPASS;ALTER TABLE;FOLDET, DRIVER=3.63.75
^^^^ ^^^ ^^^^^^^^^^ ^^^
error code user privilege table

Delete from sql server 2000?

I want to delete all rows from table in sql server 2000 but whenever I want to delete manually or with query it shows error. In help tab it shows ODBC error: <0s>.
My table contains some '0' values but its datatype is String. Is that's the reason for this
error.
code is:
stat2=conn.createStatement();
stat2.executeUpdate("Delete * from pat.dbo.PHPL");
"Key column information is insufficient or incorrect. Too many rows were affected by update" that's warning and when click help it shows: ODBC error: <0s>. An ODBC error has been generated. You might have deleted a record that has a foreign key value related to it, or you might have violated a check constraint. For details, refer to your ODBC documentation.
Use
Truncate Table PHPL
I think you have duplicate identities, check you are not allowing duplicates on this column.

SQL Server Invalid Column name after adding new column

I just added an identity column to an existing table with data through the SSMS Designer, the table updates fine and I can run a select query against it successfully, but after the query finishes I noticed that the new column is underlined in red with an error indicating it's an invalid column name.
Why does this occur? I would expect the query to fail if the column was invalid.
Does the SSMS keep some type of internal reference to the old table that must be flushed?
I tried closing the DB connection and reopening it, but still the same error. Not sure what I'm missing here.
SELECT TOP 100
[PRIMARY_NDX_Col1],
[NEW_Col], --QUERY EXECUTES SUCCESSFULLY, BUT THIS IS UNDERLINED RED AS AN INVALID COLUMN
[Col3]
FROM [dbo].[MyTable]
you can either
Press Ctrl+Shift+R
OR
Go to Edit >> IntelliSense >> Refresh Local
Cache

Access Database - Auto INSERT\UPDATE - Qt4

In a registration software made with Qt4, I open an Access .mdb database, update it with the user-provided fields.
It has currently a table clients with six fields:
CustomerNumber, FullName, CNICNumber, ResidentialAddress, ResidentialPhoneNumber, MobileNumber
where CustomerNumber is primary key and a number, while all others are text. There are a few records present. But when another record with same CustomerNumberis tried to be inserted, there is an error:
QODBCResult::exec: Unable to execute
statement: "[Microsoft][ODBC Microsoft
Access Driver] The changes you
requested to the table were not
successful because they would create
duplicate values in the index, primary
key, or relationship. Change the data
in the field or fields that contain
duplicate data, remove the index, or
redefine the index to permit duplicate
entries and try again."
"[Microsoft][ODBC Microsoft Access
Driver] The changes you requested to
the table were not successful because
they would create duplicate values in
the index, primary key, or
relationship. Change the data in the
field or fields that contain duplicate
data, remove the index, or redefine
the index to permit duplicate entries
and try again." "QODBC3: Unable to
execute statement"
I then found the UPDATE query, but the following code gives another error:
query.exec("UPDATE clients"
"SET FullName='"+cname+"', CNICNumber='"+cnic+"', ResidentialAddress='"+caddress+"', ResidentialPhoneNumber='"+cphone+"', MobileNumber='"+cmobile+"'"
"WHERE CustomerNumber="+cnumber+";");
The variables cname, cninc, caddresss, cphone, cmobile, cnumber are strings with values. But the error with the above code is:
QODBCResult::exec: Unable to execute
statement: "[Microsoft][ODBC Driver
Manager] Function sequence error"
"[Microsoft][ODBC Driver Manager]
Function sequence error" "QODBC3:
Unable to execute statement"
What is the solution to this, i.e. how to insert a new record when the primary key is not present but update existing record with same primary key?
You are missing spaces. The actual command you are executing is equivalent to
query.exec("UPDATE clientsSET Fullname...
there is no such table as clientsSET.
Here is what you intended
query.exec("UPDATE clients"
" SET FullName='"+cname+"', CNICNumber='"+cnic+"', ResidentialAddress='"+caddress+"', ResidentialPhoneNumber='"+cphone+"', MobileNumber='"+cmobile+"'"
" WHERE CustomerNumber="+cnumber+";");
If these are user-input values you are vulnerable to SQL injection. You need to be careful to scrub all the string values (eg. replace all ' with '').
What is the solution to this, i.e. how
to insert a new record when the
primary key is not present but update
existing record with same primary key?
This is known informally as an UPSERT. See this answer that relates to Access.
query.exec("UPDATE clients"
...CNICNumber='"+cnic+"', ...
My guess would be that CNICNumber shouldn't have single quotes around it.
...CNICNumber="+cnic+", ...
But it's impossible to tell for sure without knowing your table structure.
Can you try with:
+ " SET FullName='"+cname+ ...
+ " WHERE CustomerNumber="+cnumber+";");
in the second and third row?