Add new column to a table using alter table statement in Teradata
Contents
Alter table in Teradata:
Alter table statement is used to add new columns to the existing table in Teradata. It uses ADD function to perform this operation. The table structure is changed by using the alter table statement in Teradata.
Syntax of alter table
1 2 3 |
ALTER TABLE <table_name> ADD <column_name> <column_attributes> |
Example 1 : Add new column to a table
1 2 3 |
ALTER TABLE Test_DB.Customer ADD Address CHAR(400); |
The above query will add the Address column to the Customer table.
Example 2 : Add new column to a table with default value
1 2 3 |
ALTER TABLE Test_DB.Employee ADD Salary_Frequency CHAR(15) DEFAULT 'Monthly'; |
If you want to add the new column with some default value, you can use DEFAULT function along with alter table command to do that. The above query will add the Salary_Frequency column to the Employee table with the default value as ‘Monthly’.
Example 3 : Add multiple new columns to a table
1 2 3 4 5 |
ALTER TABLE Test_DB.Employee ADD Address CHAR(400), ADD BirthDate Date format 'YYYY-MM-DD'; |
Here we are adding multiple new columns such as Address and Birthdate to the the table Employee. Since we are adding multiple new columns in Teradata, multiple ADD’s are required in the ALTER TABLE query.
Recommended Articles
- Create table as Select query in Teradata with examples
- How to rename a table in Teradata?
- How to drop a column in Teradata?