Action
A table has a PK (Primary Key)
B table has a FK (Foreign Key) and referenced to A table's PK
-> User tries to truncate table A
Error
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
Solution I
Disable B table's FK
SQL> alter table HR.B disable constraint FK_B;
-- e.g. schema HR
Solution II
First truncate table B
SQL> truncate table B;
Then truncate table A
SQL> truncate table A;
Wednesday, 25 October 2017
How to disable/enable all triggers for tables?
Disable triggers for a table
SQL> alter table HR.TRG_EMPLOYEES disable all triggers;
Enable triggers for a table
SQL> alter table HR.TRG_EMPLOYEES enable all triggers;
Disable triggers belong to a schema (e.g. HR)
SQL>
DECLARE
STR_EXEC VARCHAR2 (1000);
BEGIN
FOR cur_node IN (SELECT owner, table_name
FROM all_triggers
WHERE owner = 'HR')
LOOP
BEGIN
str_exec :=
'alter table '
|| cur_node.owner
|| '.'
|| cur_node.table_name
|| ' DISABLE ALL TRIGGERS';
DBMS_OUTPUT.put_line (str_exec);
EXECUTE IMMEDIATE str_exec;
END;
END LOOP;
END;
/
Enable triggers belong to a schema (e.g. HR)
SQL>
DECLARE
STR_EXEC VARCHAR2 (1000);
BEGIN
FOR cur_node IN (SELECT owner, table_name
FROM all_triggers
WHERE owner = 'HR')
LOOP
BEGIN
str_exec :=
'alter table '
|| cur_node.owner
|| '.'
|| cur_node.table_name
|| ' ENABLE ALL TRIGGERS';
DBMS_OUTPUT.put_line (str_exec);
EXECUTE IMMEDIATE str_exec;
END;
END LOOP;
END;
/
SQL> alter table HR.TRG_EMPLOYEES disable all triggers;
Enable triggers for a table
SQL> alter table HR.TRG_EMPLOYEES enable all triggers;
Disable triggers belong to a schema (e.g. HR)
SQL>
DECLARE
STR_EXEC VARCHAR2 (1000);
BEGIN
FOR cur_node IN (SELECT owner, table_name
FROM all_triggers
WHERE owner = 'HR')
LOOP
BEGIN
str_exec :=
'alter table '
|| cur_node.owner
|| '.'
|| cur_node.table_name
|| ' DISABLE ALL TRIGGERS';
DBMS_OUTPUT.put_line (str_exec);
EXECUTE IMMEDIATE str_exec;
END;
END LOOP;
END;
/
Enable triggers belong to a schema (e.g. HR)
SQL>
DECLARE
STR_EXEC VARCHAR2 (1000);
BEGIN
FOR cur_node IN (SELECT owner, table_name
FROM all_triggers
WHERE owner = 'HR')
LOOP
BEGIN
str_exec :=
'alter table '
|| cur_node.owner
|| '.'
|| cur_node.table_name
|| ' ENABLE ALL TRIGGERS';
DBMS_OUTPUT.put_line (str_exec);
EXECUTE IMMEDIATE str_exec;
END;
END LOOP;
END;
/
Saturday, 14 October 2017
ORA-01045 solution
Error
ORA-01045: user HR lacks CREATE SESSION privilege; logon denied
Solution
Grant CREATE SESSION privilege to 'HR' user
SQL> grant CREATE SESSION to HR;
ORA-01045: user HR lacks CREATE SESSION privilege; logon denied
Solution
Grant CREATE SESSION privilege to 'HR' user
SQL> grant CREATE SESSION to HR;
Friday, 6 October 2017
ORA-28000 solution
Error
ORA-28000: the account is locked
Solution
Find the assigned profile for related user
SQL> select profile from DBA_USERS where username = 'HR';
-- e.g. DEFAULT
Disable failed_login_attempts parameter
SQL> alter profile "DEFAULT" limit failed_login_attempts UNLIMITED;
Check it
SQL> select resource_name,limit from dba_profiles where profile='DEFAULT';
Apply the new setting for user
SQL> alter user "HR" ACCOUNT UNLOCK;
ORA-28000: the account is locked
Solution
Find the assigned profile for related user
SQL> select profile from DBA_USERS where username = 'HR';
-- e.g. DEFAULT
Disable failed_login_attempts parameter
SQL> alter profile "DEFAULT" limit failed_login_attempts UNLIMITED;
Check it
SQL> select resource_name,limit from dba_profiles where profile='DEFAULT';
Apply the new setting for user
SQL> alter user "HR" ACCOUNT UNLOCK;
Subscribe to:
Posts (Atom)