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

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
小众软件
小众软件
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
S
Secure Thoughts
O
OpenAI News
P
Proofpoint News Feed
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
Tenable Blog
A
Arctic Wolf
L
LINUX DO - 热门话题
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog

博客园 - 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