比如现在有一张表:一下是它的属性开始时间   Datetime
有效期     int
是否有效   tinyint数据库是否提供从开始时间开始到有效日期结束,自动将是否有效设置为无效?谢谢!

解决方案 »

  1.   

    /* 在SQL SERVER或者Oracle中有计算列的概念,所以可以实现你的需求,如下 */create table #t(F_BeginDate datetime,
                    F_LastDay int,
                    F_Flag as case when getdate() between F_BeginDate and dateadd(d,F_LastDay,F_BeginDate) then 0 else 1 end
                    )insert #t(F_BeginDate,F_LastDay) select '2006-12-01',20
    Go
    insert #t(F_BeginDate,F_LastDay) select '2006-12-01',30
    Go/* 但是mysql中没有计算列,所以你只能通过视图来实现了 */alter view v_test
    as
    select F_BeginDate,
           F_LastDay,
           IF(sysdate() between F_BeginDate and F_BeginDate+interval F_LastDay Day,0,1) as F_Flag
    from t;select * from v_test;
      

  2.   

    alter table 表名 change 字段 字段