因为我们原来的系统是用SQL2000的
后来又开发了一个系统就用了SQL2005
但是自从装了SQL2005以后
我再去做原来的SQL2000为数据库的系统的话就很是麻烦
就是我2005添加的表生成的SQL语句在2000中不能用如何在SQL2005中生成SQL2000的语句
或者哪个工具有这个功能谢谢

解决方案 »

  1.   

    将表生成insert语句存储过程.SET QUOTED_IDENTIFIER ON 
    GO
    SET ANSI_NULLS ON 
    GOCREATE proc pGetInsertSQL (@TableName varchar(256))
    as
    begin
        set nocount on
        declare @sqlstr varchar(4000)
        declare @sqlstr1 varchar(4000)
        declare @sqlstr2 varchar(4000)
        select @sqlstr='select ''insert '+@tablename
        select @sqlstr1=''
        select @sqlstr2=' ('
        select @sqlstr1= ' values ( ''+'
        select @sqlstr1=@sqlstr1+col+'+'',''+' ,@sqlstr2=@sqlstr2+name +',' from (select case 
    --    when a.xtype =173 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end'
        when a.xtype =104 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(1),'+a.name +')'+' end'
        when a.xtype =175 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
        when a.xtype =61  then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end'
        when a.xtype =106 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end'
        when a.xtype =62  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end'
        when a.xtype =56  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(11),'+a.name +')'+' end'
        when a.xtype =60  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end'
        when a.xtype =239 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
        when a.xtype =108 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end'
        when a.xtype =231 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
        when a.xtype =59  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end'
        when a.xtype =58  then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end'
        when a.xtype =52  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(12),'+a.name +')'+' end'
        when a.xtype =122 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end'
        when a.xtype =48  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(6),'+a.name +')'+' end'
    --    when a.xtype =165 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end'
        when a.xtype =167 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
        else '''NULL'''
        end as col,a.colid,a.name
        from syscolumns a where a.id = object_id(@tablename) and a.xtype <>189 and a.xtype <>34 and a.xtype <>35 and  a.xtype <>36
        )t order by colid
        
        select @sqlstr=@sqlstr+left(@sqlstr2,len(@sqlstr2)-1)+') '+left(@sqlstr1,len(@sqlstr1)-3)+')'' from '+@tablename
    --  print @sqlstr
        exec( @sqlstr)
        set nocount off
    endGO
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO
      

  2.   

    生成脚本时,设置属性兼容级别为SQL Server2000
      

  3.   

    使用SQL2005有一段时间了,虽然基本功能的使用上与SQL2000差不多,但是还是觉得有点不顺手,毕竟SQL2000使用了好几年,要找个功能菜单之类的得心应手,慢慢适应新东西吧。
    经常要使用的就是SQL脚本的导出功能,由于SQL2005导出的格式有些与SQL2000不兼容,所以有时候还要与SQL2000兼容,原来刚装的时候也摸过一段并找到过,后来隔段时间不用又忘了。怕下次再忘,做个备忘。
    在左边对象资源管理器中右键点击数据库,在弹出菜单中选择任务-〉生成脚本,出现脚本到处向导
      

  4.   

    RE:生成脚本时,设置属性兼容级别为SQL Server2000
    ------------------------------
    在哪里有这一个设置啊
    右键盘 --> 编写表脚本为非作歹--> Create到 -->  文件  成功
    这里面没有一个地方可以设置属性兼容级别为SQL Server2000