How to create tables referenced each other

Ask a Question related to Oracle Server, Design and Development.

  1. #1

    Default How to create tables referenced each other

    I had 'SQL the complete reference' authored by James R. Groff. I can not
    believe it I can not find email or home page for this book or authors. Now I
    have a question about how to create tables referenced each other. I have a
    sql from the book. It doesn't work on Oracle. I cite it as following:

    CREATE TABLE CUSTOMERS
    (CUST_NUM INTEGER NOT NULL,
    COMPANY VARCHAR(20) NOT NULL,
    CUST_REP INTEGER,
    CREDIT_LIMIT NUMERIC(16,6),
    PRIMARY KEY (CUST_NUM),
    FOREIGN KEY HASREP (CUST_REP)
    REFERENCES SALESREPS
    ON DELETE SET NULL),

    CREATE TABLE OFFICES
    (OFFICE INTEGER NOT NULL,
    CITY VARCHAR(15) NOT NULL,
    REGION VARCHAR(10) NOT NULL,
    MGR INTEGER,
    TARGET NUMERIC(16,6),
    SALES NUMERIC(16,6) NOT NULL,
    PRIMARY KEY (OFFICE),
    FOREIGN KEY HASMGR (MGR)
    REFERENCES SALESREPS
    ON DELETE SET NULL),

    CREATE TABLE SALESREPS
    (EMPL_NUM INTEGER NOT NULL,
    NAME VARCHAR(15) NOT NULL,
    AGE INTEGER,
    REP_OFFICE INTEGER,
    TITLE VARCHAR(10),
    HIRE_DATE DATE NOT NULL,
    MANAGER INTEGER,
    QUOTA NUMERIC(16,6),
    SALES NUMERIC(16,6) NOT NULL,
    PRIMARY KEY (EMPL_NUM),
    FOREIGN KEY (MANAGER)
    REFERENCES SALESREPS
    ON DELETE SET NULL,
    FOREIGN KEY WORKSIN (REP_OFFICE)
    REFERENCES OFFICES
    ON DELETE SET NULL),

    CREATE TABLE ORDERS
    (ORDER_NUM INTEGER NOT NULL,
    ORDER_DATE DATE NOT NULL,
    CUST INTEGER NOT NULL,
    REP INTEGER,
    MFR CHAR(3) NOT NULL,
    PRODUCT CHAR(5) NOT NULL,
    QTY INTEGER NOT NULL,
    AMOUNT NUMERIC(16,6) NOT NULL,
    PRIMARY KEY (ORDER_NUM),
    FOREIGN KEY PLACEDBY (CUST)
    REFERENCES CUSTOMERS
    ON DELETE CASCADE,
    FOREIGN KEY TAKENBY (REP)
    REFERENCES SALESREPS
    ON DELETE SET NULL,
    FOREIGN KEY ISFOR (MFR, PRODUCT)
    REFERENCES PRODUCTS
    ON DELETE RESTRICT),

    CREATE TABLE PRODUCTS
    (MFR_ID CHAR(3) NOT NULL,
    PRODUCT_ID CHAR(5) NOT NULL,
    DESCRIPTION VARCHAR(20) NOT NULL,
    PRICE NUMERIC(16,6) NOT NULL,
    QTY_ON_HAND INTEGER NOT NULL,
    PRIMARY KEY (MFR_ID, PRODUCT_ID))

    Please help me.

    Jim




    Jim Guest

  2. Similar Questions and Discussions

    1. create tables in pdf using perl
      Hello All, Is there any perl module that will let me create tables inside pdf document? I need to create reports in table format in a pdf...
    2. Create tables with 'drag-to-resize' columns
      I'm new to Dreamweaver and just getting familiar with all the resources. Does anyone know of discussions, tutorials, extensions, etc., about...
    3. Create liquid window between 2 tables?
      The page contains 2 tables. One at the top and one at the bottom. The tables are measured in pixels. Top one is 20 high and the bottom one is 59...
    4. referenced records
      When I do a select on a record, is there a way that I can tell if it is being referenced by another table, and if so, can I tell by what table?
    5. Create and Drop tables in a linked server
      Hi, I have a linked server admin-new, is there a way to create and tables in the linked servers? I tried: drop table .master.dbo.tempIDs ...
  3. #2

    Default Re: How to create tables referenced each other

    The ON DELETE SET NULL and ON DELETE RESTRICT clauses are not valid for
    Oracle. And it would really help if you would run each statement and
    post any and all error messages you are receiving.

    HTH,
    Brian

    Jim wrote:
    >
    > I had 'SQL the complete reference' authored by James R. Groff. I can not
    > believe it I can not find email or home page for this book or authors. Now I
    > have a question about how to create tables referenced each other. I have a
    > sql from the book. It doesn't work on Oracle. I cite it as following:
    >
    > CREATE TABLE CUSTOMERS
    > (CUST_NUM INTEGER NOT NULL,
    > COMPANY VARCHAR(20) NOT NULL,
    > CUST_REP INTEGER,
    > CREDIT_LIMIT NUMERIC(16,6),
    > PRIMARY KEY (CUST_NUM),
    > FOREIGN KEY HASREP (CUST_REP)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL),
    >
    > CREATE TABLE OFFICES
    > (OFFICE INTEGER NOT NULL,
    > CITY VARCHAR(15) NOT NULL,
    > REGION VARCHAR(10) NOT NULL,
    > MGR INTEGER,
    > TARGET NUMERIC(16,6),
    > SALES NUMERIC(16,6) NOT NULL,
    > PRIMARY KEY (OFFICE),
    > FOREIGN KEY HASMGR (MGR)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL),
    >
    > CREATE TABLE SALESREPS
    > (EMPL_NUM INTEGER NOT NULL,
    > NAME VARCHAR(15) NOT NULL,
    > AGE INTEGER,
    > REP_OFFICE INTEGER,
    > TITLE VARCHAR(10),
    > HIRE_DATE DATE NOT NULL,
    > MANAGER INTEGER,
    > QUOTA NUMERIC(16,6),
    > SALES NUMERIC(16,6) NOT NULL,
    > PRIMARY KEY (EMPL_NUM),
    > FOREIGN KEY (MANAGER)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL,
    > FOREIGN KEY WORKSIN (REP_OFFICE)
    > REFERENCES OFFICES
    > ON DELETE SET NULL),
    >
    > CREATE TABLE ORDERS
    > (ORDER_NUM INTEGER NOT NULL,
    > ORDER_DATE DATE NOT NULL,
    > CUST INTEGER NOT NULL,
    > REP INTEGER,
    > MFR CHAR(3) NOT NULL,
    > PRODUCT CHAR(5) NOT NULL,
    > QTY INTEGER NOT NULL,
    > AMOUNT NUMERIC(16,6) NOT NULL,
    > PRIMARY KEY (ORDER_NUM),
    > FOREIGN KEY PLACEDBY (CUST)
    > REFERENCES CUSTOMERS
    > ON DELETE CASCADE,
    > FOREIGN KEY TAKENBY (REP)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL,
    > FOREIGN KEY ISFOR (MFR, PRODUCT)
    > REFERENCES PRODUCTS
    > ON DELETE RESTRICT),
    >
    > CREATE TABLE PRODUCTS
    > (MFR_ID CHAR(3) NOT NULL,
    > PRODUCT_ID CHAR(5) NOT NULL,
    > DESCRIPTION VARCHAR(20) NOT NULL,
    > PRICE NUMERIC(16,6) NOT NULL,
    > QTY_ON_HAND INTEGER NOT NULL,
    > PRIMARY KEY (MFR_ID, PRODUCT_ID))
    >
    > Please help me.
    >
    > Jim
    --
    ================================================== =================

    Brian Peasland
    [email]oracle_dba@remove_spam.peasland.com[/email]

    Remove the "remove_spam." from the email address to email me.


    "I can give it to you cheap, quick, and good. Now pick two out of
    the three"
    Brian Peasland Guest

  4. #3

    Default Re: How to create tables referenced each other

    Jim wrote:
    > I had 'SQL the complete reference' authored by James R. Groff. I can not
    > believe it I can not find email or home page for this book or authors. Now I
    > have a question about how to create tables referenced each other. I have a
    > sql from the book. It doesn't work on Oracle. I cite it as following:
    >
    > CREATE TABLE CUSTOMERS
    > (CUST_NUM INTEGER NOT NULL,
    > COMPANY VARCHAR(20) NOT NULL,
    > CUST_REP INTEGER,
    > CREDIT_LIMIT NUMERIC(16,6),
    > PRIMARY KEY (CUST_NUM),
    > FOREIGN KEY HASREP (CUST_REP)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL),
    >
    > CREATE TABLE OFFICES
    > (OFFICE INTEGER NOT NULL,
    > CITY VARCHAR(15) NOT NULL,
    > REGION VARCHAR(10) NOT NULL,
    > MGR INTEGER,
    > TARGET NUMERIC(16,6),
    > SALES NUMERIC(16,6) NOT NULL,
    > PRIMARY KEY (OFFICE),
    > FOREIGN KEY HASMGR (MGR)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL),
    >
    > CREATE TABLE SALESREPS
    > (EMPL_NUM INTEGER NOT NULL,
    > NAME VARCHAR(15) NOT NULL,
    > AGE INTEGER,
    > REP_OFFICE INTEGER,
    > TITLE VARCHAR(10),
    > HIRE_DATE DATE NOT NULL,
    > MANAGER INTEGER,
    > QUOTA NUMERIC(16,6),
    > SALES NUMERIC(16,6) NOT NULL,
    > PRIMARY KEY (EMPL_NUM),
    > FOREIGN KEY (MANAGER)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL,
    > FOREIGN KEY WORKSIN (REP_OFFICE)
    > REFERENCES OFFICES
    > ON DELETE SET NULL),
    >
    > CREATE TABLE ORDERS
    > (ORDER_NUM INTEGER NOT NULL,
    > ORDER_DATE DATE NOT NULL,
    > CUST INTEGER NOT NULL,
    > REP INTEGER,
    > MFR CHAR(3) NOT NULL,
    > PRODUCT CHAR(5) NOT NULL,
    > QTY INTEGER NOT NULL,
    > AMOUNT NUMERIC(16,6) NOT NULL,
    > PRIMARY KEY (ORDER_NUM),
    > FOREIGN KEY PLACEDBY (CUST)
    > REFERENCES CUSTOMERS
    > ON DELETE CASCADE,
    > FOREIGN KEY TAKENBY (REP)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL,
    > FOREIGN KEY ISFOR (MFR, PRODUCT)
    > REFERENCES PRODUCTS
    > ON DELETE RESTRICT),
    >
    > CREATE TABLE PRODUCTS
    > (MFR_ID CHAR(3) NOT NULL,
    > PRODUCT_ID CHAR(5) NOT NULL,
    > DESCRIPTION VARCHAR(20) NOT NULL,
    > PRICE NUMERIC(16,6) NOT NULL,
    > QTY_ON_HAND INTEGER NOT NULL,
    > PRIMARY KEY (MFR_ID, PRODUCT_ID))
    >
    > Please help me.
    >
    > Jim
    These table definitions are horrible. I use examples like this when teaching my
    students what NEVER to do.

    CHAR(3)? Never ... always use VARCHAR2(3)
    Defining constraints in a table definition without specifying constraint names,
    storage, tablespace ... yech!

    Get another book. Seriously ... get another book.

    A referential constraint between tables is a foreign key and the above creates a
    few so referential integrity has been built into what you posted. It is just
    that it is about the ugliest examples I have seen in years. I think your problem
    is one of, perhaps, not understanding them to do what you expect or how to use
    them.

    Get a decent book and it will solve multiple problems. The least of which will
    be not teaching you bad habits.
    --
    Daniel Morgan
    [url]http://www.outreach.washington.edu/extinfo/certprog/oad/oad_crs.asp[/url]
    [email]damorgan@x.washington.edu[/email]
    (replace 'x' with a 'u' to reply)


    Daniel Morgan Guest

  5. #4

    Default Re: How to create tables referenced each other

    Jim was kind enough to write:
    > I had 'SQL the complete reference' authored by James R. Groff. I can not
    > believe it I can not find email or home page for this book or authors. Now I
    > have a question about how to create tables referenced each other. I have a
    > sql from the book. It doesn't work on Oracle. I cite it as following:
    >
    > CREATE TABLE CUSTOMERS
    > (CUST_NUM INTEGER NOT NULL,
    > COMPANY VARCHAR(20) NOT NULL,
    > CUST_REP INTEGER,
    > CREDIT_LIMIT NUMERIC(16,6),
    > PRIMARY KEY (CUST_NUM),
    > FOREIGN KEY HASREP (CUST_REP)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL),
    >
    > CREATE TABLE OFFICES
    > (OFFICE INTEGER NOT NULL,
    > CITY VARCHAR(15) NOT NULL,
    > REGION VARCHAR(10) NOT NULL,
    > MGR INTEGER,
    > TARGET NUMERIC(16,6),
    > SALES NUMERIC(16,6) NOT NULL,
    > PRIMARY KEY (OFFICE),
    > FOREIGN KEY HASMGR (MGR)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL),
    >
    > CREATE TABLE SALESREPS
    > (EMPL_NUM INTEGER NOT NULL,
    > NAME VARCHAR(15) NOT NULL,
    > AGE INTEGER,
    > REP_OFFICE INTEGER,
    > TITLE VARCHAR(10),
    > HIRE_DATE DATE NOT NULL,
    > MANAGER INTEGER,
    > QUOTA NUMERIC(16,6),
    > SALES NUMERIC(16,6) NOT NULL,
    > PRIMARY KEY (EMPL_NUM),
    > FOREIGN KEY (MANAGER)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL,
    > FOREIGN KEY WORKSIN (REP_OFFICE)
    > REFERENCES OFFICES
    > ON DELETE SET NULL),
    >
    > CREATE TABLE ORDERS
    > (ORDER_NUM INTEGER NOT NULL,
    > ORDER_DATE DATE NOT NULL,
    > CUST INTEGER NOT NULL,
    > REP INTEGER,
    > MFR CHAR(3) NOT NULL,
    > PRODUCT CHAR(5) NOT NULL,
    > QTY INTEGER NOT NULL,
    > AMOUNT NUMERIC(16,6) NOT NULL,
    > PRIMARY KEY (ORDER_NUM),
    > FOREIGN KEY PLACEDBY (CUST)
    > REFERENCES CUSTOMERS
    > ON DELETE CASCADE,
    > FOREIGN KEY TAKENBY (REP)
    > REFERENCES SALESREPS
    > ON DELETE SET NULL,
    > FOREIGN KEY ISFOR (MFR, PRODUCT)
    > REFERENCES PRODUCTS
    > ON DELETE RESTRICT),
    >
    > CREATE TABLE PRODUCTS
    > (MFR_ID CHAR(3) NOT NULL,
    > PRODUCT_ID CHAR(5) NOT NULL,
    > DESCRIPTION VARCHAR(20) NOT NULL,
    > PRICE NUMERIC(16,6) NOT NULL,
    > QTY_ON_HAND INTEGER NOT NULL,
    > PRIMARY KEY (MFR_ID, PRODUCT_ID))
    >
    > Please help me.
    >
    > Jim
    >
    I think your trouble is that you're asking the dbms to create a FK
    constraint against a table that it hasn't "seen" yet. For example, your
    CUSTOMERS table references the SALESREPS table before you've created it.
    Either (1) use DEFERRED constraints or (2) create all the tables without
    FK constraints, then use a series of ALTER TABLE statements to create
    the FKs.
    --
    [:%s/Karsten Farrell/Oracle DBA/g]
    Karsten Farrell Guest

  6. #5

    Default Re: How to create tables referenced each other


    "Brian Peasland" <oracle_dba@remove_spam.peasland.com> wrote in message
    news:3F0300BF.5009A707@remove_spam.peasland.com...
    > The ON DELETE SET NULL and ON DELETE RESTRICT clauses are not valid for
    > Oracle. And it would really help if you would run each statement and
    > post any and all error messages you are receiving.
    >
    Brian,

    A minor correction:
    As tested on oracle 9.2.0.3: on delete set null is *valid*.
    Though "on delete restrict" is still invalid.

    Here is an example:
    SQL> create table t1 (a number, b varchar2(3), constraint a_pk primary key
    (a));
    Table created.

    SQL> create table t2 (a number, b varchar2(6), constraint a_fk foreign key
    (a) references t1 on delete set null);
    Table created.

    SQL> insert into t1 (a, b) values (1,'abc');
    1 row created.

    SQL> insert into t1 (a, b) values (2,'xyz');
    1 row created.

    SQL> insert into t2 (a,b) values (1,'abc');
    1 row created.

    SQL> select * from t1;
    A B
    ---------- ---
    1 abc
    2 xyz

    SQL> select * from t2;
    A B
    ---------- ------
    1 abc

    SQL> delete from t1 where a = 1;
    1 row deleted.

    SQL> select * from t1;
    A B
    ---------- ---
    2 xyz

    SQL> select * from t2;
    A B
    ---------- ------
    abc


    Anurag



    Anurag Varma Guest

  7. #6

    Default Re: How to create tables referenced each other

    Jim wrote:
    > The book has a cd with a few commercial rdbms. I expected the example
    > database has been set up once I installed one rdbms.
    > I just finished Oracle installation on my NT. There is no example database;
    > In order to learn the book, I have to create a database myself.
    > The sql given with the book doesn't work. That is what I posted.
    >
    > After I read Chapter 13 Creating a Database, I moved foreign key out of
    > table definitions and use 'Alter table tableName add foreign key ...'
    > to add foreign keys. Now I can create all five tables.
    >
    > I appreciate your help and looking for a decent book about sql. Who can
    > recommend a decent sql book?
    >
    > Jim
    >
    > "Daniel Morgan" <damorgan@exxesolutions.com> wrote in message
    > news:3F030341.7A567225@exxesolutions.com...
    > > Jim wrote:
    > >
    > > > I had 'SQL the complete reference' authored by James R. Groff. I can not
    > > > believe it I can not find email or home page for this book or authors.
    > Now I
    > > > have a question about how to create tables referenced each other. I have
    > a
    > > > sql from the book. It doesn't work on Oracle. I cite it as following:
    > > >
    > > > CREATE TABLE CUSTOMERS
    > > > (CUST_NUM INTEGER NOT NULL,
    > > > COMPANY VARCHAR(20) NOT NULL,
    > > > CUST_REP INTEGER,
    > > > CREDIT_LIMIT NUMERIC(16,6),
    > > > PRIMARY KEY (CUST_NUM),
    > > > FOREIGN KEY HASREP (CUST_REP)
    > > > REFERENCES SALESREPS
    > > > ON DELETE SET NULL),
    > > >
    > > > CREATE TABLE OFFICES
    > > > (OFFICE INTEGER NOT NULL,
    > > > CITY VARCHAR(15) NOT NULL,
    > > > REGION VARCHAR(10) NOT NULL,
    > > > MGR INTEGER,
    > > > TARGET NUMERIC(16,6),
    > > > SALES NUMERIC(16,6) NOT NULL,
    > > > PRIMARY KEY (OFFICE),
    > > > FOREIGN KEY HASMGR (MGR)
    > > > REFERENCES SALESREPS
    > > > ON DELETE SET NULL),
    > > >
    > > > CREATE TABLE SALESREPS
    > > > (EMPL_NUM INTEGER NOT NULL,
    > > > NAME VARCHAR(15) NOT NULL,
    > > > AGE INTEGER,
    > > > REP_OFFICE INTEGER,
    > > > TITLE VARCHAR(10),
    > > > HIRE_DATE DATE NOT NULL,
    > > > MANAGER INTEGER,
    > > > QUOTA NUMERIC(16,6),
    > > > SALES NUMERIC(16,6) NOT NULL,
    > > > PRIMARY KEY (EMPL_NUM),
    > > > FOREIGN KEY (MANAGER)
    > > > REFERENCES SALESREPS
    > > > ON DELETE SET NULL,
    > > > FOREIGN KEY WORKSIN (REP_OFFICE)
    > > > REFERENCES OFFICES
    > > > ON DELETE SET NULL),
    > > >
    > > > CREATE TABLE ORDERS
    > > > (ORDER_NUM INTEGER NOT NULL,
    > > > ORDER_DATE DATE NOT NULL,
    > > > CUST INTEGER NOT NULL,
    > > > REP INTEGER,
    > > > MFR CHAR(3) NOT NULL,
    > > > PRODUCT CHAR(5) NOT NULL,
    > > > QTY INTEGER NOT NULL,
    > > > AMOUNT NUMERIC(16,6) NOT NULL,
    > > > PRIMARY KEY (ORDER_NUM),
    > > > FOREIGN KEY PLACEDBY (CUST)
    > > > REFERENCES CUSTOMERS
    > > > ON DELETE CASCADE,
    > > > FOREIGN KEY TAKENBY (REP)
    > > > REFERENCES SALESREPS
    > > > ON DELETE SET NULL,
    > > > FOREIGN KEY ISFOR (MFR, PRODUCT)
    > > > REFERENCES PRODUCTS
    > > > ON DELETE RESTRICT),
    > > >
    > > > CREATE TABLE PRODUCTS
    > > > (MFR_ID CHAR(3) NOT NULL,
    > > > PRODUCT_ID CHAR(5) NOT NULL,
    > > > DESCRIPTION VARCHAR(20) NOT NULL,
    > > > PRICE NUMERIC(16,6) NOT NULL,
    > > > QTY_ON_HAND INTEGER NOT NULL,
    > > > PRIMARY KEY (MFR_ID, PRODUCT_ID))
    > > >
    > > > Please help me.
    > > >
    > > > Jim
    > >
    > > These table definitions are horrible. I use examples like this when
    > teaching my
    > > students what NEVER to do.
    > >
    > > CHAR(3)? Never ... always use VARCHAR2(3)
    > > Defining constraints in a table definition without specifying constraint
    > names,
    > > storage, tablespace ... yech!
    > >
    > > Get another book. Seriously ... get another book.
    > >
    > > A referential constraint between tables is a foreign key and the above
    > creates a
    > > few so referential integrity has been built into what you posted. It is
    > just
    > > that it is about the ugliest examples I have seen in years. I think your
    > problem
    > > is one of, perhaps, not understanding them to do what you expect or how to
    > use
    > > them.
    > >
    > > Get a decent book and it will solve multiple problems. The least of which
    > will
    > > be not teaching you bad habits.
    > > --
    > > Daniel Morgan
    > > [url]http://www.outreach.washington.edu/extinfo/certprog/oad/oad_crs.asp[/url]
    > > [email]damorgan@x.washington.edu[/email]
    > > (replace 'x' with a 'u' to reply)
    > >
    > >
    Look at Oracle8 How-To from Waite Group Press.

    --
    Daniel Morgan
    [url]http://www.outreach.washington.edu/extinfo/certprog/oad/oad_crs.asp[/url]
    [email]damorgan@x.washington.edu[/email]
    (replace 'x' with a 'u' to reply)


    Daniel Morgan Guest

  8. #7

    Default Re: How to create tables referenced each other

    The book that I first learned Oracle SQL from was Oracle, The Complete
    Reference on Oracle Press. It does a good enough job, but I'm not sure
    that I'd give it an A+.

    HTH,
    Brian

    Jim wrote:
    >
    > The book has a cd with a few commercial rdbms. I expected the example
    > database has been set up once I installed one rdbms.
    > I just finished Oracle installation on my NT. There is no example database;
    > In order to learn the book, I have to create a database myself.
    > The sql given with the book doesn't work. That is what I posted.
    >
    > After I read Chapter 13 Creating a Database, I moved foreign key out of
    > table definitions and use 'Alter table tableName add foreign key ...'
    > to add foreign keys. Now I can create all five tables.
    >
    > I appreciate your help and looking for a decent book about sql. Who can
    > recommend a decent sql book?
    >
    > Jim
    >
    > "Daniel Morgan" <damorgan@exxesolutions.com> wrote in message
    > news:3F030341.7A567225@exxesolutions.com...
    > > Jim wrote:
    > >
    > > > I had 'SQL the complete reference' authored by James R. Groff. I can not
    > > > believe it I can not find email or home page for this book or authors.
    > Now I
    > > > have a question about how to create tables referenced each other. I have
    > a
    > > > sql from the book. It doesn't work on Oracle. I cite it as following:
    > > >
    > > > CREATE TABLE CUSTOMERS
    > > > (CUST_NUM INTEGER NOT NULL,
    > > > COMPANY VARCHAR(20) NOT NULL,
    > > > CUST_REP INTEGER,
    > > > CREDIT_LIMIT NUMERIC(16,6),
    > > > PRIMARY KEY (CUST_NUM),
    > > > FOREIGN KEY HASREP (CUST_REP)
    > > > REFERENCES SALESREPS
    > > > ON DELETE SET NULL),
    > > >
    > > > CREATE TABLE OFFICES
    > > > (OFFICE INTEGER NOT NULL,
    > > > CITY VARCHAR(15) NOT NULL,
    > > > REGION VARCHAR(10) NOT NULL,
    > > > MGR INTEGER,
    > > > TARGET NUMERIC(16,6),
    > > > SALES NUMERIC(16,6) NOT NULL,
    > > > PRIMARY KEY (OFFICE),
    > > > FOREIGN KEY HASMGR (MGR)
    > > > REFERENCES SALESREPS
    > > > ON DELETE SET NULL),
    > > >
    > > > CREATE TABLE SALESREPS
    > > > (EMPL_NUM INTEGER NOT NULL,
    > > > NAME VARCHAR(15) NOT NULL,
    > > > AGE INTEGER,
    > > > REP_OFFICE INTEGER,
    > > > TITLE VARCHAR(10),
    > > > HIRE_DATE DATE NOT NULL,
    > > > MANAGER INTEGER,
    > > > QUOTA NUMERIC(16,6),
    > > > SALES NUMERIC(16,6) NOT NULL,
    > > > PRIMARY KEY (EMPL_NUM),
    > > > FOREIGN KEY (MANAGER)
    > > > REFERENCES SALESREPS
    > > > ON DELETE SET NULL,
    > > > FOREIGN KEY WORKSIN (REP_OFFICE)
    > > > REFERENCES OFFICES
    > > > ON DELETE SET NULL),
    > > >
    > > > CREATE TABLE ORDERS
    > > > (ORDER_NUM INTEGER NOT NULL,
    > > > ORDER_DATE DATE NOT NULL,
    > > > CUST INTEGER NOT NULL,
    > > > REP INTEGER,
    > > > MFR CHAR(3) NOT NULL,
    > > > PRODUCT CHAR(5) NOT NULL,
    > > > QTY INTEGER NOT NULL,
    > > > AMOUNT NUMERIC(16,6) NOT NULL,
    > > > PRIMARY KEY (ORDER_NUM),
    > > > FOREIGN KEY PLACEDBY (CUST)
    > > > REFERENCES CUSTOMERS
    > > > ON DELETE CASCADE,
    > > > FOREIGN KEY TAKENBY (REP)
    > > > REFERENCES SALESREPS
    > > > ON DELETE SET NULL,
    > > > FOREIGN KEY ISFOR (MFR, PRODUCT)
    > > > REFERENCES PRODUCTS
    > > > ON DELETE RESTRICT),
    > > >
    > > > CREATE TABLE PRODUCTS
    > > > (MFR_ID CHAR(3) NOT NULL,
    > > > PRODUCT_ID CHAR(5) NOT NULL,
    > > > DESCRIPTION VARCHAR(20) NOT NULL,
    > > > PRICE NUMERIC(16,6) NOT NULL,
    > > > QTY_ON_HAND INTEGER NOT NULL,
    > > > PRIMARY KEY (MFR_ID, PRODUCT_ID))
    > > >
    > > > Please help me.
    > > >
    > > > Jim
    > >
    > > These table definitions are horrible. I use examples like this when
    > teaching my
    > > students what NEVER to do.
    > >
    > > CHAR(3)? Never ... always use VARCHAR2(3)
    > > Defining constraints in a table definition without specifying constraint
    > names,
    > > storage, tablespace ... yech!
    > >
    > > Get another book. Seriously ... get another book.
    > >
    > > A referential constraint between tables is a foreign key and the above
    > creates a
    > > few so referential integrity has been built into what you posted. It is
    > just
    > > that it is about the ugliest examples I have seen in years. I think your
    > problem
    > > is one of, perhaps, not understanding them to do what you expect or how to
    > use
    > > them.
    > >
    > > Get a decent book and it will solve multiple problems. The least of which
    > will
    > > be not teaching you bad habits.
    > > --
    > > Daniel Morgan
    > > [url]http://www.outreach.washington.edu/extinfo/certprog/oad/oad_crs.asp[/url]
    > > [email]damorgan@x.washington.edu[/email]
    > > (replace 'x' with a 'u' to reply)
    > >
    > >
    --
    ================================================== =================

    Brian Peasland
    [email]oracle_dba@remove_spam.peasland.com[/email]

    Remove the "remove_spam." from the email address to email me.


    "I can give it to you cheap, quick, and good. Now pick two out of
    the three"
    Brian Peasland Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139