我有2个问题。
此查询用于显示脚本存储过程作为创建查询
查询:
Select object_definition(object_id) from sys.objects
where type_desc in ( 'SQL_STORED_PROCEDURE')
我可以显示所有商店程序的脚本。
问题1:我在商店程序中有TestStoreProcedure。我如何只显示TestStoreProcedure。我可以这样使用:
Select object_definition(object_id) from sys.objects
where type_desc in ( 'SQL_STORED_PROCEDURE') and ??? =TestStoreProcedure
问题2:如何对表或定义的表使用此查询?
答案 0 :(得分:2)
为了完整起见,要限制OBJECT_DEFINITION
的输出
SELECT OBJECT_DEFINITION(object_id) From sys.objects where name='TestStoredProcedure'
答案 1 :(得分:1)
我解决了表(创建定义表名的脚本)
declare @vsSQL varchar(8000)
declare @vsTableName varchar(50)
select @vsTableName = 'tblLocation'
select @vsSQL = 'CREATE TABLE ' + @vsTableName + char(10) + '(' + char(10)
select @vsSQL = @vsSQL + ' ' + sc.Name + ' ' + st.Name +
case when st.Name in ('varchar','varchar','char','nchar') then
'(' + cast(sc.Length as varchar) + ') ' else ' ' end +
case when sc.IsNullable = 1 then 'NULL' else 'NOT NULL' end + ',' + char(10)
from sysobjects so
join syscolumns sc on sc.id = so.id
join systypes st on st.xusertype = sc.xusertype
where so.name = @vsTableName
order by
sc.ColID
select substring(@vsSQL,1,len(@vsSQL) - 2) + char(10) + ')'
答案 2 :(得分:0)
EXECUTE sp_helptext proc_name --<-- Without schema name