Alterations
In this lesson we discuss how to modify various database structures once they are created.
We'll cover the following...
Alterations
MySQL allows us to change our mind about the entities we create and alter them. We can rename tables, add, remove, or rename columns, change type of an existing column, etc.
Example Syntax
ALTER TABLE table
CHANGE oldColumnName newColumnName <datatype> <restrictions>;
Connect to the terminal below by clicking in the widget. Once connected, the command line prompt will show up. Enter or copy and paste the command ./DataJek/Lessons/17lesson.sh and wait for the MySQL prompt to start-up.
Press + to interact
-- The lesson queries are reproduced below for convenient copy/paste into the terminal.-- Query 1ALTER TABLE Actors CHANGE FirstName First_Name varchar(120);-- Query 2ALTER TABLE Actors MODIFY First_Name varchar(20) DEFAULT "Anonymous";-- Query 3ALTER TABLE Actors CHANGE First_Name First_Name varchar(20) DEFAULT "Anonymous";-- Query 4ALTER TABLE Actors MODIFY First_Name INT;-- Query 5ALTER TABLE Actors MODIFY First_Name varchar(300);-- Query 6ALTER TABLE Actors ADD MiddleName varchar(100);-- Query 7ALTER TABLE Actors DROP MiddleName;-- Query 8ALTER TABLE Actors ADD MiddleName varchar(100) FIRST;-- Query 9ALTER TABLE Actors DROP MiddleName;ALTER TABLE Actors ADD MiddleName varchar(100) AFTER DoB;--Query 10ALTER TABLE Actors DROP MiddleName, ADD Middle_Name varchar(100);
-
Let’s say we want to rename the column FirstName to First_Name for the Actors table. We can do so as follows: ...
Access this course and 1400+ top-rated courses and projects.