IS is possible to script out each stored procedure to .sql file using ssis ?
I have a query as
SELECT definition
FROM sys.sql_modules procs
INNER JOIN sys.objects o ON procs.object_id = o.object_id
INNER JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE o.[type] = 'P'
I am looking each row as each .sql file on folder
I have Image example as
Note : I dont have access to exec xp_cmdshell
Thanks,
Related
We would like to remove developer comments from stored procedures for some specific reason.
Is there any mechanism available within SQL Server 2008 R2?
It may be possible to script alter statements based on meta data and strip the comments in the process.
As a starting point take a look at sys.sql_modules
SELECT OBJECT_SCHEMA_NAME(m.object_id) AS [SchemaName],
OBJECT_NAME(m.object_id) AS [ObjectName], o.type, m.definition
FROM sys.sql_modules m
inner join sys.all_objects o on o.object_id = m.object_id
where o.is_ms_shipped = 0
order by OBJECT_NAME(m.object_id) ;
But I don't know why you don't just manually script the sp's to a text file and strip it before running.
I want to find list of stored procedures having dynamic queries in them.
Is there any way to that?
Here's a start. You can execute a dynamic SQL using EXEC and sp_executesql, so you want to search for stored procedures containing those commands:
SELECT
SP_NAME = o.name
FROM sys.sql_modules m
INNER JOIN sys.objects o
ON m.object_id = o.object_id
WHERE
m.definition LIKE '%EXEC%'
OR m.definition LIKE '%SP_EXECUTESQL%'
As suggested by Coder of Code, instead of sys.objects, you could JOIN it to sys.procedures.
Here are other method's according to my google search:
Using sys.procedures:
SELECT
SP_NAME = name
FROM sys.procedures
WHERE
OBJECT_DEFINITION(object_id) LIKE '%EXEC%'
OR OBJECT_DEFINITION(object_id)LIKE '%SP_EXECUTESQL%'
Using sys.sql_modules:
SELECT
SP_NAME = OBJECT_NAME(OBJECT_ID)
FROM sys.sql_modules
WHERE
OBJECTPROPERTY(OBJECT_ID, 'IsProcedure') = 1
AND (
definition LIKE '%EXEC%'
OR definition LIKE '%SP_EXECUTESQL%'
)
may be this will help
select * from sys.syscomments where text like '%exec%' AND 'SOME OTHER CONDITIONS'
Try this.
select b.name as Sp_Names from sys.syscomments a,sys.procedures b
where a.id=b.object_id and (a.text like '%exec%' or a.text like '%sp_executesql%')
HI I need to export Database Schema from SQL Server management studio express 2005 into MSExcel? generate script is giving me the script. but i need to have Excel file contains database schema. how do i do with SQL server management studio express 2005?
What you could do is use this script to get all the table data, and copy-paste the results to an Excel file:
SELECT o.name AS TableName
, c.name AS ColumnName
, t.name AS DataType
, c.Max_Length
, c.Precision
, c.Scale
FROM sys.objects AS o
INNER JOIN sys.columns AS c ON o.object_id = c.object_id
INNER JOIN sys.types AS t ON c.user_type_id = t.user_type_id
WHERE type = 'U'
ORDER BY
o.name
, c.name
Unfortunately I am not too familiar with SQL server 2005
How about Import and Export Wizard?
The wizard should have the option to select destination type
I am using Microsoft SQL Server 2008. I have a stored procedure. Is there a simple query I can execute that will give me the parameter names?
I have found this Link but it is not for Microsoft SQL Server 2008.
To get names only you can use this query:
SELECT name
FROM sys.parameters
WHERE object_id = OBJECT_ID('YourProcedureName')
To get more detailed info (name, type and length of parameter):
SELECT p.name AS ParameterName, t.name AS ParameterType, p.max_length AS ParameterLength
FROM sys.parameters AS p
JOIN sys.types AS t ON t.user_type_id = p.user_type_id
WHERE object_id = OBJECT_ID('YourProcedureName')
On top of what Marek stated, you can also retrieve them programatically using the DeriveParameters method in the .NET library: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder.deriveparameters.aspx
Check out my blog on database files and objects. http://craftydba.com/?p=2901
I have a stored procedure called SP_STORE_PRIMES in my sample [MATH] database.
One way is to use the sys.parameters table. This can be optionally joined to types. Below is joined to sys.objects.
-- Parameters to SP & FN
select o.name, p.* from sys.parameters p join sys.objects o
on p.object_id = o.object_id where is_ms_shipped = 0
go
A older system stored procedure is sp_sproc_columns.
-- Older system stored proc - show all parameters to one
sp_sproc_columns #procedure_name = 'SP_STORE_PRIMES'
go
Both ways will get you where you want to go.
Is there a way to search for a string or literal in all stored procedures for a particular database in Microsoft SQL Server 2008?
Grab yourself a copy of the free Red-Gate SQL Search tool and start enjoying searching in SQL Server! :-)
It's a great and very useful tool, and YES! it's totally, absolutely FREE for any kind of use.
select quotename(s.name)+'.'+quotename(o.name) as object_name, o.type_desc
from sys.sql_modules m
inner join sys.objects o
on m.object_id = o.object_id
and o.type = 'P' /* stored procuedure */
inner join sys.schemas s
on o.schema_id = s.schema_id
where m.definition like '%YourSearchText%'
I think this will work for you
SELECT ROUTINE_NAME, ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%lq_Campaign%'
AND ROUTINE_TYPE='PROCEDURE'
Here is the a link I found on it.