CREATE TRIGGER Trigger_TelWav
   ON  [dbo].[TelWav] 
  for INSERT
AS 
declare @TempSize int 
select @TempSize=size*8/1024 from sysfiles where fileid=1
select @TempSize
if @TempSize>1900 then
delete from telwav  where exists(
select top 10 percent * from telwav b where telwav.Calltime=b.CallTime)
  dbcc shrinkfile(1)
  dbcc shrinkfile(2)
end 

解决方案 »

  1.   

    --这一条SQL不对,会把表中所有数据删除
    delete from telwav  where exists(
    select top 10 percent * from telwav b where telwav.Calltime=b.CallTime)
      

  2.   

    TO:libin_ftsafe
    TelWav表是一个没有主键的表,我需要删除这个表的10%的记录,那么请问你,该怎么写呢?
      

  3.   

    delete a 
    from 
        telwav a 
    where 
        a.CallTime in(select top 10 percent Calltime from telwav order by Calltime)
      

  4.   

    delete from telwav  where exists(select 1 from 
    (select top 10 percent * from telwav) b where telwav.Calltime=b.CallTime)
      

  5.   

    TO:libin_ftsafe  splory
    谢谢你们,试过了,都可以的,
    但是把你们写的删除语句放进去,那个触发器还是有问题,请你们再看看好吗?
      

  6.   

    CREATE TRIGGER Trigger_TelWav
       ON  [dbo].[TelWav] 
      for INSERT
    AS 
    BEGIN
        declare @TempSize int 
        select @TempSize=size*8/1024 from sysfiles where fileid=1
        select @TempSize
        
        IF @TempSize>1900
        BEGIN
            delete a 
            from 
                telwav a 
            where 
                a.CallTime in(select top 10 percent Calltime from telwav order by Calltime)
        
            dbcc shrinkfile(1)
            dbcc shrinkfile(2)
        END 
    END
    GO
      

  7.   

    T-SQL不是BASIC语言,没有 IF ... THEN ...
      

  8.   

    delete a from     telwav a 
    where  a.CallTime in(select top 10 percent Calltime from telwav order by Calltime)
      

  9.   

    To:libin_ftsafe
    这个触发器我是用解决这个的:
    当数据库的容量超过1.9G时,删除表Telwav(录音文件)表中10%的记录
    (说明: Telwav这个表没有主键,存在重复的数据)
    这是一个msde 2000的数据库,删除数据之后,数据库还不能进行收缩,所以在进行删除后得收缩数据库想问你是否还有更好的解决方法?
      

  10.   

    To: libin_ftsafe
    那请问要如何在后台进程来进行收缩操作呢
      

  11.   

    MSDE 2000没用过,但是估计没有JOB的功能,但是可以写一个专用的程序来定时执行收缩操作。