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!
Related
I'm pretty new to DBeaver and was wondering if it had an option to revert queries that were previously ran? For instance I ran
ALTER TABLE case_arrest_forms DROP CONSTRAINT cri_arrest_dispositionsid_fkey;
From the top menu it says it's on auto-commit. Is there a way for me to roll this back or would I have to add the constraint again? Any other suggestions?
Nope, DBeaver doesn't have such kind of functionality. Can't revert query in auto-commit mode.
Also, it is not possible to return the row deleted from the table.
But to avoid such situations, you can change the level of transactions.
I have a system to manage printers of a company and I need to understand how the workflow between the Website and database works by knowing what is added/changed in the database with each interaction of the user. Is there a way to find or create some kind of log for a database or even the entire SQL Server that can show me what I need?
you can use extended events feature in some case :
https://learn.microsoft.com/en-us/sql/relational-databases/extended-events/quick-start-extended-events-in-sql-server?view=sql-server-2017
I think what you're looking for are triggers.
You can make tables to log the currently updated or changed data and use triggers to automatically feed data in the log table on any change
CREATE OR REPLACE TRIGGER [trigger_name]
BEFORE DELETE OR INSERT OR UPDATE ON [table_name]
FOR EACH ROW
WHEN [some condition]
DECLARE
[variable declaration]
BEGIN
[create an entry in the log table here]
END;
You can use NEW and OLD keywords to refer to the data (new referring to the most recent update of data)
Just for the record, a tool for that exactly purpose exists and is installed together with SQL Server, it is called SQL Server Profiler.
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.
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."
I'm performing a bulk insert with an ADO.NET 2.0 SqlBulkCopy object from a C# method into a MS SQL 2005 database, using a database user with limited permissions. When I try to run the operation, I get the error message:
Bulk copy failed. User does not have
ALTER TABLE permission on table
'theTable'. ALTER
TABLE permission is required on the
target table of a bulk copy operation
if the table has triggers or check
constraints, but 'FIRE_TRIGGERS' or
'CHECK_CONSTRAINTS' bulk hints are not
specified as options to the bulk copy
command.
I read some documentation and created the bulk copy object with the constructor that lets me specify such things:
SqlBulkCopy bc = new SqlBulkCopy(
System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"],
SqlBulkCopyOptions.FireTriggers & SqlBulkCopyOptions.CheckConstraints);
But this doesn't change anything - I get the same error message as before. I tried fiddling with some of the other SqlBulkCopyOptions values but no luck. I really thought this would fix the problem, am I missing something?
I tested the procedure after granting ALTER on the table to my user, and the operation succeeded. However this is not an option for my situation.
Solved it! Looks like I need a refresher on flags enums. I was bitwise ANDing the enum values when I should have been ORing them.
SqlBulkCopyOptions.FireTriggers & SqlBulkCopyOptions.CheckConstraints
evaluates to zero (which is equivalent to SqlBulkCopyOptions.Default.)
SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.CheckConstraints
Worked correctly and allowed the bulk insert to complete.
Possibilities only, I'm sorry
SQL documentation for BULK INSERT specifies 3 cases where ALTER TABLE is needed. You listed 2 of them. Is the KeepIdentity option being set, even if not needed?
Another option is that the trigger on the table is disabled already, confusing the issue. Use ALTER TABLE dbo.SomeTable ENABLE TRIGGER ALL to ensure enabled.