CREATE TABLE `information` (
`infoId` int(11) NOT NULL auto_increment COMMENT '信息编号',
`score1` int(11) NOT NULL default '0' COMMENT '默认加分值',
`score2` int(11) NOT NULL default '0',
`totalScore`,
PRIMARY KEY (`infoId`)
)我想这个totalScore的字段等于score1+score2 自动计算生成,
我记得sql server里 好像totalScore as score1+score2 就可以了 可是mysql里 不行 该怎么设计呢?
`infoId` int(11) NOT NULL auto_increment COMMENT '信息编号',
`score1` int(11) NOT NULL default '0' COMMENT '默认加分值',
`score2` int(11) NOT NULL default '0',
`totalScore`,
PRIMARY KEY (`infoId`)
)我想这个totalScore的字段等于score1+score2 自动计算生成,
我记得sql server里 好像totalScore as score1+score2 就可以了 可是mysql里 不行 该怎么设计呢?
`infoId` int(11) NOT NULL auto_increment COMMENT '信息编号',
`score1` int(11) NOT NULL default '0' COMMENT '默认加分值',
`score2` int(11) NOT NULL default '0',
PRIMARY KEY (`infoId`)
);create view v_information as
select infoId,score1,score2,score1+score2 as totalScore from information;
CREATE OR REPLACE VIEW v_information AS
SELECT infoId, score1, score2, score1 + score2 AS totalScore
FROM information