<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stored Procedure &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/stored-procedure/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Sat, 20 Apr 2019 18:30:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Server: Find Stored Procedures which use Dynamic SQL and Temporary Table</title>
		<link>https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/</link>
					<comments>https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 08 Apr 2019 18:30:46 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Data Security]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[dynamic sql]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SQL Injection]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[Stored Procedure]]></category>
		<category><![CDATA[Temp Table]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4076</guid>

					<description><![CDATA[Whenever you are searching for SQL query optimization tips or prevent SQL injection tips, you can find few common suggestions like: Please do not use Dynamic SQL in your Stored Procedure. Please try to avoid the use of Temp Tables. I always tell to database developers, please try to avoid the use of Dynamic SQL [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&#038;title=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" data-a2a-url="https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/" data-a2a-title="SQL Server: Find Stored Procedures which use Dynamic SQL and Temporary Table"></a></p><p>Whenever you are searching for SQL query optimization tips or prevent SQL injection tips, you can find few common suggestions like: Please do not use Dynamic SQL in your Stored Procedure. Please try to avoid the use of Temp Tables.</p>
<blockquote><p>I always tell to database developers, please try to avoid the use of Dynamic SQL and Temp Table in your Stored Procedures.</p></blockquote>
<blockquote><p>A Temp Table requires additional CPU/IO which degrades the query performance. A Dynamic SQL is not safe against the SQL Injection and It also compiles data every time which requires more Memory. </p></blockquote>
<blockquote><p>Here, I am sharing one of the important scripts which gives you list of SQL Server Stored Procedures, which use the Dynamic SQL and Temp Table.<br />
You can easily get the list of Stored Procedures and can make plans of modifying it.</p></blockquote>
<blockquote><p>Prepared this script using sys.dm_exec_describe_first_result_set and sys.procedures where error number 4 = Dynamic SQL and error number 10 = Temporary Table.</p></blockquote>
<pre class="crayon-plain-tag">SELECT  
	SP_Name
	,error_message
	,error_type_desc 
FROM (SELECT schema_name(schema_id)+'.'+name SP_Name FROM sys.procedures) AS T
CROSS APPLY sys.dm_exec_describe_first_result_set (SP_Name, NULL, 0) 
WHERE error_type IN (4,10)</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Stored Procedure in MySQL</title>
		<link>https://www.dbrnd.com/2015/05/stored-procedure-in-mysql/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 13 May 2015 09:35:49 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<category><![CDATA[Stored Procedure]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=98</guid>

					<description><![CDATA[In this post, I am sharing the basic about MySQL Stored Procedure, type of parameter in Stored Procedure, how to call Stored Procedure. Let me start with the basic theory: What is Stored Procedures? Stored Procedure is set of SQL / PLSQL command which all are compiled and stored in database servers. Stored Procedure is [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fstored-procedure-in-mysql%2F&amp;linkname=Stored%20Procedure%20in%20MySQL" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fstored-procedure-in-mysql%2F&amp;linkname=Stored%20Procedure%20in%20MySQL" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fstored-procedure-in-mysql%2F&amp;linkname=Stored%20Procedure%20in%20MySQL" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fstored-procedure-in-mysql%2F&amp;linkname=Stored%20Procedure%20in%20MySQL" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fstored-procedure-in-mysql%2F&amp;linkname=Stored%20Procedure%20in%20MySQL" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fstored-procedure-in-mysql%2F&amp;linkname=Stored%20Procedure%20in%20MySQL" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F05%2Fstored-procedure-in-mysql%2F&#038;title=Stored%20Procedure%20in%20MySQL" data-a2a-url="https://www.dbrnd.com/2015/05/stored-procedure-in-mysql/" data-a2a-title="Stored Procedure in MySQL"></a></p><p>In this post, I am sharing the basic about MySQL Stored Procedure, type of parameter in Stored Procedure, how to call Stored Procedure.</p>
<p>Let me start with the basic theory:</p>
<p><b>What is Stored Procedures?</b></p>
<blockquote><p>Stored Procedure is set of SQL / PLSQL command which all are compiled and stored in database servers.<br />
Stored Procedure is the object of Database Server which stores all the SQL query and SQL Program into one object.<br />
After the creation of Stored Procedure, any application or program can use this in any number of times.<br />
Stored Procedure can accept input parameters in which user can pass a different parameter. At the same time, many users can call the same stored procedure with the different parameters.</p></blockquote>
<p><b>Why Stored Procedure?</b></p>
<ul>
<li>Store one time and use many times</li>
<li>Store common code in one place and avoid the duplication</li>
<li>This is will also reduce network traffic and give the best performance</li>
<li>For security purpose also Stored Procedure is being used where common user cannot see code of Stored Procedure.</li>
</ul>
<p><strong>Understand MySQL Stored Procedure using below example:</strong></p>
<p><span style="color: #660000;"><b>Step -1 :Create database and table using below script.</b></span></p><pre class="crayon-plain-tag">/*First let's create Employee Database.*/
CREATE DATABASE Employee;
/*Create sample EmployeeDetails table.*/
CREATE TABLE Employee.tbl_EmployeeDetails 
(
     EmpID INTEGER AUTO_INCREMENT
    ,EmpFirstName VARCHAR(50)
    ,EmpLastName VARCHAR(50)
    ,GENDER CHAR(1)
    ,DOB DATETIME    
    ,CONSTRAINT pk_tbl_EmployeeDetails_EmpID PRIMARY KEY (EmpID)
)ENGINE = InnoDB;</pre><p>
<p>In the above code, I created a database name is Employee and created a table for storing employee basic details. In MySQL database also called as Schema.</p>
<p>I applied Auto_Increment value for EmpID which is the default increment by one and not required to pass during insertion.</p>
<p><b><span style="color: #660000;">Step -2 :</span></b></p>
<p><strong>Create Stored Procedure to insert data into the tbl_Employee table:</strong><br />
This Stored Procedure is basically with a list of Input Parameters.</p><pre class="crayon-plain-tag">/* Sample stored procedure to insert records*/
DELIMITER //
CREATE PROCEDURE Employee.usp_InsertEmployeeDetails
(
     InputEmpFirstName VARCHAR(50)
    ,InputEmpLastName VARCHAR(50)
    ,InputGENDER CHAR(1)
    ,InputDOB DATETIME
)
/*******************************************************************
Authors Name : Anvesh Patel
Created Date : 2015-05-07
Description : This is demo stored procedure to insert 
              record into table.Basically for www.dbrnd.com readers. 
********************************************************************/
BEGIN
  INSERT INTO Employee.tbl_EmployeeDetails
  (
         EmpFirstName
         ,EmpLastName 
         ,GENDER
         ,DOB
  )
  VALUES
  (
         InputEmpFirstName 
        ,InputEmpLastName 
        ,InputGENDER 
        ,InputDOB 
  );  
END 
// DELIMITER ;</pre><p>
This is a simple stored procedure to store data into tbl_EmployeeDetails using input parameters. The user has to pass all Employee details as an input parameter and code will store all data into EmployeeDetails table.</p>
<p><strong>Below is a sample command to call the Stored Procedure for insertion:</strong></p>
<pre class="crayon-plain-tag">CALL Employee.usp_InsertEmployeeDetails('Jack','Roy','M','1990-01-26');
CALL Employee.usp_InsertEmployeeDetails('Martin','Meloy','M','1988-05-23');
CALL Employee.usp_InsertEmployeeDetails('Jenny','Rose','F','1991-09-01');</pre>
<p>Above, I called this stored procedure three different to store three employee details.</p>
<p><span style="color: #660000;"><b>Step-3:</b></span></p>
<p><strong>Now Sample stored procedure to select the employee data:</strong></p><pre class="crayon-plain-tag">DELIMITER //
CREATE PROCEDURE Employee.usp_GetEmployeeDetails()
/******************************************************************
Authors Name : Anvesh Patel
Created Date : 2015-05-07
Description : This is demo stored procedure to select 
              record from table.Basically for www.dbrnd.com readers. 
********************************************************************/
BEGIN
 SELECT 
      EmpFirstName
     ,EmpLastName 
     ,GENDER
     ,DOB
 FROM Employee.tbl_EmployeeDetails;   
END 
// DELIMITER ;</pre><p>
<p>This is a sample stored procedure is to select employee data. You can also set input parameter to apply the filters on data.</p>
<p><strong>Sample code to call the stored procedure:</strong></p><pre class="crayon-plain-tag">CALL Employee.usp_GetEmployeeDetails();</pre><p>
<p><strong>Step &#8211; 4:</strong></p>
<p>This is a sample stored procedure to show the output parameter and use of it.</p><pre class="crayon-plain-tag">DELIMITER //
CREATE PROCEDURE Employee.usp_GetEmployeeCount_ByGender
(
 InputGender CHAR(1)
    ,OUT TotalCount INTEGER
)
/***********************************************************************
Authors Name : Anvesh Patel
Created Date : 2015-05-07
Description : This is demo stored procedure to select count 
              of employee by gender.Basically for www.dbrnd.com readers. 
************************************************************************/
BEGIN
     SELECT COUNT(1)
     INTO TotalCount
     FROM Employee.tbl_EmployeeDetails
     WHERE Gender=InputGender;    
END 
// DELIMITER ;</pre><p>
<p>In the above stored procedure, I have created an output parameter. Many times output parameter is required for application when table result is not required. You can also define multiple output parameters. In the above code, I stored a count of the employee based on the gender into one output parameter.</p>
<p><strong>Now let&#8217;s call this stored procedure:</strong></p>
<pre class="crayon-plain-tag">CALL Employee.usp_GetEmployeeCount_ByGender('M',@TotalCount);
SELECT @TotalCount;</pre>
<p>When you select @TotalCount, it will return the result of this stored procedure.</p>
<p>Above are different sample of Stored Procedures. You can also drop these all stored procedures using below code.<br />
<pre class="crayon-plain-tag">DROP PROCEDURE IF EXISTS Employee.usp_InsertEmployeeDetails;
DROP PROCEDURE IF EXISTS Employee.usp_GetEmployeeDetails;
DROP PROCEDURE IF EXISTS Employee.usp_GetEmployeeCount_ByGender;</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
