Add / View Friend Database

0

I have a users table and a friends table, every friend is also a user, I would like to know how to insert items (add a friend) and how to check (list friends)?

CREATE TABLE IF NOT EXISTS usuarios(
    id                  INT NOT NULL AUTO_INCREMENT,
    nome                VARCHAR(24) NOT NULL,
    sobrenome           VARCHAR(64) NOT NULL,
    email               VARCHAR(50) NOT NULL UNIQUE,
    senha               VARCHAR(16) NOT NULL,
    dt_nasc             DATE,
    sexo                enum('M','F') NOT NULL,
    telefone            VARCHAR(18) NOT NULL UNIQUE,
    city_natal          VARCHAR(32),
    estado_civil        enum('Solteiro(a)','Namorando','Noivo(a)','Casado(a)','Separado(a)','Divorciado(a)','Viúvo(a)') NOT NULL DEFAULT 'Solteiro(a)',
    frase               VARCHAR(256) NOT NULL,
    perfil              VARCHAR(512) NOT NULL,
    capa                VARCHAR(512) NOT NULL,
    pergunta            VARCHAR(256) NOT NULL,
    resposta            VARCHAR(64) NOT NULL,
    CONSTRAINT u_id_pk  PRIMARY KEY(id)
) DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS amizade(
    id                  INT NOT NULL AUTO_INCREMENT,
    u1_id               INT,
    u2_id               INT,
    CONSTRAINT id_pk    PRIMARY KEY(id),
    CONSTRAINT u1_id_fk  FOREIGN KEY(u1_id) REFERENCES usuarios(id),
    CONSTRAINT u2_id_fk  FOREIGN KEY(u2_id) REFERENCES usuarios(id)
) DEFAULT CHARSET=utf8;
    
asked by anonymous 08.04.2018 / 15:02

0 answers