How to get the table name in the trigger definition without hard coding.

CREATE  TRIGGER db.mytablename
AFTER UPDATE,INSERT
AS
    INSERT INTO table1(col1)
    SELECT InsRec.col1   
    FROM
    INSERTED Ins
   --Below i am calling one sp for which i have to pass the table name
   EXEC myspname 'tablename'
  In the above trigger,presently i am hard coding the tablename
  but is it possible to get the table name dynamically on which the trigger is defined in order to avoid hard coding the table name

I really liked your audit table concept.  You inspired me to modify it so that, the entire recordset gets captured and added a couple of other fields.  Wanted to share my end result.
USE [YourDB]
GO
/****** Object: Trigger [dbo].[iudt_AutoAuditChanges] Script Date: 10/18/2013 12:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[iudt_AutoAuditChanges]
ON [dbo].[YourTable]
AFTER INSERT,DELETE,UPDATE
AS
BEGIN
SET NOCOUNT ON;
Declare @v_AuditID bigint
IF OBJECT_ID('dbo.AutoAudit','U') IS NULL BEGIN
CREATE TABLE [dbo].[AutoAudit]
( [AuditID] bigint identity,
[AuditDate] DateTime,
[AuditUserName] varchar(128),
[TableName] varchar(128) NULL,
[OldContent] XML NULL,
[NewContent] XML NULL
ALTER TABLE dbo.AutoAudit ADD CONSTRAINT
PK_AutoAudit PRIMARY KEY CLUSTERED
[AuditID]
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [idx_AutoAudit_TableName_AuditDate] ON [dbo].[AutoAudit]
( [TableName] ASC,
[AuditDate] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
Select * Into #AuditDeleted from deleted
Select * Into #AuditInserted from inserted
While (Select COUNT(*) from #AuditDeleted) > 0 OR (Select COUNT(*) from #AuditInserted) > 0
Begin
INSERT INTO [dbo].[AutoAudit]
( [AuditDate], [AuditUserName], [TableName], [OldContent], [NewContent])
SELECT
GETDATE(),
SUSER_NAME(),
[TableName]=object_name([parent_obj]),
[OldContent]=CAST((SELECT TOP 1 * FROM #AuditDeleted D FOR XML RAW) AS XML),
[NewContent]=CAST((SELECT TOP 1 * FROM #AuditInserted I FOR XML RAW) AS XML)
FROM sysobjects
WHERE
[xtype] = 'tr'
and [name] = OBJECT_NAME(@@PROCID)
Set @v_AuditID = SCOPE_IDENTITY()
Delete from AutoAudit
Where AuditID = @v_AuditID
AND Convert(varchar(max),oldContent) = Convert(varchar(max),NewContent)
Delete top(1) from #AuditDeleted
Delete top(1) from #AuditInserted
End
END

Similar Messages

  • How to get a server name through the load balancer

    Hi.
    I'd like to get the server name where is my application installed. There are some servers and clients access there throuth the load balancer. When I try to get it with request.getServerName(), I get the virtual address of the load balancer.
    Any suggestions?
    Thanks.

    Dear Sikindar;
    THanks for your cooperation, but I believe that these Tcodes will eb helpful if I know the table name, actually we don't know its name and that's what I'm asking about, how can I get the table name for the ABAPer?
    Appreciating your cooperation.
    Best Regards;
    Lobna

  • How can one find the table name of the Delta Que and setup table?

    Hi !
    Is there any method to find the table name of the delta que and Extraction que ?

    setup table = <extract structure>_setup
    example: setup table for MC11VA0ITM = MC11VA0ITM_SETUP
    Delta Queue is based on following 3 tables:
    ARFCSDATA
    ARFCSSTATE
    TRFCQOUT
    assign points if useful ***
    Thanks,
    Raj

  • I NEED THE TABLE NAME FOR THE  FIELD DESCRIPTION GIVEN!

    I NEED THE TABLE NAME FOR THE  FIELD DESCRIPTION GIVEN!
    Partner Type
    Partner Type Desc
    Partner no
    Partner Name
    Partner Address 1
    Partner Address 2
    Partner Address 3
    Partner Address 4

    Hi Jyotirmoy ,
                        You can get all partners and their type in table EDPP1, depending of the partner type you need to go to specific table for address and other details, like for partner type KU(customer) goto KNA1,etc for partner type LI(vendor) goto LFA1 etc for partner type B(bank) goto BNKA etc ....
    Sirish

  • Using column value is it possible to find the table name in the database?

    Hi all,
    using column value is it possible to find the table name in the database?
    guys i need the table value
    Note:
    oracle-9i
    for example:
    i don't know NIC(column value) in which table in the database.
    Thank you,
    with regards,
    JP.
    Edited by: Guest on Feb 27, 2012 5:42 AM

    Hi,
    As far as I understand what you are asking for I would suggest 4 data dictionaries that will help you to know the table name from the column names
    1. USER_TAB_COLS
    2. ALL_TAB_COLS
    3. DBA_TAB_COLS
    4. COLS
    These can give you detail information about the columns and respective tables at user, schema, dba level. Further information on the table can be found by querying ALL_OBJECTS table giving table_name as Object_name, or you can join the data dictionaries too.
    To know about various data dictionaries avalible in Oracle please query select * from cat;
    Let us know if you need further assistance.
    Twinkle

  • Hw to find the table name of the perticular field is stored in db,usingFM

    Dear all,
    I need to find out the table name of the perticular field is storing in database using FM (note: using Function Module or any standard program , not manually like press F1 -> technicall setting etc.. .) 
    [ Exmple: Field: "MATNR" is stored in table : MARA, so i need the program/FM  to findout MATNR is stoed in MARA table ]
    i need this  FM for update values of  material master ( mm01 ) stored in different warehouse using module pool program.
    it's very urgent , please send me reply asap.
    thanks,
    best regards
    srinivas

    hi Srinivas,
    Please use the following logic:
    types:
        begin of t_find,
           field(40),
        end of t_find.
    data:
        lt_find  type table of t_find,
        ls_find  type          t_find,
        lt_found type table of RSFINDLST.
    ls_find-field = 'MATNR'.
    append ls_find to lt_find.
    CALL FUNCTION 'RS_EU_CROSSREF'
    EXPORTING
       i_find_obj_cls                    = 'DTEL'
       I_SCOPE_OBJ_CLS                    = 'TABL'
       NO_DIALOG                          = 'X'
    TABLES
       I_FINDSTRINGS                      = lt_find
       O_FOUNDS                           = lt_found
    EXCEPTIONS
       NOT_EXECUTED                       = 1
       NOT_FOUND                          = 2
       ILLEGAL_OBJECT                     = 3
       NO_CROSS_FOR_THIS_OBJECT           = 4
       BATCH                              = 5
       BATCHJOB_ERROR                     = 6
       WRONG_TYPE                         = 7
       OBJECT_NOT_EXIST                   = 8
       OTHERS                             = 9
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    The table lt_found has the details for the tables having MATNR as a field; field lt_found-object will have the table names.
    Hope this helps,
    Sajan Joseph.

  • How do I read a properties file in WEB-INF without hard-coding a path?

    Hello,
    How do I read a properties file in WEB-INF without hard-coding a path?
    I tried:
    Properties properties = new Properties();
    properties.load(new FileInputStream("db.properties"));
    driver = properties.getProperty("driver");
    but it cannot find the db.properties file.
    Thanks for the help.
    Frank

    Don't use a File to read those properties.
    Better to use the servlet context and
    getResourceAsStream() method to get the InputStream.
    It'll look for any file in the CLASSPATH. If you put
    that properties file in the WEB-INF/classes directory
    you'll have no problems, even if you deploy with a
    WAR file.Completely agree with this approach. Just have to mention the following for completeness
    according to the API,
    "This method is different from java.lang.Class.getResourceAsStream, which uses a class loader. This method allows servlet containers to make a resource available to a servlet from any location, without using a class loader. "
    So using this method, the resource can be anywhere under your web context, not just in the classpath.
    Cheers,
    evnafets

  • How to get ther servlet name from the Httprequest / servletContext

    Hi,
    How can I get the servlet name from the Http Request / Servlet conext?
    Arthik

    I have a requirement to call the business logic either in local server / external server.
    Local / External server
    The original / main request is made to the server from the client and from the server if the main request requires some resource (second request from server side) available in the external server then I need to make a URL connection. If the requested resource is the local resource then I need to by-pass the HTTP call. So I need to verify the server name , port with the originally requested server.Then I need to check if the request servelt is available in local or not.
    Can you please help me.

  • Select data from all the table names in the view

    Hi,
    "I have some tables with names T_SRI_MMYYYY in my database.
    I created a view ,Say "Summary_View" for all the table names
    with "T_SRI_%".
    Now i want to select data from all the tables in the view
    Summary_View.
    How can i do that ? Please throw some light on the same?
    Thanks and Regards
    Srinivas Chebolu

    Srinivas,
    There are a couple of things that I am unsure of here.
    Firstly, does your view definition say something like ...
    Select ...
    From "T_SRI_%"
    If so, it is not valid. Oracle won't allow this.
    The second thing is that your naming convention for the
    tables suggests to me that each table is the same except
    that they store data for different time periods. This would be
    a very bad design methodology. You should have a single
    table with an extra column to state what period is referred to,
    although you can partition it into segments for each period if
    appropriate.
    Apologies if i am misinterpreting your question, but perhaps
    you could post your view definition and table definitions
    here.

  • How to use a table name in the select statement using a variable?

    Hi Everybody,
                       I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?
    Regards,
    Mallik.

    Hi all,
    Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
    for ex : select * from (tab_name) where....?
    Can we do inner join on such select statements? If so how?
    Thanks & Regards,
    Mallik.

  • How to find out table name for the field in the webUI

    Hi.
    I am in CRM2007.
    So i go to the transaction code    BSP_WD_CMPWB
    In that i provide the component name as CRM_UI_FRAME.
    I press the Test button.
    So, it opend the WebUI.
    I want how to find out table of the particular input field?
    I mean from which table the data is retrived how to find out?
    When i enter some thing in the input field how to find out in which table that data is stored?
    By pressing F2 on the input field it opend View and Component Name.
    I want find out table of that particular field. How to find it?
    If anybody know about this explain it with Screen shorts if possible.
    Thank You.
    Krishna. B.

    hi
    goto tx genil_model_browser. Suppose you want to find fields reated to your order header eg sold to name. In component set write all and press F8. Then goto access object and in access object click on node BTAdminH. Click on attribute structure. Here you will find structure and attributes. If you click relationship then you will see all the relationship wrt btadminh. open any r/s that you require. and click on other object and attribute. You will get to know the structure.
    Best regards
    Pankaj kumar

  • How to get value and name of the n'th parameter in a pl/sql funct./proced.

    procedure test(name varchar2, birthdate date, zip number, country varchar2);
    in procedure x I do
    test('Michael Postmann', to_date('03.01.1983', 'DD.MM.YYYY'), 7461, 'AUSTRIA');
    And this should htp.print the following:
    test: name=Michael Postmann,birthdate=1983/01/03,zip=7461,country=AUSTRIA
    In procedure test I want to know:
    *) What is the name of myself (the procedure)
    *) Optionally: Am I a procedure or a function?
    *) How many Parameters do I have?
    *) What are the values of them?
    *) What are the names of them?
    *) Optionally: What are the types of them?
    What I actually want to do is:
    I have a procedure for logging errors. So in my program I call this function frequently and I want it to log the current time, a string passed to the logging function, the client's ip, etc.... but it should also log a list of the parametrs and values of the procedure/function where the error occoured.
    Is there any way to do this (I think in C this is done by argc and argv, but a string containing all the information (as you get it from the WebDb when something goes wrong) would be enough)?
    Thx in advance,
    Nomike aka Michael Postmann

    Name of procedure or function can be retrieved using DBMS_UTILITY.FORMAT_CALL_STACK:
    CREATE OR REPLACE FUNCTION fn_whoami (v_in varchar2)
    RETURN varchar2
    AS
    v_stack varchar2(1000) DEFAULT DBMS_UTILITY.FORMAT_CALL_STACK;
    v_job varchar2(500);
    v_name varchar2(100);
    BEGIN
    v_job := SUBSTR(v_stack,INSTR(v_stack,'function'),256);
    v_name := SUBSTR(v_job,1,INSTR(v_job,CHR(10))-1);
    return v_name;
    END fn_whoami;
    select fn_whoami('1') from dual;
    CREATE OR REPLACE PROCEDURE pr_whoami
    AS
    v_stack varchar2(1000) DEFAULT DBMS_UTILITY.FORMAT_CALL_STACK;
    v_job varchar2(500);
    v_name varchar2(100);
    BEGIN
    v_job := SUBSTR(v_stack,INSTR(v_stack,'procedure'),256);
    v_name := SUBSTR(v_job,1,INSTR(v_job,CHR(10))-1);
    dbms_output.put_line(v_name);
    END pr_whoami;
    exec pr_whoami;

  • How to display a table name in the report

    Hi,
    I have a requirment about the display of pivot table. When we drag a column to see its result, we always see his column name, now what I want to show are both table name and column name..
    like:
    District_D
    Region District
    China Beijing
    India Chennai
    Regards,
    Anne
    Edited by: anne on Oct 25, 2011 2:39 AM

    Hi Anne,
    If you want to implement Dpka's solution (hardcoding table and column values in column heading and add line break in between), you will need to add the below entry in instanceconfig.xml file. Refer http://gerardnico.com/wiki/dat/obiee/hardenxss
    <HardenXSS>false</HardenXSS>
    This will enable the HTML elements to be treated as HTML and not plain text. After adding the above entry in the xml, restart your presentation services and test your solution.
    Thanks

  • How to change the Table name during the Run Time

    Hi
    I have to generate a Oracle Developer/2000 report.
    The input paramater is Vendor ( Ex:- Aetna,Cigna,BCBS...)
    If the input paramater is Aetna then the table report should use is Aetna_Emp_Data or
    If the input is Cigna then The table is Cigna_Emp_Data.
    The Layout and fileds selected for the report remains the same.
    Please let me know !
    Regards
    Kiran Ravuri
    Workscape

    Why don't you check with you co-worker Goran he has done this.

  • How to get source table name according to target table

    hi all
    another question:
    once a map was created and deployed,the corresponding information was stored in the repository and rtr repository.My question is how to find the source table name according to the target table,and in which table these records are recorded.
    somebody help me plz!!
    thanks a lot!

    This is a query that will get you the operators in a mapping. To get source and targets you will need some additional information but this should get you started:
    set pages 999
    col PROJECT format a20
    col MODULE format a20
    col MAPPING format a25
    col OPERATOR format a20
    col OP_TYPE format a15
    select mod.project_name PROJECT
    , map.information_system_name MODULE
    , map.map_name MAPPING
    , cmp.map_component_name OPERATOR
    , cmp.operator_type OP_TYPE
    from all_iv_xform_maps map
    , all_iv_modules mod
    , all_iv_xform_map_components cmp
    where mod.information_system_id = map.information_system_id
    and map.map_id = cmp.map_id
    and mod.project_name = '&Project'
    order by 1,2,3
    Jean-Pierre

Maybe you are looking for

  • [solved - faulty hardware]nvidia - serious problems after last update

    I'm trying to fix this for 3 days now... After last nvidia update i rebooted and my screen looked like this: http://img3.imagebanana.com/img/qogzxehj/img_1702.jpg So I googled a bit, tried to create a new xorg.conf with nvidia-xconfig, tried several

  • Error URLRequest

    Dear all. I want to write an application in flash media server. I installed FMS 4.5 Enterprise. I want to get web content that it is json format. My code: //Get web content example 1                 var url = "http://10.84.70.133:8084/?q=external_api

  • Can someone help me with a somewhat simple button function?

    I am working on a project and a small part of that project is creating a counter increases by one everytime a button is clicked. For example I have incuded a picture of a much simpler version of what I am doing. For some reason I can not get the code

  • My LMS 3.2 won't detect Switch 29xx , router 39xx and 7200

    Hi , my LMS 3.2 won't detect  my new Switchs 29xx , router 39XX and my 7200 router !!!! Thanks

  • Simple question regarding HD video

    If a movie is to be watched on a standard TV, are there any advantages of shooting in HD? What I'm saying is, can I shoot in HD 16X9 and then edit in HD 4X3?