My-Sql tips and tricks

Update column in mysql table 

update table_name set column_name = value_to_set where conditional_statement;

Alter column data_type in mysql table 

ALTER TABLE table_name CHANGE column_name column_name data_type;

Example of existing data_type is varchar(255)

ALTER TABLE editon_data CHANGE title title LONGTEXT;

Alter multiple columns data_type in mysql table 

ALTER TABLE table_name CHANGE column_name column_name data_type;

Example of existing data_type is varchar(255)

ALTER TABLE editon_data 
 CHANGE title title LONGTEXT,
 CHANGE title1 title1 LONGTEXT,
 CHANGE title2 title2 LONGTEXT,
 CHANGE title3 title3 LONGTEXT;

Trim Space from fields in sql table

UPDATE table_name SET field_name = TRIM(field_name) WHERE conditional_clause_if_any; 

Replace space with underscore in sql

REPLACE(str,from_str,to_str)
update table_name set field_name = replace(field_name, ' ', '_');

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s