Tuesday, February 2, 2010

Mysql Help

Get database size:
SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB"
FROM information_schema.TABLES GROUP BY table_schema ; 

 
use REPLACE in mysql:
UPDATE table_name SET column_name = REPLACE(column_name,”original_string”,”replace_string”)

concate & replace extra space if any field is missing
SELECT CONCAT(COALESCE(CONCAT(salutation,' '),''),COALESCE(CONCAT(first_name,' '),''),COALESCE(surname,'')) DriverName

//to check mysql version from query
select version();

Sort in ENUM fields :
To sort in ENUM fields using ORDER BY clause on  use one of these techniques:
  • Specify the ENUM list in alphabetic order.:
    like : ORDER BY FIELD(alert_type,'For Sale','For Rent','Sale Agreed') desc
  • Make sure that the column is sorted alphabetically rather than by index number by coding ORDER BY CAST(col AS CHAR) or ORDER BY CONCAT(col)
Create Wordcase in mysql :
update survey_event_question_langs set response1= CONCAT(LEFT(`response1`, 1),lower(
SUBSTRING(`response1`, 2)))

No comments:

Post a Comment