knowledgediarybd.com

Your Virtual Knowledge Campus







Drop Truncate and Alter Table in SQL DB

Drop Truncate and Alter Table in SQL DB.SQL Drop truncate and Alter  Table are more essential command  in MySQL database and other database like: like MS Access ,SQL Server , Oracle.

In this tutorial i will discuss about SQL Drop  truncate  and  Alter statement,their purpose , syntax  and suitable example.I hope this must helpful for you.

Purpose of SQL ALTER:

ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

Syntax Of SQL ALTER TABLE:

To add a column in a table, we will use the following

syntax:

ALTER TABLE  table_name   ADD column_name datatype
The “teacher info2” Table
TEACHER INFO
Example:
ALTER TABLE `teacher info2` ADD COLUMN  MobileNo  INT
If you want to run the above query then fist click on  view code then copy & past otherwise you get an extra space sign like   
The out put of the above code:
MM
To delete a column in a table,  we will use the following

syntax:

ALTER TABLE  table_name  DROP COLUMN column_name

For Example:

ALTER TABLE `teacher info2` DROP COLUMN MobileNo

If you want to run the above query then fist click on  view code then copy & past otherwise you get an extra space sign like   
After executing the above code we can see the following massage:

drop

If you press Ok button then you will see following output.

after drop

If we want t o change the data type of a column in a table,

we will use the following

syntax:

For  SQL Server / MS Access

ALTER TABLE  table_name   ALTER COLUMN clm_name datatype
For My SQL / Oracle
ALTER TABLE tbl_name  MODIFY clm_name datatype

DROP TABLE Statement:

Purpose of DROP TABLE Statement:

The DROP TABLE statement is used to delete a table.

Syntax Drop Table statement:

DROP TABLE tbl_name

DROP DATABASE Statement:

Purpose of DROP DATABASE  Statement:

DROP DATABASE statement is used to delete a database.

Example:
DROP DATABASE database_name

TRUNCATE TABLE Statement:

When we use TRUNCATE TABLE Statement:

If we only want to delete the data inside the table faster  but not the table itself.

Then we will use the TRUNCATE TABLE statement:

Syntax:

TRUNCATE TABLE table_name

Related Post or you may like:

knowledgediarybd.com © 2017
shares