How to translate fields in MySQL

0

I have some tables and fields in English in my database (and these should be like this). But on the other hand, when I make a select, the name of the fields have to be in Spanish. Example: - Name of the field in the database: employeeName - Name that should come out in my select: Name It would be something like a select employeeName as Name.

The problem is that there are many tables and many fields per table ... And if every select I do, I have to alias all the fields ... I find it impractical.

Is there any way to translate the fields automatically? As an automatic alias?

Thanks in advance.

    
asked by Enric Sauret 28.06.2017 в 23:24
source

2 answers

2

You could create a view for each table and alias each of the fields:

CREATE VIEW empleados AS
SELECT employeeName AS Nombre FROM employees;

The query would stay:

SELECT Nombre FROM empleados;
    
answered by 29.06.2017 в 07:31
0

What you can do is create an alias table to take the alias of that table and not have to write it every time.

Table esp Name Name ...

And you do the query assigning the alias

select Name as esp.Name from mitabla

Edit to extend the response

Another way if you are using PHP for example to do the query (I do not know if it is the case) is to have the fields with their alias in array to call them from a variable, but from the point of view of the MySQL sequence the idea It's the same:

$a["name"] = "Name as Nombre"; or $a["name"] = "Name as esp.Name";

select $a["name"] from mitabla;

In any case it implies that you make the translation at some point.

    
answered by 28.06.2017 в 23:43