3
I am creating a database that stores an electronic invoice - "Nfe" received.
Within the items of a tax note are always linked taxes.
Table example tblProdNFe_Entrada
with the table tblICMS00NFe_Entrada
.
I am creating the bank exactly as the object generated by the deserialization that I am doing with the following code:
T LoadFromXMLString<T>(string xmlText)
{
var stringReader = new System.IO.StringReader(xmlText);
var serializer = new XmlSerializer(typeof(T));
return (T)serializer.Deserialize(stringReader);
}
There are groups of ICMS, for example: ICMS00, ICMS10, ICMS30 and so on.
Each group becomes an object during deserialization.
My question is whether I should create tables in the database exactly like objects or whether I should create a table that contains all fields of all groups.
For example a table tblICMSGeral
containing all groups, or a table for each group: tblICMS00NFe_Entrada
, tblICMS10NFe_Entrada
, tblICMS20NFe_Entrada
and so on.
What’s the best way?
So it depends, do the ICMS types have the same attributes? If yes, I advise you to create only one table that stores all and create an additional field to check the type of ICMS, otherwise create a table for each, put the fields that are common to them in one and the information that are different in another so there is no redundancy according to the 1st Normal Way.
– Nayron Morais
@Nayronmorais, in this specific case I can not leave 100 % normalized, the government changes the rules very often. For example the field
pICMS
that in this case is the percentage of icms, it has to stay as it is in Nfe, if it is a foreign key and I changed it, all the notes already recorded would be changed, which cannot occur, because I have to leave in the bank exactly as it is in Nfe. I don’t know how to fix this.– Robss70
You could add the normalization only for the new data, then create different procedures to check the two tables and gradually migrate the old data, because it is good to solve the problem now, otherwise it will only increase along with your work.
– Nayron Morais
Robss70, was the answer given good? Or have other question yet?
– Jefferson Quesado