Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Posts
    8

    Question Unanswered: How to create a table

    What Im trying is to create a column on the table that only accepts 3 values.
    I know in Access you can add a validation rule for it, but Im wondering what is the rigth syntax for PL/SQL.
    I believe another way around would be to create a second table and create a foreign key, but seem to be too much hassle for something so silly.

    What I have try is:

    CREATE TABLE FACTURAS (
    InvoiceStatus VARCHAR2(PAID,APPROVAL,AWAITED,APPROVED,DISPUTED)) ,

    But it does not work.
    Any help appreciated.
    Thanks,

    Maria Eugenia

  2. #2
    Join Date
    Sep 2003
    Posts
    16
    I think you will need to put a validation trigger on inserts and updates to your table.

  3. #3
    Join Date
    Sep 2003
    Location
    Virginia, USA
    Posts
    246

    Re: How to create a table

    If it is a very small list of values and the list will not change, then you might want a CHECK constraint. For example, CREATE TABLE TEST (col1 varchar2(50) CONSTRAINT putnamehere CHECK (col1 IN ('PAID','APPROVAL')) ENABLE VALIDATE);

    The above can also be done with a trigger, but triggers are much slower than column level constraints.

    If the list of values is large, or the values might change over time, then it is best to use another table and a foreign key constraint.

    -Mark

  4. #4
    Join Date
    Oct 2003
    Posts
    22

    Re: How to create a table

    use markrem's solution.

    if a table is already existing use this command

    alter table table_name
    add check(column_name IN (value1, value2, value3, ...));

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •