zoukankan      html  css  js  c++  java
  • 数据库常用操作语句

    前些时候,经常的对数据库进行的反复的操作,保留了些经常用的操作语句,总结一下跟大家分享一下:
    一、SQl2005兼容SQL2000语句
         exec sp_dbcmptlevel 'dsc040320_db','80'
    二、生成清库语句
         select 'delete from ' + name from sysobjects where xtype='u' order by name
    三、SQL2005 安装时 “性能监视器计数器要求(错误)”
       请下载下面的文档学习(传了好几遍传不上去,改天补上)
    四、用存储过程生成插入语句

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go

    create   proc [dbo].[spGenInsertSQL1] (@tablename varchar(256))

    as

    begin

    declare @sql varchar(8000)

    declare @sqlValues varchar(8000)

    set @sql =' ('

    set @sqlValues = 'values (''+'

    select @sqlValues = @sqlValues + cols + ' + '','' + ' ,@sql = @sql + '[' + name + '],'

      from

          (select case

                    when xtype in (48,52,56,59,60,62,104,106,108,122,127)                              

                         then 'case when '+ name +' is null then ''NULL'' else ' + 'cast('+ name + ' as varchar)'+' end'

                    when xtype in (58,61)

                         then 'case when '+ name +' is null then ''NULL'' else '+''''''''' + ' + 'cast('+ name +' as varchar)'+ '+'''''''''+' end'

                   when xtype in (167)

                         then 'case when '+ name +' is null then ''NULL'' else '+''''''''' + ' + 'replace('+ name+','''''''','''''''''''')' + '+'''''''''+' end'

                    when xtype in (231)

                         then 'case when '+ name +' is null then ''NULL'' else '+'''N'''''' + ' + 'replace('+ name+','''''''','''''''''''')' + '+'''''''''+' end'

                    when xtype in (175)

                         then 'case when '+ name +' is null then ''NULL'' else '+''''''''' + ' + 'cast(replace('+ name+','''''''','''''''''''') as Char(' + cast(length as varchar)  + '))+'''''''''+' end'

                    when xtype in (239)

                         then 'case when '+ name +' is null then ''NULL'' else '+'''N'''''' + ' + 'cast(replace('+ name+','''''''','''''''''''') as Char(' + cast(length as varchar)  + '))+'''''''''+' end'

                    else '''NULL'''

                  end as Cols,name

             from syscolumns

            where id = object_id(@tablename)

          ) T

    set @sql ='select ''INSERT INTO ['+ @tablename + ']' + left(@sql,len(@sql)-1)+') ' + left(@sqlValues,len(@sqlValues)-4) + ')'' from '+@tablename

    --print @sql

    exec (@sql)

    end


     


  • 相关阅读:
    JQuery 学习总结及实例 !! (转载)
    JavaScript 学习笔记
    个人对JS的一些见解
    本博客欢迎交流,文章自由转载,保持署名!
    VSCode:源码编译运行,分析,踩坑
    ant design pro/前端/JS:实现本地运行https
    前端/JS/React/ES6:纯前端实现图片压缩技术
    云服务名词:软件即服务SaaS,怎么这个理解起来这么别扭
    React:effect应该怎么翻译比较合适??
    我给博客加了一个娃娃,一片雪花
  • 原文地址:https://www.cnblogs.com/ITRoad/p/1533330.html
Copyright © 2011-2022 走看看