How to create a composite entity table in SQL?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • honeybooboo
    New Member
    • Jun 2013
    • 1

    How to create a composite entity table in SQL?

    Here's my code:

    Code:
    CREATE TABLE SALARY
    	(
    	JOB_ID INT NOT NULL,
    	MP_ID INT NOT NULL,
    	SALARY_AMOUNT MONEY,
    	CONSTRAINT pk_SALARY
    	PRIMARY KEY (JOB_ID, MP_ID),
    	FOREIGN KEY (JOB_ID, MP_ID) REFERENCES JOB JOIN MP ON UPDATE CASCADE
    	);
    So the both PKs and FKs come from 2 different tables, everything is working until the foreign key, the part where we have to reference. How do you reference the 2 different tables where the FKs are found? I tried using JOIN but it doesn't work.

    Help please, I'm new to SQL.

    P.S.
    I've made both tables already so this is a new table under the same database. Thanks!
    Last edited by Rabbit; Jun 6 '13, 03:34 PM. Reason: Please use code tags when posting code.
  • fridrai
    New Member
    • Jun 2013
    • 9

    #2
    if u are using the phpmy admin editor, u can access to the relational view on the bottom of the table, click on, then you'll find the column of the forein key with two choices, so that u can add the index to the mentionned entity

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      If the two fields reference two different tables, you need to create two foreign keys, not one.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        It would really help if you had a foreign key to the table where MP_ID existed.

        It would also help if you posted the select statement that you have tried so far so that we can help you correct any mistakes that you may have made in the statement.

        -Frinny

        Comment

        Working...