1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to apply foreign key constraint in PHPMyAdmin?

Discussion in 'MySQL' started by computerzworld, Sep 23, 2007.

  1. #1
    Hi. I want to apply foreign key constraint to one of the column in the table. How can I apply it using PHPMyAdmin? I am unable to get the option of applying foreign key constraint. Please help me. Thanks in advance.
     
    computerzworld, Sep 23, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Are you using innoDB tables?
     
    krt, Sep 24, 2007 IP
  3. computerzworld

    computerzworld Active Member

    Messages:
    214
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Yes, I am using innoDB tables.......
     
    computerzworld, Sep 24, 2007 IP
  4. msteudel

    msteudel Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I know this is an old thread but to update it for the search engines:

    If you have all the pre-requirements setup for foreign keys (innodb tables, indexes, etc.)

    Click on the table you want
    Click on the structures tab
    Below the fields you should see a relation view

    Then you should see the fields to create the foreign keys constraints

    Best Mark
     
    msteudel, Apr 3, 2008 IP
  5. jepler

    jepler Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I posted some video tutorials on how to use phpMyAdmin to create foreign key restraints on my blog:

    w w w.mytechmusings.com/2008/04/using-foreign-keys-in-mysql.html

    As a new user to this forum I'm not yet permitted to post URLs. Remove the spaces between the 3 w's in the URI above and add the appropriate http scheme to the beginning of the address.
     
    jepler, Apr 14, 2008 IP
  6. vahid67

    vahid67 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    hi guys ...
    i want to convert this mysql code to phpmyadmin i can create tables and set unique and primary field but i can't understand how to set bold lines in phpmyadmin .... thank you ...
    this is my code in MYSQL ...

    
    [FONT=Tahoma]create table DISCOUNT( 
    DISCOUNT_ID SMALLINT not null ,
     STORE_ID CHAR( 12 ) not null ,
     DISC_PERSENT SMALLINT not null ,
     DISC_TYPE VARCHAR2( 20 ) ,
     [B] constraint CKC_DISC_TYPE_DISCOUNT check ( DISC_TYPE  is null or ( DISC_TYPE in ('High','Medium','Low')))[/B]
     DISC_LOWQTY NUMBER ,
     Disc_HIGHQTY NUMBER ,
     constraint PK_DISCOUNT primary key (DISCOUNT_ID) );
     [B] create index STORE_DISC_FK on DISCOUNT ( STORE_ID ASC );
     alter table DISCOUNT  add constraint FK_DISCOUNT_STORE_DIS_STORE foreign key (STORE_ID) reference STORE(STOR_ID);
    [/B][/FONT]
    Code (markup):
    and this is my code in PHPMyadmin

    
    [FONT=Tahoma]CREATE TABLE `bookshop`.`Discount` (
     `Discount_ID` SMALLINT NOT NULL ,
     `Store_ID` CHAR( 12 ) NOT NULL ,
     `Disc_Persent` SMALLINT NOT NULL ,
     `Disc_Type` VARCHAR( 20 ) NOT NULL ,
     `Disc_LowQTY` INT ,
     `Disc_HighQTY` INT NOT NULL ,
     PRIMARY KEY ( `Store_ID` ) ,
     UNIQUE ( `Discount_ID` )
     )
    ENGINE = InnoDB[/FONT]
    Code (markup):
     
    vahid67, Aug 11, 2011 IP