How to apply check constraint at a row level?

I am new to SQL. I have a schema like this. Students(student_id,student_name,club,date_of_passed_out). clubs(club_name,club_in_charge,club_inaugurated_date). The students can act as the club in charges. So it is not possible for a student to act as a club in-charge if his date_of_passed_out is less than club_inaugurated_date. I must prevent accidental inputs where the club inauguration date is greater than the date of pass out of the club in-charge. How can I achieve this. Thanks in advance.

Hi,
There should be three tables for your requirement.
Table1: Clubs ( club_name, club_inauguration_date)  -- club_name is Primary Key
Table2: Students(student_id,student_name,club_name,date_of_passed_out) -- student_id primary key, club_name - Foreign Key
Table3: club_inchrg_detail ( club_name,club_incharge); -- club_incharge is - students(student_id)
SQL> create or replace trigger club_inchrg_trig
  2  after insert or update on clubs
  3  for each row
  4  declare
  5      l_passed_out  date;
  6  begin
  7
  8        select date_of_passed_out
  9          into l_passed_out
10        from students
11        where student_id = :new.club_in_charge;
12
13    if inserting or updating then
14        if :new.club_inaugurated_date <= l_passed_out then
15              raise_application_error(-20100,' Student is not eligible for club incharge ');
16        end if;
17    end if;
18  end;
19  /
Trigger created.
As I already mentioned, you should have three tables for this requirement, and also I didnt handle the exceptions. This code is just for demonstration purpose only.

