Is there a way to know if a table is locked and what kind of lock is currently on a table? I was hoping for something through the DBC tables in teradata, but I can't find any reference to anything like this. I have normal user access and the DBA is no help. Thanks.
AFAIK only DBA utilities are available to determine the type of lock on a table.
With only user-level rights you can do something like the following (from here):
Lock Table dbName.myTable for Access nowait
Select * from dbName.myTable;
And according to the master himself (Geoffrey Rommel):
If the table is locked, you will get
error 7423, "Object already locked and
NOWAIT. Transaction Aborted."
Related
How can I lock a table preventing other users querying it while I update its contents?
Currently my data is updated by wiping the table and re-populating it (i know, its not the best way to update data, but the source data has no unique key to do a record by record update and this is the only way). There exists the unlikely, but possible scenario where a user my access the table in the middle of the update and catch it while it is empty thus returning bad info.
Is there at the SQL (or code) level a way to create a blocking statement that will wait for a DB update to complete prior to querying?
Access has very little locking capabilities. Unless you're storing your data in a different backend, you only can set a database-wide lock or no lock at all.
There is some locking capability setting table locks when the table structure of a table is being changed, but as far as I can find, that's not available to the user (neither through the GUI nor through VBA)
Note that both ADO and DAO support locking (in ADO by setting the IsolationLevel, in DAO by setting dbDenyRead + dbDenyWrite when executing the query), but in my short testing, these options do absolutely nothing in Access.
When I try this command on oracle sql-developer :
delete from my_table;
I get the following error :
ORA-00054: resource busy and acquire with NOWAIT specified
I haven't figured out how to solve this problem.
Someone or yourself(unintentionally) has a lock on the table.
Query the table V$LOCKED_OBJECTS to find the name of the user (you would want OS_USER_NAME) locking it.
You can ask the user to unlock the table. They will have to either commit/rollback their transaction. If they are unable to do so and permit you to kill their session, you can use the below:
alter system kill session 'sid, serial#'
to kill their session which has a lock on your table where 'sid' & 'serial#' is something you have to find by querying v$session,v$sqlarea tables.
This can also be done in SQL developer, you can find out the session (if your user has access to meta tables) from the menu Tools --> Monitor Sessions
Right click on the correct session record (very important) and select mark for kill. You should be able to delete the records once the session is killed.
Check with database admin. They can check if anything is going on with the table. May be someone is performing something on the table in different session. Admin can kill the session. Then, you will be able to delete/truncate the table.
How to lock a table in SQL Server ? I found running queries with lock and also read transactions but
confused how to use these.
I have two processes which are reading a table first then updating data in it . I want only one to update and other get this update in its read . working of my processes is as follows:-
Lock table
read data
update data if it is not updated by other process.
release Lock.
thanks
You can use TABLOCKX hint to lock entire table, but locking entire table is usually a bad idea, you might want to reconsider if you really need it.
If you want to ensure you're updating latest data, you can use rowversion column, and double check before update instead of locking entire table for reading.
In your select statement you can provide a "select for update" table hint: with (updlock). Depending on what percentage of records you are updating and their physical distribution this might perform better than a table lock.
But as Fedor Hajdu pointed out, what you probably want is an optimistic locking scheme. Check out the documentation for the READ COMMITTED SNAPSHOT isolation level. You might also find this article useful as an introduction.
im trying to change some types on my table in sybase, but when i change it, the output is this one.
User 'DBA' has the row in 'table' locked
How to unlock this?
I would:
determine the connection_id using sa_locks (documentation here)
issue the drop connection *connection_id* statement to the connection that is causing the lock to the table.
Use it with care!
I have an SQL table, from which data is being deleted. Nobody knows how the data is being deleted. I added a trigger and know the time, however no jobs are running that would delete the data. I also added a trigger whenever rows are being deleted from this table. I am then inserting the deleted rows and the SYSTEM_USER to a log table, however that doesnt help much. Is there anything better I can do to know who and how the data gets deleted? Would it be possible to get the server id or something? Thanks for any advice.
Sorry: I am using SQL Server 2000.
**update 1*: Its important to find out how the data gets deleted - preferably I would like to know the DTS package or SQL statement that is being executed.
Just a guess, but do you have delete cascades on one of the parent tables (those referenced by foreign keys). If so, when you delete the parent row the entries in the child table are also removed.
If the recovery mode is set to "Full", you can check the logs.
Beyond that, remove any delete grants to the table. If it still happens, whomever is doing it has root/dbo access - so change the password...
Try logging all transactions for the time being, even if if it hurts performance. MS offers a mssql profiler, including for express versions if needed. With it, you should be able to log transactions. As an alternative to profilers, you can use the trace_build stored procedure to dump activity into reference files, then just 'ctrl-f' for any instance of the word 'delete' or other similar keywords. For more info, see this SO page...
Logging ALL Queries on a SQL Server 2008 Express Database?
Also, and this may sound stupid, but investigate the possibility that what you are seeing is not deletes. Instead, investigate if records are simply being 'updated', 'replaced if already exists', 'upserted', or whatever you like to call it. In Mysql, this is the 'INSERT ... ON DUPLICATE KEY UPDATE' statement. I'm not sure of the MSSQL variant.
What recovery model is your database in? If it is full Redgate log Rescue is free and works against SQL2000 which might help you retrieve the deleted data. The Overview Video does appear to show a user column.
Or you could roll your own query against fn_dblog
Change all your passwords. Give as few people delete access as possible.