Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2012
    Posts
    4

    Unanswered: query for foreign key

    I have 2 tables like
    1. APPLICATION(Tablename)

    under which i have the following attributes:-
    -ID (Primary Key)
    -App_Name
    -Description

    2.SUB_APPLICATION(Table Name)
    -ID(Primary Key)
    -App_id(foreign key)
    -name
    -description



    now the problem is how to make App_id to foreign key which is primary key for APPLICATION....but the column name is different for example: ID(column name) of the APPLICATION table and App_id(column name) of the SUB_APPLICATION table is same but the naming is different, so how to create table for SUB_APPLICATION to make App_id as a foreign key.


    please suggest.
    Last edited by kevin87; 12-06-12 at 04:44.

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Code:
    ALTER TABLE SUB_APPLICATION 
    	ADD CONSTRAINT SUB_APPLICATION_FK FOREIGN KEY
    		(APP_ID)
    	REFERENCES APPLICATION
    		(ID)
    	ON DELETE NO ACTION
    	ON UPDATE NO ACTION
    	ENFORCED
    	ENABLE QUERY OPTIMIZATION;
    The data types should be the same for both columns (such as INT).
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

Posting Permissions

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