SQL Where do I put the foreign key table hiija or father?

0
    CREATE TABLE personajes(


    per_nombre varchar(50) not null default 'Desconocido' ,
    per_genero varchar(30) not null default 'Desconocido',
    per_raza varchar(50) not null default 'Desconocido',
    per_alias  varchar(50) not null default 'Desconocido',
    per_rol varchar(20) not null default 'Desconocido',
    per_lug_nac varchar(50) not null default 'Desconocido',
    per_ocupacion varchar(300) not null default 'Desconocida',
    per_faccion varchar(50) not null default 'Desconocida',
    per_fech_lan date default  null,

    primary key(per_nombre),

    FOREIGN KEY (per_nombre) REFERENCES habilidades(hab_nom_per) ON UPDATE CASCADE ON DELETE SET NULL
   );



    create table habilidades(

    hab_nom_per varchar(50) not null,
    hab_pas varchar(30) not null,
    hab_q varchar(30)not null,
    hab_w varchar(30)not null,
    hab_e varchar(30)not null,
    hab_r varchar(30)not null,

    PRIMARY KEY(hab_nom_per)

    );

    //tabla padre -> personajes
    //tabla hia -> habilidades

    /*
    He puesto la clave foranea en padre(personajes), pero no se si era en la hija(habilidades)
    */

- THE DAPTATION THAT I HAVE DONE DOES NOT WORK BECAUSE I HAVE TAKEN A CHARACTER THAT DOES NOT - EXISTS AND DOES NOT GIVE ME ERROR

DROP DATABASE LEAGUE_OF_LEGENDS; CREATE DATABASE LEAGUE_OF_LEGENDS; USE LEAGUE_OF_LEGENDS;

CREATE TABLE characters (

    per_nombre varchar(50) not null default 'Desconocido' ,
    per_genero varchar(30) not null default 'Desconocido',
    per_raza varchar(50) not null default 'Desconocido',
    per_alias  varchar(50) not null default 'Desconocido',
    per_rol varchar(20) not null default 'Desconocido',
    per_lug_nac varchar(50) not null default 'Desconocido',
    per_ocupacion varchar(300) not null default 'Desconocida',
    per_faccion varchar(50) not null default 'Desconocida',
    per_fech_lan date default  null,

    primary key(per_nombre)

);

create table skills (

    hab_nom_per varchar(50) not null,
    hab_pas varchar(100) not null,
    hab_q varchar(100)not null,
    hab_w varchar(100)not null,
    hab_e varchar(100)not null,
    hab_r varchar(100)not null,

    PRIMARY KEY(hab_nom_per),
    FOREIGN KEY (hab_nom_per) REFERENCES personajes(per_nombre) ON UPDATE CASCADE ON DELETE SET NULL

);

    
asked by Selito95 15.07.2017 в 20:36
source

2 answers

0

A foreign key is a reference to a unique key in another table. By convention it refers to the table that contains the foreign key as daughter table and the table that has the unique key referred to by the foreign key, parent table or referenced table.

Thus the definition of FOREIGN KEY is found in the daughter table.

    
answered by 15.07.2017 в 21:27
0

my problem was that I had not specified this - > ENGINE = INNODB

    
answered by 15.07.2017 в 21:34