国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

SQL Server編寫存儲過程小工具(二)

瀏覽:111日期:2023-10-29 15:11:04

SQL Server編寫存儲過程小工具 以下是兩個存儲過程的源程序 /*===========================================================

語法: sp_GenInsert <Table Name>,<Stored Procedure Name> 以northwind 數(shù)據(jù)庫為例 sp_GenInsert 'Employees', 'INS_Employees'

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

=============================================================*/

CREATE procedure sp_GenInsert @TableName varchar(130), @ProcedureName varchar(130) as set nocount on

declare @maxcol int, @TableID int

set @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 'INSERT INTO ' + @TableName,@maxcol + 2 as colorder union select '(',@maxcol + 3 as colorder union select 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 systypes.name <> 'sysname' union select ')',(2 * @maxcol) + 4 as colorder union select 'VALUES',(2 * @maxcol) + 5 as colorder union select '(',(2 * @maxcol) + 6 as colorder union select '@' + syscolumns.name + case when colorder < @maxcol then ',' when colorder = @maxcol then ' ' end as type, colorder + (2 * @maxcol + 6) as colorder from syscolumns join systypes on syscolumns.xtype = systypes.xtype where id = @TableID and systypes.name <> 'sysname' union select ')',(3 * @maxcol) + 7 as colorder order by colorder

select type from #tempproc order by colorder

drop table #tempproc

主站蜘蛛池模板: 新化县| 胶南市| 合川市| 北宁市| 哈尔滨市| 伊金霍洛旗| 屏东市| 长武县| 尖扎县| 霍城县| 朝阳区| 永德县| 内黄县| 将乐县| 沧源| 射阳县| 平乐县| 望奎县| 连平县| 友谊县| 轮台县| 衢州市| 罗定市| 太康县| 井研县| 西充县| 利辛县| 铁力市| 孝义市| 凤台县| 通道| 卫辉市| 抚宁县| 登封市| 乌海市| 石城县| 汉寿县| 宣威市| 望都县| 高阳县| 高邑县|