mysql 如何更改VIEW表中的列名?

v9tzhpje  于 2023-01-20  发布在  Mysql
关注(0)|答案(1)|浏览(133)

如何在SQL中更改列名?我尝试了以下方法,但出现语法错误。

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

goqiplq21#

不能直接重命名视图中的列,但可以使用所需的新名称重新创建视图:

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

相关问题