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 - Modify Column Data Type and Size

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.

Different databases support different ALTER TABLE syntax to modify the column data type and size.

The following ALTER TABLE statement modifies the size of the Address column of the Employeetable in the SQL Server database.

SQL Script: Change Column Size in SQL Server
ALTER TABLE Employee ALTER COLUMN FirstName VARCHAR(50);

The following will change the size in the Oracle database.

SQL Script:
ALTER TABLE Employee MODIFY (FirstName VARCHAR2(50));

The following will change the size in the PostgreSQL database.

SQL Script:
ALTER TABLE Employee 
ALTER COLUMN FirstName TYPE VARCHAR(50);

Be careful while decreasing the size of a column where the data exist. It will raise an error if the new size is less than any of the data in that column.

Change Column Datatype

The following statement will change the data type of PinCode column from varchar to integer in the SQL Server database.

SQL Script: Change Column Data Type in SQL Server
ALTER TABLE Employee 
ALTER COLUMN PinCode integer;

The following statement will change column data type in the Oracle database.

SQL Script: Change Column Data Type in Oracle
ALTER TABLE Employee MODIFY (PinCode number);

The following statement will change column data type in the PostgreSQL database.

SQL Script: Change Column Data Type in PostgreSQL
ALTER TABLE Employee 
ALTER COLUMN PinCode TYPE INT
USING PinCode::INTEGER;
Note:
A column must be empty while changing the type of a column; otherwise it will raise an error.
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.