Examples To ALTER and TRUNCATE Tables Using MySQL
Examples To ALTER and TRUNCATE Tables Using MySQL
Objective(s)
At the end of this reading, you will be able to:
ALTER TABLE
ALTER TABLE statements used to add or remove columns from a table, to modify the data type of columns, to add or remove keys, and
to add or remove constraints. The syntax of the ALTER TABLE statement is:
Copied!
For example, to add a telephone_number column to the author table in the library database, the statement will be written as:
1. 1
2. 2
Copied!
Copied!
For example, using a numeric data type for telephone_number means that you cannot include parentheses, plus signs, or dashes as
part of the number.
about:blank 1/2
6/22/23, 9:53 AM about:blank
You can change the column to use the CHAR data type to overcome this. To modify the data type, the statement will be written as:
1. 1
2. 2
Copied!
TRUNCATE Table
TRUNCATE TABLE statement are used to delete all of the rows in a table. The syntax of the statement is:
1. 1
Copied!
So, to truncate the author’s table, the statement will be written as:
1. 1
Copied!
TRUCATE statement will just delete the rows and not the table.
Author
D.M.Naidu
Change Log
Date (YYYY-MM-DD) Version Changed By Change Description
2023-05-11 1.5 Eric Hao & Vladislav Boyko Updated Page Frames
2023-05-10 1.4 Eric Hao & Vladislav Boyko Updated Page Frames
2023-05-10 1.3 Eric Hao & Vladislav Boyko Updated Page Frames
2023-05-10 1.2 Eric Hao & Vladislav Boyko Updated Page Frames
2022-11-08 1.1 D.M.Naidu Intial version
about:blank 2/2