现在要把数据库放到网上去,
但我现在数据库里面有几个表有记录
如省份城市两个表但在服务器的话我只能叫他们给我建立数据库的权限
也就是我发脚本给他们,他们分析看没有安全方面的问题就会给我添加数据库
但现在问题是:我现在的表里面有省份城市表的记录没有办法加进去啊他们不让我联数据库,只能运行脚本
所以想有没有办法把表记录都生成InsertInto语句啊谢谢

解决方案 »

  1.   

    没有完全看明白lz的意思。
    insert into tb
    select 语句
    行不行呢?
      

  2.   


    create proc proc_insert (@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  
     end   
    create table tb(id int,name varchar(50))
    insert into tb select 1,'abc'
    insert into tb select 2,'abc'
    insert into tb select 3,'abc'
    insert into tb select 4,'abc'exec dbo.proc_insert 'tb'
    insert tb (id,name)  values ( 1,'abc')
    insert tb (id,name)  values ( 2,'abc')
    insert tb (id,name)  values ( 3,'abc')
    insert tb (id,name)  values ( 4,'abc')
      

  3.   

    序号      代码      简称
    6 002106 莱宝高科
    1 002106 莱宝高科
    2 002212 南洋股份
    3 000816 江淮动力
    4 600666 西南药业
    5 601600 中国铝业SELECT     'insert into tb(序号,股票代码,股票简称) valuse( ' + CAST(序号 AS nvarchar) + ',' + 股票代码 + ',' + 股票简称 + ')' AS SQL
    FROM         test1
    结果如下insert into tb(序号,股票代码,股票简称) valuse( 6,002106,莱宝高科)
    insert into tb(序号,股票代码,股票简称) valuse( 1,002106,莱宝高科)
    insert into tb(序号,股票代码,股票简称) valuse( 2,002212,南洋股份)
    insert into tb(序号,股票代码,股票简称) valuse( 3,000816,江淮动力)
    insert into tb(序号,股票代码,股票简称) valuse( 4,600666,西南药业)
    insert into tb(序号,股票代码,股票简称) valuse( 5,601600,中国铝业)不知道有用不??