第一个想要实现清空数据库日志文件第二个想把a表中超过30天的数据转存到b表中,a表中不存在超过30天的数据(该存储过程每天都执行,不是只执行一次)
a+b表中的数据就是所有数据不能丢失任何一条不知道这样描述是否清楚,求教

解决方案 »

  1.   

    第一个问题:
    ——————————————————————————————
    截断事务日志:BACKUP LOG { database_name | @database_name_var }
    {
        [ WITH
            { NO_LOG | TRUNCATE_ONLY } ] 
    }
      

  2.   

    第二个:
    ————————————————————————
    insert into B
    select * from A
    where not exists (select 1 from B where a.id=b.id) and datediff(dd,A表的日期,getdate())>=30delete from A
    where exists (select 1 from B where a.id=b.id)
      

  3.   

    insert into B where select * from A where datediff(hh, 日期, GetDate()) > 30delect from A where where datediff(hh, 日期, GetDate()) > 30
      

  4.   

    上面两位大大,我实验了一下,出现下列错误服务器: 消息 8101,级别 16,状态 1,过程 backupdata,行 2
    仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'b' 中为标识列指定显式值。
      

  5.   

    delete from A
    where exists (select 1 from B where a.id=b.id)=========================
    用这个来删数据
    不要用
    delect from A where where datediff(hh, 日期, GetDate()) > 30
    =========================================
    第一个是删除A中不存在B表纪录的所有纪录第二个是删除A中大于30天的纪录,如果B中写如有问题的话,那么A的数据就丢失了
      

  6.   

    flyeq008() 大大的代码,我在查询分析器里运行时出现错误服务器: 消息 213,级别 16,状态 1,过程 backupdata,行 2
    插入错误: 列名或所提供值的数目与表定义不匹配。
    如果把表b删除,然后运行,不出现错误,但也没有结果,刚接触sql,请多多指教
      

  7.   

    insert into b  select * from a
    where datediff(dd,日期,getdate())>30delete a  
    where not exists(select 1 from b where a.id=id)
      

  8.   

    1.backup log 数据库名 with no_log2.
    服务器: 消息 8101,级别 16,状态 1,过程 backupdata,行 2
    仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'b' 中为标识列指定显式值。
    如果b中有自增列,建议把自增属性去掉,因为b表是同步a表的.如果不去掉的话要显示地写出字段列表来,不能用*
    --插入
    SET IDENTITY_INSERT ON
    insert into b(字段列表)
    select 字段列表 from a
    where datediff(day,日期字段,getdate())>30
    SET IDENTITY_INSERT OFF
    --删除
    delete from a where datediff(day,日期字段,getdate())>30