Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Thursday, 29 May 2014

Multiple Row Updates in MySQL

CREATE TABLE  `testimonial_setting` (
  `testimonial_setting_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `testimonial_label` varchar(255) NOT NULL,
  `testimonial_key` varchar(45) NOT NULL,
  `testimonial_value` varchar(45) NOT NULL,
  PRIMARY KEY (`testimonial_setting_id`)
);

Table :-  testimonial_setting
testimonial_setting_id, testimonial_label,    testimonial_key, testimonial_value
            1,                       'Background Color',    'bgcolor',            ''
            2,                        'Text Color',               'textcolor',          ''
            3,                      'Heding Text Color',    'headtextcolor',    ''
            4,               'Heding Background Color', 'headbgcolor',    ''

Query :-

UPDATE `testimonial_setting` SET
`testimonial_value` = IF(`testimonial_key`="bgcolor","#ff00ff",`testimonial_value`),
`testimonial_value` = IF(`testimonial_key`="textcolor","#ffffff",`testimonial_value`),
`testimonial_value` = IF(`testimonial_key`="headtextcolor","#ff0000",`testimonial_value`),
`testimonial_value` = IF(`testimonial_key`="headbgcolor","#ff0fff",`testimonial_value`);

After update table :-  testimonial_setting


testimonial_setting_id, testimonial_label,    testimonial_key, testimonial_value
            1,                       'Background Color',    'bgcolor',            '#ff00ff'
            2,                        'Text Color',               'textcolor',          '#ffffff'
            3,                      'Heding Text Color',    'headtextcolor',    '#ff0000'
            4,               'Heding Background Color', 'headbgcolor',    '#ff0fff'

Monday, 24 February 2014

Import a SQL file using the command line in MySQL

A common use of mysqldump is for making a backup of an entire database:

  shell> mysqldump db_name > backup-file.sql

 You can load the dump file back into the server like this:

  UNIX
shell> mysql db_name < backup-file.sql

  Same in Windows comand prompt
mysql -p -u[user] [database] < backup-file.sql

  PowerShell
C:\> cmd.exe /c "mysql -u root -p db_name < backup-file.sql"

  MySQL command line
mysql> use db_name; mysql> source backup-file.sql;