Renaming a column

To change a column's name, re-add the atbats column first so that you can change it with the following query: 

USE foraltering; 
ALTER TABLE tableforaltering
ADD COLUMN atbats SMALLINT NULL AFTER yearID;

Let's say you wanted to rename this column to numberofatbats. You can execute the following script to do that: 

USE foraltering;
ALTER TABLE tableforaltering
CHANGE COLUMN atbats numberofatbats SMALLINT;

You can see, in the previous query, that you put in the current name of the column, then the new column name. You also have to put the column data type in, which in this case stays the same, so you just put the current data type into the query. The following screenshot shows the updated column name: 

In the next section, you will learn how to change the data type of a column. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.78.30