Results 1 to 4 of 4

Thread: Please Help Me With This Create Statement

  1. #1
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    3

    Please Help Me With This Create Statement

    HELLO ALL
    i am having troubles creating some tables please someone help me out.
    the tables have Foreign keys and they make up th Composite Primary key

    CREATE TABLE Transaction
    (Order_NO char(5),
    Product_ID char(6),
    Product_Quantity INTEGER,
    Discount_Amount INTEGER,
    Transaction_Unit_Price INTEGER,
    CONSTRAINT cfkOrderNO_ProductID FOREIGN KEY (Order_NO, Product_ID) REFERENCES Order(Order_NO), Product (Product_ID);


    CREATE TABLE Quote
    (Quote_NO char(10) ,this is a primary key
    Order_NO char(5), this is foreign key but also makes it composite pk with Product_ID,
    Product_ID Char(6),
    Quote_Date DATE,
    CONSTRAINT ???????????????????HOW DO I DO THIS?????

  2. #2
    Join Date
    Mar 2003
    Posts
    468
    not quite sure of the columns and references you are trying to do. here is an example of a composite key and a foreign key for you to look at and hopefully will help you out.

    CREATE TABLE dept
    (dept_id NUMBER,
    dept_loc NUMBER,
    dept_name VARCHAR2(30),
    CONSTRAINT dept_pk PRIMARY KEY (dept_id, dept_loc));

    CREATE TABLE employee
    (emp_id NUMBER,
    emp_name VARCHAR2(30),
    dept_id NUMBER,
    dept_loc NUMBER,
    CONSTRAINT employee_pk PRIMARY KEY (emp_id),
    CONSTRAINT employee_fk FOREIGN KEY ( dept_id, dept_loc) REFERENCES dept(dept_id,dept_loc) ON DELETE CASCADE)

  3. #3
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    3

    Unhappy SOS SOS

    hello

    sorry if i didnt clearly eplain myself before but here i go.

    i am trying to create a table clled 'transaction' it has the following colums that make it up

    Order_NO char(5),
    Product_ID char(6),
    Product_Quantity INTEGER,
    Discount_Amount INTEGER,
    Transaction_Unit_Price INTEGER,

    the top to colums 'Order_NO char(5)' AND
    Product_ID char(6),

    are both foreign keys that are coming from to different tables, so the problem that i have is that i have neva created a composite primary key that has to keys coming from different tables, i am stuk with this please help me. what should i do to make it work

  4. #4
    Join Date
    Mar 2003
    Posts
    468
    if i understand properly, the table transaction has a primary key of (Order_NO, Product_ID) and is referenced from two different tables.
    solution is to:
    1. define the transaction table with the primary key (see my dept example).
    2. go to each of the two tables that reference the transaction table and alter them to have a foreign key to the transaction table (see my employee example that references the dept table).

Posting Permissions

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