How can I export the content of a stored procedure using a SQL Statement?
如何使用SQL语句导出存储过程的内容?
4 个解决方案
#1
If by 'Content' you are talking about the code, look into sp_helptext()
如果通过'Content'谈论代码,请查看sp_helptext()
http://msdn.microsoft.com/en-us/library/ms176112.aspx
Here's a sample based on the old PUBS sample database
这是基于旧PUBS示例数据库的示例
USE pubs;
GO
EXEC sp_helptext 'pubs.dbo.byroyalty';
GO
And here are the results
以下是结果
Text --------
CREATE PROCEDURE byroyalty @percentage int
AS
select au_id from titleauthor
where titleauthor.royaltyper = @percentage
BUT, if by 'Content' you mean the results; you can either run the proc with the 'Results to File...' setting, or 'Results in Grid' and right click in the grid, and do a 'Save as...'
但是,如果用'内容'表示结果;您可以使用“结果到文件...”设置运行proc,或者“结果在网格中”并右键单击网格,然后执行“另存为...”
#2
sp_helptext system stored procedure might help.
sp_helptext系统存储过程可能有所帮助。
sp_helptext YourProcedureName
Also I use print to see my generated sql inside a stored procedure, if you're looking for something like it :
另外我使用print来查看我在存储过程中生成的sql,如果你正在寻找类似的东西:
CREATE PROCEDURE YourProcedureName
AS
DECLARE @sql varchar(100)
SET @sql = 'SELECT * FROM MyTable'
print @sql
--EXEC @sql
GO
#3
By the content you mean the code?
你的内容是指代码吗?
if so, you can call
如果是的话,你可以打电话
EXEC sp_helptext proc_name
Note you can call it also with a view name
请注意,您也可以使用视图名称调用它
#4
You can query the "sys.sql_modules" catalog view to find the SQL source code for your stored procs and stored funcs:
您可以查询“sys.sql_modules”目录视图,以查找存储过程和存储的func的SQL源代码:
SELECT definition
FROM sys.sql_modules
WHERE object_id = OBJECT_ID('your stored proc name here')
Marc
#1
If by 'Content' you are talking about the code, look into sp_helptext()
如果通过'Content'谈论代码,请查看sp_helptext()
http://msdn.microsoft.com/en-us/library/ms176112.aspx
Here's a sample based on the old PUBS sample database
这是基于旧PUBS示例数据库的示例
USE pubs;
GO
EXEC sp_helptext 'pubs.dbo.byroyalty';
GO
And here are the results
以下是结果
Text --------
CREATE PROCEDURE byroyalty @percentage int
AS
select au_id from titleauthor
where titleauthor.royaltyper = @percentage
BUT, if by 'Content' you mean the results; you can either run the proc with the 'Results to File...' setting, or 'Results in Grid' and right click in the grid, and do a 'Save as...'
但是,如果用'内容'表示结果;您可以使用“结果到文件...”设置运行proc,或者“结果在网格中”并右键单击网格,然后执行“另存为...”
#2
sp_helptext system stored procedure might help.
sp_helptext系统存储过程可能有所帮助。
sp_helptext YourProcedureName
Also I use print to see my generated sql inside a stored procedure, if you're looking for something like it :
另外我使用print来查看我在存储过程中生成的sql,如果你正在寻找类似的东西:
CREATE PROCEDURE YourProcedureName
AS
DECLARE @sql varchar(100)
SET @sql = 'SELECT * FROM MyTable'
print @sql
--EXEC @sql
GO
#3
By the content you mean the code?
你的内容是指代码吗?
if so, you can call
如果是的话,你可以打电话
EXEC sp_helptext proc_name
Note you can call it also with a view name
请注意,您也可以使用视图名称调用它
#4
You can query the "sys.sql_modules" catalog view to find the SQL source code for your stored procs and stored funcs:
您可以查询“sys.sql_modules”目录视图,以查找存储过程和存储的func的SQL源代码:
SELECT definition
FROM sys.sql_modules
WHERE object_id = OBJECT_ID('your stored proc name here')
Marc