久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

SQL Server編寫存儲(chǔ)過程小工具(三)

瀏覽:121日期:2023-10-29 15:14:08

SQL Server編寫存儲(chǔ)過程小工具 功能:為給定表創(chuàng)建Update存儲(chǔ)過程 語法: sp_GenUpdate <Table Name>,<Primary Key>,<Stored Procedure Name> 以northwind 數(shù)據(jù)庫為例 sp_GenUpdate 'Employees','EmployeeID','UPD_Employees'

注釋:如果您在Master系統(tǒng)數(shù)據(jù)庫中創(chuàng)建該過程,那您就可以在您服務(wù)器上所有的數(shù)據(jù)庫中使用該過程。

===========================================================*/ CREATE procedure sp_GenUpdate @TableName varchar(130), @PrimaryKey varchar(130), @ProcedureName varchar(130) as set nocount on

declare @maxcol int, @TableID int 'knowsky.comset @TableID = object_id(@TableName)

select @MaxCol = max(colorder) from syscolumns where id = @TableID

select 'Create Procedure ' + rtrim(@ProcedureName) as type,0 as colorder into #TempProc union select convert(char(35),'@' + syscolumns.name) + rtrim(systypes.name) + case when rtrim(systypes.name) in ('binary','char','nchar','nvarchar','varbinary','varchar') then '(' + rtrim(convert(char(4),syscolumns.length)) + ')' when rtrim(systypes.name) not in ('binary','char','nchar','nvarchar','varbinary','varchar') then ' ' end + case when colorder < @maxcol then ',' when colorder = @maxcol then ' ' end as type, colorder from syscolumns join systypes on syscolumns.xtype = systypes.xtype where id = @TableID and systypes.name <> 'sysname' union select 'AS',@maxcol + 1 as colorder union select 'UPDATE ' + @TableName,@maxcol + 2 as colorder union select 'SET',@maxcol + 3 as colorder union select syscolumns.name + ' = @' + syscolumns.name + case when colorder < @maxcol then ',' when colorder = @maxcol then ' ' end as type, colorder + @maxcol + 3 as colorder from syscolumns join systypes on syscolumns.xtype = systypes.xtype where id = @TableID and syscolumns.name <> @PrimaryKey and systypes.name <> 'sysname' union select 'WHERE ' + @PrimaryKey + ' = @' + @PrimaryKey,(2 * @maxcol) + 4 as colorder order by colorder

select type from #tempproc order by colorder

drop table #tempproc /*=======源程序結(jié)束=========*/

標(biāo)簽: Sql Server 數(shù)據(jù)庫
主站蜘蛛池模板: 旬阳县| 睢宁县| 广汉市| 丹江口市| 浮山县| 平江县| 建水县| 中宁县| 城固县| 会宁县| 独山县| 竹溪县| 常山县| 吴江市| 小金县| 吉水县| 独山县| 志丹县| 雷州市| 太保市| 青浦区| 麻江县| 微博| 霍山县| 南木林县| 密云县| 张家港市| 石首市| 沙洋县| 中牟县| 大埔县| 莆田市| 乌拉特前旗| 博罗县| 宁陵县| 扶余县| 定边县| 绍兴县| 怀柔区| 广水市| 论坛|