SET @tableExists := (
    SELECT COUNT(*)
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'nfse_usuario'
);

SET @sql := IF(@tableExists = 0,
'CREATE TABLE nfse_usuario (
id INT NOT NULL AUTO_INCREMENT,
usuario VARCHAR(50) NOT NULL,
senha VARCHAR(255) NOT NULL,
data_cadastro TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
tentativas_login INT DEFAULT 0,
bloqueado TINYINT(1) DEFAULT 0,
PRIMARY KEY (id),
UNIQUE KEY usuario (usuario)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;',
'SELECT "Tabela nfse_usuario já existe."'
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;