Similar Messages

  • . How to put Check box in every row in Table

    Hi Friends,
    I have one doubt in Webdynpro with java. How to put Check box in every row in Table?
    For Exam My requirement is I am getting BAPI from ECC System. So I have to go given input details in first view and output details in SecondView. So in Second View I will taken Table that data will displayed in rows. I need each and every row first I need check box.
    Here Select Check Box of particular row then click GetData button.  That row data will be displayed in one popup window.
    In table suppose 6 rows available in table. Every Row first Check box available.
                             empid, name, sal  ,firstname, last Name
                             empid, name, sal  ,firstname, last Name
                             empid, name, sal  ,firstname, last Name 
    How to put Check box in every row in Table?  can you send any examples applications
    Regards
    Vijay

    Hi Friend,
    When we are getting BAPI From ECC System. that BAPI Have nodes and Attribues...in under node we can't create "CheckBox"
    attribute.
    So i am doing like this.I am create on Checbox attribue out side of Node. Check Box data type is boolean.
    next i am creating table ( that table having rows and columns) Right click on table-->Click on Insert GroupedColumn->again right click on nsert GroupedColumn---> Here Select Check Box.
    Okay...here i am getting one problem. i have got Check boxes .But i am select check box in  first row. that time all check boxes will be selected.
    i need select first row check box that only first row will be selected suppose i selected second row check box that only second will be selected.
    i need this can u help me....
    Regards
    Vijay

  • How to apply the constraint ONLY to new rows

    Hi, Gurus:
       I have one question as follows:
       We need to migrate a legacy system to a new production server. I am required to add two columns to every table in order to record who updates the row most recently through triggers, and  I should apply not null constraint to the columns . However, since legacy system already has data for every table, and old data does not have value for the 2 new columns. If we apply the constraint, all of existing rows will raise exception. I wonder if there is possibility to apply the constraint ONLY to new rows to come in future.
    Thanks.
    Sam

       We need to migrate a legacy system to a new production server. I am required to add two columns to every table in order to record who updates the row most recently through triggers, and  I should apply not null constraint to the columns .
    The best suggestion I can give you is that you make sure management documents the name of the person that came up with that hair-brained requirement so they can be sufficiently punished in the future for the tremendous waste of human and database resources they caused for which they got virtually NOTHING in return.
    I have seen many systems over the past 25+years that have added columns such as those: CREATED_DATE, CREATED_BY, MODIFIED_DATE, MODIFIED_BY.
    I have yet to see even ONE system where that information is actually useful for any real purpose. Many systems have application/schema users and those users can modify the data. Also, any DBA can modify the data and many of them can connect as the schema owner to do that.
    Many tables also get updated by other applications or bulk load processes and those processes use generic connections that can NOT be tied back to any particular system.
    The net result is that those columns will be populated by user names that are utterly useless for any auditing purposes.
    If a user is allowed to modify a table they are allowed to modify a table. If you want to track that you should implement a proper security strategy using Oracle's AUDIT functionality.
    Cluttering up ALL, or even many, of your tables with such columns is a TERRIBLE idea. Worse is adding triggers that server no other purpose but capture useless infomation but, because they are PL/SQL cause performance impacts just aggravates the total impact.
    It is certainly appropriate to be concerned about the security and auditability of your important data. But adding columns and triggers such as those proposed is NOT the proper solution to achieve that security.
    Before your organization makes such an idiotic decision you should propose that the same steps be taken before adding that functionality that you should take before the addition of ANY MAJOR structural or application changes:
    1. document the actual requirement
    2. document and justify the business reasons for that requirement
    3. perform testing that shows the impact of that requirement on the production system
    4. determine the resource cost (people, storage, etc) of implementing that requirement
    5. demonstrate how that information will actually be used EFFECTIVELY for some business purpose
    As regards items #1 and #2 above the requirement should be stated in terms of the PROBLEM to be solved, not some preconceived notion of the solution that should be used.
    Your org should also talk to other orgs or other depts in your same org that have used your proposed solution and find out how useful it has been for them. If you do this research you will likely find that it hasn't met their needs at all.
    And in your own org there are likely some applications with tables that already have such columns. Has anyone there EVER used those columns and found them invaluable for identifying and resolving any actual problem?
    If you can't use them and their data for some important process why add them to begin with?
    IMHO it is a total waste of time and resources to add such columns to ALL of your tables. Any such approach to auditing or security should, at most, be limited to those tables with key data that needs to be protected and only then when you cannot implement the proper 'best practices' auditing.
    A migration is difficult enough without adding useless additional requirements like those. You have FAR more important things you can do with the resources you have available:
    1. Capture ALL DDL for the existing system into a version control system
    2. Train your developers on using the version control system
    3. Determining the proper configuration of the new server and system. It is almost a CERTAINTY that settings will get changed and performance will suffer even though you don't think you have changed anything at all.
    4. Validating that the data has been migrated successfully. That can involve extensive querying and comparison to make sure data has not been altered during the migration. The process of validating a SINGLE TABLE is more difficult if the table structures are not the same. And they won't be if you add two columns to every table; every single query you do will have to specify the columns by name in order to EXCLUDE your two new columns.
    5. Validating the performance of the app on the new system. There WILL BE problems where things don't work like they used to. You need to find those problems and fix them
    6. Capturing the proper statistics after the data has been migrated and all of the indexes have been rebuilt.
    7. Capturing the new execution plans to use a a baseline for when things go wrong in the future.
    If it is worth doing it is worth doing right.

  • How to Disable check constraint in cronacle

    Hi All,
    We found that one job failed in cronacle with the following error
    *ORA-20800: JCS-02138: problem with parameter "PRINT_BANNERPAGE"
    SAP recommended the soultion saying
    Disable the "Check Constraints" that are being used in the scripts currently in Cronacle or apply some patch.So we want to explore the first option i.e check constraint
    Can any one help me in Regarding the check constraints.
    Thanks in advance
    shylaja

    Hi,
    Scripts can have check constraints and reference contraints, you will find these under the script properties when you edit the script.
    I would set the constraint to optional, meaning that you still have the dropdown available but it no longer complains if it does not like the chosen value.
    Regards,
    Anton.

  • How to apply different colors to specific rows in JTable

    hi,
    Anybody could tell me the way of colorising the rows in jtable.. I want to apply different colors to diff rows..
    If i get a piece of code that could help me a lot..
    thanks in advance,
    Sapna

    you'll find the answer at http://www2.gol.com/users/tame/swing/examples/SwingExamples.html

  • How to update UDF based upon the row level dimensions.

    Hello Experts,
    I have made 4 new udf at Sales Order.  Its displaying at Righthand side under General Category.
    Now at row level im entering item detail, and other things with 4 profit center vaues.
    So i want that if i enter value in those 4 proft center in row level then it should automatically update those 4 udf with that value.
    It always happen in Add mode of SO, if SO open in update mode then i can update those udf with other values also, which can be differ then row level profit center values.
    If we need to create any trigger or any query for that, then guide me for that.
    Regards,

    Hi Chintesh,
    You can use the option of changing value when the exising column value changes. (also check the option refersh only option)
    pls revert in case more help.
    Regards,
    Datta Kharat

  • How to restrict table data at a row level?

    Hi everybody,
    I need create a database user and restrict his data access to certain tables.
    What is the best way to do this?
    Eg Table Emp has two columns, sal and dept. Sal has three distinct values: 500, 1000, 1500.
    I need to make it so that new_user can only see the data in table emp where the sal value = 500.
    Many thanks
    Rup

    You can use row-level security (VPD) for this sort of thing, so you assign a policy to the table that restricts which rows a particular user can see.
    You can also roll your own solution by creating a view on the table and granting the user access to that view rather than direct access to the table.
    Justin

  • How to get the measure total at row level for another measure calculation in DAX?

    Hi There,
    Using DAX, I am trying to get an expression for a calculated measure as follow:
    So basically, I would like to get the AMeasure total highlighted in yellow in the A2Measure calculation:
    Smeasure -(Ameasure total * WMeasure) where Ameasure total is the one highlighted. 
    I think my question would be how to get the total of a measure in order to used in the calculation of another measure.
    Thanks and best regards,
    Joss

    Hi Joss83,
    If you're trying to get the result for [AMeasure] at the total level (i.e. 5.09 in your example) you can do this by creating a version of this measures that is evaluated after ignoring the filters (indirectly or explicitly) placed on
    the 'Customer' and 'Player' columns. You may also need to ignore the filters place on some other tables or columns that must be ignored in order for the correct total to be returned.
    Without knowing much more about your data model, I can only take a vague guess as to what this calculation would look like in your scenario:
    AMeasureTotal:=
    CALCULATE(
    [AMeasure],
    ALL(Customer[Customer]),
    ALL(Player[Player])
    You can read more about the 'ALL' DAX function here:
    http://technet.microsoft.com/en-us/library/ee634802.aspx
    Hope this helps,
    Michael

  • Checking status of matrix row

    Greetings All,
    Does anyone know how i can check if a matrix row is enabled or disabled prior to updating the field? I need to know because my add on is throwing an exception stating invalid form item if the matrix row is disabled.
    Any ideas?

    Hi Curtis
    I'm not aware if you can make a row enabled or disabled...never seen it. I know you can make a whole matrix enabled or disabled. Also if you want an extra line in the matrix you add a extra one and that then becomes available. When you say disabled is this when you haven't said you want an extra row and it doesn't allow to add the row details?
    Well, to check if a matrix is enabled you do something like
    Dim item As SAPbouiCOM.Item
    item = oForm.Items.Item("matrixID")
    If item.Enabled = False Then item.Enabled = True
    Then to see how many records are in your matrix use
    oMatrix.RowCount
    It will return the number of records in the matrix. But remeber if its your own matrix you should always add a line omatrix.addrow before specifying the row contents.
    Hope this helps

  • Apply check tables to database tables

    how to apply check tables to database tables???
    plz help

    Hi
    Check Table: means the Table that contains the Primary key in the Foreign key definition.
    It has 2 important uses:
    1. To validate the inputs in the foriegn key field (For Eg: MARC-MATNR) with the values existing in the check table - Primary key field (Eg: MARA-MATNR)
    Here MARA is the Check table for the MARC-MATNR
    2. To provide the input help(F4) for foreign key field
    check table is the field level checking. we can use the Cardinality based on ur requirment.
    see the example.
    if ur using two tables like ekko and ekpo.
    ekko tables having the fields ebeln , bukrs and lifnr.
    here primery key is ebeln.
    ebeln bukrs lifnr
    101 1000 1000
    102 1000 1000
    103 2000 1001(this is entry for ekko).
    we want to insert the entry based on ekko tables.so ekko table is the ckeck table.
    ekpo table is the itam table.
    ekpo tables having the fields ebeln , matnr , menge .
    here forign key is ebeln.
    ebeln matnr menge
    101 m-1 10
    101 m-2 2
    101 m-4 18
    102 m-8 7
    103 m-5 8
    in ekpo table we can't enter other than ekko-ebeln value.
    so we can enter only based on ekko-ebeln table entries.

  • How can i apply maxlength constraint on TextField Through JavaScript ?

    How can i apply maxlength constraint on TextField Through JavaScript ,
    when i am adding the row dynamically & adding the textfield dynamically into it . I can set its attributes like name, size, focus & else, But why its not setting maxlength attribute through javascript ?
    If any body is fammiliar with this problem Please answer the question.

    Hi Ashoka,
    here is the code to get the length of the test field. then you can set your own textfield restriction. I hope this what you are searching. or else you can set the max length of the text field in HTML tag itself it is very easy.
    HTML : <input name="textfield" type="text" maxlength="25">
    JAVASCRIPT:
    <html>
    <head>
    <title>mAX tEXT <title>
    <script>
    function maX()
         var data = document.form1.textfield.value
         len = data.length
         alert("Max Value "+len);
         return true;
    </script>
    </head>
    <body>
    <form name="form1" method="post" action="">
    <input name="textfield" type="text">
    <input type="button" name="but" onClick="return maX()">
    </form>
    </body>
    </html>

  • How to apply List box for multiple selection of rows  in ALV report ?

    Hi Exprots,
    1: How to apply List box for multiple selection of rows  in ALV report ?
    Thanking you.
    Subash

    hi,
    check the below program.
    REPORT zalv_dropdowns.
    *Type pools declarations for ALV
    TYPE-POOLS : slis.
    *data declarations for ALV container,ALV grid, Fieldcatalogues & layout
    DATA: g_grid  TYPE REF TO cl_gui_alv_grid,
          g_custom_container TYPE REF TO cl_gui_custom_container,
          gt_fieldcat TYPE lvc_t_fcat,
          gs_layout TYPE lvc_s_layo.*INTERNAL TABLE AND WA DECLARATIONS FOR t517 A table
    DATA: gt_outtab TYPE STANDARD TABLE OF t517a INITIAL SIZE 0,
          wa_outtab TYPE t517a.
    START-OF-SELECTION.*Call to ALV
      CALL SCREEN 600.*On this statement double click  it takes you to the screen painter SE51.
    *Create a Custom container and name it CCONT and OK code as OK_CODE.
    *Save check and Activate the screen painter.
    *Now a normal screen with number 600 is created which holds the ALV grid.
    PBO of the actual screen , Here we can give a title and customized menus
    Here we also call the subroutine for ALV output.
          MODULE PBO OUTPUT                                             *
    MODULE pbo OUTPUT.
      PERFORM alv_output.
    ENDMODULE.                    "pbo OUTPUT
          MODULE PAI INPUT                                              *
    MODULE pai INPUT.
    ENDMODULE.                    "pai INPUT
    *&      Form  BUILD_FIELDCAT
    FORM build_fieldcat.
    DATA ls_fcat TYPE lvc_s_fcat.
    *Build the field catalogue
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name = 'T517A'
        CHANGING
          ct_fieldcat      = gt_fieldcat.
    To assign dropdown in the fieldcataogue
      LOOP AT gt_fieldcat INTO ls_fcat.   
    CASE ls_fcat-fieldname.
       WHEN 'SLART'.
    *is the first list box
            ls_fcat-drdn_hndl = '1'.
            ls_fcat-outputlen = 15.
            MODIFY gt_fieldcat FROM ls_fcat.
    is the second list box    
    WHEN 'ABART'.       
            ls_fcat-drdn_hndl = '2'.
            ls_fcat-outputlen = 15.
            MODIFY gt_fieldcat FROM ls_fcat.   
    ENDCASE.
      ENDLOOP.
    ENDFORM.                    "build_fieldcat
    *&      Form  ALV_OUTPUT
    FORM alv_output .*Create object for container
      CREATE OBJECT g_custom_container
             EXPORTING container_name = 'CCONT'.
    *create object for grid
      CREATE OBJECT g_grid
             EXPORTING i_parent = g_custom_container.
    Build fieldcat and set column
    *Assign a handle for the dropdown listbox.
      PERFORM build_fieldcat.
    *Build layout
      PERFORM build_layout.
    Define a drop down table.
      PERFORM dropdown_table.
    *fetch values from the T517A table
      SELECT * FROM t517a INTO TABLE gt_outtab.
    *Display ALV output
      CALL METHOD g_grid->set_table_for_first_display
        EXPORTING
          is_layout       = gs_layout
        CHANGING
          it_fieldcatalog = gt_fieldcat
          it_outtab       = gt_outtab.ENDFORM.                               "ALV_OUTPUT
    *&      Form  dropdown_table
          text
    -->  p1        text
    <--  p2        text
    FORM dropdown_table.*Declarations for drop down lists in ALV.
      DATA: lt_dropdown TYPE lvc_t_drop,
            ls_dropdown TYPE lvc_s_drop.
    First SLART listbox (handle '1').
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '01 Primary school'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '1'.
      ls_dropdown-value = '02 Lower Secondary'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '1'.
      ls_dropdown-value = '03 Upper Secondary'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '04 Professional School'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '05 College'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '06 University'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '09 Other Establishment'.
      APPEND ls_dropdown TO lt_dropdown.* Second ABART listbox (handle '2').  ls_dropdown-handle = '2'.
      ls_dropdown-value = '10 Primary School certificate'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '2'.
      ls_dropdown-value = '20 Lower secondary/Junior high'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '30 High school diploma(B-levels)'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '2'.
      ls_dropdown-value = '31 Vocational'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '32 Matriculation'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '40 Specialist vocational certificate'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '50 College degree Level1'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '51 College degree Level2'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '52 Masters degree'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '60 Univ Degree level1'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '61 Bachelors degree'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '62 Masters degree'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '63 Licenciate'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '64 Doctors Degree Ph.D'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '89 None'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '90 Unknown'.
      APPEND ls_dropdown TO lt_dropdown.*method to display the dropdown in ALV
      CALL METHOD g_grid->set_drop_down_table
        EXPORTING
          it_drop_down = lt_dropdown.ENDFORM.                               " dropdown_table
    *&      Form  build_layout
          text
    *layout for ALV output
    FORM build_layout .  gs_layout-cwidth_opt = 'X'.
      gs_layout-grid_title = 'ALV DROPDOWN LISTS'.
      gs_layout-no_toolbar = 'X'.ENDFORM.                    " build_layout
    endform.
    Edited by: S.r.v.r.Kumar on Jun 1, 2009 2:48 PM

  • How to check the row level security in TOAD for oracle

    Hi ,
    for ex, i have 2 types of users
    normal user and super user
    super user can see the group set (some column name) created by normal user
    but normal user can not see the set created by super user
    this set crestion aslso has 3 types "U','P',S'
    P & S can be viewed by even normal user
    but U should not
    so here we are having some row level security for the normal user .....
    So, in TOAD for oracle how to check that......
    Let me know if i'm not clear

    Like
    I'm the super user....
    And some records are inserted to a table by different users ('a' , 'b', etc....)
    So,if user 'a' logins then he can be able to see only the records inserted by 'a' only...
    how to see in TOAD where such type of scripts (filter conditions) are written.....

  • How to use external functions in check constraints

    I created my own function:
    create or replace
    function if_num_get_num (inval in varchar2)
    return number
    is
    dummy number;
    Begin
    dummy := to_number(inval);
    return dummy;
    exception
    when others then return null;
    end;Can I use it in table check constraint?
    When I use standard function INSTR everything is OK.
    ALTER TABLE A_S
    ADD CONSTRAINT A_S_CHK1 CHECK
      (INSTR(NAZWA_ZA, ':') > 0)
    ENABLE;but when I try to create it with my function:
    ALTER TABLE A_S
    ADD CONSTRAINT A_S_CHK1 CHECK
      (IF_NUM_GET_NUM(INSTR(NAZWA_ZA, ':')) > 0)
    ENABLE;I get a message "Invalid column IF_NUM_GET_NUM"

    Read the restrictions.
    >
    Restrictions on CHECK Constraints
    A CHECK constraint requires that a condition be true or unknown for every row of the table. If a statement causes the condition to evaluate to false, then the statement is rolled back. The condition of a CHECK constraint has these limitations:
    * The condition must be a boolean expression that can be evaluated using the values in the row being inserted or updated.
    * The condition cannot contain subqueries or sequences.
    * The condition cannot include the SYSDATE, UID, USER, or USERENV SQL functions.
    * The condition cannot contain the pseudocolumns LEVEL or ROWNUM.
    * The condition cannot contain the PRIOR operator.
    ** The condition cannot contain a user-defined function.*
    >
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17125/adfns_constraints.htm#ADFNS282

  • How to add a check constraint to a column to accept values in the following format: "L214"?

    All I could come up with is this:
    check (column_name like '____');
    But That doesn't enforce the first character to be a letter and the other three to be numbers.

    Hi,
    "PS: Why the f***you have so many subforums here?"
    Because it is much easier to seperate and let experts answer to specific details of SQL Server. SQL Server is not a small product as many people think ;-)
    Here is the solution:
    CREATe table SampleA (A INT, B VARCHAR(MAX) CHECK (B LIKE '[A-Z][0-9][0-9][0-9]'))
    INSERT INTO SampleA VALUES (1,'0000')
    Msg 547, Level 16, State 0, Line 2
    The INSERT statement conflicted with the CHECK constraint "CK__SampleA__B__38B96646". The conflict occurred in database "master", table "dbo.SampleA", column 'B'.
    The statement has been terminated.
    INSERT INTO SampleA VALUES (1,'L000')
    --(1 row(s) affected)
    INSERT INTO SampleA VALUES (1,'L0001')
    Msg 547, Level 16, State 0, Line 2
    The INSERT statement conflicted with the CHECK constraint "CK__SampleA__B__38B96646". The conflict occurred in database "master", table "dbo.SampleA", column 'B'.
    The statement has been terminated.
    -Jens
    Jens K. Suessmeyer http://blogs.msdn.com/Jenss

Maybe you are looking for