Gambas Documentation - /comp/gb.mysql/_field/foreignkey

/comp/gb.mysql/_field/foreignkey

# _Field.ForeignKey (gb.mysql)

Sub ForeignKey ( Field As String, RefTable As String, RefField As String [ , OnDelete As String, OnUpdate As String ] )

Stores the information for a foreign key, later, that information will be used to create a table.

Field: Is the field to reference.
RefTable: Is the table we are referencing.
RefField: Is the field we are referencing.
OnDelete: Which action execute on delete.
OnUpdate: Which action execute on update.

When the table is created all the foreign key's information is cleaned.

### Examples

    Dim hCon As New Connection

    With hCon
      .Type = "mysql"
      .Port = "3306"
      .Host = "localhost"
      .User = "root"
      .Password = "mypass"
      .Name = "Gambas"
      .Open()
    End With

    hCon.MySQL.Field.ForeignKey("country_id", "country", "country_id", "RESTRICT", "CASCADE")

    Part of the MySQL statement:
    KEY `idx_fk_country_id` (`country_id`),
    CONSTRAINT `city_ibfk_1` FOREIGN KEY (`country_id`) REFERENCES `country` (`country_id`) ON UPDATE CASCADE