Mysql – alter, drop, rename, modify

The alter command is used to modify an existing database, table, view or other database objects that might need to change during the life cycle of a database.

Let’s suppose that we have completed our database design and it has been implemented. Database query example Our database users are using it and then they realize some of the vital information was left out in the design phase. Database migration They don’t want to lose the existing data but just want to incorporate the new information.


Data recovery free The alter command comes in handy in such situations. Database vs spreadsheet We can use the alter command to change the data type of a field from say string to numeric, change the field name to a new name or even add a new column in a table.

The basic syntax used to add a column to an already existing table is shown below ALTER TABLE `table_name` ADD COLUMN `column_name` `data_type`;

• “ADD COLUMN `column_name` `data_type`” is the command that tells MySQL server to add a new column named `column_name` with data type `data_type’.

Let’s suppose that Myflix has introduced online billing and payments. Database name sql Towards that end, we have been asked to add a field for the credit card number in our members table. Database management We can use the ALTER command to do that. Data recovery miami Let’s first look at the structure of the members table before we make any amendments. H2 database viewer The script shown below helps us to do that. Database replication SHOW COLUMNS FROM `members`;

We can use the script shown below to add a new field to the members table. Database record ALTER TABLE `members` ADD COLUMN `credit_card_number` VARCHAR(25);

Executing the above script in MySQL against the Myflixdb adds a new column named credit card number to the members table with VARCHAR as the data type. Data recovery certification Executing the show columns script gives us the following results.

As you can see from the results returned, credit card number has been added to the members table. Database programs The data contained in the members’ data is not affected by the addition of the new column. Raid 1 data recovery WHAT IS THE DROP COMMAND?

Executing the above script in MySQL workbench against myflixdb and then executing the show columns script given above gives the following results.

In the CHANGE example above, we had to change the field name as well other details. Database 2016 Omitting the field name from the CHANGE statement will generate an error. Key value database Suppose we are only interested in changing the data type and constraints on the field without affecting the field name, we can use the MODIFY keyword to accomplish that.

Executing the above script in MySQL workbench against myflixdb and then executing the show columns script given above gives the following results shown below. Database mirroring Field

The script below adds “date_of_registration” just after the date of birth in the members table. Data recovery techniques ALTER TABLE `members` ADD `date_of_registration` date NULL AFTER `date_of_birth`;

Executing the above script in MySQL workbench against myflixdb and then executing the show columns script given above gives the following results shown below. Data recovery using linux Field

banner