db2 SQLCODE -668 when inserting - sql

While I was inserting data into a table (db2), I got this error:
Message: Operation not allowed for reason code "7" on
table "ELSAG.ICGR1106".. SQLCODE=-668, SQLSTATE=57016, DRIVER=3.50.152,...
when I googled it, I found that the previous ALTER TABLE statement attempted to add a column to a table that has an edit procedure that is defined with row attribute sensitivity. No columns can be added to this table.
Is there is a way to rectify it?
Once I drop and re-create the table I can insert again.
Thanks in advance.

To add to James' answer and save people time looking around, you could execute
CALL SYSPROC.ADMIN_CMD('REORG TABLE MY_TABLE_NAME')
via any available SQL client (i.e. even over ODBC or JDBC connection) to rectify this problem. However, the connection has to be in autocommit mode and you have to have admin privileges to execute this command.
I highly recommend to read the documentation on REORG before calling it.

According to this:
SQL0668
You have done some alteration to the table which requires a REORG before you can further update the table.
Run the REORG utility against the table and you should be OK.

CALL SYSPROC.ADMIN_CMD('REORG TABLE TABLE_NAME') solves the problem

SELECT REORG_PENDING FROM SYSIBMADM.ADMINTABINFO where TABSCHEMA = '<schema_name>' and tabname = '<table_name>';
If above query returns Y
Then run below query:
call sysproc.admin_cmd('reorg table <schema_name>.<table_name>');
For more info visit: SQL0668N Operating not allowed for reason code '7'

I turned off integrity checks on some table and got that error message afterwards when altering data. This here generated the statements which helped:
select 'SET INTEGRITY FOR ' || rtrim(tabname) || ' IMMEDIATE CHECKED;'
from syscat.tables
where CONST_CHECKED like '%N%'
or status != 'N'
or access_mode != 'F'
with ur;

Related

Update query stuck forever

I am executing following UPDATE sql query against oracle database server -
UPDATE TEST.SS_USER_CREDENTIALS SET CREDENTIAL = 'UUHs4w4Nk45gHrSIHA==';
After executing this query in Oracle SQL developer, I can see spinner of execution status of query keeps spinning forever and hence no output is returned. However following SELECT query on same table returns result immediately -
SELECT * FROM TEST.SS_USER_CREDENTIALS;
Could you please help to understand why UPDATE query is not executed?
If you don't have autocommit enabled, you may need to run
COMMIT;
Otherwise oracle updates aren't actually applied to your data set
try with where clause
UPDATE TEST.SS_USER_CREDENTIALS SET CREDENTIAL = 'UUHs4w4Nk45gHrSIHA==' where id='someid';
as I see your command if the table has trillion of rows it will take time (as I guess this should not be foreign key)
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
If you are looking for a temp solution you can also change the ON UPDATE action to CASCADE and modify your ids if you got a foreign key problem
it can be you have another open uncommitted transaction for the same set of records, so they are locked for that transaction.
if you locked them, running the same UPDATE in another transaction.
Just Commit/rollback your transactions
This works for me:
Close the database connection and refresh it
Refresh the table
Restart the SQL Server in services
I know this is not a complete answer to this, hope it helped!

pyodbc - insert into 'select' not working

I am trying to run INSERT INTO SELECT statement in cur.execute. The code executes without any error, but there are no records inserted in the table.
Here is the table data:
I execute the following query,
cursor = conn.cursor()
query = 'INSERT INTO destination_test_hist SELECT * FROM destination_test'
cursor.execute(query)
conn.commit()
Where am I going wrong? I need some assistance
Syntax-wise, I don't see any errors.
Just a few simple things to check to be sure:
Check that your connection is correct and you are checking that server/db, your source table(in this case destination_test) and target table (in this case destination_test_hist) are correct.
Check your database environment and relevant tables in the same. You might have checked the QA test environment maybe or post the query with output of no records with database name and tables.
Also, at programming level it may appear that it might not have got executed in the database do debug the query output what it returns at programming level too.

Creating table in Firebird script causes "unsuccessful metadata update" with deadlock

