In my previous video of mysql series I have discussed about difference Between Alter and update in mysql
Today I am going to discuss about Alter table statement in mysql
So without any further delay let's get started
MySQL ALTER TABLE Statement
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
The ALTER TABLE statement is also used to add and drop various constraints on an existing table.
ALTER TABLE - ADD Column
To add a column in a table, use the following syntax:
ALTER TABLE table_name
ADD column_name datatype;
Let us see with an example
Today I am using persons table under order info1 database
Query to add a column to the existing table
Alter table persons
Add column phone_no integer;
Here integer is the datatype of phn no column
To add data to the column using update table statement
I.e
Update persons
Set phone_no=6213457856
Where personid=1;
Select *from persons to view the changes
Nxt command is drop column
delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a column):
ALTER TABLE table_name
DROP COLUMN column_name;
Example
Query to drop a column from
the existing table
ALTER table persons
Drop column phn no ;
Nxt is modify column
ALTER TABLE - MODIFY COLUMN
To change the data type of a column in a table, use the following syntax:
ALTER TABLE table_name
MODIFY COLUMN column_name datatype;
Query to Modify a column from
the existing table
Example
ALTER table persons
Modify column orderid varchar(20);
that's all for today Hope you all will get some help from this video
If it's so then don't forget to subscribe my channel Code with Neha and press the Bell Icon for Regular Updates
See you in the next video till then Stay Safe Stay Happy
#mysql
#mysqldb
#mysqltutorials
#mysqltutorialforbeginners
#mysqlupdatecommand
#sqlupdatecommand
#updatedatawithsql
#updatetabledatainmysql
#mysqldatabasetutorial
#updatingadatabase
#addingtablestoadatabase
#insertintostatement
#updatequeryinsql
#altertable
#altertablestatement
#altertablestatementinmysql
#altertablestatementinsql
#mysqlupdatequery
#whatisupdateinmysql
#sqlupdate
#mysqlupdatestatement
#mysqldatabase
#mysqlcourse
#mysqldatabasetutorial
#mysqlcrashcourse
#mysqltutorialforbeginners
#learnmysql
#learnsql
#SqlDMLcommands
#createinsertupdateinsql
#sqlupdatequery
#sqlcommands
#sqlqueries
#structuredquerylanguage
#sqlinterviewquestions
#sqlbasics
#sqlforbeginners