thesuhu

MySQL Information Schema

Feb 28th, 2022 (edited)
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.63 KB | None | 0 0
  1. # cek tabel berdasarkan tanggal pembuatan terakhir
  2. select table_name, create_time
  3. from information_schema.TABLES
  4. where table_schema = 'andomar'
  5. order by CREATE_TIME desc
  6.  
  7. # cek table yg mempunyai field tertentu
  8. SELECT *
  9.     FROM INFORMATION_SCHEMA.COLUMNS
  10.     WHERE COLUMN_NAME = '<nama field>'
  11.  
  12. # bulk alter
  13. # Forget looping. Just do this:
  14. select concat( 'alter table ', a.table_name, ' add index `fields` (`field`);' )
  15. from information_schema.tables a
  16. where a.table_name like 'table_prefix_%';
  17. # Then take the result set and run it as a SQL script.
  18. # BTW, you probably mean create index index_name on table_name( column_name)
Add Comment
Please, Sign In to add comment