A
A
Alexander2020-06-16 09:14:36
MySQL
Alexander, 2020-06-16 09:14:36

How is XML + XSD in SQL?

Tell me how you can automate the process of creating a database table, according to the existing XSD schema?
Example: There is xml with the data of the Unified State Register of Legal Entities or EGRIP, and there is an XSD schema for these files. How can I automatically generate field names in a table to fill with data?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Vodakov, 2020-06-16
@cry_san

It depends on what field names you need. You can, for example, parse an XSD, generate a query text for creating tables based on its data, and execute it. Or you can stupidly create a table with field names FIELD_1 ... FIELD_N. It all depends on your task.
Let's start by explaining why you need to cram data into one table.
In your table, there will be as many records as there are activities of one company, for each type of activity one record. For example:

godtable: 
compani_id, company_name, ... (any more fields of company) ... , 
id_activity, name_activity, is_base, grnip, record_date

In this case, you will get an unnormalized database, with redundant information, because each record will duplicate similar information from other records. You will have repeated data about the company, as many times as the company has activities. And also, you will have repeated information about the type of activity, as many times as many companies use it.
In order to get a normalized base, you need for example three tables:
1. Юрлица (companies): id. name, и т.д.
2. Виды деятельности юрлиц (compani_activity): id_company, id_activity, is_base, grnip, record_date
3. Реестр видов деятельности: (activities): id, name

If you had an idea to store all activities in one record but in different columns, then this was not the right idea, then you will have different numbers of columns for different records, and sooner or later you will stumble upon the fact that you do not have enough columns .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question