CREATE DATABASE IF NOT EXISTS Inversion;
USE Inversion;

CREATE TABLE usuario (
    idusu INT AUTO_INCREMENT PRIMARY KEY,
    nomusu VARCHAR(100) NOT NULL,
    usu VARCHAR(50) NOT NULL UNIQUE,
    conusu VARCHAR(255) NOT NULL
);

CREATE TABLE inversionista (
    idinv INT AUTO_INCREMENT PRIMARY KEY,
    nominv VARCHAR(150) NOT NULL,
    mailinv VARCHAR(150) UNIQUE,
    dirinv TEXT,
    telinv VARCHAR(20)
);

CREATE TABLE inversion (
    idreginv INT AUTO_INCREMENT PRIMARY KEY,
    idinv INT NOT NULL,
    fecinv DATE NOT NULL,
    mntinv DECIMAL(10,2) NOT NULL,
    reninv INT NOT NULL,
    estado TINYINT(1) NOT NULL DEFAULT 1,
    FOREIGN KEY (idinv) REFERENCES inversionista(idinv) ON DELETE CASCADE
);
