Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    136

    Unanswered: create-table-question

    Hello!

    how can i implement the following table-concept:


    create table book(
    id integer constraint PK_book,
    name varchar2 (20),
    author varchar2(20),

    ..

    borrow boolean,
    borrow_days integer
    );

    Restrictions:
    if borrow = "Yes" --> borrow_days = (0, 1,2 .....)
    if borrow = "No" ---> borrow_days doesn't exist
    Regards,
    Julia

  2. #2
    Join Date
    Jan 2004
    Posts
    2

    Re: create-table-question

    Since I'm quite a newbie, I hope that some of the experienced developers will correct me, if I'm wrong, but I think you can use a check like this:

    create table book
    (
    id integer,
    name varchar2 (20),
    author varchar2(20),
    borrow integer,
    borrow_days integer,
    constraint PK_book PRIMARY KEY (id)
    );


    ALTER TABLE book ADD CONSTRAINT table_check check ((borrow != 0 AND borrow_days IS NOT NULL AND borrow_days >= 0)
    or
    (borrow = 0 AND borrow_days IS NULL));

    , where I use an integer (0...FALSE, <>0 ....TRUE) to represent a boolean.

    hons

Posting Permissions

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