提取SQL脚本代码

提取SQL脚本代码
None.gif   public   static  IList < string >  GenerateStoredProcedures()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
int i = 0;
InBlock.gif            IList
<string> list = new List<string>();
InBlock.gif            DBUitility db 
= new DBUitility();
InBlock.gif
InBlock.gif            SqlConnection conn 
= db.CreateConnection(@"Data Source=.\sqlExpress;Initial Catalog=PBCS;Integrated Security=True");
InBlock.gif
InBlock.gif            
InBlock.gif            DataTable dt 
= db.GetDataAsDataTable(
InBlock.gif                
"select name, object_id from sys.objects where type='P' and charindex( '_', [name]) =0 and objectproperty(object_id,'IsProcedure' ) =1");
InBlock.gif
InBlock.gif            
foreach (DataRow dr in dt.Rows)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string id = dr["object_id"].ToString();
InBlock.gif                
string name = dr["name"].ToString();
InBlock.gif              
InBlock.gif                DataTable dtText 
= db.GetDataAsDataTable(
InBlock.gif                            
string.Format("exec sp_helptext '{0}'", name));
InBlock.gif                i
++;
InBlock.gif
InBlock.gif                StringBuilder sb 
= new StringBuilder();
InBlock.gif                sb.AppendLine(
string.Format("if exists (select * from dbo.sysobjects where id = object_id('[dbo].[{0}]') and OBJECTPROPERTY(id, 'IsProcedure') = 1)", name));
InBlock.gif                sb.AppendLine(
"begin");                
InBlock.gif                sb.AppendLine(
string.Format(" drop procedure [dbo].[{0}]", name));
InBlock.gif                sb.AppendLine(
"end");                
InBlock.gif                sb.AppendLine(
"go");
InBlock.gif                sb.AppendLine();
InBlock.gif                
bool bStart = true;
InBlock.gif                
foreach (DataRow drText in dtText.Rows)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (bStart && drText[0].ToString().Trim() != "")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        bStart 
= false;                        
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
if (!bStart)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        sb.Append(drText[
0].ToString());
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
InBlock.gif                sb.AppendLine(); 
InBlock.gif                sb.AppendLine(
"go");
InBlock.gif                sb.AppendLine();
InBlock.gif
InBlock.gif                Debug.AutoFlush 
= true;
InBlock.gif                Debug.WriteLine(sb.ToString());
InBlock.gif
InBlock.gif                list.Add(sb.ToString());
ExpandedSubBlockEnd.gif            }

InBlock.gif            conn.Dispose();
InBlock.gif            
return list;
ExpandedBlockEnd.gif        }

 

 

None.gif   public   static  IList < string >  GenerateFunctions()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
int i = 0;
InBlock.gif            IList
<string> list = new List<string>();
InBlock.gif            DBUitility db 
= new DBUitility();
InBlock.gif
InBlock.gif            SqlConnection conn 
= db.CreateConnection(@"Data Source=.\sqlExpress;Initial Catalog=PBCS;Integrated Security=True");
InBlock.gif
InBlock.gif
InBlock.gif            DataTable dt 
= db.GetDataAsDataTable(
InBlock.gif                
"select name, object_id from sys.objects where type='TF' and charindex( '_', [name]) =0");
InBlock.gif
InBlock.gif            
foreach (DataRow dr in dt.Rows)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string id = dr["object_id"].ToString();
InBlock.gif                
string name = dr["name"].ToString();
InBlock.gif
InBlock.gif                DataTable dtText 
= db.GetDataAsDataTable(
InBlock.gif                            
string.Format("exec sp_helptext '{0}'", name));
InBlock.gif                i
++;
InBlock.gif
InBlock.gif                StringBuilder sb 
= new StringBuilder();
InBlock.gif                sb.AppendLine(
string.Format("if exists (select * from dbo.sysobjects where id = object_id('[dbo].[{0}]'))", name));
InBlock.gif                sb.AppendLine(
"begin");
InBlock.gif                sb.AppendLine(
string.Format(" drop function [dbo].[{0}]", name));
InBlock.gif                sb.AppendLine(
"end");
InBlock.gif                sb.AppendLine(
"go");
InBlock.gif                sb.AppendLine();
InBlock.gif                
bool bStart = true;
InBlock.gif                
foreach (DataRow drText in dtText.Rows)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (bStart && drText[0].ToString().Trim() != "")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        bStart 
= false;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
if (!bStart)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        sb.Append(drText[
0].ToString());
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                sb.AppendLine();
InBlock.gif                sb.AppendLine(
"go");
InBlock.gif                sb.AppendLine();
InBlock.gif
InBlock.gif                Debug.AutoFlush 
= true;
InBlock.gif                Debug.WriteLine(sb.ToString());
InBlock.gif
InBlock.gif                list.Add(sb.ToString());
ExpandedSubBlockEnd.gif            }

InBlock.gif            conn.Dispose();
InBlock.gif            
return list;
ExpandedBlockEnd.gif}

None.gif
posted on 2007-05-20 15:26  阿牛-专注金融行业开发 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/rockniu/archive/2007/05/20/753210.html

你可能感兴趣的:(提取SQL脚本代码)