惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Cyberwarzone
Cyberwarzone
博客园_首页
爱范儿
爱范儿
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
H
Help Net Security
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
S
SegmentFault 最新的问题
L
LINUX DO - 热门话题
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
N
News | PayPal Newsroom
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LangChain Blog
L
Lohrmann on Cybersecurity
P
Palo Alto Networks Blog
云风的 BLOG
云风的 BLOG
A
Arctic Wolf
N
News and Events Feed by Topic
AWS News Blog
AWS News Blog
美团技术团队
U
Unit 42
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Secure Thoughts
有赞技术团队
有赞技术团队
C
Cyber Attacks, Cyber Crime and Cyber Security
Schneier on Security
Schneier on Security
Cloudbric
Cloudbric
B
Blog
NISL@THU
NISL@THU
Help Net Security
Help Net Security
Y
Y Combinator Blog
J
Java Code Geeks
S
Securelist
宝玉的分享
宝玉的分享
T
Threat Research - Cisco Blogs
S
Security @ Cisco Blogs
O
OpenAI News
D
DataBreaches.Net
Know Your Adversary
Know Your Adversary
Hacker News - Newest:
Hacker News - Newest: "LLM"
Vercel News
Vercel News
Forbes - Security
Forbes - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed

博客园 - WinkSky

索引 This is a test post by Windows Live Writer [提问]升级至SQL2005后续问题讨论. [提问]SQL2005关于点对点事务型映射 李开复:21世纪7种人才最抢手 SQL2000中奇怪的NULL值记录问题[求助] SQL2005常见性能问题排错演示代码[收藏] 上海Oracle高峰会感悟 Microsoft® Visual Studio® .NET™ 2003 Service Pack 1 ASP.NET(C#) 編碼規範[整理讨论] 颜色代码表[转] Gmail的图片签名[收藏] 精妙SQL语句收集[转载] [转载]61条面向对象设计的经验原则 需求工程16字方针 SQL各种写法的效率问题-转载自邹建专栏 SQL2000视图问题[请教] 讨论String与string的区别. 一道终身受用的测试题
存储过程编写小工具[收藏]
WinkSky · 2006-08-10 · via 博客园 - WinkSky


/*===============源程序開始==================*/ 

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(@ProcedureNameas 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 + 6as 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

/*===============源程序結束==================*/

GO


/*===============源程序開始==================*/ 

CREATE procedure sp_GenUpdate 
@TableName varchar(130), 
@PrimaryKey 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(@ProcedureNameas 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

/*===============源程序結束==================*/

GO