Categories
Linux MySql Open Source Solutions

How to Rename Column in Mysql

Modifying database schemas is a routine task, but the exact syntax to alter structural properties varies heavily across database versions. If you are trying to rename a column in MySQL, using the wrong command can lead to syntax errors or accidental data loss.

How you rename a column depends entirely on whether your environment runs modern MySQL 8.0+ engines or legacy MySQL 5.7 configurations.

Here is the exact syntax and production-ready code blocks to rename your database columns safely.

The Modern Way: MySQL 8.0+ (RENAME COLUMN)

If you are running MySQL 8.0 or newer, the development team introduced a native, simplified syntax. You no longer need to re-specify the entire data type definition just to change the column name.

SQL

ALTER TABLE table_name
RENAME COLUMN old_column_name TO new_column_name

Example: To change a column named user_pass to password inside a table called users:

SQL

ALTER TABLE users 
RENAME COLUMN user_pass TO password;

The Legacy Way: MySQL 5.7 and Older (CHANGE)

In older versions of MySQL, the RENAME COLUMN statement does not exist. Attempting to use it triggers a generic syntax error. Instead, you must use the CHANGE clause.

Crucially, you must explicitly re-state the complete data type definition along with any attributes (like NOT NULL or DEFAULT). Failing to include the data type will break the query.

SQL

ALTER TABLE table_name 
CHANGE old_column_name new_column_name DATA_TYPE CHARACTER_SET_ATTRIBUTES;

Example: To rename user_pass to password where the column data type is a VARCHAR(255) that cannot be null:

SQL

ALTER TABLE users 
CHANGE user_pass password VARCHAR(255) NOT NULL;

Warning: Be extremely careful when using CHANGE. If you accidentally specify a different data type definition during the rename step, MySQL will attempt to convert the underlying data, which can lead to truncated strings or corrupted records.

Can I rename multiple columns at once in MySQL?

Yes, in modern MySQL 8.0, you can chain operations within a single statement by separating them with commas. For example: ALTER TABLE users RENAME COLUMN old_a TO new_a, RENAME COLUMN old_b TO new_b;.

Why does MySQL rename column throw a syntax error?

This typically happens if you try to use the native RENAME COLUMN syntax on a server running an older version like MySQL 5.7. For legacy setups, you must use the ALTER TABLE CHANGE statement instead

Categories
Laptop OsX

How To Take A ScreenShot on Mac

You can capture a Screenshot of your entire screen or just a selected portion of it. The screenshot is automatically saved to your desktop.

How to take a screenshot of your entire screen

  1. Press Shift+Command (⌘)+3.
  2. The screenshot will be saved as a .png file on your desktop

How to take a screenshot of a selected portion of your screen

how to take screenshot in mac

  1. Press Shift+Command (⌘)+4. The pointer changes to a crosshair.
  2. Move the crosshair to where you want to start the screenshot, then click and drag to select an area.
    Note: While dragging the Crosshair, you can hold Shift, Option, or Space bar to change the way the selection moves
  3. When you have selected the area that you want, release your mouse or trackpad button. To cancel, press the Esc (Escape) key before you release the button.
  4. The screenshot will be saved as a .png file on your desktop
Categories
Android Apps Device Nexus 5

Error 70 Gapps install – Fixed

If you are encountering the following error while trying to flash Gapps with your custom rom:

Error 70: Insufficient storage space available in System partition.

Here is the simple fix for the problem:

  • Flash a smaller size version of the Gapps ROM via TWRP.  Pick either Pico/Micro versions of the ram.
  • For Nexus 5 and CM14/Lineage the Micro Version works just fine
  • After installing the smaller version you can install the remaining apps via the Play Store

 

Categories
JavaScript Open Source Solutions Web

JavaScript Date Format YYYY-MM-DD

Here is a simple function that takes the input of JS Date and returns a string of format YYYY-MM-DD:

var getDateFromDateTime = function(date) {
date = new Date(date); //Using this we can convert any date format to JS Date
var mm = date.getMonth() + 1; // getMonth() is zero-based
var dd = date.getDate();
if(mm<10){ mm="0"+mm; } if(dd<10){ dd="0"+dd; } return [date.getFullYear(), mm, dd].join('-'); // padding };

Categories
JavaScript Open Source Solutions Web

Convert JavaScript Date format YYYYMMDD

Here is a simple function that takes the input of JS Date and returns a string of format YYYYMMDD:

var getDateFromDateTime = function(date) {
date = new Date(date); //Using this we can convert any date format to JS Date
var mm = date.getMonth() + 1; // getMonth() is zero-based
var dd = date.getDate();
if(mm<10){ mm="0"+mm; } if(dd<10){ dd="0"+dd; } return [date.getFullYear(), mm, dd].join(''); // padding };