判断SQL Server的计算列
目的:需要将一个计算列改成非计算列
if columnproperty(object_id('test'),'TotalPrice',N'IsComputed')=1
BEGIN
print '是计算列'
ALTER TABLE test DROP COLUMN TotalPrice
END
else
print '不是计算列'
go
IF NOT EXISTS(SELECT * FROM SysObjects a, SysColumns b
WHERE a.id = b.id AND a.NAME = 'test' AND a.xtype='U' AND b.NAME='TotalPrice')
BEGIN
ALTER TABLE test
ADD TotalPrice [Money] DEFAULT 0 WITH VALUES
EXEC('UPDATE test SET totalprice = price * amount')
END
GO