;
Conta
delete ain : |
iy the rows from student table, the statement will be:
als sh
iter SP TRUNCATE TABLE Student
ence
Ubypae PCtWeen DELETE and TRUNCATE Statements
i le based on the on
Bren iy ttements This command deletes only the rows from ay we a
ry fia here clause or deletes all the rows from the table if n 4
‘he space containing the table.
his command is used to dele
table and free
te all the rows from the>
10. ALTER TABLE Command tates ues meee
‘ ed to modify the definition
dates SHAE a nee TABLA, hint is used to perform the towne
» To add a column to an existing table,
» ‘To rename any existing column,
» To change the data type of any column or to modify its size,
» To remove or physically delete a column,
(a) Adding a column to an existing table
Once a table has been created, new columns can be added later on, if required, ‘The n
column is added with NULL values for all the records/rows in the table, Itis POSSible tp
add, delete and modify columns with ALTER TABLE statement,
Syntax for adding a new column:
A
For example, to add a new column Mobile_no of type integer in the table student:
mysql> ALTER TABLE Stud
TABLE
ADD( [size});
nt ADD (Mobile no integer);
‘Thus, the above si
NULL value in it.
tement shall add 4 new column Mobile_no into the table student with
We have just added a column and there will be no d,
be used to supply values/data to this column,
ata (NULL) under this attribute, UPDATE command can
(b) Adding a column with default value
ALTER TABLE command can be
values.
used to add a new column to an existing table with default
Syntax for adding a column with a default value:
ALTER TABLE
ADD ([column_namet}default data);
For example, mysql> nit ER ‘YAR
The above command will
student table,
tudent ADD (City (6) default "DELHI");
It value as “DELHI” to the
add a new column City with d
Resultant table: student
A Te Ty
1 Raj Kumar mM 93 17-Nov-2000 NULL DELHI"
2 Deep Singh M 98 22-Aug-1996 NULL DELHI
3 Ankit Sharma ” 76 02-Feb-2000 NULL DELHI
7 me oe F 78 03-Dec-1999 NULL DELHI
- sie : _ fi 82 21-April-1998 NULL DELHI
aaa y 80 17-Dec-1999 NULL DELHI
8 Akshay Dureja M a NU ae
oka sae res : 90. 05-May-1997 NULL DELHI :
10 Prateek Mittal M on aaa aa al
75 25-Dec-2000 NULL DELHIPa ail existing column definition
se can be used with ALTER TABLE ¢
posit!
Jated to any column of the table, mmand to change the data a
yoolF¥ lau!
HE pstraint TO :
se jor difying existing column data type:
ox
gs ‘ABLE