Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Kieran Gibbons
Kieran Gibbons
17,434 Points

Database Foundations issue

I'm having trouble figuring out the following question in Database Foundations. Can anyone point me in the right direction please?

In one statement, in the movies table rename the year to release_year and change the type to the type of YEAR.

ALTER TABLE movies CHANGE COLUMN year release_year, release_year type int YEAR;

1 Answer

Placid Rodrigues
Placid Rodrigues
12,630 Points

Hi,

Same syntax is used for changing column name and column data-type.

Suppose, in person table, there is a column named first_name of data-type VARCHAR(60). If you want to change the column name to f_name but not the data-type, you still need to declare the original data-type in your SQL statement. LIke this:

ALTER TABLE person CHANGE COLUMN first_name f_name VARCHAR(60);

If you want to change a data-type of the column, you will use the same syntax. In this case the original column name and new column name will be same and the data-type will be changed. Like this:

ALTER TABLE person CHANGE COLUMN first_name first_name TEXT;

So, as shown in the video, you change both the column-name (from year to release_year) and data-type (from INT to YEAR) in the following way:

ALTER TABLE movies CHANGE COLUMN year release_year YEAR;

Hope that helps,

Placid