Triggers on every table in schema

Hi All,
I want to know every details that whenever someone performs a DML in schema A on any tables to logged into a table.
I have attempted these:
-Create log table
CREATE TABLE audit_rst(
user_id VARCHAR2(30),
session_id NUMBER,
host varchar2(30),
ip_add varchar2(30),
action CHAR(3),
date_executed DATE);
--Create a row based trigger for every tabel available
--this exampel shows only one table
CREATE OR REPLACE TRIGGER AUDIT_cc_2008
AFTER INSERT OR DELETE OR UPDATE ON cc_2008 FOR EACH ROW
DECLARE
v_operation VARCHAR2(10) := NULL;
BEGIN
IF INSERTING THEN
   v_operation := 'I';
ELSIF UPDATING THEN
   v_operation := 'U';
ELSE
   v_operation := 'D';
END IF;
IF INSERTING OR UPDATING THEN
  INSERT INTO audit_rst(
  USER_ID,
  SESSION_ID,
  HOST,
  ACTION,
  DATE_EXECUTED)
  VALUES (
  user,
  sys_context('USERENV','SESSIONID'),
  sys_context('USERENV','HOST'),
  SYS_CONTEXT('USERENV', 'IP_ADDRESS', 15)
  v_operation, SYSDATE);
ELSE
  INSERT INTO audit_rst (
  USER_ID,
  SESSION_ID,
  HOST,
  ACTION,
  DATE_EXECUTED)
  VALUES (
  user,
  sys_context('USERENV','SESSIONID'),
  sys_context('USERENV','HOST'),
  v_operation, SYSDATE);
END IF;
END;Do I need to create this trigger for every table available in teh schema...or is tehre a schema level trigger that can scan through the schema and pick up any dml changes to any table and log it into teh audit_rst table?

fyi
Schema-Level Events for Trigger Definitions Event
SERVERERROR : Oracle fires the trigger whenever a server error message is logged.
LOGON : Oracle fires the trigger after a client application logs on to the database successfully.
LOGOFF : Oracle fires the trigger before a client application logs off the database.
CREATE : Oracle fires the trigger whenever a CREATE statement adds a new database object to the schema.
DROP : Oracle fires the trigger whenever a DROP statement removes an existing database object from the
schema.
ALTER : Oracle fires the trigger whenever an ALTER statement modifies an existing database object in the
schema.

