Tags:
create new tag
view all tags

Useful SQL

Getting information

  • Get table information
    • describe MY_DB_NAME;
  • Get the column names from your table
    • select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='MY_DB_NAME';
  • See what processes are running
    • SHOW [FULL] PROCESSLIST;
  • Get size of all databases
    • SELECT table_schema "Database Name", sum( data_length + index_length) / 1024 / 1024 "Database Size in MB" FROM information_schema.TABLES GROUP BY table_schema;
  • Get size breakdown for a single database named "my_database"
    • SELECT table_name, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "my_database";
  • Get all columns of a table are enums
    • select COLUMN_NAME from information_schema.COLUMNS WHERE table_schema = "MODEL_DB" and TABLE_NAME='CPLEX_CONFIGURATION_12_1_MILP' and DATA_TYPE = 'enum';

Backing up and moving

  • Copy a table
    • CREATE TABLE NEW_TABLE SELECT * FROM OLD_TABLE ;
  • Copying distinct lines from a table
    • CREATE TABLE DISTINCT_METRICS AS (SELECT DISTINCT * FROM METRICS_JMALT);
Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r4 - 2010-11-09 - FrankHutter
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback