5
I have a field on my table:
tipoEndereco char(1);
But this field only receives two possible values, which are:
1-> i (Instalação)
2-> c (Cobrança)
Because of that, I’m thinking, and I’d like your opinion, to exchange it for:
tipo enum("i", "c");
The change is for performance. What do you think?
The other orientation, and the most important one, is that I would like to create a rule in Mysql that allows the insertion of empty values in the fields, if the value that arrives via query is "c" (from Billing).
That’s possible?
Here is the table:
CREATE TABLE enderecos (
idEnderecos int(1) unsigned NOT NULL AUTO_INCREMENT,
idClientes int(10) NOT NULL,
tipoEndereco char(1) NOT NULL,
endereco varchar(100) NOT NULL,
numero varchar(5) NOT NULL DEFAULT '',
complemento varchar(50) NOT NULL,
bairro varchar(100) NOT NULL,
cidade varchar(150) NOT NULL,
estado char(2) NOT NULL,
cep char(8) NOT NULL,
PRIMARY KEY (idEnderecos)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
The idea here is that once the client is written into the table Clientes
, get your idClientes
generated (insert_id
) and save address data to table endereços
.
The form has two addresses, one for installation and one for billing. In the bank, the table addresses all NOT NULL
. But if the address is type "c" (charging), I need the table to accept null values.
Like?
There are conflicts of logic in your description. If no value is provided for the field (HTML input) is empty, you automatically want "c" to be the default value for the "type" column of the table?
– felipsmartins
Default value is Installation i
– Carlos Rocha
The field being char(1) and receiving 1, 2, i, or c makes no difference to performance.
– Rafael Mena Barreto