Inserted data in the table. If I execute select query, I can see the data inserted. But once I execute commit, then execute select query on the same window, no record found.
It is looks strange. Don't know what is the issue.
I found the reason. It is a Global Temporary Table, where the table is created as
ON COMMIT DELETE ROWS.
Related
I deleted several rows in a table in Oracle Sql Developer. Then I called a GET API to return all the rows in the table, and I found the deleted rows are returned too. After I restarted the Sql developer, I found the deleted rows appears in the table again in Sql developer too. Looks the delete transaction was not committed. I think each transaction in sql developer is commited automatically. Do I need to commit manually in Sql developer after perform a delete operation?
I am trying to delete data from Bigquery tables and facing a challenge. At the moment only one date partitioned table drops/deletes at a time. Based on some research and docs on google, I understand I need to use DML operations.
Below are the commands that I used for deletion and it doesn’t work
1.delete from bigquery-project.dataset1.table1_*
2.drop table bigquery-project.dataset1.table1_*;
3.delete from bigquery-project.dataset1.table1_* where _table_suffix='20211117';
The third query works for me and it deletes only for that particular date.
For the 1 and 2 queries, I’ve got a exception saying “Illegal operation (write) on meta-table bigquery-project.dataset1.table1_”
How would I go about deleting over 300 date partitioned tables in one go?
Thanks in advance.
You can go the route of creating a stored procedure to generate your statements in this scenario
CREATE OR REPLACE PROCEDURE so_test.so_delete_table()
BEGIN
DECLARE fqtn STRING;
FOR record IN
(
select concat(table_catalog,".",table_schema,".",table_name) as tn
from so_test.INFORMATION_SCHEMA.TABLES
where table_name like 'test_delete_%'
)
DO
SET fqtn=record.tn;
-- EXECUTE IMMEDIATE format('TRUNCATE TABLE %s',fqtn);
EXECUTE IMMEDIATE format('DROP TABLE %s',fqtn);
END FOR;
END
call so_test.so_delete_table();
In the above I query for the tables I would like to remove records from, then pass that to the appropriate statement. In your scenario I could not tell if you were wanting to remove records or the entire table so I included logic for both depending on the scenario.
This could also be modified to take in a table prefix and pass that to the for loop where clause fairly simply.
Alternatively you could just perform the select statement in the for loop, copy the results into a sheet and construct the appropriate DML statements, copy back into the console and execute.
I'm learning DML for my class and trying to insert new rows and using oracle 18c. Even after I use the commit command the row isn't saved. After I close the sql plus window and open it again and type
SELECT*FROM acctmanager;
it still says No rows selected. What could be the problem?
[enter image description here]
My bet is ACCTMANAGER is a global temporary table. These are permanent data structures, but any data persists only for the duration of a transaction or a session, depending on how the table was created. Find out more.
I am able to access the row after commit and before closing.
This strong suggests the table was created with ON COMMIT PRESERVE ROWS clause.
Easy enough to check:
select table_name, temporary
from user_tables
where table_name = 'ACCTMANAGER'
I have a SQL Server table with only one column and below is the query I use to insert data. I always "COMMIT TRAN" after the row has been inserted, but the newly added row disappears a few days after I inserted/commit tran. I have never had this issue with any other table and I use these transaction statements often. Any anyone help as to why this keeps happening with this table?
Here is the query I run:
Begin tran
insert into ur77_licensee ([licensee name])
values ('8210 - J.Crew')
select *
from ur77_licensee
where [licensee name] like '%8210%'
commit tran
You'd have to build some kind of audit system which would be quite a challenge. Your code is not causing the delete. My guess is there is some kind of maintenance job doing it, but who knows? I would:
change the permissions on the table to only allow a specific user to make changes
make your code use that user
wait for somebody to come complain about how they can no longer delete
If everybody is running as an admin, well.. that's why you don't have everybody run as admin!
Alternatively you could:
create a delete trigger. When an item is deleted have it insert into a delete table, that would at least let you seen when it happened.
I would like to run my UPDATE statement on my table and see what the results will be without actually changing the table.
For example:
UPDATE MyTable SET field1=TRIM(field1);
I would like to see the result of that without actually changing the tables content. Is this possible?
Specifically I am asking about MySQL.
Also, I know I could just run a SELECT statement as follows:
SELECT TRIM(field1) FROM MyTable;
But I would like to know if I can do it the other way.
If you are using InnoDB tables - use a transaction. If you don't like the results, ROLLBACK - If they are OK, the COMMIT
START TRANSACTION;
UPDATE MyTable SET field1=TRIM(field1);
COMMIT; (or ROLLBACK;)
If you can't use a transaction, you can push the content of that table into a temporary table (insert select), and do your update on that first.