Similar Messages

  • Displaying the sizes of every table in a database

    Hello All,
    I need to get the table sizes for each and every table in a database.
    I would have checked it manually but there are many number of tables.
    I am using SQL Server 2008 R2.
    Thanks and Regards, Readers please vote for my posts if the questions i asked are helpful.

    Hi,
    Please make habit of searching net before posting or if you dont know how to write a query. A simple search would lead you to
    http://stackoverflow.com/questions/7892334/get-size-of-all-tables-in-database
    SELECT
    t.NAME AS TableName,
    s.Name AS SchemaName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB,
    SUM(a.used_pages) * 8 AS UsedSpaceKB,
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
    FROM
    sys.tables t
    INNER JOIN
    sys.indexes i ON t.OBJECT_ID = i.object_id
    INNER JOIN
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
    INNER JOIN
    sys.allocation_units a ON p.partition_id = a.container_id
    LEFT OUTER JOIN
    sys.schemas s ON t.schema_id = s.schema_id
    WHERE
    t.NAME NOT LIKE 'dt%'
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255
    GROUP BY
    t.Name, s.Name, p.Rows
    ORDER BY
    t.Name
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
    My TechNet Wiki Articles

  • Trigger for logging changes(DML changes) for All tables in Schema

    Hi ,
    Is there a way to create a schema level trigger to audit the DML changes that affect all the tables.I need the output in my log table as
    1) the table name on which the DML occurred
    2) type of DML
    3) column names affected.
    I know this can be achieved through enabling AUDIT or by creating dynamically, triggers for each tables...
    Is there a way to create a single trigger to achieve this??

    It's not possible to create DML trigger on schema level
    I think the only way is to create the triggers dynamically for each table..
    Re: Schema level Database triggers by Kamran Agayev
    Edited by: jeneesh on Oct 12, 2012 6:39 PM

  • How to write two triggers on same table how it works?

    Hello sir..
    I have to write two triggers on same table for auditing different columns of different pages (may be different modules).
    I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_ val,timestamp)
    Now different users from different pages will update the data on same table may be same columns!
    If we write directly, we will not be able to know which column is updated from different pages.
    My question is how can we control the triggers to raise based on the pages

    A trigger is executed whenever the table is inserted / updated / deleted (depend on trigger definition). It won't know what 'page' caused the operation. You can prepare a trigger for one page.
    In order to fulfill your need, you need some way to tell the trigger where you are. There are many ways to accomplish this. Some possible methods are (please check the documents for detail)
    DBMS_SESSION.SET_IDENTIFIER
    DBMS_APPLICATION_INFO.SET_MODULEFor example, you can call DBMS_SESSION.SET_IDENTIFIER to set an ID from your page, and then call sys_context to read the ID back:
    In Page:
    exec dbms_session.set_identifier('Page1');
    ...In Trigger
    pageid  := sys_context('USERENV', 'CLIENT_IDENTIFIER') ;
    ...Note that if you use a connection pool, you may need to properly reset the session information before return, in order to avoid messing up the session information when the connection is used next time.

  • Two triggers on same table

    Hi Friend.
    I have to write two triggers on same table for auditing different columns of different users(may be different modules).
    I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_val,timestamp)
    Now different users from different modules will update the data on same table may be same columns from different front end forms!
    If we write directly, we will not be able to know which column is updated by which user.
    My question is in this case how can we control the triggers to raise differently?

    You can use WHEN clause to fire a trigger only when some condition is true - you can check an user also,
    look at simple example:
    - suposse we have two users US1 and US2:
    C:\>sqlplus sys as sysdba
    SQL*Plus: Release 10.2.0.1.0 - Production on Pn Gru 6 13:14:22 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Enter password:
    Connected to:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> create user us1 identified by us1;
    User created.
    SQL> create user us2 identified by us2;
    User created.
    SQL> grant connect, resource to us1, us2;
    Grant succeeded.
    SQL> grant create public synonym to us1, us2;
    Grant succeeded.and suposse we have a table with three columns + audit table:
    SQL> connect us1
    Enter password:
    Connected.
    SQL> create table tab123(
      2  col1 number,
      3  col2 number,
      4  col3 number);
    Table created.
    SQL> create table audit_tab123(
      2  username varchar2(100),
      3  col1 number,
      4  col2 number,
      5  col3 number );
    Table created.
    SQL>  grant select, update, insert on tab123 to us2;
    Grant succeeded.
    SQL>  grant select, update, insert on audit_tab123 to us2;
    Grant succeeded.
    SQL> create public synonym tab123 for tab123;
    Synonym created.
    SQL> insert into tab123 values( 1, 1, 1 );
    1 row created.
    SQL> commit;
    Commit complete.We want a trigger that is fired only by user US1 and only after update of COL1 and COL2
    (COL3 is ignored):
    SQL> connect us1/us1
    Connected.
    SQL> CREATE OR REPLACE TRIGGER Trig_123_US1
      2  AFTER UPDATE OF col1, col2 ON tab123
      3  FOR EACH ROW
      4  WHEN ( user = 'US1' )
      5  BEGIN
      6    INSERT INTO audit_tab123( username, col1, col2 )
      7    VALUES( user, :new.col1, :new.col2 );
      8 END;
    SQL> /
    Trigger created.And we want a second trigger that is fired only by user US2 and only after update of COL2 and COL3
    (COL1 is ignored):
    SQL> connect us1/us1
    Connected.
    SQL> CREATE OR REPLACE TRIGGER Trig_123_US2
      2  AFTER UPDATE OF col2, col3 ON tab123
      3  FOR EACH ROW
      4  WHEN ( user = 'US2' )
      5  BEGIN
      6    INSERT INTO audit_tab123( username, col2, col3 )
      7    VALUES( user, :new.col2, :new.col3 );
      8  END;
      9  /
    Trigger created.and now let test our triggers:
    SQL> connect us1/us1
    Connected.
    SQL> update tab123 set col1 = 22;
    1 row updated.
    SQL> update tab123 set col2 = 22;
    1 row updated.
    SQL> update tab123 set col3 = 22;
    1 row updated.
    SQL> commit;
    Commit complete.
    SQL> select * from audit_tab123;
    USERNAME         COL1       COL2       COL3
    US1                22          1
    US1                22         22
    SQL> connect us2/us2
    Connected.
    SQL> update tab123 set col1 = 333;
    1 row updated.
    SQL> update tab123 set col2 = 333;
    1 row updated.
    SQL> update tab123 set col3 = 333;
    1 row updated.
    SQL> commit
      2  ;
    Commit complete.
    SQL> select * from us1.audit_tab123;
    USERNAME         COL1       COL2       COL3
    US1                22          1
    US1                22         22
    US2                          333         22
    US2                          333        333As you see, each trigger is fired only once, first triger only for user US1 and columns COL1 and COL2,
    and second trigger only for user US2 and only after update of COL2 and COL3.
    I hope this will help.

  • Training an SVM on table with schema flexibility fails

    Dear colleagues,
    I'm trying to train a Support Vector Machine on a table with schema flexibility.
    On a small test table with only a couple of columns both the training and the prediction using the PAL libraries work fine. However, on my large sparse table with more than 1000 columns and "schema flexibility" set at creation time, I constantly run into the following error:
    Could not execute 'CALL SYSTEM.AFL_WRAPPER_GENERATOR ('PAL_SV', 'AFLPAL', 'SVMTRAIN', PAL_SV_SIGNATURE)' in 30 ms 529 µs .
    SAP DBTech JDBC: [423]: AFL error:  [423] "SYSTEM"."AFL_WRAPPER_GENERATOR": line 32 col 1 (at pos 1346): [423] (range 3) AFL error exception: AFL error: registration finished with errors, see indexserver trace
    The indexserver trace gives me something strange like:
    AFLPM_SQLDriverObj.cpp(02439) : aflpm_creator : direction must be in or out
    As far as I see it, all parameters are fine, though.
    Is there a limitation that does not allow PAL functions to be executed on tables with schema flexibility? I suspect so, because I'm running into similar problems with the SUBSTITUTE_MISSING_VALUES function.
    Thanks for any help,
    Daniel

    Hey there,
    isn't there anyone who came across this issue? I'd love to know if this is a known technical limitation with tables that use the "schema flexibility" or rather a bug. In the former case, can anyone suggest a workaround?
    I'd be grateful for any help or any pointer to further documentation.
    Best,
    Daniel

  • Every table need primary key in toplink mapping to fetch the data

    Hi everyone,
    we are working on toplink mapping , it neccessary every table needs primary key. if yes, gave me example.

    Hi everyone,
    Alterations in database will not be automatically reflected in toplink so, there is any alternative
    with regards
    abusufian

  • How to exclude tables from Schema level replication

    Hi All,
    I am currently trying to setup Oracle Streams (Oracle 11.1.0.6 on RHEL5) to replicate a schema from one instance to another.
    The basic schema level replication is working well, and copying DDL and DML changes without any problems. However there are a couple of tables that I need to exclude from the stream, due to incompatible datatypes.
    Does anybody have any ideas or notes on how I could achieve this?? I have been reading the Oracle documentation and find it difficult to follow and confusing, and I have not found any examples in the internet.
    Thanks heaps.
    Gavin

    When you use SCHEMA level rules for capture and need to skip the replication of a few tables, you create rules in the negative rule set for the table.
    Here is an example of creating table rules in the negative rule set for the capture process.
    begin
    dbms_streams_adm.add_table_rules(
    table_name => 'schema.table_to_be_skipped',
    streams_type => 'CAPTURE',
    streams_name => 'your_capture_name',
    queue_name => 'strmadmin.capture_queue_name',
    include_dml => true,
    include_ddl => true,
    inclusion_rule => false
    end;
    table_name parameter identifies the fully qualified table name (schema.table)
    streams_name identifies the capture process for which the rules are to be added
    queue_name specifies the name of the queue associated with the capture process.
    Inclusion_rule=> false indicates that the create rules are to be placed in the negative rule set (ie, skip this table)
    include_dml=> true indicates DML changes for the table (ie, skip DML changes for this table)
    include_ddl=> true indicates DDL changes for the table (ie, skip DDL changes for this table)

  • Why not partition every table

    Hi ,
    In our project we propse to partition all the tables(Even though they are small which are in MBs) in order to use exchange partiion feature.
    But Our DBAs are saying that Maintainance will be a problem if we create partitions for each and every table.We said ,single tablespace is fine for all the partitions as We thought maintaining different tablespaces is a problem.
    But Still DBAs are not approving it.
    I just want to know what are the disadvantages of partitioning.Why DBAs in general are against the idea of creating partitions.If we use same tablespace for all partitions is there any down side for creating partitions for every table ?
    Is there are disadvantage ?
    Thanks
    Pramod Garre

    Pramod Garre wrote:
    We are planning to use range partitioning (on quarters).
    There is requirement to delete one quarter data from the table and then refresh with new data as and when user update some recored from frontend.this should happen in real time.Sounds like you are having the app trigger partition management ... which doesn't strike me as a good idea.
    It also sounds like you really only have justification for partitioning on a few tables. Far from the "every" table you asked about. And even at that it sounds like your concept of the usage of those partitions may be flawed.
    Why not work with your DBAs instead of looking to strangers for justification to fight them. Sounds to me like they are doing exactly what they were hired to do.
    We thought instead of delete and insert , if we use excahnge partitions , this will be real quick as exchange partition just update the dictionary.
    On these lines,do you think will there be any disadvantages of using partitioning ?
    Note : Delete and Insert is working OK (2 Mins ) as compared to exchange partition ( 20 ms ).
    And Yes,Every table has PK.
    Thanks
    Pramod Garre

  • How to truncate  schema1 table from schema 2 -URGENT

    Hi all
    Please tell me is there any grant like that
    regards

    IS this
    grant drop any table to schema 2
    only way PapinRTFM: http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_107a.htm
    Prerequisites
    To truncate a table or cluster, the table or cluster must be in your schema or you must have DROP ANY TABLE system privilege. :)

  • Exporting tables from schema by expdp

    I created user test having read write writes on directory mydir(at os level), there are 1000 tables in my test user schema, i wnt to export those tables in mydir (using expdp) which table names did not contain '9' ......
    i tried some below soln whcih didnt work
    $expdp userid=test/test directory=mydir dumpfile=tables_not9.dat query=tab:"where tname not like '%9%'"
    $expdp userid=tet/test directory=mydir dumpfile=tables_not9.da schema query=user_tables:"where table_name not like '%9%'"
    plz guide for correct solution

    915415 wrote:
    I created user test having read write writes on directory mydir(at os level), there are 1000 tables in my test user schema, i wnt to export those tables in mydir (using expdp) which table names did not contain '9' ......
    i tried some below soln whcih didnt work
    $expdp userid=test/test directory=mydir dumpfile=tables_not9.dat query=tab:"where tname not like '%9%'"
    $expdp userid=tet/test directory=mydir dumpfile=tables_not9.da schema query=user_tables:"where table_name not like '%9%'"
    plz guide for correct solutionSee below, exported all the objects except EMP table of schema SCOTT
    C:\Users\bn2676>expdp system/manager directory=data_pump_dir dumpfile=exp_scott2.dmp logfile=exp_scott2.log schemas=scott EXCLUDE=TABLE:\"LIKE \'EMP%\'\"
    Export: Release 11.2.0.1.0 - Production on Tue Feb 21 09:16:44 2012
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01":  system/******** directory=data_pump_dir dumpfile=exp_scott2.dmp logfile=exp_scott2.log schemas=scott EXCLUDE=TABLE:"LIKE \'EMP%\'"
    Estimate in progress using BLOCKS method...
    Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 128 KB
    Processing object type SCHEMA_EXPORT/USER
    Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
    Processing object type SCHEMA_EXPORT/ROLE_GRANT
    Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
    Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
    Processing object type SCHEMA_EXPORT/TABLE/TABLE
    Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
    Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    . . exported "SCOTT"."DEPT"                              5.937 KB       4 rows
    . . exported "SCOTT"."SALGRADE"                          5.867 KB       5 rows
    . . exported "SCOTT"."BONUS"                                 0 KB       0 rows
    Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
    Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
      C:\ORACLE\ADMIN\ORCL\DPDUMP\EXP_SCOTT2.DMP
    Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at 09:17:04
    C:\Users\bn2676>

  • Analyze Table Or Schema

    when we want to query the dba_tables or user_tables to find the no of rows in a particular table or no of rows of all the tables then why do we need to analyze that particual table or schema to get the num_rows columns values??

    "RTFM" is the best teacher always"
    When you analyze the table:
    Oracle collects the following statistics for a table. Statistics marked with an
    asterisk are always computed exactly. Table statistics, including the status of
    domain indexes, appear in the data dictionary views USER_TABLES,
    ALL_TABLES, and DBA_TABLES in the columns shown in parentheses.
    ->"Number of rows (NUM_ROWS) "
    -> * Number of data blocks below the high water mark (that is, the number of data
    blocks that have been formatted to receive data, regardless whether they currently
    contain data or are empty) (BLOCKS)
    -> * Number of data blocks allocated to the table that have never been used (EMPTY_BLOCKS)
    -> Average available free space in each data block in bytes (AVG_SPACE)
    -> Number of chained rows (CHAIN_COUNT)
    -> Average row length, including the row's overhead, in bytes (AVG_ROW_LEN) Jameel

  • How to exclude some tables from schema level replicatio????

    Hi,
    I am working on oracle10g stream replication.
    My replication type is "Schema Based".
    So can anyone assist me to undersatnd, how to exclude some tables from schema based replication.
    Thanks,
    Faziarain

    You can use rules and include them in the rule set, lets say you dont want LCR to be queued for table_1 in schema SALES, write two rules one for DDL and another for DML with NOT logical condition.
    DBMS_RULE_ADM.CREATE_RULE(
    rule_name => 'admin.SALES_not_TALBE_1_dml', condition => ' (:dml.get_object_owner() = ''SALES'' AND NOT ' ||
    ' :dml.get_object_name() = ''REGIONS'') AND ' ||
    ' :dml.is_null_tag() = ''Y'' ');
    DBMS_RULE_ADM.CREATE_RULE(
    rule_name => 'admin.hr_not_regions_dlll',
    condition => ' (:dml.get_object_owner() = ''SALES'' AND NOT ' ||
    ' :ddl.get_object_name() = ''table_!'') AND ' ||
    ' :dsl.is_null_tag() = ''Y'' ');
    just go through this document once, http://download.oracle.com/docs/cd/B28359_01/server.111/b28321/strms_rules.htm#i1017376
    Edited by: user8710159 on Sep 16, 2009 5:21 PM

  • Analyzing all tables in schema

    Hello everyone,
    I am used below command to analyze all tables in schema
    EXEC DBMS_STATS.gather_schema_stats (ownname => 'CONTRACT', cascade =>true,estimate_percent => dbms_stats.auto_sample_size);when look at tables in dba_tables, for none of the tables LAST_ANALYZED date is changed to today. But when I did below
    EXECUTE DBMS_STATS.GATHER_TABLE_STATS(ownname => 'CONTRACT', tabname => 'CONT_NAME', method_opt => 'FOR ALL COLUMNS', granularity => 'ALL', cascade => TRUE, degree => DBMS_STATS.DEFAULT_DEGREE);I am see LAST_ANALYZED changed to today in dba_tables.
    If I need to change LAST_ANALYZED to all tables do I need to produce the above command for all tables? There are more then 700 tables for this application.
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    user3636719 wrote:
    EXEC DBMS_STATS.gather_schema_stats (ownname => 'CONTRACT', cascade =>true,estimate_percent => dbms_stats.auto_sample_size);
    and
    EXECUTE DBMS_STATS.GATHER_TABLE_STATS(ownname => 'CONTRACT', tabname => 'CONT_NAME', method_opt => 'FOR ALL COLUMNS', granularity => 'ALL', cascade => TRUE, degree => DBMS_STATS.DEFAULT_DEGREE);are fundamentally different, you cannot compare them. In gather_schema_stats, oracle used most defaults, decided none needed new stats collected, so it didn't do anything. In the second, you changed method_opt, granularity and degree etc from default values (as set in your db perhaps), so db went ahead and collected stats.
    You need to look up manual and try to understand the default and non-default behavior for parameters and then make an educated decision. Changing stats randomly is not generally a great idea.

  • Can every table have different editor or renderer?

    I just know that every table column can have the same editor or renderer. Now i want some cell in the same column have differnet editor or renderer. I do not know about this. Can anybody help me?
    Thank you very much!
    coral9527

    Another approach would be to override JTable methods: getCellRenderer and getCellEditor

Maybe you are looking for

  • SAP HANA Privileges for Frontend Tools

    Hello, I am pretty new to HANA and having problems to access my created views from Frontend Tools like Design Studio or Lumira. I have created several tables and on top created an Analytic View. Tables and views are in the same schema, but I assigned

  • Connecting infinity to a new PC

    We had infinity put in just before Xmas and had it connected via Ethernet to the desktop, where the old system was. Unfortunately that PC was giving us problems and gave up over Xmas so we have ordered a new one. Are there likely to be any difficulti

  • Nested SpringLayout panels

    I've been trying to organize some panels using SpringLayout, which I'm fairly new to. What I've got is a summary panel and below it a large table. The Summary panel is divided horizontally into three sub panels (contrasting background) each of which

  • Disable iphoto when importing digi pics?

    whenever i load pics from my camera, iphoto automatically opens. how do i disable this?

  • Full backup everytime

    Guys, every time that I connect my MacBook Pro on my Time Capsule WiFi network, the total size of backup is over 70Gb. This MacBook is used just for work, and I have no photos, music, videos, etc. Why the backup is not a incremental like occurs on my