Confusion On Creating Foreign Key

I'm confused about creating a foreign key in my table since two tables in the schema will hold identical info:
EMP_ID
EMP_NAME
EMP_MANAGER
DEPT_ID
DEPT_NAME
DEPT_MANAGER
Now my 1st confusion is if I'm creating a foreign key, do I point EMP_MANAGER to DEPT_ID or DEPT_MANAGER? How can I configure the EMPLOYEES.EMP_MANAGER to pull the values from DEPARTMENT.DEPT_MANAGER? Would I need to point it to DEPT_ID for any reason or would it be a direct link between the two _MANAGER columns?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

>
the two column names have to be exact
>
No! The data in the columns needs to be exact. It doesn't matter what the column names are.
The column names you provided appear to show that YOUR emp table is denormalized. It has an EMP_MANAGER column which presumably contains the NAME of the manager, rather than the DEPT_ID of the manager. If it actually contains the NAME and the DEPT_MANAGER column of the other table has names you could create a foreign key between them.
But that means you are duplicating the manager name in both tables. If the EMP_MANAGER column actually contains the DEPT_ID of the employees manager then create a foreign key between EMP_MANAGER and DEPT_ID.

Similar Messages

  • Unable to create foreign key: InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index

    I am running an SQL(CE) script to create a DB. All script commands succeed, but the DB get "broken" after creating the last costaint: after running the script, viewing table properties of Table2 and clicking on "Manage relations" gives the following error: Unable to create foreign key: InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index. Wondering what does that refer to...
    Here it is the script. Please note that no error is thrown by running the following queries (even from code that passing the queries by hand, one-by-one to sql server management studio).
    CREATE TABLE [table1] (
    [id_rubrica] numeric(18,0) NOT NULL
    , [id_campo] numeric(18,0) NOT NULL
    , [nome] nvarchar(100) NOT NULL
    GO
    ALTER TABLE [table1] ADD PRIMARY KEY ([id_rubrica],[id_campo]);
    GO
    CREATE UNIQUE INDEX [UQ__m_campi] ON [table1] ([id_campo] Asc);
    GO
    CREATE TABLE [table2] (
    [id_campo] numeric(18,0) NOT NULL
    , [valore] nvarchar(4000) NOT NULL
    GO
    ALTER TABLE [table2] ADD PRIMARY KEY ([id_campo],[valore]);
    GO
    ALTER TABLE [table2] ADD CONSTRAINT [campo_valoriFissi] FOREIGN KEY ([id_campo]) REFERENCES [table1]([id_campo]);
    GO
    Sid (MCP - http://www.sugata.eu)

    I know this is kind of old post, but did this realy solved your problem?
    I'm getting this same error message after adding a FK constraint via UI on VS2008 Server Explorer.
    I can add the constraint with no errors, but the constraint is not created on the DataSet wizard (strongly typed datasets on Win CE 6) and when I click "Manage Relations" on the "Table Properties" this error pop out:
    "InvalidArgument=Value or '0' is not valid for 'index'.
    Parameter name: index"
    Even after vreating my table with the relation in SQL the same occurs:
    CREATE TABLE pedidosRastreios (
        idPedidoRastreio INT NOT NULL IDENTITY PRIMARY KEY,
        idPedido INT NOT NULL CONSTRAINT FK_pedidosRastreios_pedidos REFERENCES pedidos(idPedido) ON DELETE CASCADE,
        codigo NVARCHAR(20) NOT NULL

  • How to create foreign key automatically?

    I am writing to seek help, in regards creating foreign key automatically, when I insert data into my ''price'' table.  I have 2 tables, one called prices and names.  the relationship between them, if that one name can have many prices and one price
    can have many names (many-to-many). Hence, i have junction table called  "Name_Prices", as shown below in the sample database schema:
    Names
    name_id [pk]
    name
    type
    UploadDate
    Prices
    Price_id [pk]
    name_id [fk]
    price
    uploadDate
    Name_Prices
    name_id REFERENCE names (name_id)
    price_id REFERENCE prices (price_id)
    PRIMARY KEY (name_id, price_id)
    The  price's data input comes in as CSV file everyday. (please see the example below) :
    name name_type price UploadDate
    ALBA MBS 93.5 17/10/2014
    ALESC Trup 58 17/10/2014
    ALESC Trup 52 17/10/2014
    My desire goal/output is to be able to create a functionality, where I can insert the price's data into the database (''prices''), it will automatically insert foreign key in the price
    table (from the names table), and if there is a new price's name, then the database will create a new name id for it, in the name's table, transferring the name, its type, from the CSV input data. 
    In order to achieve this task, where would I start implementing this logic?(in SQL server or application-side) what steps does this involve and is this task achievable, all in sql server side (i.e. store procedure, functions etc..). 
    Apology in advance, if the question is not clear to understand, i happy to follow up with further questions, if required.  
    Any help would be very appreciated. Many thanks

    As noted above, I modified the design:
    Products
    Product_id [pk]
    Product
    type
    UploadDate
    Prices
    Price_id [pk]
    price
    uploadDate
    Product_Prices
    Product_id REFERENCE Products (Product_id)
    price_id REFERENCE prices (price_id)
    PRIMARY KEY (Product_id, price_id)
    Note
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Is it possible to create foreign key from composite key in other table.

    SQL> desc PRODUCT_CONFIG_OPTION;
    Name Null? Type
    CONFIG_ITEM_ID NOT NULL VARCHAR2(20) --composite primary key
    CONFIG_OPTION_ID NOT NULL VARCHAR2(20) --composite primary key
    CONFIG_OPTION_NAME VARCHAR2(100)
    DESCRIPTION VARCHAR2(255)
    SEQUENCE_NUM NUMBER(18)
    LAST_UPDATED_STAMP TIMESTAMP(6)
    LAST_UPDATED_TX_STAMP TIMESTAMP(6)
    CREATED_STAMP TIMESTAMP(6)
    CREATED_TX_STAMP TIMESTAMP(6)
    SQL> DESC PRODUCT_CONFIG_ITEM;
    Name Null? Type
    CONFIG_ITEM_ID NOT NULL VARCHAR2(20)
    CONFIG_ITEM_TYPE_ID VARCHAR2(20)
    CONFIG_ITEM_NAME VARCHAR2(100)
    DESCRIPTION VARCHAR2(255)
    LONG_DESCRIPTION CLOB
    IMAGE_URL VARCHAR2(255)
    LAST_UPDATED_STAMP TIMESTAMP(6)
    LAST_UPDATED_TX_STAMP TIMESTAMP(6)
    CREATED_STAMP TIMESTAMP(6)
    CREATED_TX_STAMP TIMESTAMP(6)
    SQL> desc product;
    Name Null? Type
    PRODUCT_ID NOT NULL VARCHAR2(20)
    PRODUCT_TYPE_ID VARCHAR2(20)
    PRIMARY_PRODUCT_CATEGORY_ID VARCHAR2(20)
    MANUFACTURER_PARTY_ID VARCHAR2(20)
    FACILITY_ID VARCHAR2(20)
    INTRODUCTION_DATE TIMESTAMP(6)
    SUPPORT_DISCONTINUATION_DATE TIMESTAMP(6)
    SALES_DISCONTINUATION_DATE TIMESTAMP(6)
    SALES_DISC_WHEN_NOT_AVAIL CHAR(1)
    INTERNAL_NAME VARCHAR2(255)
    BRAND_NAME VARCHAR2(100)
    COMMENTS VARCHAR2(255)
    =========
    CREATE TABLE PROD_CONFIG_PROD_CONFIG_OPTION (
    PRODUCT_ID VARCHAR2(20),
    CONFIG_ITEM_ID VARCHAR2(20),
    CONFIG_OPTION_ID VARCHAR2(20),
    PAGE_NUM_TO NUMBER(18),
    ALTERNATE_PAGE_NUM_TO1 NUMBER(18),
    ALTERNATE_PAGE_NUM_TO2 NUMBER(18),
    ALTERNATE_PAGE_NUM_TO3 NUMBER(18),
    LAST_UPDATED_STAMP TIMESTAMP(6),
    LAST_UPDATED_TX_STAMP TIMESTAMP(6),
    CREATED_STAMP TIMESTAMP(6),
    CREATED_TX_STAMP TIMESTAMP(6),
    CONSTRAINT PK_PROD_CAT_CONFIG_MOD PRIMARY KEY (PRODUCT_ID),
    CONSTRAINT FK_PRODUCT_ID FOREIGN KEY (PRODUCT_ID) REFERENCES PRODUCT(PRODUCT_ID),
    CONSTRAINT FK_CONFIG_ITEM_ID FOREIGN KEY (CONFIG_ITEM_ID) REFERENCES PRODUCT_CONFIG_ITEM(CONFIG_ITEM_ID),
    CONSTRAINT FK_CONFIG_OPTION_ID FOREIGN KEY (CONFIG_OPTION_ID) REFERENCES PRODUCT_CONFIG_OPTION(CONFIG_OPTION_ID) )
    TABLESPACE DATA_SMALL
    i try to create this table if i omit 3rd foreign key constraint then table successfully created.but including trd foreign key constraint it return error "ORA-02270: no matching unique or primary key for this column-list"
    i checked everything is it possible to create foreign key from composite key in other table.

    And
    CONSTRAINT FK_CONFIG_OPTION_ID FOREIGN KEY (CONFIG_ITEM_ID,CONFIG_OPTION_ID) REFERENCES PRODUCT_CONFIG_OPTION(CONFIG_ITEM_ID,CONFIG_OPTION_ID)
    ?

  • Create Foreign Keys between two Schemata

    Hello,
    I use Oracle 10g and I trying to create a ForeignKey constraint between two tables in different schemata.
    This is my DDL-Script
    SQL> CREATE TABLE PROJECT.LOCATION (
    ID INTEGER NOT NULL,
    MAIN INTEGER,
    KURZ VARCHAR(40),
    NAME VARCHAR(40),
    STRASSE VARCHAR(40),
    ORT VARCHAR(40),
    TELEFON VARCHAR(40),
    FAX VARCHAR(40),
    EMAIL VARCHAR(40),
    PLZ VARCHAR(40),
    CONSTRAINT PK_LOCATION PRIMARY KEY (ID)
    Tablespace PROJECT;
    CREATE TABLE Diary.Diary (
    ID INTEGER NOT NULL,
    LOCATION_ID INTEGER NOT NULL,
    CONSTRAINT PK_Diary PRIMARY KEY (ID)
    Tablespace Diary;
    ALTER TABLE Diary.Diary
    ADD CONSTRAINT FK_Diary_Has_LOCATION
    FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID);
    This is the Message that gives my SQLplus :
    SQL> ALTER TABLE Diary.Diary
    2 ADD CONSTRAINT FK_Diary_Has_LOCATION
    3 FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID);
    FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID)
    FEHLER in Zeile 3:
    ORA-00942: Tabelle oder View nicht vorhanden
    All Grants (select,alter,references) are given to the User for the tables.
    Whats then Problem?

    You miss some priviledge:
    SQL> create user project identified by project;
    Utente creato.
    SQL> grant connect, resource to project;
    Concessione riuscita.
    SQL> create user diary identified by diary;
    Utente creato.
    SQL> grant connect, resource to diary;
    Concessione riuscita.
    SQL> CREATE TABLE PROJECT.LOCATION (
      2  ID INTEGER NOT NULL,
      3  MAIN INTEGER,
      4  KURZ VARCHAR(40),
      5  NAME VARCHAR(40),
      6  STRASSE VARCHAR(40),
      7  ORT VARCHAR(40),
      8  TELEFON VARCHAR(40),
      9  FAX VARCHAR(40),
    10  EMAIL VARCHAR(40),
    11  PLZ VARCHAR(40),
    12  CONSTRAINT PK_LOCATION PRIMARY KEY (ID)
    13  )
    14  ;
    Tabella creata.
    SQL> CREATE TABLE Diary.Diary (
      2  ID INTEGER NOT NULL,
      3  LOCATION_ID INTEGER NOT NULL,
      4  CONSTRAINT PK_Diary PRIMARY KEY (ID)
      5  )
      6  ;
    Tabella creata.
    SQL> ALTER TABLE Diary.Diary
      2  ADD CONSTRAINT FK_Diary_Has_LOCATION
      3  FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID);
    FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID)
    ERRORE alla riga 3:
    ORA-00942: tabella o vista inesistente
    -- DIARY CAN'T SEE PROJECT.LOCATION
    SQL> grant select on project.location to diary;
    Concessione riuscita.
    SQL> ALTER TABLE Diary.Diary
      2  ADD CONSTRAINT FK_Diary_Has_LOCATION
      3  FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID);
    FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID)
    ERRORE alla riga 3:
    ORA-01031: privilegi insufficienti
    -- DIARY CAN SEE PROJECT.LOCATION BUT CAN'T REFERENCE IT
    SQL> grant references on project.location to diary;
    Concessione riuscita.
    SQL> ALTER TABLE Diary.Diary
      2  ADD CONSTRAINT FK_Diary_Has_LOCATION
      3  FOREIGN KEY (LOCATION_ID) REFERENCES PROJECT.LOCATION (ID);
    Tabella modificata.
    -- NOW IT'S ALL OK!!Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/18/table-elimination-oppure-join-elimination-lottimizzatore-si-libera-della-zavorra/]

  • Syntax for creating foreign key across users in a database

    There are two user present A,B.They are granted all privileges.Now in USER A, there is a table PARENT whose primary key is PARENT_NO.In USER B I have created a table CHILD whose primary key is CHILD_NO.
    In the CHILD table of USER B, I want to create a foreign key relation to the PARENT table of USER A.For this I have created a column CHILD_PARENT_NO in the CHILD table.If anybody knows the syntax please post the syntax for creating the required foreign key relationship?

    Please post your code. Cut'n'paste from SQL*Plus like this...
    SQL> conn a/a
    Connected.
    SQL> desc t1
    Name                                      Null?    Type
    COL1                                               NUMBER
    COL2                                               VARCHAR2(10)
    SQL> grant references on t1 to b;
    Grant succeeded.
    SQL> conn b/b
    SQL> create synonym a_t for a.t1;
    Synonym created.
    SQL> alter table test add constraint fk foreign key (n) references a_t(col1);
    Table altered.
    SQL> Note that Oracle will translate the synonym anyway...
    SQL> select constraint_name, r_owner, r_constraint_name
      2  from  user_constraints
      3  where table_name = 'TEST'
      4  /
    CONSTRAINT_NAME R_OWNER R_CONSTRAINT_NAME
    FK              A       T1_PK
    SQL> By the way, this ...
    GRANT ALL PRIVILEGES TO B;... is a mindbendingly unsafe way of proceeding. In real life you would have given user B the power to utterly destroy your database. It's always easier to start with good habits than to break bad ones so please get used to granting only the minimum set of privileges necessary.
    Cheers, APC

  • Create foreign keys to delete child records

    I am unfamiliar with foreign keys, I have 3 tables one is the parent table if a record is deleted in the parent table I would like the record to be deleted from the child record but I think that I am also confused about which should be the parent table
    (purpose is to use in a form)
    parent table (i think)
    AdminEntry table
    entryid ,
    date1,
    date1desc,
    date2,
    date2desc,
    date3,
    date3desc
    In a form each date and its description is placed in the following table
    CalendarEntry table
    calendarid,
    date,
    datedesc
    entryid (fk)?
    so CalendarEntry will have many entries at least 3 from one entryId, this I get but what if I want to delete lets say date2 and date2desc record. If I delete it from AdminEntry table how will calendarEntry table know which one to delete?
    Please help very confused.
    (the other table also inserts to the CalendarEntry table)

    There is a demo of this functionality in Morgan's Library at www.psoug.org under Foreign Keys.
    Look for ON DELETE CASCADE.

  • Please help me to create foreign key.

    oracle 10g, using sqldbx
    I tried everything I could but all in vain,
    CREATE TABLE folder(
    folderid INT NOT NULL PRIMARY KEY,
    foldername VARCHAR(255) NOT NULL,
    createdby VARCHAR(255) NOT NULL,
    createdate TIMESTAMP NOT NULL
    CREATE TABLE document(
    documentid INT NOT NULL PRIMARY KEY,
    folderid INT NOT NULL,
    documenttitle VARCHAR(255) NOT NULL,
    documentauthor VARCHAR(255) NOT NULL,
    createdate TIMESTAMP NOT NULL
    ALTER TABLE document ADD CONSTRAINT fkdocument FOREIGN KEY (document.folderid) REFERENCES (folder.FOLDERID)
    the last statement is saying invalid folder name. Please help

    Hi,
    Welcome to the forum!
    See the SQL Language manual for the correct syntax:
    ALTER TABLE     document
    ADD CONSTRAINT      fkdocument
    FOREIGN KEY      (folderid)
    REFERENCES      folder (FOLDERID)
    ;Thanks for posting your code! That's very helpful.
    Have you seen the forum FAQ yet? {message:id=9360002}

  • What's the privileges to create foreign key to a different schema.table ?

    Hi
    In my current schema I want to add a new foreign key. But this key is referencing to a table in a different schema, like this:
    Alter table some_table ADD ( Constraint FK_01 Foreign Key (L_ID) References schema.table (LL_ID));
    and getting the error - ORA-01031 insufficient privileges
    Which privileges do I need for this (At this time, I have only GRANT Select)? Any help would be much appreciated
    Best regards
    Remo

    Hi,
    You need GRANT REFERENCES object privilege to the user.
    Cheers

  • I am unable to create the Foreign key

    Hi,
    I need to create the Foreign key which reffered to composite primary key.
    the following table structure
    Parent table
    DIVISION, PROJECT_NUMBER, COMPETITION_PROJECT_NUMBER, COMPETITIVE_STMT_TYPE, SEQUENCE, CATEGORY, STATEMENT, USER_ID, RECORD_MODIFICATION_DATE
    Here composite primary key columns(DIVISION, PROJECT_NUMBER, COMPETITION_PROJECT_NUMBER, COMPETITIVE_STMT_TYPE, SEQUENCE)
    Child Table
    DIVISION          VARCHAR2 (4)          
    PROJECT_NUMBER          NUMBER (10)COMPETITION_PROJECT_NUMBER     NUMBER (10)          
    COMPETITIVE_STMT_TYPE          VARCHAR2 (2)          
    SEQUENCE     NUMBER (2)          
    CATEGORY          VARCHAR2 (100)     
    STATEMENT     LONG          
    USER_ID     VARCHAR2 (100)          
    RECORD_MODIFICATION_DATE     DATE     
    ALTER TABLE COMPETITION_STMT ADD (CONSTRAINT COMPET_STMT_FK_PROJ_NUM foreign key
              (PROJECT_NUMBER) REFERENCES PROD_COMPET_XREF (PROJECT_NUMBER));
    when i am trying to create foreign key i got this error
    ORA-02270: no matching unique or primary key for this column-list
    this is production issue Please help me.
    Thanks in advance
    Regards
    Kumar.s

    ALTER TABLE PROD_COMPET_XREF ADD (
    CONSTRAINT PROD_COMP_XREF_PK_DPNCPNCT
    PRIMARY KEY
    (COMPETITION_PROJECT_NUMBER, PROJECT_NUMBER, DIVISION, PRODUCT_LOC_INDICATOR)
    When you create a foreign key, it must reference a unique or primary key. The primary or Unique key must consist ONLY of those columns upon which the Primary key is based.
    You must Alter the table and add a Unique key if you want to keep your compsite primary key constraint. The Unique key must be for only the column that your foreign key references. Then try to recreate your foreign key.
    I doubt you will be able to add a foreign key because I suspect you might have multiple rows with the same value for this column based on your composite key; however, if you only intend for the project number to be listed only once and to be unique for each row, then the unique key may work or you may want to revist your primary key on this table. Perhaps you don't need it to be a composite PK???
    If you can't work around that, one thing you can do is build a table based just on PROJECT_NUMBER that contains details about the project number and have other tables reference that. That is, if you have multiple rows with the same project number in that table. You may already have one? Perhaps you can build your foreign key to reference that?

  • Data Modeler 3.0 EA1 - Logical Relation to Foreign Key not generating

    When use "Engineer to Relational Model" the only time it creates foreign keys from my relations is when those relations are of the type many-to-many. I've added a Primary UID for each table and I have tried to use the Apply Naming Standard options but nothing seems to work.
    I tested my design with the design rules feature I have no errors.
    Does anyone have any ideas?
    Greg

    Hi Greg,
    probably you added primary uid after first engineering to relational model. You can check whether those uids are selected in engineering dialog.
    Also you can check log file in datamodeler\datamodeler\log directory for logged problems there.
    Philip

  • Primary key foreign key dependencies

    hi gems...
    I have a table with composite primary key (COL1, COL2)..
    create table TABLE1 (COL1, COL2);
    alter table TABLE1 add constraint PK_TABLE1 primary key (COL1, COL2);
    Now i am trying to make another table which will refer to the COL1 of the first table.
    create table TABLE2 (COL3, COL4);
    alter table TABLE2 add constarint FK_TABLE2 (COL3) references TABLE1(COL1);
    but it is failing with "no matching unique or primary key" error.

    You have created a composite primary key, so there must be composite foreign key that references the composite primary key. You cannot create Foreign key that references to single column of the composite primary key.

  • Foreign key primary relationship

    Can we create foreign key on composite primary key? how?
    Edited by: 854624 on Apr 25, 2011 8:30 PM

    Hi,
    854624 wrote:
    But can we relate one column as foreign key with composite primary key ?Sorry, I don't understand what you're asking. Please post a concrete example, like
    "If I have these tables: CREATE TABLE ...
    and they contain this data: ...
    can I have a foreign key constraint that would allow these statements: INSERT ...
    but not allow these: INSERT ...
    because ...?"
    In the referenced table, the column for a foreign key must be unique. If column_a is unique, then it can be part of a composite primary key, but it doesn't make any sense. if column_a is unique, why isn't column_a, all by itself, the primary key?

  • Optional Composite Foreign Key

    The tool doesn't seem to be handling this correctly when some of the columns are mandatory and others are nullable. I have a composite foreign key where one column is part of the primary key and the other is not. In the Columns properties of the Table dialog, it shows the column that is part of the primary key as mandatory. But on the diagram, the "red dot" indicator is missing. It also give me an error on the Foreign Keys properties when I click OK or Apply.

    No, You cant get a composite keys based on two different primary keys. Reason for this can be like unique index is being used when we create any primary key. When we create a composite primary key, one index is created for the two fields and thus one index store the values for two columns involved in the composite primary key and these values are stored in pairs. So when any foreign key references this composite primary key, it will match the data in pairs as it is stored in the index(unique index).
    Now when we say to create a composite foreign key based on two different primary keys , we are taking into account two indexes for two different fields. So there is no pairing in these two indexes. So when we will create foreign key using this, it will not get a pair of values or we can say oracle cant get us consistent pair of values from two indexes. So maintaining integrity will not be possible.
    Yes you can create two foreign keys on one column which can refer two different primary keys.
    Regards

  • Composite Foreign Key

    Dear All
    please correct this syntax for composite foreign key.
    Ater Table emp_pays
    Add Constraints emp_pt_fk Foreign Key(emp_id,pt_id) Referenes emp(emp_id),pay_type(pt_id);
    Thanks in advances
    Regards,

    No, You cant get a composite keys based on two different primary keys. Reason for this can be like unique index is being used when we create any primary key. When we create a composite primary key, one index is created for the two fields and thus one index store the values for two columns involved in the composite primary key and these values are stored in pairs. So when any foreign key references this composite primary key, it will match the data in pairs as it is stored in the index(unique index).
    Now when we say to create a composite foreign key based on two different primary keys , we are taking into account two indexes for two different fields. So there is no pairing in these two indexes. So when we will create foreign key using this, it will not get a pair of values or we can say oracle cant get us consistent pair of values from two indexes. So maintaining integrity will not be possible.
    Yes you can create two foreign keys on one column which can refer two different primary keys.
    Regards

Maybe you are looking for