Teradata ALTER TABLE RENAME COLUMN is used to rename the column name of an existing Teradata table.
Teradata ALTER TABLE RENAME COLUMN syntax
The syntax for renaming a Teradata column is as follows.
ALTER TABLE database_name.table_name RENAME column_name to new_column_name;
Teradata ALTER TABLE RENAME COLUMN example
Let’s understand the concept of the Teradata ALTER TABLE RENAME COLUMN
with the help of examples.
Consider the definition of table Student
as below.
SHOW TABLE TUTORIALSBOOK.Student; *** Text of DDL statement returned. *** Total elapsed time was 1 second. --------------------------------------------------------------------------- CREATE SET TABLE TUTORIALSBOOK.Student ,FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT, DEFAULT MERGEBLOCKRATIO, MAP = TD_MAP1 ( ROLLNO INTEGER, FIRSTNAME VARCHAR(50) CHARACTER SET LATIN NOT CASESPECIFIC FORMAT 'X (30)', LASTNAME VARCHAR(30) CHARACTER SET LATIN NOT CASESPECIFIC, COURSE VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL) UNIQUE PRIMARY INDEX ( ROLLNO );
The following statement renames the COURSE
column to COURSENAME
.
ALTER TABLE TUTORIALSBOOK.Student RENAME COURSE to COURSENAME; *** Table has been modified. *** Total elapsed time was 1 second.
We can verify the definition of the Student
table now using the SHOW TABLE
statement.
SHOW TABLE TUTORIALSBOOK.Student; *** Text of DDL statement returned. *** Total elapsed time was 1 second. --------------------------------------------------------------------------- CREATE SET TABLE TUTORIALSBOOK.Student ,FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT, DEFAULT MERGEBLOCKRATIO, MAP = TD_MAP1 ( ROLLNO INTEGER, FIRSTNAME VARCHAR(50) CHARACTER SET LATIN NOT CASESPECIFIC FORMAT 'X (30)', LASTNAME VARCHAR(30) CHARACTER SET LATIN NOT CASESPECIFIC, COURSENAME VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL ) UNIQUE PRIMARY INDEX ( ROLLNO );
As we can see that the name of the column COURSE
changes to COURSENAME
.