SQL - MODIFY COLUMN SQL ALTER TABLE Statement - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
SQL - MODIFY COLUMN

SQL - MODIFY COLUMN SQL ALTER TABLE Statement

Sometimes we need to change the data type of a column. To do this, we use the ALTER TABLE Modify Column command. For Oracle and MySQL, the SQL syntax for ALTER TABLE Modify Column is,

ALTER TABLE "table_name"
MODIFY "column_name" "New Data Type";
For SQL Server, the syntax is,

ALTER TABLE "table_name"
ALTER COLUMN "column_name" "New Data Type";
Let's look at the example. Assuming our starting point is the Customer table created in the CREATE TABLE section:
Table Customer
Column NameData Type
First_Namechar(50)
Last_Namechar(50)
Addresschar(50)
Citychar(50)
Countrychar(25)
Birth_Datedatetime
Our goal is to alter the data type of the "Address" column to char(100). To do this, we key in:

MySQL
ALTER TABLE Customer MODIFY Address char(100);
Oracle
ALTER TABLE Customer MODIFY Address char(100);
SQL Server
ALTER TABLE Customer ALTER COLUMN Address char(100);
Resulting table structure:

Table Customer
Column NameData Type
First_Namechar(50)
Last_Namechar(50)
Addresschar(100)
Citychar(50)
Countrychar(25)
Birth_Datedatetime

About Mariano

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.