I have the following script that I run using "isql -i scriptfile.sql":
CONNECT C:\Databasefile.fdb USER user PASSWORD password;
SET TERM !! ;
EXECUTE BLOCK AS BEGIN
IF (EXISTS(SELECT 1 FROM rdb$relations WHERE rdb$relation_name = 'MYTABLE')) THEN
EXECUTE STATEMENT 'DROP TABLE MYTABLE;';
END!!
SET TERM ; !!
CREATE TABLE MYTABLE
(
MYCOLUMN VARCHAR(14) NOT NULL
);
The very first time I run this (when the table does not already exist) the table is created as expected.
If I run the script again I get the following error:
Statement failed, SQLCODE = -607
unsuccessful metadata update
-STORE RDB$RELATIONS failed
-deadlock
After line 8 in file d:\myscript.sql
When the script exits, MYTABLE has been deleted and can no longer be found in the database.
If I run the script a third time the table is once again created and no errors are thrown.
Why can't the script both delete and then recreate a table?
DDL from PSQL is not allowed, using EXECUTE STATEMENT it is not directly forbidden, and usually possible, but still not wise exactly because of these kinds of problems. I am not exactly sure about the reasons, but part of it have to do with how DDL changes are applied in Firebird; the use of execute statement adds additional locks iirc which conflict with a subsequent DDL for the same table name.
Instead of dropping and creating this way, you should use the DDL statement RECREATE TABLE instead.
Note that the word deadlock in this error is actually a bit of a misnomer (there is no real deadlock).

How to Truncate Multiple Table in SSIS ( using ADO.NET Destination and Oracle Database)

I got a little trouble in SSIS. I have multiple table and i want adding Truncate statement so that table can't create double data.
This is the image of package that I made :
each Data Flow, i used Flat File Source and ADO NET Destination.
And then, in Execute SQL Task i want to apply Truncate Table
After that, i have error message :
"[Execute SQL Task] Error: Executing the query "truncate table Table1
truncate table Tabl..." failed with the following error: "ERROR
[HY000] [Oracle][ODBC][Ora]ORA-00911: invalid character". Possible
failure reasons: Problems with the query, "ResultSet" property not set
correctly, parameters not set correctly, or connection not established
correctly."
What i must suppose to do?
P.S
Sorry if my english is not good
Since the destination is an Oracle Database you should use this syntax:
begin
execute immediate 'truncate table t1';
execute immediate 'truncate table t2';
end;
Does this syntax work:
truncate table table1;
truncate table table2;
Note the semi colons.

Informix SQL update command error 746

I tried to update the field "contract_id" in the table "contract_scan_image".
However, the update was failed and an error "746: Field contract_id and type of contract_scan_image cannot be updated!" was shown.
My SQL command is:
update contract_scan_image
set contract_id = '14864730'
where contract_id = '1486473'
and type = 'RM'
and account = '00193400944'
Does anyone know what happened and how to fix it?
Error message -746 is for user-defined errors. It typically is used in stored procedures in a RAISE EXCEPTION statement:
RAISE EXCEPTION -746, 0, "Field contract_id and type of contract_scan_image cannot be updated!"
The actual message text for error -746 in the message files is:
%s
That is, it prints the string it is given as a string.
So, you are going to need to track down the triggers and stored procedures invoked by those triggers on the contract_scan_image table, and deduce from where the error is generated what you are doing wrong. Superficially, though, it appears that you are not allowed to alter the contract ID, yet that is what you are trying to do.
First things first, I would take a look at a list of Reserved words in SQL - https://drupal.org/node/141051
I would get in the habit of surrounding fields with `` See below:
update contract_scan_image
set `contract_id` = '14864730'
where `contract_id` = '1486473'
and `type` = 'RM'
and `account` = '00193400944'
** Note - type is a reserved word
The error is caused by something being triggered. Then no table can be modified by UPDATE command.
Finally I deleted the record I want to update. Then added back the modified record.
I copy the error description here from the net for reference.
BTW, I asked my supervisor and he said he did trigger something to cause this. (He didn't tell me how to un-trigger it...)
-746
THE SQL STATEMENT IN FUNCTION, TRIGGER, OR IN STORED PROCEDURE name VIOLATES THE NESTING SQL RESTRICTION
Explanation
If a table is being modified (by INSERT, DELETE, UPDATE, or MERGE), the table can not be accessed by the lower level nesting SQL statement.
If any table is being accessed by a SELECT statement, no table can be modified (by INSERT, DELETE, UPDATE, or MERGE) in any lower level nesting SQL statement.
System action
The SELECT, INSERT, DELETE, UPDATE or MERGE SQL statement failed.
Programmer response
Remove the failing statement from the named function, trigger or the stored procedure.
SQLSTATE
57053