<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.projectskyfire.org/index.php?action=history&amp;feed=atom&amp;title=How-to%3AMySQLStoredProcedures</id>
	<title>How-to:MySQLStoredProcedures - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.projectskyfire.org/index.php?action=history&amp;feed=atom&amp;title=How-to%3AMySQLStoredProcedures"/>
	<link rel="alternate" type="text/html" href="https://wiki.projectskyfire.org/index.php?title=How-to:MySQLStoredProcedures&amp;action=history"/>
	<updated>2026-04-18T11:57:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.projectskyfire.org/index.php?title=How-to:MySQLStoredProcedures&amp;diff=578&amp;oldid=prev</id>
		<title>Admin: /* MySQL Stores Procedures on Trinity */</title>
		<link rel="alternate" type="text/html" href="https://wiki.projectskyfire.org/index.php?title=How-to:MySQLStoredProcedures&amp;diff=578&amp;oldid=prev"/>
		<updated>2013-01-21T21:55:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;MySQL Stores Procedures on Trinity&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:55, 21 January 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l18&quot;&gt;Line 18:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 18:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* See more information at: [http://dev.mysql.com/doc/refman/5.0/en/stored-routines-syntax.html MySQL Reference Manual]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* See more information at: [http://dev.mysql.com/doc/refman/5.0/en/stored-routines-syntax.html MySQL Reference Manual]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==MySQL Stores Procedures on &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Trinity&lt;/del&gt;==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==MySQL Stores Procedures on &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;SkyFire&lt;/ins&gt;==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Since updatepack 27 we’re implementing stored MySQL procedures to be used for fix submissions.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;MySQL stored procedures are expected to be used in most of &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;submitted &lt;/ins&gt;fixes on &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;SkyFire &lt;/ins&gt;forums once the project&#039;s fully established.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;MySQL stored procedures are expected to be used in most of &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;submited &lt;/del&gt;fixes on &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;TDB &lt;/del&gt;forums once the project&#039;s fully established.&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Error-Handling Procedure===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Error-Handling Procedure===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.projectskyfire.org/index.php?title=How-to:MySQLStoredProcedures&amp;diff=577&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;{| align=&quot;right&quot; | __TOC__ |} Category: Guides for SkyFire  ==What is a MySQL Stored Procedure==  * A procedure in MySQL is a &#039;&#039;&#039;set of queries&#039;&#039;&#039; that will be run once pr...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.projectskyfire.org/index.php?title=How-to:MySQLStoredProcedures&amp;diff=577&amp;oldid=prev"/>
		<updated>2013-01-21T21:53:27Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{| align=&amp;quot;right&amp;quot; | __TOC__ |} &lt;a href=&quot;/index.php?title=Category:Guides_for_SkyFire&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:Guides for SkyFire (page does not exist)&quot;&gt;Category: Guides for SkyFire&lt;/a&gt;  ==What is a MySQL Stored Procedure==  * A procedure in MySQL is a &amp;#039;&amp;#039;&amp;#039;set of queries&amp;#039;&amp;#039;&amp;#039; that will be run once pr...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| align=&amp;quot;right&amp;quot;&lt;br /&gt;
| __TOC__&lt;br /&gt;
|}&lt;br /&gt;
[[Category: Guides for SkyFire]]&lt;br /&gt;
&lt;br /&gt;
==What is a MySQL Stored Procedure==&lt;br /&gt;
&lt;br /&gt;
* A procedure in MySQL is a &amp;#039;&amp;#039;&amp;#039;set of queries&amp;#039;&amp;#039;&amp;#039; that will be run once procedures is called. &lt;br /&gt;
&lt;br /&gt;
* Procedures are objects &amp;#039;&amp;#039;&amp;#039;stored inside the database&amp;#039;&amp;#039;&amp;#039; and once created, they’re always there for use.&lt;br /&gt;
&lt;br /&gt;
* Procedures and functions in MySQL are called &amp;#039;&amp;#039;&amp;#039;stored routines&amp;#039;&amp;#039;&amp;#039;, because they’re meant to ease often repeated actions.&lt;br /&gt;
&lt;br /&gt;
* See TDB documentation on how to use procedures: [http://docs.google.com/present/view?id=dc98z2zz_58dgdphpgd Stored Procedures for Users]&lt;br /&gt;
&lt;br /&gt;
* See TDB project documentation: [http://docs.google.com/present/view?id=dc98z2zz_5pgwcbpdw Stored Procedures]&lt;br /&gt;
&lt;br /&gt;
* See more information at: [http://dev.mysql.com/doc/refman/5.0/en/stored-routines-syntax.html MySQL Reference Manual]&lt;br /&gt;
&lt;br /&gt;
==MySQL Stores Procedures on Trinity==&lt;br /&gt;
Since updatepack 27 we’re implementing stored MySQL procedures to be used for fix submissions.&lt;br /&gt;
MySQL stored procedures are expected to be used in most of submited fixes on TDB forums once the project&amp;#039;s fully established.&lt;br /&gt;
&lt;br /&gt;
===Error-Handling Procedure===&lt;br /&gt;
Error handlers are used for data validation inside of other procedures.&lt;br /&gt;
They consist of regular MySQL queries and logical operations such as IF or CASE.&lt;br /&gt;
They validate data by either proving its existence in the database or making sure data is within proper ranges and types, etc. If this fails – the procedure raises an error, failing the procedure call.&lt;br /&gt;
As a standard, these procedures have names starting with &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;sp_tdb_Check*&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
====`sp_CheckNpcEntry`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT || Entry of the npc to check&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Error handling for TDB procedure: check if npc of provided ID exists in database&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; none&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2|creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_CheckNpcEntry`(257); -- will error out if invalid npc entry (creature_template.entry = 257)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_CheckTriggerId`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| trigger_id || IN INT(10) || ID to check against the db for quest objective&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Check if provided creature ID is requirement of any quest into database (quest_template)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; none&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Quest_template_tc2|quest_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_CheckTriggerId`(257); -- make sure trigger (creature_template.entry = 257) is requirement for a quest&amp;lt;/pre&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====`sp_CheckQuestEntry`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| quest_entry || IN INT(10) || Entry of quest from quest_template&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Check if provided quest exists in database (quest_template)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; none&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Quest_template_tc2|quest_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_CheckQuestEntry`(9876); -- check if quest with ID 9876 exists in database&amp;lt;/pre&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====`sp_CheckNPCOrGO`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_or_go_entry || IN INT(10) || Entry of creature or gameobject from *_template&lt;br /&gt;
|-&lt;br /&gt;
| entry_type || IN VARCHAR(10) || must be &amp;#039;GO&amp;#039; or &amp;#039;NPC&amp;#039;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Check if npc or gameobject with provided entry exists in database (creature_template or gameobject_template)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; none&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Gameobject_template_tc2|gameobject_template]], [[Creature_template_tc2|creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_CheckNPCOrGO`(257,&amp;#039;NPC&amp;#039;); -- check if NPC with entry = 257 exists in database&amp;lt;/pre&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====`sp_CheckGobjEntry`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| gameobject_entry || IN INT(10) || Entry of the npc to check&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Check if provided gameobject exists in database (table gameobject_template)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; none&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Gameobject_template_tc2|gameobject_template]], [[Creature_template_tc2|creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_CheckGobjEntry`(175124); -- check if Rookery Egg exists in database, error if not&amp;lt;/pre&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Utility Procedure===&lt;br /&gt;
Utility procedures are typically only used within other, more complex procedures. They tend to help with small pieces of a larger solution. Using utility procedures is usually more complicated than just a basic procedure because there is often cleanup needed after using them (or other special circumstances requiring expert knowledge of the procedure). Use these with care.&lt;br /&gt;
&lt;br /&gt;
====`sp_GetEntryList`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| input || IN TEXT || A comma-delimited list of entries to be split and inserted individually into a temporary table&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Utility procedure to split a comma-delimited list into a temporary table to be used outside of the procedure. Drop up the temporary table after using it. USE WITH CARE.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; none&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[#`tdb_entry_list`|tdb_entry_list]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_GetEntryList`(&amp;#039;1,2,3,4,5,6&amp;#039;); -- creates a temp table with 6 rows containing the values 1-6 respectively&lt;br /&gt;
SELECT * FROM `tdb_entry_list`; -- use this table as a source for other actions&lt;br /&gt;
DROP TEMPORARY TABLE `tdb_entry_list`; -- always drop the table when finished!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_ReGuid`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| new_base_guid || IN INT(10) || All creature guids will be re-numbered with the first guid being this number&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Will re-number all existing guids in creature table starting with a provided value&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; `sp_ReGuidAlterTables`&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; Any with creature.guid value in use&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_ReGuid`(1000); -- will renumber all existing guids in creature table starting with 1000 as initial&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic Procedure===&lt;br /&gt;
Basic procedures are simple, concise, and only accommodate one piece of functionality. These differ from [[#Utility Procedure | Utility Procedures]] in that they can be used by themselves safely and easily without knowledge of any other procedures (outside of [[#Error-Handling Procedure | Error-Handling Procedures]]). They do one thing, and only one thing.&lt;br /&gt;
&lt;br /&gt;
====`sp_TriggerSettings`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT || Entry of the npc for whom template is updated&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Sets NPC as a trigger (disable movements, ignore aggro, and disable targetting)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; none&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_tc2 | creature]], [[Creature_template_tc2 | creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_tdb_TriggerSettings`(257); -- sets npc having `creature_template`.`entry` = 257 to act as trigger&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_SpellScriptTarget`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| spell_ID || IN INT || ID of spell we want to set target for&lt;br /&gt;
|-&lt;br /&gt;
| target_type || IN VARCHAR(10) || Choose from (&amp;#039;GO&amp;#039;,&amp;#039;NPC&amp;#039;,&amp;#039;DEAD_NPC&amp;#039;,&amp;#039;MINION&amp;#039;)&lt;br /&gt;
|-&lt;br /&gt;
| spell_target_entry || IN INT(11) || ID of creature or gameobject&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Sets target requirement for spellcast&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; none&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]], [[Spell_script_target | spell_script_target]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_SpellScriptTarget`(4444,&amp;#039;NPC&amp;#039;,257); -- allows spell 4444 to be cast only on living creature with `creature_template`.`entry` = 257&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_KillQuestgiver`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry`&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Update creature to appear death but still react to eAI / give or take quests&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry`|sp_CheckNpcEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_addon_tc2 | creature_template_addon]], [[Creature_tc2 | creature]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `TDB_sp_KillQuestgiver`(257); -- Makes creature with entry 257 appear dead but still albe to give / take quests or react to spellhits&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_MakeAttackable`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry` who should be made attackable&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Update npc to be attackable&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry`|sp_CheckNpcEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_MakeAttackable`(257); -- enables attacking for NPC with ID 257 (creature_template.entry)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_IgnoreAggro`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry` who should be made to ignore aggro&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Update npc to be ignore aggro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry`|sp_CheckNpcEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_IgnoreAggro`(257); -- makes NPC with ID 257 ignore aggro&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_MakeLootable`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry` who should be made lootable&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Update npc to become lootable&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry`|sp_CheckNpcEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_MakeLootable`(257); -- makes NPC with ID 257 lootable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_SetFaction`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry` whose faction is to be changed&lt;br /&gt;
|-&lt;br /&gt;
| faction_A || IN INT(10) || Alliance faction to set&lt;br /&gt;
|-&lt;br /&gt;
| faction_H || IN INT(10) || Horde faction to set&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Update npc&amp;#039;s faction for both alliance and horde&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry`|sp_CheckNpcEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; CALL `sp_SetFaction`(257,7,7); -- sets faction to 7 for NPC with ID 257 (Kobold Worker)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_SetSelectable`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry` who should be made selectable&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Update npc to become selectable&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry`|sp_CheckNpcEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_SetSelectable`(257); -- makes NPC with ID 257 selectable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_SetQuestlevel`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| quest_entry || IN INT(10) || ID of a quest from quest_template&lt;br /&gt;
|-&lt;br /&gt;
| quest_level || IN INT(10) || New MinLevel value for the selected quest&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Update quest to provided level. Only for seasonal quests where levels are not correct from WDB.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckQuestEntry`|sp_CheckQuestEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Quest_template_tc2 | quest_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; CALL `sp_SetQuestlevel`(11335,30) - sets MinLevel of quest ID 11335 (Call to Arms: Arathi Basin) to 30&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_SetNotSelectable`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry` who should be not selectable&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Update npc to become not selectable&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry`|sp_CheckNpcEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_SetNotSelectable`(257); -- makes NPC with ID 257 not selectable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_MakeNotLootable`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry` who should not be lootable&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Update npc to become not lootable&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry`|sp_CheckNpcEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_MakeNotLootable`(257); -- makes creature of ID 257 (Kobold Worker) not lootable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_NotIgnoreAggro`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry` who should aggro normally&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Update npc to aggro normally&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry`|sp_CheckNpcEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_NotIgnoreAggro`(257); -- makes creature of ID 257 (Kobold Worker) stop ignoring aggro&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_MakeNotAttackable`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry` who should be unattackable&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Update npc to become unattackable&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry`|sp_CheckNpcEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_MakeNotAttackable`(257); -- disables attacking of creature with ID 257 (creature_template.entry - Kobold Worker)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_GetLootIdForChest`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| go_id || IN MEDIUMINT(6) || ID of the gameobject whose loot id is to be gathered&lt;br /&gt;
|-&lt;br /&gt;
| go_loot_id || OUT INT(10) || variable to store the retrieved value in&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Get the loot ID for a specified gameobject (data1 field). Must be a chest (type=3).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckGobjEntry`|sp_CheckGobjEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Gameobject_template_tc2 | gameobject_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_GetLootIdForChest`(194200,@Test); -- get the loot id for g194200 (Rare Cache of Winter) and put it in a variable&lt;br /&gt;
SELECT * FROM `gameobject_loot_template` WHERE `entry`=@Test; -- use the variable containing the lootid for a fix&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_get_ref_id`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| ref_type || IN VARCHAR(10) || Must be one of the following: &amp;#039;SKIN&amp;#039;, &amp;#039;ITEM&amp;#039;, &amp;#039;FISH&amp;#039;, &amp;#039;MILL&amp;#039;, &amp;#039;RAID_GOBJ&amp;#039;, &amp;#039;MINE&amp;#039;, &amp;#039;PROSPECT&amp;#039;, &amp;#039;WORLD&amp;#039;, &amp;#039;RAID_CRE&amp;#039;, &amp;#039;DUNGEON&amp;#039; or &amp;#039;PICKPOCKET&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
| reference || OUT MEDIUMINT(5) || variable to store the calculated reference id&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Get a generated loot reference id based on the type of loot its to be used for&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; none&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Loot_template_tc2 | reference_loot_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_get_ref_id`(&amp;#039;RAID_CRE&amp;#039;,@Test); -- store the next available reference ID in the range for raid creatures in a variable&lt;br /&gt;
SELECT @Test; -- use the variable however we like in a fix&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_SetLootId`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || Entry of the npc whose lootid you would like to set&lt;br /&gt;
|-&lt;br /&gt;
| loot_id || IN MEDIUMINT(5) || NULLABLE. If provided, set the specified NPC&amp;#039;s lootid to this value. If NULL, NPC uses its own entry.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Sets the loot id of a specified NPC&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry`|sp_CheckNpcEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_SetLootId`(10184,NULL); -- sets the lootid of c10184 (Onyxia) to its own entry number&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Average Procedure===&lt;br /&gt;
Average level procedures are significantly more complex than [[#Basic Procedure | Basic Procedures]]. They involve multiple tables, multiple procedure dependencies, and frequently perform more than one action. They do, however, still exist for often-used functionality. These types of procedures tend to mask complex behavior using only a few parameters.&lt;br /&gt;
&lt;br /&gt;
====`sp_SetLootIdByList`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| entry_list || IN TEXT || Entry of the npc whose lootid you would like to set&lt;br /&gt;
|-&lt;br /&gt;
| loot_id || IN INT(10) || NULLABLE. If provided, set the specified NPC&amp;#039;s lootid to this value. If NULL, NPC uses its own entry.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Sets the loot id of a list of NPCs to either their own entry numbers or a specified value&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_GetEntryList` | sp_GetEntryList]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]], [[#`tdb_entry_list` | tdb_entry_list]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_SetLootIdByList` (&amp;#039;1,2,3,4,5&amp;#039;,&amp;#039;99999&amp;#039;); -- sets the loot id of 5 specified npcs to 99999&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_QuestRelations`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_or_go_entry || IN INT(10) || ID of NPC from `creature_template`.`entry` OR GameObject from `gameobject_template`&lt;br /&gt;
|-&lt;br /&gt;
| switch_give_take || IN VARCHAR(10) || Must be either &amp;#039;QGIVER&amp;#039;, &amp;#039;QTAKER&amp;#039;, &amp;#039;BOTH&amp;#039; - defines if NPC / GO will only give quest / take quest / do both&lt;br /&gt;
|-&lt;br /&gt;
| quest_entry || IN INT(10) || Entry of quest from quest_template&lt;br /&gt;
|-&lt;br /&gt;
| entry_type || IN VARCHAR(10) || Either &amp;#039;NPC&amp;#039; or &amp;#039;GO&amp;#039; based on the type of entry given&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Sets the loot id of a list of NPCs to either their own entry numbers or a specified value&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNPCOrGO` | sp_CheckNPCOrGO]], [[#`sp_CheckQuestEntry` | sp_CheckQuestEntry]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_questrelation_tc2 | creature_questionrelation]], [[Creature_involvedrelation_tc2 | creature_involvedrelation]], [[Gameobject_questrelation_tc2 | gameobject_questionrelation]], [[Gameobject_involvedrelation_tc2 | gameobject_involvedrelation]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_SetLootIdByList`(&amp;#039;1,2,3,4,5&amp;#039;,&amp;#039;99999&amp;#039;); -- sets the loot id of 5 specified npcs to 99999&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Advanced Procedure===&lt;br /&gt;
Advanced procedures are used rarely. They involved many tables, procedures, and have many dependencies and clean up measures required. They are to be used with great care as they will often take a significant amount of time to execute as well. Not for beginners, use any of these with care.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;No procedures accepted.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
===Event AI Procedures===&lt;br /&gt;
These procedures are specific to ScriptDev2-based content, namely the Event AI tables. All eAI procedures relate to the same tables, which are described in the [[Event_AI | Event AI Guide]].&lt;br /&gt;
&lt;br /&gt;
====`sp_eai_selectID`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| creature_entry || IN INT(10) || Creature entry to check against&lt;br /&gt;
|-&lt;br /&gt;
| event_id || OUT INT(10) || Best EventAI ID to associate with the specified creature&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Check if eAI exists and get best id for new entries. To be used inside other eAI procs only.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Degree:&amp;lt;/var&amp;gt; [[#Utility Procedure | Utility]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; none&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_ai_scripts_tc2 | creature_ai_scripts]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_eai_selectID`(8956,@eventID); -- gets an appropriate eAI event id for c8956 (Angerclaw Bear) and places it in the @eventID variable&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_eai_KillCreditOnSpellhit`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry`&lt;br /&gt;
|-&lt;br /&gt;
| spell_id || IN INT(10) || ID of spell we want to set target for&lt;br /&gt;
|-&lt;br /&gt;
| trigger_id || IN INT(10) || ID of trigger NPC that needs to be killed for quest objective&lt;br /&gt;
|-&lt;br /&gt;
| despawn_time || IN INT(10) || time (milliseconds) before NPC despawns&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Perform eAI script for NPC to give credit on spellhit&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Degree:&amp;lt;/var&amp;gt; [[#Average Procedure | Average]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry` | sp_CheckNpcEntry]], [[#`sp_CheckTriggerId` | sp_CheckTriggerId]], [[#`sp_eai_selectID` | sp_eai_selectID]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]], [[Creature_ai_scripts_tc2 | creature_ai_scripts]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-- Creature of ID 257 when hit with spell of ID 4444 will give credit for killing NPC of ID 1235 and will then despawn after 10 seconds&lt;br /&gt;
CALL `sp_tdb_eai_KillCreditOnSpellhit`(257,4444,1235,10000); &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_eai_CastSpellOnSpawn`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry`&lt;br /&gt;
|-&lt;br /&gt;
| spell_id || IN INT(6) || ID of spell we want to set target for&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Perform eAI script for NPC to cast spell on self upon spawn&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Degree:&amp;lt;/var&amp;gt; [[#Average Procedure | Average]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry` | sp_CheckNpcEntry]], [[#`sp_eai_selectID` | sp_eai_selectID]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]], [[Creature_ai_scripts_tc2 | creature_ai_scripts]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_eai_CastSpellOnSpawn`(257,4444); -- Creature of ID 257 (Kobold Worker) will cast spell of ID 4444 on self when spawned&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_eai_KillCreditOnDeath`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry`&lt;br /&gt;
|-&lt;br /&gt;
| trigger_id || IN INT(10) || ID of trigger NPC that needs to be killed for quest objective&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Create eAI script for NPC to give credit on death&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Degree:&amp;lt;/var&amp;gt; [[#Average Procedure | Average]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry` | sp_CheckNpcEntry]], [[#`sp_eai_selectID` | sp_eai_selectID]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]], [[Creature_ai_scripts_tc2 | creature_ai_scripts]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CALL `sp_eai_KillCreditOnDeath`(46,257); -- NPC of ID 46 (Murloc Forager) when killed will give credit for killing NPC with ID 257 (Kobold Worker)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====`sp_eAI_SpawnOnSpellhit`====&lt;br /&gt;
&amp;lt;var&amp;gt;Parameters:&amp;lt;/var&amp;gt;&lt;br /&gt;
{| border=1 cellpadding=3 cellspacing=0&lt;br /&gt;
! Name !! Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| npc_entry || IN INT(10) || ID of NPC from `creature_template`.`entry`&lt;br /&gt;
|-&lt;br /&gt;
| spell_id || IN INT(10) || ID of spell we want to set target for&lt;br /&gt;
|-&lt;br /&gt;
| spawn_id || IN INT(10) || NPC that will be spawned at current location of the provided npc_entry&lt;br /&gt;
|-&lt;br /&gt;
| despawn_time || IN INT(10) || time (milliseconds) before summoned NPC despawns&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Description:&amp;lt;/var&amp;gt; Create eAI script for NPC to give credit on death&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Degree:&amp;lt;/var&amp;gt; [[#Average Procedure | Average]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Dependencies:&amp;lt;/var&amp;gt; [[#`sp_CheckNpcEntry` | sp_CheckNpcEntry]], [[#`sp_eai_selectID` | sp_eai_selectID]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;var&amp;gt;Tables Affected:&amp;lt;/var&amp;gt; [[Creature_template_tc2 | creature_template]], [[Creature_ai_scripts_tc2 | creature_ai_scripts]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;-- NPC of id 1234 will summon NPC of id 1235 upon being cast spell 4444. NPC 1235 will despawn after 100s&lt;br /&gt;
CALL `sp_eAI_SpawnOnSpellhit`(1234,4444,1235,100000);&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Temporary Tables==&lt;br /&gt;
Temporary tables are a way to store complex data that needs to be used in more than one place but should not be stored permanently. For TDB procedures, we will use them to pass data from one procedure call to another. This method is clean but often requires knowledge of the temporary table(s) being used and how to clean them up properly. Remember: if you use a procedure that uses a temporary table, make sure you drop that table afterwards.&lt;br /&gt;
&lt;br /&gt;
===`tdb_entry_list`===&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;#039;&amp;#039;&amp;#039;Structure&amp;#039;&amp;#039;&amp;#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Field&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Type&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Attributes&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Key&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Null&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Default&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Extra&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Comment&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
|[[#entry|entry]]&lt;br /&gt;
|int&lt;br /&gt;
|unsigned&lt;br /&gt;
|&lt;br /&gt;
|NO&lt;br /&gt;
|0&lt;br /&gt;
|&lt;br /&gt;
|any entry&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;#039;&amp;#039;&amp;#039;Description of the fields&amp;#039;&amp;#039;&amp;#039;&amp;lt;/big&amp;gt;&lt;br /&gt;
====entry====&lt;br /&gt;
Any entry, used by multiple tables&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
Here are some raw views at what the stored procedures actually look like. We hope you can use these to better understand what, exactly, a stored procure is (and maybe, use these as inspiration to write your own!). Please refer to the PDF manuals at the [[#What is a MySQL Stored Procedure | top of this page]] for more information on stored procedures and how they are used here at TDB.&lt;br /&gt;
&lt;br /&gt;
===sp_CheckNpcEntry===&lt;br /&gt;
&amp;lt;pre&amp;gt;DELIMITER //&lt;br /&gt;
CREATE PROCEDURE `sp_CheckNpcEntry` (IN creature_entry INT)&lt;br /&gt;
BEGIN&lt;br /&gt;
/**&lt;br /&gt;
 * DEGREE: UTILITY&lt;br /&gt;
 * TABLES AFFECTED: creature_template&lt;br /&gt;
 * PROCS USED: none&lt;br /&gt;
 *&lt;br /&gt;
 * Error handling for TDB procedure: check if creature of provided ID exists in database&lt;br /&gt;
 *&lt;br /&gt;
 * creature_entry - Entry of the npc to check&lt;br /&gt;
 *&lt;br /&gt;
 * CALL `sp_CheckNpcEntry` (257); -- will error out if invalid npc entry (creature_template.entry = 257)&lt;br /&gt;
 */&lt;br /&gt;
    DECLARE Check_entry INT;&lt;br /&gt;
    SET Check_entry = (SELECT COUNT(entry) FROM `creature_template` WHERE `entry`= creature_entry);&lt;br /&gt;
&lt;br /&gt;
    IF Check_entry = 0 THEN &lt;br /&gt;
        CALL INVALID_CREATURE_ENTRY();&lt;br /&gt;
    ELSE &lt;br /&gt;
        SET Check_entry = 0;&lt;br /&gt;
    END IF;&lt;br /&gt;
END//&lt;br /&gt;
&lt;br /&gt;
DELIMITER ;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===sp_CheckNPCOrGO===&lt;br /&gt;
&amp;lt;pre&amp;gt;DELIMITER //&lt;br /&gt;
CREATE PROCEDURE `sp_CheckNPCOrGO`(IN npc_or_go_entry INT(10), IN entry_type VARCHAR(10)) &lt;br /&gt;
BEGIN&lt;br /&gt;
/**&lt;br /&gt;
 * DEGREE: ERROR HANDLER&lt;br /&gt;
 * TABLES AFFECTED: creature_template, gameobject_template&lt;br /&gt;
 * PROCS USED: none&lt;br /&gt;
 * &lt;br /&gt;
 * npc_or_go_entry - entry of creature or gameobject from *_template&lt;br /&gt;
 * entry_type: [&amp;quot;GO&amp;quot;|&amp;quot;NPC&amp;quot;]&lt;br /&gt;
 *&lt;br /&gt;
 * ex: CALL `sp_CheckNPCOrGO` (257, &amp;quot;NPC&amp;quot;); -- check if NPC with entry = 257 exists in database&lt;br /&gt;
 */&lt;br /&gt;
DECLARE Check_entry INT;&lt;br /&gt;
CASE entry_type&lt;br /&gt;
        WHEN &amp;quot;NPC&amp;quot; THEN&lt;br /&gt;
SET Check_entry = (SELECT COUNT(`entry`) FROM `creature_template` WHERE `entry`=npc_or_go_entry);&lt;br /&gt;
        WHEN &amp;quot;GO&amp;quot; THEN&lt;br /&gt;
SET Check_entry = (SELECT COUNT(`entry`) FROM `gameobject_template` WHERE `entry`=npc_or_go_entry);&lt;br /&gt;
        ELSE&lt;br /&gt;
        CALL INCORRECT_ENTRY_TYPE();&lt;br /&gt;
END CASE;&lt;br /&gt;
IF Check_entry=0 THEN&lt;br /&gt;
CALL INCORRECT_CREATURE_OR_GO_ID();&lt;br /&gt;
END IF;&lt;br /&gt;
END //&lt;br /&gt;
&lt;br /&gt;
DELIMITER ;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===sp_MakeNotLootable===&lt;br /&gt;
&amp;lt;pre&amp;gt;DELIMITER //&lt;br /&gt;
CREATE PROCEDURE `sp_MakeNotLootable`(IN npc_entry INT(10))&lt;br /&gt;
BEGIN&lt;br /&gt;
/**&lt;br /&gt;
 * DEGREE: BASIC&lt;br /&gt;
 * TABLES AFFECTED: creature_template&lt;br /&gt;
 * PROCS USED: sp_CheckNpcEntry&lt;br /&gt;
 *&lt;br /&gt;
 * Update creature to become not lootable&lt;br /&gt;
 *&lt;br /&gt;
 * creature_entry - ID of NPC from `creature_template`.`entry`&lt;br /&gt;
 * &lt;br /&gt;
 * ex: CALL `sp_MakeNotLootable` (257); -- makes creature of ID 257 (Kobold Worker) not lootable&lt;br /&gt;
 */&lt;br /&gt;
    CALL `sp_CheckNpcEntry` (npc_entry);&lt;br /&gt;
    UPDATE `creature_template` SET `dynamicflags`=`dynamicflags`&amp;amp;~1 WHERE `entry`= npc_entry;&lt;br /&gt;
END //&lt;br /&gt;
&lt;br /&gt;
DELIMITER ;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===sp_SetLootIdByList===&lt;br /&gt;
&amp;lt;pre&amp;gt;DELIMITER //&lt;br /&gt;
CREATE PROCEDURE `sp_SetLootIdByList` (IN entryList TEXT,IN lootID MEDIUMINT(5))&lt;br /&gt;
BEGIN    &lt;br /&gt;
/**&lt;br /&gt;
 * DEGREE: AVERAGE&lt;br /&gt;
 * TABLES AFFECTED: creature_template, tdb_entry_list (temp)&lt;br /&gt;
 * PROCS USED: sp_GetEntryList&lt;br /&gt;
 *&lt;br /&gt;
 * Sets the loot id of a specified NPC&lt;br /&gt;
 *&lt;br /&gt;
 * npcEntry - Entry of the npc whose lootid you would like to set&lt;br /&gt;
 * loot - NULLABLE. If provided, set the specified NPC&amp;#039;s lootid to this value. If NULL, NPC uses its own entry.&lt;br /&gt;
 * &lt;br /&gt;
 * ex: CALL `sp_SetLootIdByList` (&amp;#039;1,2,3,4,5&amp;#039;,&amp;#039;99999&amp;#039;); -- sets the loot id of 5 specified npcs to 99999&lt;br /&gt;
 */&lt;br /&gt;
    CALL `sp_GetEntryList` (entryList);&lt;br /&gt;
    UPDATE `creature_template` SET `lootid`=IFNULL(lootID,`entry`) WHERE `entry` IN (SELECT DISTINCT * FROM `tdb_entry_list`);&lt;br /&gt;
    &lt;br /&gt;
    DROP TEMPORARY TABLE `tdb_entry_list`; -- dont forget the cleanup!&lt;br /&gt;
END//&lt;br /&gt;
&lt;br /&gt;
DELIMITER ;&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>