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

时间:2015-03-16 10:25:16

标签: mysql view default-value

我编写了以下代码来在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; 注意:功能表,服务器表和webserver表都没有“type_id”属性。

1 个答案:

答案 0 :(得分:0)

尝试在查询中添加值为{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