row is not inserting into table - database

The table is present in oracle database, I am updating that table with one record. It's executing and when I type select * from that table it's showing that record.
But the problem is when I commit the changes. The table is showing nothing - I am not seeing anythng inside table, it's showing 0 records.
Can you please help me?
insert into recon values(1,'sri',-1,'20090806');
after this if i write
select * from recon;
It's showing that record but after commit it's showing nothing. There is no trigger for that table.
its not a view.

It's a global temporary table, after commiting it is emptied.
There are two kind of temp tables, 1 after commit emptied, 2.after ending session emptied.

My guess would be that the transaction was not committed properly, initially I thought that it was because of nested transactions (I work in SQLServer) but could be basically because of not properly committed transaction

If you are the admin, Check if other users are logged into the the database and are using that table, unlock the user from that table/database.

Related

Sql Server Stored Procedure Concurrency Issue

We have some SQL Server stored procedure.
It selects some rows from a table and puts them into the temp table to apply and calculate some data validations.
The next part of the procedure either updates the actual table based on the temp table data or sends back the error status.
Initially selected rows can only be updated once and no further updates are allowed to the same rows.
The problem, we are facing is like some time, 2 simultaneous threads execute the procedure at the same time and both pass the initial validation block as in-memory temp data is not processed yet. 2nd thread is able to overwrite the first transaction.
We applied the transaction mechanism to prevent duplicate inserts and updates by checking the affected rows count by update query and aborting the transaction.
I am not sure if it's correct and optimized or not.
Also, can we lock rows with a select statements as well ?
This has been solved using the UPDLOCK on select query inside the transaction.
It locks the specific rows and allow the transaction to proceed in isolation.
Thanks Everyone for your help.

[SymmetricDS]: Missing changes in SYM_DATA

I have new records insert into source database but some records are not synced to target database. When I look into SYM_DATA, between 2 consecutive insert there are some update event triggered to the same table but different row. Log file has deadlocks error but after retry becomes OK.
My question is can SymmetricDS trigger update and insert if both event type happen together ? How to avoid deadlocks and make sure no missing records to sync from source to target ?
Data can not be synced only if it hasn't been inserted or editing data updated in the database. SymmetricDs extraction of data happens in the same transaction as the application uses. Check if there data has been successfully inserted or updates. Maybe some transactions have been rolled back. If they have been successfully committed order the table sym_data by its primary key data_id description to be sure you haven't missed a row.

Sql Server rows being auto inserted without a trigger

I have a table in sql server, for which, if I delete a row from it, a new row is inserted with the same data, and userid as the one I deleted. There are no triggers on this table. In addition, I did a search of all database objects that reference this table, and there are no triggers anywhere in the database that reference this table, only some stored procedures, none of which have any code that would cause this behavior.
To be clear, if I run this query:
delete from my_table where id = 1
the row with the id of 1 will be deleted, but a new row will be inserted that has the same userid, and date as the deleted row. No application code involved, just a straight sql delete statement run directly on the database causes this.
What else besides a trigger could be causing this to happen? I've never encountered something like this before.
It took me a long time, but I discovered this was being caused by a "rogue" linq-to-sql dll that was running in spite of it's parent app being killed.
The good news is, there isn't some weird non-trigger way to insert rows on delete in SQL, so we can all resume our normal lives now, knowing all is as it was.

How to avoid deadlock while updating table with two different updates statements on same table in SQL server

I am using update statement in a script task of SSIS which updates a particular row of a table. This process happens in a loop for multiple rows.
Sometimes it happens that another application also fires an update on that same table for a different set of rows. For this application I'm getting deadlock exception on lock.
How can I avoid this situation? I want both updates to work at same time as the row sets being updated are different.
Is the anything to lock only that row which is getting updated?
Regards,
Solo
From the MSDN site with a search on TSQL, UPDATE RowLock. There are also PageLock and TableLocks. You can also use transactions if you need to update more than one table. On your reads you may want to use (NOLOCK) if dirty reads are OK (the up side is no read locks).
update Production.Location with (ROWLOCK)
set CostRate = 100.00
where LocationID = 1

Deleting Rows from a SQL Table marked for Replication

I erroneously delete all the rows from a MS SQL 2000 table that is used in merge replication (the table is on the publisher). I then compounded the issue by using a DTS operation to retrieve the rows from a backup database and repopulate the table.
This has created the following issue:
The delete operation marked the rows for deletion on the clients but the DTS operation bypasses the replication triggers so the imported rows are not marked for insertion on the subscribers. In effect the subscribers lose the data although it is on the publisher.
So I thought "no worries" I will just delete the rows again and then add them correctly via an insert statement and they will then be marked for insertion on the subscribers.
This is my problem:
I cannot delete the DTSed rows because I get a "Cannot insert duplicate key row in object 'MSmerge_tombstone' with unique index 'uc1MSmerge_tombstone'." error. What I would like to do is somehow delete the rows from the table bypassing the merge replication trigger. Is this possible? I don't want to remove and redo the replication because the subscribers are 50+ windows mobile devices.
Edit: I have tried the Truncate Table command. This gives the following error "Cannot truncate table xxxx because it is published for replication"
Have you tried truncating the table?
You may have to truncate the table and reset the ID field back to 0 if you need the inserted rows to have the same ID. If not, just truncate and it should be fine.
You also could look into temporarily dropping the unique index and adding it back when you're done.
Look into sp_mergedummyupdate
Would creating a second table be an option? You could create a second table, populate it with the needed data, add the constraints/indexes, then drop the first table and rename your second table. This should give you the data with the right keys...and it should all consist of SQL statements that are allowed to trickle down the replication. It just isn't probably the best on performance...and definitely would impose some risk.
I haven't tried this first hand in a replicated environment...but it may be at least worth trying out.
Thanks for the tips...I eventually found a solution:
I deleted the merge delete trigger from the table
Deleted the DTSed rows
Recreated the merge delete trigger
Added my rows correctly using an insert statement.
I was a little worried bout fiddling with the merge triggers but every thing appears to be working correctly.

Resources