I have a field in my table:
tipoEndereco char(1);
However this field only receives two possible values, which are:
1-> i (Instalação)
2-> c (Cobrança)
Because of this, I'm thinking, and I would like your opinion, to change it to:
tipo enum("i", "c");
The change is for performance effect. What do you think?
The other guideline, and most importantly, is that I would like to create a rule in MySQL that allows insertion of empty values in the fields, if the value that arrives via query is "c" (Collection). >
Is this possible?
Here's 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 as soon as the client is written to the Clientes
table, get its idClientes
generated ( insert_id
) and save the address data in the endereços
table.
The form has two addresses, one for installation and one for billing. In the database, the address table is NOT NULL
. But if the address is of type "c" (collection), I need the table to accept null values.
How?