问题描述
我想为数据库对象生成脚本,例如- 表
- views
- 存储过程
- 功能
原因:
- (不推荐使用)
不会全新安装:
- Windows XP
- Windows Vista
- Windows 7
也不能重新分配它们,它们不是一种选择(它将在客户的计算机上运行)。
(编辑:看起来SMO实际上是
是否有任何源代码可将 SELECT 从系统表转换为关联的脚本?
我将以伪代码开始,该脚本编写存储过程,视图,触发器的脚本或用户定义的函数:
String GetStoredProcedureScript(StringstoredProcedureName)
{
return GetHelpText(storedProcedureName );
}
字符串GetViewScript(String viewName)
{
return GetHelpText(viewName);
}
字符串GetTriggerScript(String triggerName)
{
return GetHelpText(storedProcedureName);
}
字符串GetUserDefinedFunctionScript(String userDefinedFunctionName)
{
return GetHelpText(userDefinedFunctionName);
}
所有这些都可以在内部使用单个帮助器功能:
String GetHelpText(String objectName)
{
String szQuery ='EXECUTE sp_helptext'+ QuotedStr(objectName);
字符串sql:=’’;
使用(Recordset rs = connection.Execute(szQuery))
{
而没有rs.EOF执行
{
sql = sql + rs [ '文本'];
rs.Next;
}
}
返回sql;
}
编辑:谢谢指出 sp_helptext
。这就是为什么我有一个类将这些内容抽象化的原因。
您尝试过sp_helptext吗?
字符串szQuery ='EXEC sp_helptext'+ QuotedStr(storedProcedureName)
i want to generate scripts for database objects, e.g.
- tables
- views
- stored procedures
- functions
Since:
are not installed on a fresh install of:
- Windows XP
- Windows Vista
- Windows 7
nor are they redistributable, they are not an option (it will run on a customer's machine).
(EDIT: It looks as if SMO is actually redistributable as of today.)
Is there any source code that converts SELECTs from system tables into associated scripts?
i'll start us off with the pseudo-code that scripts a stored procedures, views, triggers, or user-defined functions:
String GetStoredProcedureScript(String storedProcedureName)
{
return GetHelpText(storedProcedureName);
}
String GetViewScript(String viewName)
{
return GetHelpText(viewName);
}
String GetTriggerScript(String triggerName)
{
return GetHelpText(storedProcedureName);
}
String GetUserDefinedFunctionScript(String userDefinedFunctionName)
{
return GetHelpText(userDefinedFunctionName);
}
All which can internally use a single helper function:
String GetHelpText(String objectName)
{
String szQuery = 'EXECUTE sp_helptext '+QuotedStr(objectName);
String sql := '';
using (Recordset rs = connection.Execute(szQuery))
{
while not rs.EOF do
{
sql = sql+rs['text'];
rs.Next;
}
}
return sql;
}
Edit: Thanks servicesharvest316 for pointing out sp_helptext
. That's why i have a class that abstracts these things away.
Have you tried sp_helptext?
String szQuery = 'EXEC sp_helptext '+QuotedStr(storedProcedureName)
这篇关于SQL Server:如何在没有DMO / SMO的情况下生成对象脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!