How to Create a DML AFTER trigger

Hi Friends,
I need a help from you.
THe Scenario is We have Tables like parent and Child Table.
Like we have Child Table as  Name AcademyContacts,In that we have Columns like 
Guid(PK)Not Null,
AcademyId(FK), Not Null,
Name,Null
WorkPhone,Null
CellPhone,Null
Email Id,Null
Other.Null
Since we have given Null to ''Workphone'',''Cellphone '', ''Email ID''.when inserting the data into these table 
if the particular columns are empty while inserting also the data will get populate into the table.And
I need is if these columns are ''Workphone'',''Cellphone'' , ''Email ID''  they cant insert the data into table.
Like it must trigger like ''Please enter atleast one of these ''Workphone'',''Cellphone'' , ''Email ID'' columns.
How to do this in triggers please suggests me friends !!!!
I am waiting for your response !!!
Arunraj Kumar

Respecting all i would suggest it is not manager who decide which is right or wrong. Business should decide which is a good  solution. 
Trigger also use for business validation and you can put this validation is Stored procedure also.
Question is how are you inserting  data to parent table , whether your parent  and child table are in within same transaction or not . Other wise if you insert data to parent and while inserting to child table you throw this message it will not
be consistent and   where you want to show this message . You have to consider all these scenarios.
If you use Stored procedure you can return your message. Or It is advisable if you have a front end better handle this in front end.
For your scenario if you want to go for trigger , for you , you need to implement Instead of DML trigger.
Example :
CREATE TRIGGER IO_Trig_INS_Child ON ChildTable
INSTEAD OF INSERT
AS
BEGIN
SET NOCOUNT ON;
IF NOT EXISTS( SELECT * FROM Inserted I where I.Workphone IS NOT NULL OR I.Cellphone IS NOT NULL OR I.EmailID IS NOT NULL)
THROW; -- Refer http://msdn.microsoft.com/en-IN/library/ee677615.aspx for detail use of throw
END
Create storedprocedure InsertSp
AS
Begin Try 
Begin Tran 
Insert into parenttable values ( <<your values>>)
--If you want to handle in sp , here you can check the column value and throw error befor inserting to child
Insert into child table values (<<>>) 
Commit
END Try 
Begin Catch 
THROW 'Your message'
End Catch 
Sandip Pani http://SQLCommitted.com

