如何在 MySQL 视图中设置默认值?

How can I set default value in MySQL view?

我写了下面的代码在MySQL中创建视图:

CREATE VIEW anag AS  SELECT f.NAME AS NAME ,f.id AS id,s.map_level AS map_level FROM server s ,functionalci f WHERE s.id = f.id
union
SELECT f.NAME AS NAME ,f.id AS id,ws.map_level AS map_level FROM webserver ws ,functionalci f WHERE ws.id = f.id

我想在视图中添加新属性 "type_id",我想将默认值设置为 0; 注意:功能 table、服务器 table 和网络服务器 table 都没有 "type_id" 属性。

尝试在您的查询中添加值为 0 的 type_id

CREATE VIEW anag AS  SELECT f.NAME AS NAME ,f.id AS id,s.map_level AS map_level, 0 as type_id FROM server s ,functionalci f WHERE s.id = f.id
union
SELECT f.NAME AS NAME ,f.id AS id,ws.map_level AS map_level, 0 as type_id FROM webserver ws ,functionalci f WHERE ws.id = f.id