http://topic.csdn.net/u/20080303/14/0eb238ca-14e3-4da7-973e-f7d96095674d.htmlif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[d]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[d]
GOCREATE TABLE [dbo].[d] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[type] [int] NOT NULL ,
[counts] AS ([dbo].[test_fun]([type])) 
) ON [PRIMARY]
GOif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[c]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[c]
GOCREATE TABLE [dbo].[c] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[type] [int] NULL 
) ON [PRIMARY]
GOinsert into c select 1....insert into c select 2....
insert into c select 3....CREATE function test_fun(@type int)
returns int
as
begin
declare @s int
select @s=case when count(0)>0 then count(0) else 0 end from c where type=@type
return @s
end