Home » SQL

Alterations on table in SQL

In this article, we are going to learn about the alterations on the tables in SQL.
Submitted by Manu Jemini, on March 06, 2018

A Table is a set of fields which defines the way the records will store in the database and also many more things. These things are very useful, but sometimes also very restrictive.

Therefore, the need to change or alter the rules or fields with a SQL query becomes eminent. For example, if you want to add another field called status in the already made table all you will need to do is this:

 ALTER TABLE table_name ADD status varchar(45);

Now, it will make another field with a name called status. The Field will be blanked for all the saved records in table.

Now, we can also drop tables, change the data type of the fields or modify the column in some other way. This is probably very useful to know the basic concept of both of these concepts. Let’s drop a column name from the table with a SQL query:

 ALTER TABLE table_name DROP COLUMN status;

This will drop the column from the table and also the fields from the already saved records in the table. Similarly, we can also drop table from the database.

Dummy data:

Alterations on table in SQL

Syntax (ADD column)

ALTER TABLE table_name ADD column_name datatype;

Syntax (DROP column)

ALTER TABLE table_name DROP COLUMN column_name;

Syntax (MODIFY column)

ALTER TABLE table_name MODIFY COLUMN column_name datatype;

Example (DROP primary key)

ALTER TABLE 'includehelp'.'employees' DROP PRIMARY KEY;

Example (ADD column)

ALTER TABLE 'includehelp'.'employees' ADD BONUS int;
Alterations on table in SQL Query 2

Example (DROP column)

ALTER TABLE 'includehelp'.'employees' DROP BONUS;
Alterations on table in SQL Query 3



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.