filmov
tv
Using MySQL Server 5.1 Alter Table, Truncate Table,Drop Table,Desc |Alter Table using MySQL 5.1

Показать описание
Create table link:
Alter Table
Alter table query is used to modify structure of a table.
we can add, delete or modify column.
1.Adding New column in a Table
ALTER TABLE table_name
ADD column_name datatype;
Example:
Adding column grade in the table student
ALTER TABLE student
ADD grade varchar(2);
2.Dropping column from table
ALTER TABLE table_name
DROP COLUMN column_name;
Example:
Deleting column grade from the table student.
ALTER TABLE student
DROP COLUMN grade;
3.Modifying Column of a Table
ALTER TABLE table_name
MODIFY COLUMN column_name data_type;
Example:
Changing the data type and size of column roll_no of student table.
ALTER TABLE student
modify column roll_no varchar(4);
4.Rename
Alter table can also used to rename a table.
Syntax:
alter table table_name rename to new_table_name;
Example:
alter table student
rename to studentdata;
Truncate Table
This command is used to delete all the records from table
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE studentnew;
DROP TABLE
DROP TABLE query is used to delete table permanently from the database.
Syntax:
drop table table_name;
Example:
drop table studentnew;
Desc
Desc query is used to display structure of table.
desc table_name;
Example:
desc student;
Alter Table
Alter table query is used to modify structure of a table.
we can add, delete or modify column.
1.Adding New column in a Table
ALTER TABLE table_name
ADD column_name datatype;
Example:
Adding column grade in the table student
ALTER TABLE student
ADD grade varchar(2);
2.Dropping column from table
ALTER TABLE table_name
DROP COLUMN column_name;
Example:
Deleting column grade from the table student.
ALTER TABLE student
DROP COLUMN grade;
3.Modifying Column of a Table
ALTER TABLE table_name
MODIFY COLUMN column_name data_type;
Example:
Changing the data type and size of column roll_no of student table.
ALTER TABLE student
modify column roll_no varchar(4);
4.Rename
Alter table can also used to rename a table.
Syntax:
alter table table_name rename to new_table_name;
Example:
alter table student
rename to studentdata;
Truncate Table
This command is used to delete all the records from table
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE studentnew;
DROP TABLE
DROP TABLE query is used to delete table permanently from the database.
Syntax:
drop table table_name;
Example:
drop table studentnew;
Desc
Desc query is used to display structure of table.
desc table_name;
Example:
desc student;