Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • SQL - Getting Started
  • What is SQL
  • Create Table
  • ALTER TABLE Statements
  • Rename Columns
  • Modify Column Type
  • Drop Columns
  • Rename Tables
  • Drop Tables
  • Insert Statement
  • Update Statement
  • Delete Statement
  • Truncate Statement
  • Merge Statement
  • Null Value
  • Select Query
  • WHERE Clause
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause
  • SQL - Inner Join
  • SQL - Left Join
  • SQL - Right Join
  • SQL - Full Join
  • SQL - BETWEEN
  • SQL - IN
  • SQL - LIKE
  • SQL - INTERSECT
  • SQL - MINUS
  • SQL - UNION
  • SQL - UNION ALL
  • SQL - DISTINCT
  • SQL - ANY, SOME
  • SQL - ALL
  • SQL - AVG()
  • SQL - COUNT()
  • SQL - MAX()
  • SQL - MIN()
  • SQL - SUM()
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

SQL - ALTER TABLE

The ALTER command is a DDL command to modify the structure of existing tables in the database by adding, modifying, renaming, or dropping columns and constraints. You can add columns, rename columns, delete columns, or change the data type of columns using the ALTER command.

Add Columns in the Table

Use ALTER TABLE ADD command to add new columns in the database table.

Syntax:

ALTER TABLE table_name ADD column_name1 data_type, column_name2 data_type, ...

As per the above ALTER TABLE command, use the ADD keyword to add one or more new columns. Please note that data type names are different in different databases, so use the data types based on the database you are working.

In the Create Table section, we created the Employee table, as shown below. Now, let's add new columns to it using the ALTER command.

EmpIdFirstNameLastNameEmailPhoneNoSalary
      

The following ALTER command adds Address, city, and Pin Code columns to the Employee table in SQL Server, MySQL, PostgreSQL, SQLite.

SQL Script: Adding Columns in DB Table
ALTER TABLE Employee 
ADD Address VARCHAR(100),
    City VARCHAR(25),
    PinCode integer;

The following ALTER command adds Address, city, and Pin Code columns to the Employee table in Oracle database. Notice that it supports the different data types.

SQL Script: Adding Columns in Table in Oracle
ALTER TABLE Employee 
ADD(Address VARCHAR2(100),
    City VARCHAR2(25),
    PinCode NUMBER);

The above ALTER script will add new columns in the Employee table, as shown below.

EmpIdFirstNameLastNameEmailPhoneNoSalaryAddressCityPinCode
         

Learn how to rename an existing column name in the next chapter.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.