<?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>Head.SmackOnTable(); &#187; Code Snippet</title>
	<atom:link href="http://www.unauthorised-access.com/category/code-snippet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.unauthorised-access.com</link>
	<description>Contains Nuts.</description>
	<lastBuildDate>Fri, 02 Jul 2010 17:46:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Deleting all data from a Database</title>
		<link>http://www.unauthorised-access.com/2009/12/deleting-all-data-from-a-database/</link>
		<comments>http://www.unauthorised-access.com/2009/12/deleting-all-data-from-a-database/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 17:09:04 +0000</pubDate>
		<dc:creator>Monty</dc:creator>
				<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=364</guid>
		<description><![CDATA[SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' DROP CONSTRAINT [' + f.name + ']' FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id UNION ALL SELECT 'TRUNCATE TABLE ' + name FROM dbo.sysobjects WHERE (type = 'u') and name != 'sysdiagrams' UNION ALL SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: sql;">

SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' DROP CONSTRAINT [' + f.name + ']'
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id
UNION ALL
SELECT 'TRUNCATE TABLE ' + name FROM dbo.sysobjects WHERE (type = 'u') and name != 'sysdiagrams'
UNION ALL
SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' ADD CONSTRAINT '  + f.name + ' FOREIGN KEY (' + COL_NAME(fc.parent_object_id, fc.parent_column_id) + ') REFERENCES ' + OBJECT_NAME (f.referenced_object_id) + '(' + COL_NAME(fc.referenced_object_id, fc.referenced_column_id) + ')' FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.unauthorised-access.com/2009/12/deleting-all-data-from-a-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Output all properties for any object</title>
		<link>http://www.unauthorised-access.com/2009/07/output-all-properties-for-any-object/</link>
		<comments>http://www.unauthorised-access.com/2009/07/output-all-properties-for-any-object/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 08:51:07 +0000</pubDate>
		<dc:creator>Monty</dc:creator>
				<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[Code Sample]]></category>

		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=325</guid>
		<description><![CDATA[private void outputValues(object inputObject) { List&#60;PropertyInfo&#62; propertyInfos = new List&#60;PropertyInfo&#62;(inputObject.GetType().GetProperties()); foreach (PropertyInfo info in propertyInfos) { try { object obj = info.GetValue(inputObject, null); if (obj == null) { continue; } Console.WriteLine(&#34;[{0}]:{1}&#34;, info.Name, obj.ToString()); } catch (Exception) { continue; } } } Replace the Console.WriteLine with whatever you want, log4net,  Debug, trace, etc, and it works!]]></description>
			<content:encoded><![CDATA[<pre class="brush: csharp;">

private void outputValues(object inputObject)
{
List&lt;PropertyInfo&gt; propertyInfos = new List&lt;PropertyInfo&gt;(inputObject.GetType().GetProperties());

foreach (PropertyInfo info in propertyInfos)
{
try
{
object obj = info.GetValue(inputObject, null);
if (obj == null)
{
continue;
}
Console.WriteLine(&quot;[{0}]:{1}&quot;, info.Name, obj.ToString());

}
catch (Exception)
{
continue;
}

}

}
</pre>
<p>Replace the Console.WriteLine with whatever you want, log4net,  Debug, trace, etc, and it works!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unauthorised-access.com/2009/07/output-all-properties-for-any-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Snippets &#8211; Text on images</title>
		<link>http://www.unauthorised-access.com/2009/05/code-snippets-text-on-images/</link>
		<comments>http://www.unauthorised-access.com/2009/05/code-snippets-text-on-images/#comments</comments>
		<pubDate>Mon, 04 May 2009 12:13:02 +0000</pubDate>
		<dc:creator>Monty</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[R&D Lab]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=237</guid>
		<description><![CDATA[Two code snippets for you: private void drawTextWithBackground (string Text, Font font, Graphics grpaphics, Brush backgroundBrush, Brush foregroundBrush, int x, int y) { SizeF size = grpaphics.MeasureString(Text, font); grpaphics.FillRectangle(backgroundBrush, x,y,size.Width, size.Height); grpaphics.DrawString(Text,font,foregroundBrush,x+1,y+1); } private void drawTextAtBottom (String Text, Font font, Graphics graphics, Image sourceImage, Brush backgroundBrush, Brush foregroundBrush) { SizeF size = graphics.MeasureString(Text, font); int [...]]]></description>
			<content:encoded><![CDATA[<p>Two code snippets for you:</p>
<div style="background: #242424 none repeat scroll 0% 0%; font-family: ProFontWindows; font-size: 9pt; color: #e8f3f6;">
<p style="margin: 0px;"><span style="color: #8ac6f2;">private</span> <span style="color: #8ac6f2;">void</span> drawTextWithBackground (<span style="color: #8ac6f2;">string</span> Text, <span style="color: #cae682;">Font</span> font, <span style="color: #cae682;">Graphics</span> grpaphics, <span style="color: #cae682;">Brush</span> backgroundBrush, <span style="color: #cae682;">Brush</span> foregroundBrush, <span style="color: #8ac6f2;">int</span> x, <span style="color: #8ac6f2;">int</span> y)</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;"><span style="color: #e5786d;">SizeF</span> size = grpaphics.MeasureString(Text, font);</p>
<p style="margin: 0px;">grpaphics.FillRectangle(backgroundBrush, x,y,size.Width, size.Height);</p>
<p style="margin: 0px;">grpaphics.DrawString(Text,font,foregroundBrush,x+<span style="color: #e5786d;">1</span>,y+<span style="color: #e5786d;">1</span>);</p>
<p style="margin: 0px;">}</p>
<p style="margin: 0px;">
<p style="margin: 0px;"><span style="color: #8ac6f2;">private</span> <span style="color: #8ac6f2;">void</span> drawTextAtBottom (<span style="color: #cae682;">String</span> Text, <span style="color: #cae682;">Font</span> font, <span style="color: #cae682;">Graphics</span> graphics, <span style="color: #cae682;">Image</span> sourceImage, <span style="color: #cae682;">Brush</span> backgroundBrush, <span style="color: #cae682;">Brush</span> foregroundBrush)</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;"><span style="color: #e5786d;">SizeF</span> size = graphics.MeasureString(Text, font);</p>
<p style="margin: 0px;">
<p style="margin: 0px;"><span style="color: #8ac6f2;">int</span> y = (<span style="color: #8ac6f2;">int</span>) (sourceImage.Height &#8211; size.Height);</p>
<p style="margin: 0px;">
<p style="margin: 0px;">drawTextWithBackground(Text,font,graphics,backgroundBrush,foregroundBrush,<span style="color: #e5786d;">1</span>,y);</p>
<p style="margin: 0px;">}</p>
</div>
<p>Does exactly what it says on the tin!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unauthorised-access.com/2009/05/code-snippets-text-on-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LAB: Image Detection, Part 1</title>
		<link>http://www.unauthorised-access.com/2009/05/lab-image-detection-part-1/</link>
		<comments>http://www.unauthorised-access.com/2009/05/lab-image-detection-part-1/#comments</comments>
		<pubDate>Sun, 03 May 2009 23:30:09 +0000</pubDate>
		<dc:creator>Monty</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[R&D Lab]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[R&D]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=228</guid>
		<description><![CDATA[Every now and then, I get a crazy idea, to try something rather hard in .net – maybe hard isnt the right word for it, but something that hasn&#8217;t really been attempted before, or if it has, nothing public about it. So the idea I have is for some form of image detection, to say [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Every now and then, I get a crazy idea, to try something rather hard in .net – maybe hard isnt the right word for it, but something that hasn&#8217;t really been attempted before, or if it has, nothing public about it. So the idea I have is for some form of image detection, to say that Image X is x % similar to Image Y. I prefer to use the terms Source and Target, but it doesn&#8217;t really matter.</p>
<p style="text-align: justify;">The <a href="http://www.unauthorised-access.com/wp-content/uploads/2009/05/source.jpg">source</a> and the <a href="http://www.unauthorised-access.com/wp-content/uploads/2009/05/comparetarget.jpg">target</a> images are here. That&#8217;s a photo I took a few weeks ago, if you do decide to steal it, please put a message on there that points back to me <img src='http://www.unauthorised-access.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Anyway, the target image is 14&#215;15 pixels smaller – that&#8217;s a whopping 210 pixels different! It shouldn&#8217;t be too hard to match up the two images, or should it?</p>
<h2>Histograms</h2>
<p style="text-align: justify;">My first attempt was with Histograms. I grabbed some open source (unsafe!) code that generates an array of int[] and lists the histogram values, so I shoved both images through that, and got it to output the Source’s histogram value, the Target’s histogram value, the difference between them both, and the percentage of how similar it is, like so: (The first number is the key# of the int in the array, just because)</p>
<p><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="image" src="http://www.unauthorised-access.com/wp-content/uploads/2009/05/image-thumb.png" border="0" alt="image" width="320" height="264" /></p>
<p style="text-align: justify;">Right at the bottom, I had an average of all the percentages, to see how “similar” the image is. I was expecting the percentage to be fairly high, since there is only a few hundred pixels difference, and I didn&#8217;t change any of the levels or colours when I cut the images out of each other, but it told me there was a <strong>87.7% similarity</strong>! That was very shockingly low. If you see something wrong with my maths from the code below, please let me know:</p>
<div style="font-size: 9pt; background: #242424; color: #e8f3f6; font-family: profontwindows">
<p style="margin: 0px"><span style="color: #8ac6f2">public</span> HistogramCompareResults(<span style="color: #8ac6f2">int</span> key, <span style="color: #8ac6f2">int</span> source, <span style="color: #8ac6f2">int</span> target)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: #8ac6f2">this</span>.key = key;</p>
<p style="margin: 0px"><span style="color: #8ac6f2">this</span>.source = source;</p>
<p style="margin: 0px"><span style="color: #8ac6f2">this</span>.target = target;</p>
<p style="margin: 0px">difference = source &#8211; target;</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: #8ac6f2">if</span> (difference &lt; <span style="color: #e5786d">0</span>)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">difference = difference*-<span style="color: #e5786d">1</span>;</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: #8ac6f2">if</span> (source != <span style="color: #e5786d">0</span> &amp;&amp; target !=<span style="color: #e5786d">0</span>)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"><span style="color: #8ac6f2">if</span> (source &gt; target)</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">percentage = (<span style="color: #8ac6f2">double</span>)target / (<span style="color: #8ac6f2">double</span>)source;</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px"><span style="color: #8ac6f2">else</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">percentage = (<span style="color: #8ac6f2">double</span>)source / (<span style="color: #8ac6f2">double</span>)target;</p>
<p style="margin: 0px">}</p>
<p style="margin: 0px">
<p style="margin: 0px">percentage = percentage*<span style="color: #e5786d">100</span>;</p>
<p style="margin: 0px">
<p style="margin: 0px">}</p>
<p style="margin: 0px">}</p>
</div>
<h2>Image Processing</h2>
<p style="text-align: justify;">My next port of call was basically image processing, like what I did with my <a href="http://www.unauthorised-access.com/2008/09/pet-project-personal-anpr/" target="_blank">ANPR</a> project that I created – basically filtering stuff out and building a “thumbprint” of the image, that hopefully will withstand being resized and stuff like that. Using image filters, flattening images and looking for large “blobs” of images, sofar I have come up with this:</p>
<p><img style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" title="image" src="http://www.unauthorised-access.com/wp-content/uploads/2009/05/image-thumb1.png" border="0" alt="image" width="500" height="751" /></p>
<p>That is the current “thumbprint” for the red channel, on the source image.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unauthorised-access.com/2009/05/lab-image-detection-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Just a reminder &#8211; DropDownList in ASP.NET</title>
		<link>http://www.unauthorised-access.com/2009/02/just-a-reminder-dropdownlist-in-aspnet/</link>
		<comments>http://www.unauthorised-access.com/2009/02/just-a-reminder-dropdownlist-in-aspnet/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 16:14:02 +0000</pubDate>
		<dc:creator>Monty</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code Snippet]]></category>

		<guid isPermaLink="false">http://www.unauthorised-access.com/2009/02/just-a-reminder-dropdownlist-in-aspnet/</guid>
		<description><![CDATA[DropDownList.Items.FindByValue(string) is case sensitive. Just a reminder.]]></description>
			<content:encoded><![CDATA[<p>DropDownList.Items.FindByValue(string) is case sensitive. Just a reminder.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unauthorised-access.com/2009/02/just-a-reminder-dropdownlist-in-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nesting Repeaters without OnItemDataBound</title>
		<link>http://www.unauthorised-access.com/2009/02/nesting-repeaters-without-onitemdatabound/</link>
		<comments>http://www.unauthorised-access.com/2009/02/nesting-repeaters-without-onitemdatabound/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 19:12:53 +0000</pubDate>
		<dc:creator>Monty</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[OnItemDataBound]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[WebControls]]></category>

		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=110</guid>
		<description><![CDATA[And the page result is: abc 12345 def 67890]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-112" title="windowclipping-106" src="http://www.unauthorised-access.com/wp-content/uploads/2009/02/windowclipping-106.png" alt="windowclipping-106" width="397" height="172" /></p>
<p><img class="alignnone size-full wp-image-111" title="windowclipping-107" src="http://www.unauthorised-access.com/wp-content/uploads/2009/02/windowclipping-107.png" alt="windowclipping-107" width="462" height="118" /></p>
<p>And the page result is:</p>
<p><cite>abc                          12345<br />
def                          67890 </cite></p>
]]></content:encoded>
			<wfw:commentRss>http://www.unauthorised-access.com/2009/02/nesting-repeaters-without-onitemdatabound/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Delete YAF from my database</title>
		<link>http://www.unauthorised-access.com/2009/02/delete-yaf-from-my-database/</link>
		<comments>http://www.unauthorised-access.com/2009/02/delete-yaf-from-my-database/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 16:12:25 +0000</pubDate>
		<dc:creator>Monty</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[YAF]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[Yet Another Forum]]></category>

		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=93</guid>
		<description><![CDATA[BEGIN TRAN DROP PROCEDURE yaf_registry_list DROP PROCEDURE yaf_checkemail_save DROP PROCEDURE yaf_registry_save DROP PROCEDURE yaf_user_delete DROP PROCEDURE yaf_active_updatemaxstats DROP PROCEDURE yaf_user_approve DROP PROCEDURE yaf_eventlog_delete DROP PROCEDURE yaf_poll_stats DROP PROCEDURE yaf_eventlog_create DROP PROCEDURE yaf_poll_save DROP PROCEDURE yaf_bannedip_save DROP PROCEDURE yaf_choice_vote DROP PROCEDURE yaf_bannedip_list DROP PROCEDURE yaf_pollvote_check DROP PROCEDURE yaf_bannedip_delete DROP PROCEDURE yaf_post_list DROP PROCEDURE yaf_category_list DROP PROCEDURE [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: sql;">

BEGIN TRAN
DROP PROCEDURE yaf_registry_list
DROP PROCEDURE yaf_checkemail_save
DROP PROCEDURE yaf_registry_save
DROP PROCEDURE yaf_user_delete
DROP PROCEDURE yaf_active_updatemaxstats
DROP PROCEDURE yaf_user_approve
DROP PROCEDURE yaf_eventlog_delete
DROP PROCEDURE yaf_poll_stats
DROP PROCEDURE yaf_eventlog_create
DROP PROCEDURE yaf_poll_save
DROP PROCEDURE yaf_bannedip_save
DROP PROCEDURE yaf_choice_vote
DROP PROCEDURE yaf_bannedip_list
DROP PROCEDURE yaf_pollvote_check
DROP PROCEDURE yaf_bannedip_delete
DROP PROCEDURE yaf_post_list
DROP PROCEDURE yaf_category_list
DROP PROCEDURE yaf_user_accessmasks
DROP PROCEDURE yaf_category_save
DROP PROCEDURE yaf_forum_simplelist
DROP PROCEDURE yaf_category_simplelist
DROP PROCEDURE yaf_topic_delete
DROP PROCEDURE yaf_topic_active
DROP PROCEDURE yaf_forum_delete
DROP PROCEDURE yaf_topic_latest
DROP PROCEDURE yaf_forum_listpath
DROP PROCEDURE yaf_post_last10user
DROP PROCEDURE yaf_forum_listSubForums
DROP PROCEDURE yaf_message_approve
DROP PROCEDURE yaf_forum_moderatelist
DROP PROCEDURE yaf_message_delete
DROP PROCEDURE yaf_forum_list
DROP PROCEDURE yaf_pageload
DROP PROCEDURE yaf_forum_listall_fromcat
DROP PROCEDURE yaf_forum_listall
DROP PROCEDURE yaf_forum_save
DROP PROCEDURE yaf_forum_listallmymoderated
DROP PROCEDURE yaf_forum_updatelastpost
DROP PROCEDURE yaf_category_listread
DROP PROCEDURE yaf_forum_updatestats
DROP PROCEDURE yaf_user_list
DROP PROCEDURE yaf_forumaccess_group
DROP PROCEDURE yaf_nntpforum_update
DROP PROCEDURE yaf_group_save
DROP PROCEDURE yaf_topic_updatelastpost
DROP PROCEDURE yaf_message_update
DROP PROCEDURE yaf_topic_move
DROP PROCEDURE yaf_nntptopic_savemessage
DROP PROCEDURE yaf_system_initialize
DROP PROCEDURE yaf_nntpforum_list
DROP PROCEDURE yaf_system_updateversion
DROP PROCEDURE yaf_message_save
DROP PROCEDURE yaf_active_list
DROP PROCEDURE yaf_topic_prune
DROP PROCEDURE yaf_attachment_list
DROP PROCEDURE yaf_topic_save
DROP PROCEDURE yaf_board_create
DROP PROCEDURE yaf_board_delete
DROP PROCEDURE yaf_watchforum_list
DROP PROCEDURE yaf_board_poststats
DROP PROCEDURE yaf_category_delete
DROP PROCEDURE yaf_accessmask_delete
DROP PROCEDURE yaf_forumaccess_list
DROP PROCEDURE yaf_forumaccess_save
DROP PROCEDURE yaf_group_delete
DROP PROCEDURE yaf_forum_moderators
DROP PROCEDURE yaf_user_find
DROP PROCEDURE yaf_user_guest
DROP PROCEDURE yaf_pmessage_save
DROP PROCEDURE yaf_group_list
DROP PROCEDURE yaf_group_member
DROP PROCEDURE yaf_active_stats
DROP PROCEDURE yaf_usergroup_list
DROP PROCEDURE yaf_mail_createwatch
DROP PROCEDURE yaf_mail_delete
DROP PROCEDURE yaf_mail_list
DROP PROCEDURE yaf_message_findunread
DROP PROCEDURE yaf_message_getReplies
DROP PROCEDURE yaf_message_list
DROP PROCEDURE yaf_message_unapproved
DROP PROCEDURE yaf_board_stats
DROP PROCEDURE yaf_message_simplelist
DROP PROCEDURE yaf_watchtopic_list
DROP PROCEDURE yaf_post_list_reverse10
DROP PROCEDURE yaf_topic_listmessages
DROP PROCEDURE yaf_user_activity_rank
DROP PROCEDURE yaf_pmessage_list
DROP PROCEDURE yaf_forum_listread
DROP PROCEDURE yaf_pmessage_prune
DROP PROCEDURE yaf_topic_list
DROP PROCEDURE yaf_userpmessage_list
DROP PROCEDURE yaf_user_deleteold
DROP PROCEDURE yaf_pmessage_delete
DROP PROCEDURE yaf_smiley_delete
DROP PROCEDURE yaf_smiley_list
DROP PROCEDURE yaf_smiley_listunique
DROP PROCEDURE yaf_smiley_save
DROP PROCEDURE yaf_topic_lock
DROP PROCEDURE yaf_topic_findnext
DROP PROCEDURE yaf_topic_findprev
DROP PROCEDURE yaf_topic_info
DROP PROCEDURE yaf_topic_simplelist
DROP PROCEDURE yaf_forum_listtopics
DROP PROCEDURE yaf_user_removepointsbytopicid
DROP PROCEDURE yaf_user_resetpoints
DROP PROCEDURE yaf_user_removepoints
DROP PROCEDURE yaf_user_login
DROP PROCEDURE yaf_user_recoverpassword
DROP PROCEDURE yaf_user_nntp
DROP PROCEDURE yaf_user_savepassword
DROP PROCEDURE yaf_user_saveavatar
DROP PROCEDURE yaf_user_suspend
DROP PROCEDURE yaf_user_setpoints
DROP PROCEDURE yaf_active_listtopic
DROP PROCEDURE yaf_user_savesignature
DROP PROCEDURE yaf_active_listforum
DROP PROCEDURE yaf_userforum_list
DROP PROCEDURE yaf_user_upgrade
DROP PROCEDURE yaf_eventlog_list
DROP PROCEDURE yaf_user_simplelist
DROP PROCEDURE yaf_user_emails
DROP PROCEDURE yaf_user_getsignature
DROP PROCEDURE yaf_user_addpoints
DROP PROCEDURE yaf_user_adminsave
DROP PROCEDURE yaf_user_avatarimage
DROP PROCEDURE yaf_user_changepassword
DROP PROCEDURE yaf_user_deleteavatar
DROP PROCEDURE yaf_user_getpoints
DROP PROCEDURE yaf_watchforum_delete
DROP PROCEDURE yaf_watchforum_add
DROP PROCEDURE yaf_watchforum_check
DROP PROCEDURE yaf_watchtopic_delete
DROP PROCEDURE yaf_watchtopic_check
DROP PROCEDURE yaf_watchtopic_add
DROP PROCEDURE yaf_attachment_save
DROP PROCEDURE yaf_attachment_delete
DROP PROCEDURE yaf_attachment_download
DROP PROCEDURE yaf_usergroup_save
DROP PROCEDURE yaf_rank_delete
DROP PROCEDURE yaf_rank_list
DROP PROCEDURE yaf_rank_save
DROP PROCEDURE yaf_accessmask_save
DROP PROCEDURE yaf_accessmask_list
DROP PROCEDURE yaf_userforum_save
DROP PROCEDURE yaf_userforum_delete
DROP PROCEDURE yaf_board_save
DROP PROCEDURE yaf_board_list
DROP PROCEDURE yaf_nntpserver_delete
DROP PROCEDURE yaf_nntpserver_list
DROP PROCEDURE yaf_nntpserver_save
DROP PROCEDURE yaf_nntpforum_save
DROP PROCEDURE yaf_nntpforum_delete
DROP PROCEDURE yaf_nntptopic_list
DROP PROCEDURE yaf_pmessage_info
DROP PROCEDURE yaf_userpmessage_delete
DROP PROCEDURE yaf_pmessage_markread
DROP PROCEDURE yaf_replace_words_delete
DROP PROCEDURE yaf_replace_words_edit
DROP PROCEDURE yaf_replace_words_list
DROP PROCEDURE yaf_user_save
DROP PROCEDURE yaf_replace_words_save
DROP PROCEDURE yaf_checkemail_update
DROP VIEW yaf_vaccess
DROP FUNCTION yaf_forum_topics
DROP FUNCTION yaf_forum_posts
DROP FUNCTION yaf_bitset

ALTER TABLE yaf_Choice DROP CONSTRAINT [FK_yaf_Choice_yaf_Poll]
ALTER TABLE yaf_PollVote DROP CONSTRAINT [FK_yaf_PollVote_yaf_Poll]
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_Poll]
ALTER TABLE yaf_AccessMask DROP CONSTRAINT [FK_yaf_AccessMask_yaf_Board]
ALTER TABLE yaf_Active DROP CONSTRAINT [FK_yaf_Active_yaf_Board]
ALTER TABLE yaf_BannedIP DROP CONSTRAINT [FK_yaf_BannedIP_yaf_Board]
ALTER TABLE yaf_Category DROP CONSTRAINT [FK_yaf_Category_yaf_Board]
ALTER TABLE yaf_Group DROP CONSTRAINT [FK_yaf_Group_yaf_Board]
ALTER TABLE yaf_NntpServer DROP CONSTRAINT [FK_yaf_NntpServer_yaf_Board]
ALTER TABLE yaf_Rank DROP CONSTRAINT [FK_yaf_Rank_yaf_Board]
ALTER TABLE yaf_Registry DROP CONSTRAINT [FK_yaf_Registry_yaf_Board]
ALTER TABLE yaf_Smiley DROP CONSTRAINT [FK_yaf_Smiley_yaf_Board]
ALTER TABLE yaf_User DROP CONSTRAINT [FK_yaf_User_yaf_Board]
ALTER TABLE yaf_User DROP CONSTRAINT [FK_yaf_User_yaf_Rank]
ALTER TABLE yaf_Active DROP CONSTRAINT [FK_yaf_Active_yaf_User]
ALTER TABLE yaf_CheckEmail DROP CONSTRAINT [FK_yaf_CheckEmail_yaf_User]
ALTER TABLE yaf_EventLog DROP CONSTRAINT [FK_yaf_EventLog_yaf_User]
ALTER TABLE yaf_Forum DROP CONSTRAINT [FK_yaf_Forum_yaf_User]
ALTER TABLE yaf_Message DROP CONSTRAINT [FK_yaf_Message_yaf_User]
ALTER TABLE yaf_PMessage DROP CONSTRAINT [FK_yaf_PMessage_yaf_User1]
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_User]
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_User2]
ALTER TABLE yaf_UserForum DROP CONSTRAINT [FK_yaf_UserForum_yaf_User]
ALTER TABLE yaf_UserPMessage DROP CONSTRAINT [FK_yaf_UserPMessage_yaf_User]
ALTER TABLE yaf_WatchForum DROP CONSTRAINT [FK_yaf_WatchForum_yaf_User]
ALTER TABLE yaf_WatchTopic DROP CONSTRAINT [FK_yaf_WatchTopic_yaf_User]
ALTER TABLE yaf_Forum DROP CONSTRAINT [FK_yaf_Forum_yaf_Category]
ALTER TABLE yaf_Active DROP CONSTRAINT [FK_yaf_Active_yaf_Forum]
ALTER TABLE yaf_Forum DROP CONSTRAINT [FK_yaf_Forum_yaf_Forum]
ALTER TABLE yaf_ForumAccess DROP CONSTRAINT [FK_yaf_ForumAccess_yaf_Forum]
ALTER TABLE yaf_NntpForum DROP CONSTRAINT [FK_yaf_NntpForum_yaf_Forum]
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_Forum]
ALTER TABLE yaf_UserForum DROP CONSTRAINT [FK_yaf_UserForum_yaf_Forum]
ALTER TABLE yaf_WatchForum DROP CONSTRAINT [FK_yaf_WatchForum_yaf_Forum]
ALTER TABLE yaf_Attachment DROP CONSTRAINT [FK_yaf_Attachment_yaf_Message]
ALTER TABLE yaf_Forum DROP CONSTRAINT [FK_yaf_Forum_yaf_Message]
ALTER TABLE yaf_Message DROP CONSTRAINT [FK_yaf_Message_yaf_Message]
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_Message]
ALTER TABLE yaf_Active DROP CONSTRAINT [FK_yaf_Active_yaf_Topic]
ALTER TABLE yaf_Forum DROP CONSTRAINT [FK_yaf_Forum_yaf_Topic]
ALTER TABLE yaf_Message DROP CONSTRAINT [FK_yaf_Message_yaf_Topic]
ALTER TABLE yaf_NntpTopic DROP CONSTRAINT [FK_yaf_NntpTopic_yaf_Topic]
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_Topic]
ALTER TABLE yaf_WatchTopic DROP CONSTRAINT [FK_yaf_WatchTopic_yaf_Topic]
ALTER TABLE yaf_NntpForum DROP CONSTRAINT [FK_yaf_NntpForum_yaf_NntpServer]
ALTER TABLE yaf_NntpTopic DROP CONSTRAINT [FK_yaf_NntpTopic_yaf_NntpForum]
ALTER TABLE yaf_ForumAccess DROP CONSTRAINT [FK_yaf_ForumAccess_yaf_AccessMask]
ALTER TABLE yaf_UserForum DROP CONSTRAINT [FK_yaf_UserForum_yaf_AccessMask]
ALTER TABLE yaf_ForumAccess DROP CONSTRAINT [FK_yaf_ForumAccess_yaf_Group]
ALTER TABLE yaf_UserGroup DROP CONSTRAINT [FK_yaf_UserGroup_yaf_Group]
ALTER TABLE yaf_UserPMessage DROP CONSTRAINT [FK_yaf_UserPMessage_yaf_PMessage]

drop table dbo.yaf_AccessMask
drop table dbo.yaf_Active
drop table dbo.yaf_Attachment
drop table dbo.yaf_BannedIP
drop table dbo.yaf_Board
drop table dbo.yaf_Category
drop table dbo.yaf_CheckEmail
drop table dbo.yaf_Choice
drop table dbo.yaf_EventLog
drop table dbo.yaf_Forum
drop table dbo.yaf_ForumAccess
drop table dbo.yaf_Group
drop table dbo.yaf_Mail
drop table dbo.yaf_Message
drop table dbo.yaf_NntpForum
drop table dbo.yaf_NntpServer
drop table dbo.yaf_NntpTopic
drop table dbo.yaf_PMessage
drop table dbo.yaf_Poll
drop table dbo.yaf_PollVote
drop table dbo.yaf_Rank
drop table dbo.yaf_Registry
drop table dbo.yaf_Replace_Words
drop table dbo.yaf_Smiley
drop table dbo.yaf_Topic
drop table dbo.yaf_User
drop table dbo.yaf_UserForum
drop table dbo.yaf_UserGroup
drop table dbo.yaf_UserPMessage
drop table dbo.yaf_WatchForum
drop table dbo.yaf_WatchTopic

IF @@ERROR &amp;lt;&amp;gt; 0
BEGIN
ROLLBACK TRAN
return 11
END

COMMIT TRAN
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.unauthorised-access.com/2009/02/delete-yaf-from-my-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dropping views, functions and proc&#8217;s</title>
		<link>http://www.unauthorised-access.com/2009/02/dropping-views-functions-and-stored-procedures/</link>
		<comments>http://www.unauthorised-access.com/2009/02/dropping-views-functions-and-stored-procedures/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 15:44:00 +0000</pubDate>
		<dc:creator>Monty</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[YAF]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[Yet Another Forum]]></category>

		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=86</guid>
		<description><![CDATA[Part 3 of my &#8220;Getting rid of YAF&#8221; series involves dropping views, functions and stored procedures. SELECT 'DROP PROCEDURE '+name FROM dbo.sysobjects WHERE (type = 'P') union all SELECT 'DROP VIEW ' + name from dbo.sysobjects WHERE (type = 'V') union all SELECT 'DROP FUNCTION ' + name from dbo.sysobjects WHERE (type = 'FN') Which [...]]]></description>
			<content:encoded><![CDATA[<p>Part 3 of my &#8220;Getting rid of YAF&#8221; series involves dropping views, functions and stored procedures.</p>
<pre class="brush: sql;">

SELECT 'DROP PROCEDURE '+name FROM dbo.sysobjects WHERE (type = 'P') union all
SELECT 'DROP VIEW ' + name from dbo.sysobjects WHERE (type = 'V') union all
SELECT 'DROP FUNCTION ' + name from dbo.sysobjects WHERE (type = 'FN')
</pre>
<p>Which should hopefully give you the following:</p>
<pre class="brush: sql;">

DROP PROCEDURE yaf_registry_list
DROP PROCEDURE yaf_checkemail_save
DROP PROCEDURE yaf_registry_save
DROP PROCEDURE yaf_user_delete
DROP PROCEDURE yaf_active_updatemaxstats
DROP PROCEDURE yaf_user_approve
DROP PROCEDURE yaf_eventlog_delete
DROP PROCEDURE yaf_poll_stats
DROP PROCEDURE yaf_eventlog_create
DROP PROCEDURE yaf_poll_save
DROP PROCEDURE yaf_bannedip_save
DROP PROCEDURE yaf_choice_vote
DROP PROCEDURE yaf_bannedip_list
DROP PROCEDURE yaf_pollvote_check
DROP PROCEDURE yaf_bannedip_delete
DROP PROCEDURE yaf_post_list
DROP PROCEDURE yaf_category_list
DROP PROCEDURE yaf_user_accessmasks
DROP PROCEDURE yaf_category_save
DROP PROCEDURE yaf_forum_simplelist
DROP PROCEDURE yaf_category_simplelist
DROP PROCEDURE yaf_topic_delete
DROP PROCEDURE yaf_topic_active
DROP PROCEDURE yaf_forum_delete
DROP PROCEDURE yaf_topic_latest
DROP PROCEDURE yaf_forum_listpath
DROP PROCEDURE yaf_post_last10user
DROP PROCEDURE yaf_forum_listSubForums
DROP PROCEDURE yaf_message_approve
DROP PROCEDURE yaf_forum_moderatelist
DROP PROCEDURE yaf_message_delete
DROP PROCEDURE yaf_forum_list
DROP PROCEDURE yaf_pageload
DROP PROCEDURE yaf_forum_listall_fromcat
DROP PROCEDURE yaf_forum_listall
DROP PROCEDURE yaf_forum_save
DROP PROCEDURE yaf_forum_listallmymoderated
DROP PROCEDURE yaf_forum_updatelastpost
DROP PROCEDURE yaf_category_listread
DROP PROCEDURE yaf_forum_updatestats
DROP PROCEDURE yaf_user_list
DROP PROCEDURE yaf_forumaccess_group
DROP PROCEDURE yaf_nntpforum_update
DROP PROCEDURE yaf_group_save
DROP PROCEDURE yaf_topic_updatelastpost
DROP PROCEDURE yaf_message_update
DROP PROCEDURE yaf_topic_move
DROP PROCEDURE yaf_nntptopic_savemessage
DROP PROCEDURE yaf_system_initialize
DROP PROCEDURE yaf_nntpforum_list
DROP PROCEDURE yaf_system_updateversion
DROP PROCEDURE yaf_message_save
DROP PROCEDURE yaf_active_list
DROP PROCEDURE yaf_topic_prune
DROP PROCEDURE yaf_attachment_list
DROP PROCEDURE yaf_topic_save
DROP PROCEDURE yaf_board_create
DROP PROCEDURE yaf_board_delete
DROP PROCEDURE yaf_watchforum_list
DROP PROCEDURE yaf_board_poststats
DROP PROCEDURE yaf_category_delete
DROP PROCEDURE yaf_accessmask_delete
DROP PROCEDURE yaf_forumaccess_list
DROP PROCEDURE yaf_forumaccess_save
DROP PROCEDURE yaf_group_delete
DROP PROCEDURE yaf_forum_moderators
DROP PROCEDURE yaf_user_find
DROP PROCEDURE yaf_user_guest
DROP PROCEDURE yaf_pmessage_save
DROP PROCEDURE yaf_group_list
DROP PROCEDURE yaf_group_member
DROP PROCEDURE yaf_active_stats
DROP PROCEDURE yaf_usergroup_list
DROP PROCEDURE yaf_mail_createwatch
DROP PROCEDURE yaf_mail_delete
DROP PROCEDURE yaf_mail_list
DROP PROCEDURE yaf_message_findunread
DROP PROCEDURE yaf_message_getReplies
DROP PROCEDURE yaf_message_list
DROP PROCEDURE yaf_message_unapproved
DROP PROCEDURE yaf_board_stats
DROP PROCEDURE yaf_message_simplelist
DROP PROCEDURE yaf_watchtopic_list
DROP PROCEDURE yaf_post_list_reverse10
DROP PROCEDURE yaf_topic_listmessages
DROP PROCEDURE yaf_user_activity_rank
DROP PROCEDURE yaf_pmessage_list
DROP PROCEDURE yaf_forum_listread
DROP PROCEDURE yaf_pmessage_prune
DROP PROCEDURE yaf_topic_list
DROP PROCEDURE yaf_userpmessage_list
DROP PROCEDURE yaf_user_deleteold
DROP PROCEDURE yaf_pmessage_delete
DROP PROCEDURE yaf_smiley_delete
DROP PROCEDURE yaf_smiley_list
DROP PROCEDURE yaf_smiley_listunique
DROP PROCEDURE yaf_smiley_save
DROP PROCEDURE yaf_topic_lock
DROP PROCEDURE yaf_topic_findnext
DROP PROCEDURE yaf_topic_findprev
DROP PROCEDURE yaf_topic_info
DROP PROCEDURE yaf_topic_simplelist
DROP PROCEDURE yaf_forum_listtopics
DROP PROCEDURE yaf_user_removepointsbytopicid
DROP PROCEDURE yaf_user_resetpoints
DROP PROCEDURE yaf_user_removepoints
DROP PROCEDURE yaf_user_login
DROP PROCEDURE yaf_user_recoverpassword
DROP PROCEDURE yaf_user_nntp
DROP PROCEDURE yaf_user_savepassword
DROP PROCEDURE yaf_user_saveavatar
DROP PROCEDURE yaf_user_suspend
DROP PROCEDURE yaf_user_setpoints
DROP PROCEDURE yaf_active_listtopic
DROP PROCEDURE yaf_user_savesignature
DROP PROCEDURE yaf_active_listforum
DROP PROCEDURE yaf_userforum_list
DROP PROCEDURE yaf_user_upgrade
DROP PROCEDURE yaf_eventlog_list
DROP PROCEDURE yaf_user_simplelist
DROP PROCEDURE yaf_user_emails
DROP PROCEDURE yaf_user_getsignature
DROP PROCEDURE yaf_user_addpoints
DROP PROCEDURE yaf_user_adminsave
DROP PROCEDURE yaf_user_avatarimage
DROP PROCEDURE yaf_user_changepassword
DROP PROCEDURE yaf_user_deleteavatar
DROP PROCEDURE yaf_user_getpoints
DROP PROCEDURE yaf_watchforum_delete
DROP PROCEDURE yaf_watchforum_add
DROP PROCEDURE yaf_watchforum_check
DROP PROCEDURE yaf_watchtopic_delete
DROP PROCEDURE yaf_watchtopic_check
DROP PROCEDURE yaf_watchtopic_add
DROP PROCEDURE yaf_attachment_save
DROP PROCEDURE yaf_attachment_delete
DROP PROCEDURE yaf_attachment_download
DROP PROCEDURE yaf_usergroup_save
DROP PROCEDURE yaf_rank_delete
DROP PROCEDURE yaf_rank_list
DROP PROCEDURE yaf_rank_save
DROP PROCEDURE yaf_accessmask_save
DROP PROCEDURE yaf_accessmask_list
DROP PROCEDURE yaf_userforum_save
DROP PROCEDURE yaf_userforum_delete
DROP PROCEDURE yaf_board_save
DROP PROCEDURE yaf_board_list
DROP PROCEDURE yaf_nntpserver_delete
DROP PROCEDURE yaf_nntpserver_list
DROP PROCEDURE yaf_nntpserver_save
DROP PROCEDURE yaf_nntpforum_save
DROP PROCEDURE yaf_nntpforum_delete
DROP PROCEDURE yaf_nntptopic_list
DROP PROCEDURE yaf_pmessage_info
DROP PROCEDURE yaf_userpmessage_delete
DROP PROCEDURE yaf_pmessage_markread
DROP PROCEDURE yaf_replace_words_delete
DROP PROCEDURE yaf_replace_words_edit
DROP PROCEDURE yaf_replace_words_list
DROP PROCEDURE yaf_user_save
DROP PROCEDURE yaf_replace_words_save
DROP PROCEDURE yaf_checkemail_update
DROP VIEW yaf_vaccess
DROP FUNCTION yaf_forum_topics
DROP FUNCTION yaf_forum_posts
DROP FUNCTION yaf_bitset
</pre>
<p>Using the scrips below and this script should be all you need to have a YAF free database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.unauthorised-access.com/2009/02/dropping-views-functions-and-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating FK&#8217;s</title>
		<link>http://www.unauthorised-access.com/2009/02/creating-fks/</link>
		<comments>http://www.unauthorised-access.com/2009/02/creating-fks/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 13:05:10 +0000</pubDate>
		<dc:creator>Monty</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[YAF]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[Yet Another Forum]]></category>

		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=79</guid>
		<description><![CDATA[If you get the following error, when trying to export data from YAF: You might want to try running this script, to generate the create FK statements. Inconjuction with the drop FK statements, it will alow you to generate YAF scripts painlessly. SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' ADD CONSTRAINT '  + f.name [...]]]></description>
			<content:encoded><![CDATA[<p>If you get the following error, when trying to export data from YAF:</p>
<p><a href="http://www.unauthorised-access.com/wp-content/uploads/2009/02/sqlpubwiz.png"><img class="alignnone size-full wp-image-81" title="sqlpubwiz" src="http://www.unauthorised-access.com/wp-content/uploads/2009/02/sqlpubwiz.png" alt="sqlpubwiz" width="500" height="128" /></a></p>
<p>You might want to try running this script, to generate the create FK statements. Inconjuction with the drop FK statements, it will alow you to generate YAF scripts painlessly.</p>
<pre class="brush: sql;">

SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' ADD CONSTRAINT '  + f.name + ' FOREIGN KEY (' + COL_NAME(fc.parent_object_id, fc.parent_column_id) + ') REFERENCES ' + OBJECT_NAME (f.referenced_object_id) + '(' + COL_NAME(fc.referenced_object_id, fc.referenced_column_id) + ')' FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
</pre>
<p>It should give you an output like:</p>
<pre class="brush: sql;">

ALTER TABLE yaf_Choice ADD CONSTRAINT FK_yaf_Choice_yaf_Poll FOREIGN KEY (PollID) REFERENCES yaf_Poll(PollID)
ALTER TABLE yaf_Topic ADD CONSTRAINT FK_yaf_Topic_yaf_Poll FOREIGN KEY (PollID) REFERENCES yaf_Poll(PollID)
ALTER TABLE yaf_PollVote ADD CONSTRAINT FK_yaf_PollVote_yaf_Poll FOREIGN KEY (PollID) REFERENCES yaf_Poll(PollID)
ALTER TABLE yaf_AccessMask ADD CONSTRAINT FK_yaf_AccessMask_yaf_Board FOREIGN KEY (BoardID) REFERENCES yaf_Board(BoardID)
ALTER TABLE yaf_Active ADD CONSTRAINT FK_yaf_Active_yaf_Board FOREIGN KEY (BoardID) REFERENCES yaf_Board(BoardID)
ALTER TABLE yaf_BannedIP ADD CONSTRAINT FK_yaf_BannedIP_yaf_Board FOREIGN KEY (BoardID) REFERENCES yaf_Board(BoardID)
ALTER TABLE yaf_Category ADD CONSTRAINT FK_yaf_Category_yaf_Board FOREIGN KEY (BoardID) REFERENCES yaf_Board(BoardID)
ALTER TABLE yaf_Group ADD CONSTRAINT FK_yaf_Group_yaf_Board FOREIGN KEY (BoardID) REFERENCES yaf_Board(BoardID)
ALTER TABLE yaf_NntpServer ADD CONSTRAINT FK_yaf_NntpServer_yaf_Board FOREIGN KEY (BoardID) REFERENCES yaf_Board(BoardID)
ALTER TABLE yaf_Rank ADD CONSTRAINT FK_yaf_Rank_yaf_Board FOREIGN KEY (BoardID) REFERENCES yaf_Board(BoardID)
ALTER TABLE yaf_Registry ADD CONSTRAINT FK_yaf_Registry_yaf_Board FOREIGN KEY (BoardID) REFERENCES yaf_Board(BoardID)
ALTER TABLE yaf_Smiley ADD CONSTRAINT FK_yaf_Smiley_yaf_Board FOREIGN KEY (BoardID) REFERENCES yaf_Board(BoardID)
ALTER TABLE yaf_User ADD CONSTRAINT FK_yaf_User_yaf_Board FOREIGN KEY (BoardID) REFERENCES yaf_Board(BoardID)
ALTER TABLE yaf_User ADD CONSTRAINT FK_yaf_User_yaf_Rank FOREIGN KEY (RankID) REFERENCES yaf_Rank(RankID)
ALTER TABLE yaf_Active ADD CONSTRAINT FK_yaf_Active_yaf_User FOREIGN KEY (UserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_CheckEmail ADD CONSTRAINT FK_yaf_CheckEmail_yaf_User FOREIGN KEY (UserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_EventLog ADD CONSTRAINT FK_yaf_EventLog_yaf_User FOREIGN KEY (UserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_Forum ADD CONSTRAINT FK_yaf_Forum_yaf_User FOREIGN KEY (LastUserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_Message ADD CONSTRAINT FK_yaf_Message_yaf_User FOREIGN KEY (UserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_PMessage ADD CONSTRAINT FK_yaf_PMessage_yaf_User1 FOREIGN KEY (FromUserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_Topic ADD CONSTRAINT FK_yaf_Topic_yaf_User FOREIGN KEY (UserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_Topic ADD CONSTRAINT FK_yaf_Topic_yaf_User2 FOREIGN KEY (LastUserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_UserForum ADD CONSTRAINT FK_yaf_UserForum_yaf_User FOREIGN KEY (UserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_UserGroup ADD CONSTRAINT FK_yaf_UserGroup_yaf_User FOREIGN KEY (UserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_UserPMessage ADD CONSTRAINT FK_yaf_UserPMessage_yaf_User FOREIGN KEY (UserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_WatchForum ADD CONSTRAINT FK_yaf_WatchForum_yaf_User FOREIGN KEY (UserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_WatchTopic ADD CONSTRAINT FK_yaf_WatchTopic_yaf_User FOREIGN KEY (UserID) REFERENCES yaf_User(UserID)
ALTER TABLE yaf_Forum ADD CONSTRAINT FK_yaf_Forum_yaf_Category FOREIGN KEY (CategoryID) REFERENCES yaf_Category(CategoryID)
ALTER TABLE yaf_Active ADD CONSTRAINT FK_yaf_Active_yaf_Forum FOREIGN KEY (ForumID) REFERENCES yaf_Forum(ForumID)
ALTER TABLE yaf_Forum ADD CONSTRAINT FK_yaf_Forum_yaf_Forum FOREIGN KEY (ParentID) REFERENCES yaf_Forum(ForumID)
ALTER TABLE yaf_ForumAccess ADD CONSTRAINT FK_yaf_ForumAccess_yaf_Forum FOREIGN KEY (ForumID) REFERENCES yaf_Forum(ForumID)
ALTER TABLE yaf_NntpForum ADD CONSTRAINT FK_yaf_NntpForum_yaf_Forum FOREIGN KEY (ForumID) REFERENCES yaf_Forum(ForumID)
ALTER TABLE yaf_Topic ADD CONSTRAINT FK_yaf_Topic_yaf_Forum FOREIGN KEY (ForumID) REFERENCES yaf_Forum(ForumID)
ALTER TABLE yaf_UserForum ADD CONSTRAINT FK_yaf_UserForum_yaf_Forum FOREIGN KEY (ForumID) REFERENCES yaf_Forum(ForumID)
ALTER TABLE yaf_WatchForum ADD CONSTRAINT FK_yaf_WatchForum_yaf_Forum FOREIGN KEY (ForumID) REFERENCES yaf_Forum(ForumID)
ALTER TABLE yaf_Attachment ADD CONSTRAINT FK_yaf_Attachment_yaf_Message FOREIGN KEY (MessageID) REFERENCES yaf_Message(MessageID)
ALTER TABLE yaf_Forum ADD CONSTRAINT FK_yaf_Forum_yaf_Message FOREIGN KEY (LastMessageID) REFERENCES yaf_Message(MessageID)
ALTER TABLE yaf_Message ADD CONSTRAINT FK_yaf_Message_yaf_Message FOREIGN KEY (ReplyTo) REFERENCES yaf_Message(MessageID)
ALTER TABLE yaf_Topic ADD CONSTRAINT FK_yaf_Topic_yaf_Message FOREIGN KEY (LastMessageID) REFERENCES yaf_Message(MessageID)
ALTER TABLE yaf_Active ADD CONSTRAINT FK_yaf_Active_yaf_Topic FOREIGN KEY (TopicID) REFERENCES yaf_Topic(TopicID)
ALTER TABLE yaf_Forum ADD CONSTRAINT FK_yaf_Forum_yaf_Topic FOREIGN KEY (LastTopicID) REFERENCES yaf_Topic(TopicID)
ALTER TABLE yaf_Message ADD CONSTRAINT FK_yaf_Message_yaf_Topic FOREIGN KEY (TopicID) REFERENCES yaf_Topic(TopicID)
ALTER TABLE yaf_NntpTopic ADD CONSTRAINT FK_yaf_NntpTopic_yaf_Topic FOREIGN KEY (TopicID) REFERENCES yaf_Topic(TopicID)
ALTER TABLE yaf_Topic ADD CONSTRAINT FK_yaf_Topic_yaf_Topic FOREIGN KEY (TopicMovedID) REFERENCES yaf_Topic(TopicID)
ALTER TABLE yaf_WatchTopic ADD CONSTRAINT FK_yaf_WatchTopic_yaf_Topic FOREIGN KEY (TopicID) REFERENCES yaf_Topic(TopicID)
ALTER TABLE yaf_NntpForum ADD CONSTRAINT FK_yaf_NntpForum_yaf_NntpServer FOREIGN KEY (NntpServerID) REFERENCES yaf_NntpServer(NntpServerID)
ALTER TABLE yaf_NntpTopic ADD CONSTRAINT FK_yaf_NntpTopic_yaf_NntpForum FOREIGN KEY (NntpForumID) REFERENCES yaf_NntpForum(NntpForumID)
ALTER TABLE yaf_ForumAccess ADD CONSTRAINT FK_yaf_ForumAccess_yaf_AccessMask FOREIGN KEY (AccessMaskID) REFERENCES yaf_AccessMask(AccessMaskID)
ALTER TABLE yaf_UserForum ADD CONSTRAINT FK_yaf_UserForum_yaf_AccessMask FOREIGN KEY (AccessMaskID) REFERENCES yaf_AccessMask(AccessMaskID)
ALTER TABLE yaf_ForumAccess ADD CONSTRAINT FK_yaf_ForumAccess_yaf_Group FOREIGN KEY (GroupID) REFERENCES yaf_Group(GroupID)
ALTER TABLE yaf_UserGroup ADD CONSTRAINT FK_yaf_UserGroup_yaf_Group FOREIGN KEY (GroupID) REFERENCES yaf_Group(GroupID)
ALTER TABLE yaf_UserPMessage ADD CONSTRAINT FK_yaf_UserPMessage_yaf_PMessage FOREIGN KEY (PMessageID) REFERENCES yaf_PMessage(PMessageID)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.unauthorised-access.com/2009/02/creating-fks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deleting FK&#8217;s from MSSQL</title>
		<link>http://www.unauthorised-access.com/2009/01/deleting-fks-from-mssql/</link>
		<comments>http://www.unauthorised-access.com/2009/01/deleting-fks-from-mssql/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 15:34:54 +0000</pubDate>
		<dc:creator>Monty</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[YAF]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#.net]]></category>
		<category><![CDATA[Yet Another Forum]]></category>

		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=76</guid>
		<description><![CDATA[SQL SERVER &#8211; 2005 &#8211; Find Tables With Foreign Key Constraint in Database via SQL SERVER &#8211; 2005 &#8211; Find Tables With Foreign Key Constraint in Database « Journey to SQL Authority with Pinal Dave. This script is a godsend. Basically, we had a botched install of Yet Another Forum, and we had to delete [...]]]></description>
			<content:encoded><![CDATA[<p>SQL SERVER &#8211; 2005 &#8211; Find Tables With Foreign Key Constraint in Database</p>
<p>via <a href="http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/">SQL SERVER &#8211; 2005 &#8211; Find Tables With Foreign Key Constraint in Database « Journey to SQL Authority with Pinal Dave</a>.</p>
<p>This script is a godsend. Basically, we had a botched install of Yet Another Forum, and we had to delete it (YAY!), but because of the FK constraints, we couldnt do a simple &#8220;DROP TABLE *&#8221; on the database, and nor could we just drop the database.</p>
<p>So I came up with this script that generated the SQL Script for me, based on the above:</p>
<pre class="brush: sql;">

SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' DROP CONSTRAINT [' + f.name + ']' AS Moo, f.name AS ForeignKey,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id,
fc.parent_column_id) AS ColumnName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id,
fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id
</pre>
<p>Can be refined alot better, but works. The resulting script is as follows &#8211; note I added the &#8220;drop table&#8221; by hand:</p>
<pre class="brush: sql;">
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_Forum]
ALTER TABLE yaf_Active DROP CONSTRAINT [FK_yaf_Active_yaf_Forum]
ALTER TABLE yaf_ForumAccess DROP CONSTRAINT [FK_yaf_ForumAccess_yaf_Forum]
ALTER TABLE yaf_WatchForum DROP CONSTRAINT [FK_yaf_WatchForum_yaf_Forum]
ALTER TABLE yaf_NntpForum DROP CONSTRAINT [FK_yaf_NntpForum_yaf_Forum]
ALTER TABLE yaf_UserForum DROP CONSTRAINT [FK_yaf_UserForum_yaf_Forum]
ALTER TABLE yaf_Forum DROP CONSTRAINT [FK_yaf_Forum_yaf_Forum]
ALTER TABLE yaf_Forum DROP CONSTRAINT [FK_yaf_Forum_yaf_Message]
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_Message]
ALTER TABLE yaf_Attachment DROP CONSTRAINT [FK_yaf_Attachment_yaf_Message]
ALTER TABLE yaf_Message DROP CONSTRAINT [FK_yaf_Message_yaf_Message]
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_Poll]
ALTER TABLE yaf_Choice DROP CONSTRAINT [FK_yaf_Choice_yaf_Poll]
ALTER TABLE yaf_PollVote DROP CONSTRAINT [FK_yaf_PollVote_yaf_Poll]
ALTER TABLE yaf_Forum DROP CONSTRAINT [FK_yaf_Forum_yaf_Topic]
ALTER TABLE yaf_Message DROP CONSTRAINT [FK_yaf_Message_yaf_Topic]
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_Topic]
ALTER TABLE yaf_Active DROP CONSTRAINT [FK_yaf_Active_yaf_Topic]
ALTER TABLE yaf_WatchTopic DROP CONSTRAINT [FK_yaf_WatchTopic_yaf_Topic]
ALTER TABLE yaf_NntpTopic DROP CONSTRAINT [FK_yaf_NntpTopic_yaf_Topic]
ALTER TABLE yaf_Forum DROP CONSTRAINT [FK_yaf_Forum_yaf_User]
ALTER TABLE yaf_Message DROP CONSTRAINT [FK_yaf_Message_yaf_User]
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_User]
ALTER TABLE yaf_Topic DROP CONSTRAINT [FK_yaf_Topic_yaf_User2]
ALTER TABLE yaf_Active DROP CONSTRAINT [FK_yaf_Active_yaf_User]
ALTER TABLE yaf_CheckEmail DROP CONSTRAINT [FK_yaf_CheckEmail_yaf_User]
ALTER TABLE yaf_PMessage DROP CONSTRAINT [FK_yaf_PMessage_yaf_User1]
ALTER TABLE yaf_WatchForum DROP CONSTRAINT [FK_yaf_WatchForum_yaf_User]
ALTER TABLE yaf_WatchTopic DROP CONSTRAINT [FK_yaf_WatchTopic_yaf_User]
ALTER TABLE yaf_UserGroup DROP CONSTRAINT [FK_yaf_UserGroup_yaf_User]
ALTER TABLE yaf_UserForum DROP CONSTRAINT [FK_yaf_UserForum_yaf_User]
ALTER TABLE yaf_UserPMessage DROP CONSTRAINT [FK_yaf_UserPMessage_yaf_User]
ALTER TABLE yaf_EventLog DROP CONSTRAINT [FK_yaf_EventLog_yaf_User]
ALTER TABLE yaf_User DROP CONSTRAINT [FK_yaf_User_yaf_Rank]
ALTER TABLE yaf_Category DROP CONSTRAINT [FK_yaf_Category_yaf_Board]
ALTER TABLE yaf_Rank DROP CONSTRAINT [FK_yaf_Rank_yaf_Board]
ALTER TABLE yaf_AccessMask DROP CONSTRAINT [FK_yaf_AccessMask_yaf_Board]
ALTER TABLE yaf_Active DROP CONSTRAINT [FK_yaf_Active_yaf_Board]
ALTER TABLE yaf_User DROP CONSTRAINT [FK_yaf_User_yaf_Board]
ALTER TABLE yaf_BannedIP DROP CONSTRAINT [FK_yaf_BannedIP_yaf_Board]
ALTER TABLE yaf_Group DROP CONSTRAINT [FK_yaf_Group_yaf_Board]
ALTER TABLE yaf_NntpServer DROP CONSTRAINT [FK_yaf_NntpServer_yaf_Board]
ALTER TABLE yaf_Smiley DROP CONSTRAINT [FK_yaf_Smiley_yaf_Board]
ALTER TABLE yaf_Registry DROP CONSTRAINT [FK_yaf_Registry_yaf_Board]
ALTER TABLE yaf_ForumAccess DROP CONSTRAINT [FK_yaf_ForumAccess_yaf_Group]
ALTER TABLE yaf_UserGroup DROP CONSTRAINT [FK_yaf_UserGroup_yaf_Group]
ALTER TABLE yaf_UserPMessage DROP CONSTRAINT [FK_yaf_UserPMessage_yaf_PMessage]
ALTER TABLE yaf_ForumAccess DROP CONSTRAINT [FK_yaf_ForumAccess_yaf_AccessMask]
ALTER TABLE yaf_UserForum DROP CONSTRAINT [FK_yaf_UserForum_yaf_AccessMask]
ALTER TABLE yaf_NntpForum DROP CONSTRAINT [FK_yaf_NntpForum_yaf_NntpServer]
ALTER TABLE yaf_NntpTopic DROP CONSTRAINT [FK_yaf_NntpTopic_yaf_NntpForum]
ALTER TABLE yaf_Forum DROP CONSTRAINT [FK_yaf_Forum_yaf_Category]

drop table dbo.yaf_AccessMask
drop table dbo.yaf_Active
drop table dbo.yaf_Attachment
drop table dbo.yaf_BannedIP
drop table dbo.yaf_Board
drop table dbo.yaf_Category
drop table dbo.yaf_CheckEmail
drop table dbo.yaf_Choice
drop table dbo.yaf_EventLog
drop table dbo.yaf_Forum
drop table dbo.yaf_ForumAccess
drop table dbo.yaf_Group
drop table dbo.yaf_Mail
drop table dbo.yaf_Message
drop table dbo.yaf_NntpForum
drop table dbo.yaf_NntpServer
drop table dbo.yaf_NntpTopic
drop table dbo.yaf_PMessage
drop table dbo.yaf_Poll
drop table dbo.yaf_PollVote
drop table dbo.yaf_Rank
drop table dbo.yaf_Registry
drop table dbo.yaf_Replace_Words
drop table dbo.yaf_Smiley
drop table dbo.yaf_Topic
drop table dbo.yaf_User
drop table dbo.yaf_UserForum
drop table dbo.yaf_UserGroup
drop table dbo.yaf_UserPMessage
drop table dbo.yaf_WatchForum
drop table dbo.yaf_WatchTopic
drop view dbo.yaf_vaccess
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.unauthorised-access.com/2009/01/deleting-fks-from-mssql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
