SQL - Changing Field Names within a Column

Asked

Viewed 36 times

0

Good, I have a doubt, I have for example a column called "Categories" and within this column I have several fields (categories) and wanted to change the name of these fields.

For example "category column" - and within it I have several categories with the following names : RMS-FOOTBALL ; RMS-BASQUET ; RMS-TENIS; RMS-BADMITON ; (...); and wanted to change these names within that column to: Football; Basquet; Tennis; Badminton , and so on.

Can someone help me? I have an idea that by update it may be possible to do but I don’t see how changing several field names within the same column would add a help with this example that I thank. L

  • 1

    Which database do you use? All columns start with RMS or have variation?

  • Use SQL MANAGEMENT STUDIO. All have variation for example one is RMS-FOOTBALL , Another is TRA-HANDBALL what I want only and reduce this text to FOOTBALL HANDBALL among others. Column "Category" --> Fields/Values within column category "RMS-FOOTBALL", "TRA-HANDBALL", (...) among other categories. I don’t want to change column name but rather the fields/values that are inside that column if I’m explaining myself well.

1 answer

1

You can spin these UPDATEs:

UPDATE sua_tabela SET categorias = 'Futebol' WHERE categorias = 'RMS-FUTEBOL';
UPDATE sua_tabela SET categorias = 'Basquet' WHERE categorias = 'RMS-BASQUET';
UPDATE sua_tabela SET categorias = 'Tenis' WHERE categorias = 'RMS-TENIS';
UPDATE sua_tabela SET categorias = 'Badminton' WHERE categorias = 'RMS-BADMITON';

To check if something is still missing to be changed:

SELECT DISTINCT categorias FROM sua_tabela WHERE categorias LIKE 'RMS-%';

Or else, to see all the categories and check if there is no wrong:

SELECT DISTINCT categorias FROM sua_tabela;

In all these cases sua_tabela is the name of the table that has the column categorias.

  • obg Victor I will try it later and then give the feedback.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.