SQLServer编写存储过程小工具(三)
来源:互联网 发布:网络综合布线施工方案 编辑:程序博客网 时间:2024/04/30 16:39
编写存储过程小工具
功能:为给定表创建Update存储过程
语法:sp_GenUpdate<TableName>,<PrimaryKey>,<StoredProcedureName>
以northwind为例
sp_GenUpdate'Employees','EmployeeID','UPD_Employees'
注释:如果您在Master系统数据库中创建该过程,那您就可以在您服务器上所有的数据库中使用该过程。
===========================================================*/
CREATEproceduresp_GenUpdate
@TableNamevarchar(130),
@PrimaryKeyvarchar(130),
@ProcedureNamevarchar(130)
as
setnocounton
declare@maxcolint,
@TableIDint
'acnow.net
set@TableID=object_id(@TableName)
select@MaxCol=max(colorder)
fromsyscolumns
whereid=@TableID
select'CreateProcedure'+rtrim(@ProcedureName)astype,0ascolorderinto#TempProc
union
selectconvert(char(35),'@'+syscolumns.name)
+rtrim(systypes.name)
+casewhenrtrim(systypes.name)in('binary','char','nchar','nvarchar','varbinary','varchar')then'('+rtrim(convert(char(4),syscolumns.length))+')'
whenrtrim(systypes.name)notin('binary','char','nchar','nvarchar','varbinary','varchar')then''
end
+casewhencolorder<@maxcolthen','
whencolorder=@maxcolthen''
end
astype,
colorder
fromsyscolumns
joinsystypesonsyscolumns.xtype=systypes.xtype
whereid=@TableIDandsystypes.name<>'sysname'
union
select'AS',@maxcol+1ascolorder
union
select'UPDATE'+@TableName,@maxcol+2ascolorder
union
select'SET',@maxcol+3ascolorder
union
selectsyscolumns.name+'=@'+syscolumns.name
+casewhencolorder<@maxcolthen','
whencolorder=@maxcolthen''
end
astype,
colorder+@maxcol+3ascolorder
fromsyscolumns
joinsystypesonsyscolumns.xtype=systypes.xtype
whereid=@TableIDandsyscolumns.name<>@PrimaryKeyandsystypes.name<>'sysname'
union
select'WHERE'+@PrimaryKey+'=@'+@PrimaryKey,(2*@maxcol)+4ascolorder
orderbycolorder
selecttypefrom#tempprocorderbycolorder
droptable#tempproc
/*=======源程序结束=========*/
- SQLServer编写存储过程小工具(三)
- SQLServer编写存储过程小工具(二)
- SQLServer编写存储过程小工具(一)
- SQL Server编写存储过程小工具
- SQL SERVER编写存储过程小工具
- SQL Server编写存储过程小工具(一)
- 编写sqlserver存储过程
- [小工具]代码统计小工具编写
- sqlserver编写存储过程汇总
- 小工具:SQL存储过程解密修改工具
- SqlServer存储过程编写经验和优化
- SqlServer存储过程编写经验和优化
- SqlServer存储过程编写经验和优化
- SqlServer存储过程编写经验和优化
- 编写的SQLServer扩展存储过程
- SQLServer存储过程编写和优化措施
- SqlServer 存储过程编写经验和优化
- sqlServer 存储过程编写和调用
- Proxima:一个面向表示的结构化文档编辑器
- linux常用配置文件以及说明
- 一些有用的sql语句实例
- MYSQL使用简述
- Eclipse+JBoss+开发环境设置
- SQLServer编写存储过程小工具(三)
- Java中的易混问题
- Monday, April,27,2008 心情日记
- SQLServer编写存储过程小工具(二)
- xp_cmdshell---MSSQL系统漏洞
- SQLServer编写存储过程小工具(一)
- 无日志文件恢复数据库方法两则(一)
- 无日志文件恢复数据库方法两则(二)
- ASCⅡ码表