Alter Table Statement | How to Alter Table in SQL | SQL Server Alter Table | Intellipaat

ArticlesBlog

Written by:


Hey guys welcome back to this SQL
tutorial series. In this session we’ll be working with the alter table statement.
So the alter table statement is used to add, delete and modify columns in an
existing table. Now let’s have a look at the syntax to add a column to an existing
table. So we’ll start by giving the keywords alter table and then we’ll give
the name of the table after that will give the add keyword and the name of the
column which you want to add to our table and finally we’ll have to assign a
datatype to this new column. So to our existing employee table I’ll add a new
column date of birth using the alter table statement. So let me start with the
syntax alter table then I’ll give the name of the table which would be
employee, after that I will give in the add keyword and then give in the name of
the column so I’ll name the new column to be e_dob which would stand for
employee date of birth and then I will finally give the datatype of this new
column so the data type would be date. So I will press semicolon. I’ll hit execute. So commands have been completed successfully. Now let me have a
glance at the modified table. Select start from employee you see that this new column employee
date of birth has been added to our employee table. Now let’s see how can we drop up a
column from a table. Again we’ll start by giving the keywords alter table and
then we will give the table name, after that we’ll give the keywords drop column
and specify the name of the column which is to be dropped so I want to drop this
new column e DOB which I’ve just added to this employ table so let me write the
command for that alter table and then the name of the
table is employee, after that I will give in the keywords drop column and I want
to drop the e DOB column from this employee database. I’ll put a semicolon hit execute. So again the commands have been successfully executed. Now let me have a
glance at the modified table. Select start from employee, i will put a semicolon, execute. So again the new column which you had just added has been dropped. So this is how we can work with the alter table statement So thanks for attending the session
let’s meet in the next class.

One Reply to “Alter Table Statement | How to Alter Table in SQL | SQL Server Alter Table | Intellipaat”

  1. Intellipaat says:

    Got a question on how to alter table statement in SQL server? Do write it in the comment and you will get a response immediately by our expert. For MS SQL Server training & certification, call us at US: 1800-216-8930 (Toll Free) or India: +917022374614. You can also write us at [email protected]

Leave a Reply

Your email address will not be published. Required fields are marked *