mysqlsqlddlsql-viewcreate-view

How to change column name in VIEW table?


How to change column name in SQL? I have tried the following but giving a syntax error.

create view cView as select * from College;
alter table cView
rename cName to collegeName,
rename enrollment to seats;

Solution

  • You can't directly rename columns in a view, but you can recreate it with the new names you want:

    CREATE OR REPLACE cView AS
    SELECT col1,
           col2,
           cName AS collageName,
           enrollment AS seat,
           someOtherColumn
           -- etc...
    FROM   myTable