SQL. Unique and Primary Key
<p>My requirement is having a table of products which cannot have similar vendor, product and version at the same time.</p>

<p>But, I also want this table to be referenced on another table by its primary key, as for the distinct vendor, product version I use <code>unique</code>.</p>

<pre><code>create table Products
    (
    vendor varchar(100),
    product varchar(100),
    version varchar(30),
    unique (vendor, product, version, cve)        
);
</code></pre>

<p>But this way I cannot reference it by its <code>product_id</code>, as I want to in another table:</p>

<pre><code>create table Product_cve(

    product_id int,
    cve varchar(14),
    foreign key (product_id) references Products(product_id),
    foreign key (cve) references VulnerabilitiesCVE(cve)
);
</code></pre>

<p>, another thing I can do is that</p>

<pre><code>   create table Products
    (
    product_id int NOT NULL AUTO_INCREMENT,
    vendor varchar(100),
    product varchar(100),
    version varchar(30),
    primary key (product_id)

    );
</code></pre>

<p>This way, I am going to end up having duplicated products...</p>