Trying to add column of CLOB type to table in DB2 - sql

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

Related

Weird error: relation <schema name> does not exist

I am running a DDL statement like this in Postgres 11
ALTER SEQUENCE kwt.VisitReport_seq OWNED BY kwt.VisitReport;
I am running it as DBADMIN.
Yet I get some weird error:
SQL Error [42P01]: ERROR: relation "kwt" does not exist
ERROR: relation "kwt" does not exist
ERROR: relation "kwt" does not exist
But this is strange... kwt is not a relation, it is a schema.
What is going on?!
As often happens right after posting here I found the problem.
The statement should be:
ALTER SEQUENCE kwt.VisitReport_seq OWNED BY kwt.VisitReport.ID;
i.e. it should refer (of course) to the column name, not to the table name.

Microsoft SQL - "Invalid column name" after deleting column

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];

How to truncate table that my user owns in Oracle without error message

Thanks for reading this post. I am running into a strange issue in Oracle 10g. I am trying to figure out how to truncate a table without errors being generated.
What I need to do:
truncate a table that my user owns
truncate table EXAMPLE_USER.EXAMPLE_TABLE;
What is happening: rows within the table are successfully removed, but the following error is generated:
Error starting at line 1 in command:
truncate table EXAMPLE_USER.EXAMPLE_TABLE
Error report:
SQL Error: ORA-00604: error occurred at recursive SQL level 1
ORA-00942: table or view does not exist
ORA-06512: at line 50
00604. 00000 - "error occurred at recursive SQL level %s"
*Cause: An error occurred while processing a recursive SQL statement
(a statement applying to internal dictionary tables).
*Action: If the situation described in the next error on the stack
can be corrected, do so; otherwise contact Oracle Support.
What I have already done:
Ensure that EXAMPLE_USER has the "drop any table" privilege
Make sure that the rows are removed after truncate statement is ran
Additional Info:
I cannot simply drop and re-create the table because the truncation happens as part of a large database upgrade/update script which is out of my control.
The error is leading me to believe that the truncate statement within Oracle uses some sort of sys package or procedure that my user does not have privilege to access or use, based on the "at line 50" portion of the message. The actual truncate statement itself is a single line script. Does anyone have experience with this issue in Oracle?
Regards,
Dave

For a read only user why do DROP and INSERT fail with different errors

I have a database user with read only permissions for table example_table.
Select * from example_table;
Works fine.
insert into example_table values('example');
Fails as expected. "insufficient privileges"
drop table example_table;
Fails with error message "table or view does not exist"
My question is. Why do the last two examples not both fail with "insufficient privileges" why when used in the ddl statement can it not even see the table?
Oracle 10g
Thank you.
Your SELECT would fail without a synonym, so you're not selecting directly from the table, but through a synonym.
DROP TABLE is DDL, and synonyms can't be used in most DDL statements. So in your case the statement goes after a real object (by default in the current schema if you have not specified an owner), doesn't find any object by that name, hence the (admittedly unhelpful) error message.
If instead you had written:
drop table owner.example_table;
Then you would have received the expected error message.

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.