0

It's a large db and it's really messy, I would like to order all columns in all tables, without resorting to manual drag and drop...

EDIT I know the order doesn't matter. It's a design think. It will be much easier to read and to find things if they are ordered. ,I have also many columns like "is_visible", "is_editable" etc... if they are all together it looks better.

2
  • Do you mean columns order in a table structure ???
    – Akina
    Commented Feb 20, 2020 at 12:49
  • SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM information_schema.columns ORDER BY COLUMN_NAME;
    – Luuk
    Commented Feb 20, 2020 at 13:18

4 Answers 4

2

No need to order. And thinking of ordering by all columns is pretty much problematic. You will create a bigger mess than...

Just create a view for each of your requirement.

create or replace view db1_name_wise as 
  (select required_field_list from db1 order by name);

And create as many views as you wish.

2
  • hmm maybe this could be a nice solution
    – Glasnhost
    Commented Feb 20, 2020 at 16:35
  • And if you notice, the views are always ready to access - gets updated real time - always read-only - you shall think them of a layer above all your dbs which can be accessed by any higher level code. Commented Feb 20, 2020 at 16:41
2

I would like to order all columns in all tables

The order of column [names] within a Table should not matter.

Every "select" statement that goes anywhere near your database should explicitly specify the columns that it wants, in the order that it wants them. How the actual table is arranged matters not a jot.

If you have lots of columns with similar names, this may be indicative of a larger problem.

1

The order doesn't matter, because table are by definition unordered.

I also like it Tight and Needy in an order, but if the database grows it is unavoidable.

If you really want it and i stress the words really want it, you can always Create a new table and use INSER INTO..SELECT, but this would only work if the related tables don't use uuid or auto_increment value for reference

And then delete the old table and rename the new one table.

But that would be a lot of work, without any benefit for the database and can cause a lot of problems, because this must be tested in a non production enviromenbt and never on a live system.

0

This is all about the SELECT QUERY and the ORDER BY keyword i recommend you to read about ORDER BY in w3Schools

And if you are starting with SQL database you might read some CRUD commands documentation :)!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.