I have a table in Mysql with the following fields:
CREATE TABLE table_1(
camp_1 boolean,
tree varchar(50),
name varchar(50),
serv varchar(50),
number varchar(50),
PRIMARY KEY (camp_1, tree, name)
);
then i can have something like that:
select* from table_1
aa, bb, cc, null, 123
dd, ee, ff, null, 512
The problem is that i need that when serv is null, then my primary key will be like (or i need the three unique values): camp_1, tree, name
And if serv is not null i need can insertd somethin like:
select* from table_1
aa, bb, cc, ddd, 123
aa, bb, cc, ert, 123
dd, ee, ff, null, 512
In this way if serv is not null i can have camp_1 , tree, name two or more times (aa, bb, cc appear 2 times) with diferent values, but if serv is not null i can not have camp_1 , tree, name (dd, ee, ff only 1 time) with more than 1 value.
I try with an index, but it not found because i can not insert null in my primary key.
Something can help me?