Similar Messages

  • How to create an ods after creating info objects?

    Hi,
    Please Explain me How to create an ods after creating info objects with all screenshots in BW 7.0?
    Thanks,
    Jini

    Hi Jini,
    In the create screen u will find some settings related information which u need to check and then there are key fields and data fields option.
    In Key field u need to include those objects which should make ur ODS Key fields. and then rest of the fields in the data fields.
    For setting related information u can search in help.sap.com or even on SDN threads.
    Thanks,
    Nagesh.

  • Hi Experts, how to create a subform after a subform?

    Hi Experts,
    does anyone know how to create a subform after a subform? thanks in advance!
    Kind regards
    Dawson

    Dear everyone,
    does anyone know the answer? thanks in advance! and the subform is in the content node, and at this time I have another question that is the content used in the pages of master page automatically? because there is a untitled content area in the pages of master page, can anyone give some tips?
    thanks.
    Kind regards
    Dawson

  • How to create a user defined trigger and execute my form

    Hi All,
    I am working with oracle Apps r12 and oracle forms 10g.
    I have created a custom form. So i need to create a special menu and when the user click the menu it need to open a new block and query it accordingly.
    I have followed this link
    http://egeapp.egeseramik.com:8000/pls/prod/fndgfm/fnd_help.get/us/fnd/@g_special#g_special
    and created a special menu in my custom form
    In PRE_FORM trigger i have coded this
    APP_SPECIAL.INSTANTIATE('SPECIAL3','&ACTION HISTORY DETAILS',NULL,TRUE,'LINE');
    and IN PRE_BLOCK i have coded this
    APP_SPECIAL.ENABLE('SPECIAL3',PROPERTY_ON);.
    Now the special menu is enabled when i press it shows error
    that frm-40700 no such trigger:special3.
    Now i came to know that we need to create a user defined trigger put the code and when we press special menu it need to query it accordingly.
    Can any one tell the steps that how to do that accordingly.
    Thanks & regards
    Srikkanth

    Hi ,
    The problem is fixed, the link mentioned below might be use full for doing this.
    http://docs.oracle.com/cd/E18727_01/doc.121/e12897/T302934T457083.htm
    regards
    Srikkanth

  • How to create a file after ElapsedTime

    Hi, I have a situation where my BPEL process consumes messages off of a queue and creates a output file using them via a FTP Adapter. The number of messages vary greatly depending on the day and the business needs only 1 file a day with the appropriate dateTime stamped to it. I tried using the elapsedTime option on the FTP adapter but it seems to be waiting for invocation before creating the file. I set the time to 2 minutes but instead of creating the file after 2 minutes of inactivity, it waits for a message to be triggered with more than 2 minutes time difference from the last one. Since the messages come in a burst on this queue, the next message wont come in until the next day for the file to be triggered.
    I also tried appending to a file but this is over a SFTP connection so it just kept overwriting the file and in the end I just have 1 record on the file. Any suggestions on this would be really helpful as to how should I go about creating this file in a way that it captures all the messages for today and creates the file the same day as well. Thanks!

    like an action class?Huh? What exactly is your requirement?
    Creating a file is usually done with java.io API. Read the java.io tutorials how to play with files.

  • How to create a Idoc  after a salesorder is created.(Different approaches.)

    Dear Experts,
    First of all I would like to thank SDN as continuously helping me to deliver  better  and faster.
    My requirement is to generate  a Custom idoc whenever a SalesOrder is created. with net value more then 1,00,000.
    Can u please help me by providing what are the different ways we can do this and which one is the best and easier one.
    If possible provide some sample code also.
    Thanks,
    jeevan

    Hai Thirumulan,
    I think the approaches u suggested going to help me out ..
    Can you pls go into details.
    thx,
    jeevan

  • How to create .sites file after the work is done?

    I've lost one or two of my sites regarding to this problem.
    I just know that I need .site files if you need to come back and modify it later.
    Any way to create domain.site files?

    to retieve file content from the databse i have done this.... but its not working . i m using mysql database... i m getting
    1)BLOB cannot be resolved to a type
    2)The method getBLOB(String) is undefined for the type ResultSet
    3)path cannot be resolved
    anyone pls help me...
    my jsp code is...
    <%
    try
    int returnValue = 0;
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    InputStream is = null;
    OutputStream os = null;
    BLOB blob = null;
    String text;
         text=request.getParameter("text");
         Class.forName("com.mysql.jdbc.Driver");
    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/sushikha","root","root");
         final String query = "SELECT data,path FROM pro WHERE data LIKE = " + text;
         conn.setAutoCommit(false);
         stmt = conn.createStatement();
         rs = stmt.executeQuery(query);
         if(rs.next())
         blob = rs.getBLOB("data");
              is = blob.getBinaryStream();
              final String fileName = rs.getString("path");
              final Stri0ng filePath = path + fileName;
              os = new FileOutputStream(filePath);
              final int bufferSize = blob.getBufferSize();
              final byte[] buffer = new byte[bufferSize];
              int bytesRead = 0;
              while ((bytesRead = is.read(buffer)) != -1)
              os.write(buffer, 0, bytesRead);
    else
         returnValue = 1;
         catch(Exception e)
         out.println(e);
    %>
    thanx in advance..sush

  • How to create Request programmatically to trigger Approval Process

    My scenario is dificult... I need to start Approval Process when the user want to assign AD Resource to other user without Request service. So I want to create Request programmatically from Event Handler to start Approval Process for Provision Resource request type.
    Is this right Way?

    If you talk of request, you will have to use RequestService. You can use code to work with the RequestService to create the request and the approval for you.
    -Bikash

  • How to create delivery order after SO was created and before in storage ?

    HI ALL:
        The title is my question ? Is there any one know how to set ?
    please,  thanks first.

    Hi ,
    I faced the same problem once..
    Msgno: VL367 - An item with no delivery quantity is not permitted. Item will be deleted.
    You can solve it by doing either of the following..
    1.Enter storage location for the item in Sale Order where you have stock..
    or
    2.find the storage location assigned in OVL3(Picking Location Determination). In case if Storage location has assigned, but stock is not maintained in storage location - then we will get this error.
    Try to change the storage location in this or in the sale order..
    I would suggest u to add stock for that particular storage location..
    Thanks,
    Venkatesh.S.P

  • How to create a .env after clone?

    Hi:
    I am doing a clone. The database clone is done. Now the apps tier. I copied files from prod to target. And now trying change APPS password. but got error. FNDCPASS: error while loading shared libraries:libclntsh.so.10.1: cannot open shared object file: No such file or directory
    Hussien said in a thread that i need to run .env file. But i don't have one, only have prod's env file. What i should do?
    OS: Linux; EBS: 12.1.3

    I am doing a clone. The database clone is done. Now the apps tier. I copied files from prod to target. And now trying change APPS password. but got error. FNDCPASS: error while loading shared libraries:libclntsh.so.10.1: can not open shared object file: No such file or directory
    Hussien said in a thread that i need to run .env file. But i don't have one, only have prod's env file. What i should do? You need to complete the application tier cloning before using FNDCPASS, and only then you will have the env file generated for you under $APPL_TOP directory (assuming Rapid Clone completes successfully at the application tier node).
    Cloning Oracle Applications Release 12 with Rapid Clone [ID 406982.1]
    Thanks,
    Hussein

  • How to create a label after hitting a button

    l = new JLabel();
    l.setSize(22, 22);
    l.setBackground(Color.blue);
    jContentPane.add(l, null);
    i tried this code in actionPerformed but nothing happens
    could anyone help me plz

    l = new JLabel();
    l.setSize(22, 22);
    l.setBackground(Color.blue);
    l.setOpaque(true); //<-- insert this line to see a blue label
    jContentPane.add(l, null);

  • How to create an INSERT trigger which creates a "sequence number"

    Imagine a table T_Q with columns C_1, C_2, C_3 and UN_123.
    C_1, C_2 and C_3 are all numeric and given by the user.
    UN_123 has to be a calculated sequence number starting by 1 and incremented by 1 for each combination of C_1, C_2 and C_3, i.e., the sequence number depends on the key values C_1, C_2 and C_3.
    Could anybody provide a code sample on how to create a BEFORE INSERT trigger , which calculates the value of the column UN_123 based on the values of C_1, C_2 and C_3 ??
    Premise: Rather than using any sequence, the trigger code should only be based on the table T_Q
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Rainer Wagner ([email protected]):
    Imagine a table T_Q with columns C_1, C_2, C_3 and UN_123.
    C_1, C_2 and C_3 are all numeric and given by the user.
    UN_123 has to be a calculated sequence number starting by 1 and incremented by 1 for each combination of C_1, C_2 and C_3, i.e., the sequence number depends on the key values C_1, C_2 and C_3.
    Could anybody provide a code sample on how to create a BEFORE INSERT trigger , which calculates the value of the column UN_123 based on the values of C_1, C_2 and C_3 ??
    Premise: Rather than using any sequence, the trigger code should only be based on the table T_Q<HR></BLOCKQUOTE>
    null

  • How to create an ADF table which has a command button column?

    Hi
    Thank you for reading my post
    how i can create a tabl that one of its column is a command button.
    when i press the command button it will , for example delete that row or do some action.
    indeed i want to know
    -how to have a command button column
    -how to find the rowID or some row identifier that help me locate that row in the database.
    thanks

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Rainer Wagner ([email protected]):
    Imagine a table T_Q with columns C_1, C_2, C_3 and UN_123.
    C_1, C_2 and C_3 are all numeric and given by the user.
    UN_123 has to be a calculated sequence number starting by 1 and incremented by 1 for each combination of C_1, C_2 and C_3, i.e., the sequence number depends on the key values C_1, C_2 and C_3.
    Could anybody provide a code sample on how to create a BEFORE INSERT trigger , which calculates the value of the column UN_123 based on the values of C_1, C_2 and C_3 ??
    Premise: Rather than using any sequence, the trigger code should only be based on the table T_Q<HR></BLOCKQUOTE>
    null

  • Create Info objects after extracting ds from ecc

    Hi All,
    I have replicated ds from ecc to bi and executed the infopackage. Now the data is upto psa level. How to create info objects after loading data to psa level to load the info objects to data targets like infocubes and dso. I have done to sucessfully to a flat file.
    Thank you.

    Hi Sudhir,
    You can go into 2 directions: use as much as possible Business Content InfoObjects or use custom InfoObjects. A combination is also possible.
    Especially in conjunction with SAP ECC extractions the Business Content InfoObjects are a safe choice. However, please consider the advantages it can have to use custom InfoObjects.
    If you would like to go into the direction of custom InfoObjects, then I suggest reading the following blogs:
    Generating Data Warehouse InfoObjects - Part 1: Introduction;
    Generating Reporting InfoObjects based on Business Content - Part 1: Introduction.
    Best regards,
    Sander

  • How to create a new FTP folder for a child theme for Word Press?

    Hello, I am getting hung up on creating a new ftp folder in OS X 10.5.8 in order to set up a child theme. Once I am in the ftp file listing <Go - Connect to Server> I'm not sure how to create the folder after that.  I've tried right clicking (external mouse).  Newer Macs seem to have an Add Folder button at the top of the page. Does anyone know how to do this?

    Hi laundry,
    I tried that but it didn't work.  I'm thinking I need to move in a different direction than the child theme option.  Maybe I'll need to do this further down the road when my blog is more advanced.  The Command +Shift+ N shortcut should work in other windows though right?

Maybe you are looking for