<?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>Transactional SQL | Woody Hayday | Blog</title>
	<atom:link href="https://blog.woodylabs.com/category/code/transactional-sql/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.woodylabs.com</link>
	<description>An exploration of life, technology and writing</description>
	<lastBuildDate>Tue, 13 Jan 2015 15:22:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.woodylabs.com/wp-content/uploads/2015/01/cropped-woody-hayday-yosemite-glacier-point-32x32.jpg</url>
	<title>Transactional SQL | Woody Hayday | Blog</title>
	<link>https://blog.woodylabs.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>MySQL datetime examples &#8211; first/last day of the year &#8211; dates and unix-times</title>
		<link>https://blog.woodylabs.com/2011/11/mysql-datetime-examples-firstlast-day-of-the-year-dates-and-unix-times/</link>
					<comments>https://blog.woodylabs.com/2011/11/mysql-datetime-examples-firstlast-day-of-the-year-dates-and-unix-times/#comments</comments>
		
		<dc:creator><![CDATA[Woody]]></dc:creator>
		<pubDate>Thu, 10 Nov 2011 09:09:22 +0000</pubDate>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Transactional SQL]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Technology]]></category>
		<category><![CDATA[data schemas]]></category>
		<category><![CDATA[facebook data acquisition]]></category>
		<category><![CDATA[facebook graph api]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL Workbench]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[Timestamps]]></category>
		<category><![CDATA[UNIX]]></category>
		<guid isPermaLink="false">http://blog.woodylabs.com/?p=797</guid>

					<description><![CDATA[<p>For some reason I had an abstract memory of SQL SERVER 2000, timestamps and pain. Who knows why. Perhaps its a faulty memory. lol. Anyhow working with timestamps in MySQL/MSSQL these days is nothing short of simple. With MySQL Workbench free its ridiculous how far the barrier of entry for database design has come, its [&#8230;]</p>
<p>The post <a href="https://blog.woodylabs.com/2011/11/mysql-datetime-examples-firstlast-day-of-the-year-dates-and-unix-times/">MySQL datetime examples – first/last day of the year – dates and unix-times</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p><hr /><a href="https://blog.woodylabs.com">Visit Woody Haydays Blog</a><hr />]]></description>
										<content:encoded><![CDATA[<p>For some reason I had an abstract memory of SQL SERVER 2000, timestamps and pain. Who knows why. Perhaps its a faulty memory. lol. Anyhow working with timestamps in MySQL/MSSQL these days is nothing short of simple. With MySQL Workbench free its ridiculous how far the barrier of entry for database design has come, its now all pleasant schema&#8217;s and error messages that make sense, gone are the days of spending half the time fixing/navigating the database system, they just work now (99% of the time) what a lucky generation of programmers! Anyhow here&#8217;s some datetime examples that you might find useful:</p>
<p>Get last day of last year &#8211; obvious, but still (+1 this for first day):</p>
<pre class="brush: sql; title: ; notranslate">SELECT DATE(CURDATE()- INTERVAL DAYOFYEAR(CURDATE()) DAY);</pre>
<p>And how useful&#8230; FROM_UNIXTIME takes a unix timestamp and makes it a friendly datetime, its like they KNOW I am coding for facebook data acquisition&#8230;Anyhow&#8230;</p>
<p>To make a GMT UNIX time-stamp for the first day of this month:</p>
<pre class="brush: sql; title: ; notranslate">SELECT UNIX_TIMESTAMP(CONVERT_TZ(DATE(CURDATE()- INTERVAL DAYOFMONTH(CURDATE()) DAY), '+0:00', 'SYSTEM'));</pre>
<p>You can switch out the dates obviously, and there are probably other ways, still, mostly pain free.  </p><p>The post <a href="https://blog.woodylabs.com/2011/11/mysql-datetime-examples-firstlast-day-of-the-year-dates-and-unix-times/">MySQL datetime examples – first/last day of the year – dates and unix-times</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.woodylabs.com/2011/11/mysql-datetime-examples-firstlast-day-of-the-year-dates-and-unix-times/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>From SQL Server 2008 r2 to SQL Compact Edition. Doing things the wrong way.</title>
		<link>https://blog.woodylabs.com/2010/12/from-sql-server-2008-r2-to-sql-compact-edition-doing-things-the-wrong-way/</link>
		
		<dc:creator><![CDATA[Woody]]></dc:creator>
		<pubDate>Tue, 21 Dec 2010 11:56:59 +0000</pubDate>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Transactional SQL]]></category>
		<guid isPermaLink="false">http://blog.woodylabs.com/?p=451</guid>

					<description><![CDATA[<p>Program written using csharp and SQL Server 2008 r2? Great eh? &#8230; What about your users? &#8230;Doh. Anyway its good to re look at your data layer, so if this crops up and you need to switch to a more portable solution (Compact edition means anyone can use it on windows) then put in the [&#8230;]</p>
<p>The post <a href="https://blog.woodylabs.com/2010/12/from-sql-server-2008-r2-to-sql-compact-edition-doing-things-the-wrong-way/">From SQL Server 2008 r2 to SQL Compact Edition. Doing things the wrong way.</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p><hr /><a href="https://blog.woodylabs.com">Visit Woody Haydays Blog</a><hr />]]></description>
										<content:encoded><![CDATA[<p>Program written using csharp and SQL Server 2008 r2? Great eh? &#8230; What about your users? &#8230;Doh. Anyway its good to re look at your data layer, so if this crops up and you need to switch to a more portable solution (Compact edition means anyone can use it on windows) then put in the time. Heres a few snippets of SQL changes that you will need to deal with in recreating your tables in SQL Compact Edition (moving from full blown SQL server auto scripting)</p>
<ul>
<li>Dont try to SET anything, skip them. ANSI_NULLs, ANSI_PADDING</li>
<li>Replace CURRENT_TIMESTAMP with (getdate()) &#8211; easy to forget this but I always seem to use it as a default.</li>
<li>Keep constraints on line</li>
</ul>
<div align="center"><img fetchpriority="high" decoding="async" class="aligncenter size-full wp-image-452" title="sql-full-to-sql-compact" src="https://blog.woodylabs.com/wp-content/uploads/2010/12/sql-full-to-sql-compact.png" alt="" width="256" height="256" srcset="https://blog.woodylabs.com/wp-content/uploads/2010/12/sql-full-to-sql-compact.png 256w, https://blog.woodylabs.com/wp-content/uploads/2010/12/sql-full-to-sql-compact-250x250.png 250w" sizes="(max-width: 256px) 100vw, 256px" /><br />
Of course if you wrote your tables from scratch in T-SQL it probably wont be a problem.</div><p>The post <a href="https://blog.woodylabs.com/2010/12/from-sql-server-2008-r2-to-sql-compact-edition-doing-things-the-wrong-way/">From SQL Server 2008 r2 to SQL Compact Edition. Doing things the wrong way.</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Google BigQuery and Predictions API &#8211; Swap data for processing time?</title>
		<link>https://blog.woodylabs.com/2010/08/google-bigquery-and-predictions-api-swap-data-for-processing-time/</link>
					<comments>https://blog.woodylabs.com/2010/08/google-bigquery-and-predictions-api-swap-data-for-processing-time/#comments</comments>
		
		<dc:creator><![CDATA[Woody]]></dc:creator>
		<pubDate>Tue, 10 Aug 2010 20:17:37 +0000</pubDate>
				<category><![CDATA[Business Intelligence]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Transactional SQL]]></category>
		<category><![CDATA[Web Technology]]></category>
		<guid isPermaLink="false">http://blog.woodylabs.com/?p=399</guid>

					<description><![CDATA[<p>Something led me to happen across the following video from google I/O 2010 which gives a full expo (57 minutes) on their BigQuery and Prediction API&#8217;s. You can see they have made a lot of ground with ridiculous processing, claiming to be able to run SQL queries (or a derivative) on trillion&#8217;s of rows in [&#8230;]</p>
<p>The post <a href="https://blog.woodylabs.com/2010/08/google-bigquery-and-predictions-api-swap-data-for-processing-time/">Google BigQuery and Predictions API – Swap data for processing time?</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p><hr /><a href="https://blog.woodylabs.com">Visit Woody Haydays Blog</a><hr />]]></description>
										<content:encoded><![CDATA[<p>Something led me to happen across the following video from google I/O 2010 which gives a full expo (57 minutes) on their BigQuery and Prediction API&#8217;s. You can see they have made a lot of ground with ridiculous processing, claiming to be able to run SQL queries (or a derivative) on trillion&#8217;s of rows in seconds, essentially for free. BigQuery lets us, the general techy public do that, cool eh? Well yeah it is, but I cant help but ask the cynical, why? Data, I would presume is their goal, and if it&#8217;s yours to share and insensitive, BigQuery is probably a BigWin. Otherwise its often we find ourselves as technological problem solvers seeking services such as this, a way to fix X, a quicker way of processing Y, a ladder Z to climb fence A to get to B, which can lead us blind with determination down paths, data under arm, paths that are not as safe, sensitive or secure as we thought.</p>
<div align="center"><object width="450" height="278"><param name="movie" value="http://www.youtube.com/v/dbkwv1wjs3A&amp;hl=en_GB&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/dbkwv1wjs3A&amp;hl=en_GB&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="450" height="278"></embed></object><br />I look forward to someone tooling up the predictions API onto the lottery results.</div><p>The post <a href="https://blog.woodylabs.com/2010/08/google-bigquery-and-predictions-api-swap-data-for-processing-time/">Google BigQuery and Predictions API – Swap data for processing time?</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.woodylabs.com/2010/08/google-bigquery-and-predictions-api-swap-data-for-processing-time/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Multiple WordPress blogs from 1 instance / 1 wordpress folder to maintain</title>
		<link>https://blog.woodylabs.com/2010/01/multiple-wordpress-blogs-from-1-instance-1-wordpress-folder-to-maintain/</link>
					<comments>https://blog.woodylabs.com/2010/01/multiple-wordpress-blogs-from-1-instance-1-wordpress-folder-to-maintain/#comments</comments>
		
		<dc:creator><![CDATA[Woody]]></dc:creator>
		<pubDate>Sat, 23 Jan 2010 16:34:27 +0000</pubDate>
				<category><![CDATA[Affiliate Marketing]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Transactional SQL]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Technology]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">http://blog.woodylabs.com/?p=142</guid>

					<description><![CDATA[<p>WordPress is a victim of its own success, but its no victim. It is huge. Millions upon millions of people use wordpress to power their blogs (like this one for example) to make money and to have their voice present on the internet. It has become a first stop for a huge host of people [&#8230;]</p>
<p>The post <a href="https://blog.woodylabs.com/2010/01/multiple-wordpress-blogs-from-1-instance-1-wordpress-folder-to-maintain/">Multiple WordPress blogs from 1 instance / 1 wordpress folder to maintain</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p><hr /><a href="https://blog.woodylabs.com">Visit Woody Haydays Blog</a><hr />]]></description>
										<content:encoded><![CDATA[<p>WordPress is a victim of its own success, but its no victim. It is huge. Millions upon millions of people use wordpress to power their blogs (like this one for example) to make money and to have their voice present on the internet. It has become a first stop for a huge host of people making their way online and is often one that leaves such a positive impression that it never leaves that same user. Its free, its slick, its efficient, its easy&#8230;literally I have nothing but good things to say about wordpress and the people that support it. I could spend hours applauding the democratisation of tools that is wordpress and discuss how its helped the internet blossom and why its so key to understanding the web today but that&#8217;s not what this post is about. If you haven&#8217;t already got a wordpress blog then I would suggest you get one, either for free at wordpress.com or from wordpress.org (the latter if you have your own hosting) &#8211; and once you have one you might soon realise the huge benefit of having 2, 3, 4 or more wordpress blogs. These are real benefits.</p>
<p>The question then comes after  you have 30 wordpress blogs on the go, various niche market&#8217;s blogged too or personal sites about cats or what have you, what then? Updates then. WordPress do update fairly regularly, they aren&#8217;t the slow moving behemoths some other companies are because they are open source, and that&#8217;s a good thing. Anyway maintaining 30 copies of wordpress is actually a lot easier than it sounds, an update is usually nothing more than 10 minutes uploading the new wordpress files over the old ones via FTP. But say you had a little project where you wanted to create a few more wordpress blogs. For the sake of this post lets say you wanted 90 blogs. 90 WordPress blogs installed on an average web host (I suggest 1and1) is not a big deal. It can be as big a deal as you make of it but in your pursuits and interests online its potentially likely to crop up.</p>
<p>You can run 90 wordpress blogs (or 1000 etc.) from 1 instance of wordpress. That is 1 wordpress folder on your host serving to 90 blogs at blogsite1.co.uk, blogsite2.com etc. thats nothing new &#8211; I am sure the quicker off the mark or longer in the tooth of wordpress users have been doing it for a while, but somehow I missed this up until I got past the 30 blog mark and so I thought its about time I looked at the option of hundreds of wordpress-blogs running from 1 folder, a project has come up. The reason this works by the way is the wonderful way (take not web developers) that wordpress splits its config files and its database. The only file in the wordpress files you upload to your blog that contains any site specific data is the config file, which pulls everything from the database.</p>
<p>On the preface there are both good and bad things about doing this with word press, here are the pro&#8217;s and con&#8217;s as I see them pre-project.</p>
<p><strong>Pros</strong></p>
<ul>
<li>Single central wordpress folder  &#8211; 1 wordpress folder to update periodically</li>
<li>File size &#8211; rather than using up 4mb per wordpress install, this method uses 4mb per x number of wordpress installs, although space isn&#8217;t an issue really in current web hosting</li>
<li>Plugins and themes only need to be copied once &#8211; they can effectively be shared</li>
<li>Easier to backup &#8211; backing up files of wordpress blogs is pretty pointless apart from wp-content (uploaded images, themes, etc) &#8211; putting all your blogs in one basket means backing up the whole lot is a breeze, 1 folder not 90!</li>
<li>WordPress database is seperate &#8211; you could potentially run all the blogs from 1 database too &#8211; (capacity dependant) &#8211; as wordpress allows table prefix&#8217;s</li>
<li>Adding a blog can be automated <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> &#8211; replicating the first wp database from an install can mean tons less setup work</li>
</ul>
<p><strong>Cons</strong></p>
<ul>
<li>Permalink structure may have to be the same? *not 100% on this one and havent tested but there may be issues with permalink setups across multiple blogs as htaccess is shared*</li>
<li>Other .htaccess differences &#8211; because you will effectively only have 1 .htaccess file for all domains pointing to this folder, this puts all that custom .htaccess code out of the window</li>
<li>Flip side of themes being easy to install is that editing one theme will lead to all blogs using that theme to notice the change, fine if your blogs are stable in design but multiple versions of the same theme will be required if you want to tweak these on a blog specific level, which could make for a messy confusing setup if not through through</li>
<li>If you are running a network of blogs and want to stay under the radar or just want the sites to be as different as possible &#8211; by nature of single resource they will leave footprints unless you are aware and make sure you do things like rename folders for themes non-sequentially etc ( or maybe don&#8217;t be paranoid :p )</li>
<li>Centralising the files for all domains/sites/blogs does mean this folder on this box does then become a single point of failure, loose/break this and the whole of your blog network/project is down. Probably not such an issue with stable hosts these days</li>
<li>As previous point if you do update, change a file or accidentally delete anything it does effect every site &#8211; its a risk but not a big one just be careful!</li>
</ul>
<p><strong>Limitations</strong></p>
<ul>
<li>Unsure about .htaccess but presume custom rewriting becomes a pain as all sites share a file</li>
<li>There will be a limit as to how many blogs you can run off a single install. It&#8217;s probably thousands though &#8211; if you had 30,000 sites for example &#8211; the file which points the install to the right database tables would become bloated</li>
</ul>
<p><strong>How to run tens, hundreds or thousands of wordpress blogs from 1 instance &#8211; install wordpress once for hundreds of blogs &#8211; without MU.</strong></p>
<ol>
<li>Install wordpress into a folder on you hosting (download latest from wordpress.org and then upload via FTP/copy across network)</li>
<li>Get your database details together, you will need Database Name, Database Username, Database Password and the Database host for each of the databases you are going to host wordpress tables in</li>
<li>Install a single blog using the normal method &#8211; point a domain at the folder, go to that domain and follow the wordpress wizard, entering your database connection details and this blogs title.
<ol>
<li>Go through this newly installed blog and commit any changes that you will want duplicated throughout the new installs &#8211; delete the &#8220;hello world&#8221; post/default wp links for example.</li>
<li>Imagine this like creating a ghost image for a network of pc&#8217;s &#8211; you want to make a bare bones default wordpress setup so you can replicate this onwards without having to redo it.</li>
</ol>
</li>
<li>Happy with  your ghost blog setup? go to your phpmyadmin (assuming you have it) and export all the tables for this blog into SQL.</li>
<li>Open that SQL into your favourite text editor, in this case I am using Dreamweaver because I like its find+replace.</li>
<li>You will need to do several find + replaces here, but by doing this you can literally clone a wordpress installation &#8211; (works as at 2.9.1 anyway) &#8211; this is great for mass distribution (This is quicker than installing and can be automated)</li>
<li>For example if your site was &#8220;harrysblog1.co.uk&#8221; with a title of  &#8220;Harrys Blog 1&#8221; then do a find and replace for &#8220;harrysblog1.co.uk&#8221;, switching out the new domain to be added, same with title&#8217;s, users, post&#8217;s etc. This way you could clone a wordpress site and switch out words&#8230;you can change the table prefix this way too.</li>
<li>Run this newly modified SQL on whatever mysql database you want to run the blog from (could be same one if you mass replaced the table prefix&#8217;s)</li>
<li>Alter your wp-config.php file very simply:
<ol>
<li>Open it up and put a bit of logic which basically says &#8220;what domain am I loading from, ah this one &#8211; use this DB and this table prefix&#8221; &#8211; This logic can be as simple or as complex as you want it to be &#8211; I kept mine short and sweet with literally:</li>
</ol>
</li>
</ol>
<div style="border:1px solid #09C; background-color:#b5d1ea;padding:4px;margin:10px;">$thisDom = $_SERVER[&#8216;HTTP_HOST&#8217;];</p>
<p>if ($thisDom == &#8220;www.specificDomainWhatever.co.uk&#8221; || $thisDom == &#8220;specificDomainWhatever.co.uk&#8221;){ $useDB = 1; $table_prefix = &#8220;specificDomainWhatever_&#8221;; }</p>
<p>if ($useDB == 1){</p>
<p>define(&#8216;DB_NAME&#8217;, &#8216;xxx&#8217;);</p>
<p>/** MySQL database username */<br />
define(&#8216;DB_USER&#8217;, &#8216;xxx&#8217;);</p>
<p>/** MySQL database password */<br />
define(&#8216;DB_PASSWORD&#8217;, &#8216;xxx&#8217;);</p>
<p>/** MySQL hostname */<br />
define(&#8216;DB_HOST&#8217;, &#8216;xxx&#8217;);</p>
<p>/** Database Charset to use in creating database tables. */<br />
define(&#8216;DB_CHARSET&#8217;, &#8216;utf8&#8217;);</p>
<p>/** The Database Collate type. Don&#8217;t change this if in doubt. */<br />
define(&#8216;DB_COLLATE&#8217;, &#8221;);</p>
<p>}</p></div>
<p>*note this is just how I did it, there are other ways &#8211; the code works but was just to test the theory &#8211; when upscaled to a network of xxx or x,xxx sites this is automated quite easily</p>
<p>*note2 I am having to cut this post short but if anyone has any questions or wants to know more/help on replicating wordpress or multi blog &#8211; 1 wordpress instance installs let me know in the comments</p>
<p><strong>References</strong></p>
<p>Striderweb &#8211; <a rel="nofollow" href="http://striderweb.com/nerdaphernalia/2006/10/hello-again-world/">this post</a> pretty much explains the theory, a bit like this post &#8211; but I actually happened across it after writing the post &#8211; well worth reading if your going to do this &#8211; Stephen Rider has made a great plugin that will do everything you want it to do as above, I winged it and just modified the wp-config which simply worked in my case so personally I didn&#8217;t use it, but no doubt its probably worth a try if  you want a more deep solution.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">Woody Hayday<br />
9a Holywell Hill</p>
<p>Hi Jo</p>
<p>I have just found out that I will be away to thailand in the beginning of march and as my 6 months of tenancy is up in feb (08th) I was wondering how it worked with regards to rolling contracts?</p>
<p>I would like to move out just before</p>
</div><p>The post <a href="https://blog.woodylabs.com/2010/01/multiple-wordpress-blogs-from-1-instance-1-wordpress-folder-to-maintain/">Multiple WordPress blogs from 1 instance / 1 wordpress folder to maintain</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://blog.woodylabs.com/2010/01/multiple-wordpress-blogs-from-1-instance-1-wordpress-folder-to-maintain/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>ReSeed Identity column &#8211; TSQL</title>
		<link>https://blog.woodylabs.com/2009/11/reseed-identity-column-tsql/</link>
		
		<dc:creator><![CDATA[Woody]]></dc:creator>
		<pubDate>Mon, 09 Nov 2009 18:08:24 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Transactional SQL]]></category>
		<guid isPermaLink="false">http://blog.woodylabs.com/?p=113</guid>

					<description><![CDATA[<p>Randomly I didn&#8217;t remember the code to reseed the identity column in tsql, this works though on ms sql 2008 &#8211; DBCC CHECKIDENT (tbl_crazyTableName, RESEED, 20000) TSQL</p>
<p>The post <a href="https://blog.woodylabs.com/2009/11/reseed-identity-column-tsql/">ReSeed Identity column – TSQL</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p><hr /><a href="https://blog.woodylabs.com">Visit Woody Haydays Blog</a><hr />]]></description>
										<content:encoded><![CDATA[<p>Randomly I didn&#8217;t remember the code to reseed the identity column in tsql, this works though on ms sql 2008 &#8211; DBCC CHECKIDENT (tbl_crazyTableName, RESEED, 20000)</p>
<div align="center" style="font-size:50px;height:60px;"><span style="color:#ccc">T</span>SQL</div><p>The post <a href="https://blog.woodylabs.com/2009/11/reseed-identity-column-tsql/">ReSeed Identity column – TSQL</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>xp_fileexist Network Drive &#8211; T SQL Based File checking</title>
		<link>https://blog.woodylabs.com/2009/05/xp_fileexist-network-drive-t-sql-based-file-checking/</link>
		
		<dc:creator><![CDATA[Woody]]></dc:creator>
		<pubDate>Thu, 07 May 2009 16:17:31 +0000</pubDate>
				<category><![CDATA[Social Media]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Transactional SQL]]></category>
		<guid isPermaLink="false">http://blog.woodylabs.com/?p=63</guid>

					<description><![CDATA[<p>If you didn&#8217;t already know you can check whether files exist, find file sizes and all sorts of other useful things directly from within Transactional SQL Query. In this example I had a table containing a few columns that gave me the network drive location and filename of a few thousand files and I wanted [&#8230;]</p>
<p>The post <a href="https://blog.woodylabs.com/2009/05/xp_fileexist-network-drive-t-sql-based-file-checking/">xp_fileexist Network Drive – T SQL Based File checking</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p><hr /><a href="https://blog.woodylabs.com">Visit Woody Haydays Blog</a><hr />]]></description>
										<content:encoded><![CDATA[<p>If you didn&#8217;t already know you can check whether files exist, find file sizes and all sorts of other useful things directly from within Transactional SQL Query. In this example I had a table containing a few columns that gave me the network drive location and filename of a few thousand files and I wanted to verify that every file at this address existed in reality.</p>
<p>Here is how I managed it:</p>
<blockquote>
<p>&#8211;make procedure to cycle trhough entrants and assign them to a room<br />
create procedure [dbo].[files_2_check] as<br />
DECLARE @fileAt varchar(2000)<br />
DECLARE @fileEx int</p>
<p>DECLARE checkCursor CURSOR FOR<br />
&#8211;select top 10 FileDirectory + FileName from files &#8211; USE to test it first<br />
select FileDirectory + FileName fromfiles</p>
<p>OPEN checkCursor</p>
<p>FETCH NEXT FROM checkCursor<br />
INTO @fileAt</p>
<p>WHILE @@FETCH_STATUS = 0<br />
BEGIN</p>
<p>set @fileAt = &#8216;\\192.168.1.8\f$\Files\&#8217; + @fileAt<br />
&#8211;this will depend on your network address</p>
<p>print &#8216;Searching for &#8216;+@fileAt<br />
EXEC master..xp_fileexist @fileAt, @fileEx OUTPUT;</p>
<p>if @fileEx = 0<br />
begin<br />
insert into dbo.tbl_fileCheck (fileLoc) Values (@fileAt)<br />
&#8211;doesnt check for already existing, archives by date though<br />
print &#8216;&#8230;NOT FOUND &#8211; Recorded to DB&#8217;<br />
end<br />
if @fileEx = 1<br />
begin<br />
print &#8216;&#8230;OK&#8217;<br />
end</p>
<p>set @fileEx = 0<br />
set @fileAt = &#8221;<br />
FETCH NEXT FROM checkCursor<br />
INTO @fileAt<br />
END</p>
<p>CLOSE checkCursor<br />
DEALLOCATE checkCursor</p>
</blockquote>
<p>Which basically grabs the rows containing the file directory/filename and uses a cursor to cycle through each one checking them using the xp_fileexist command. There were a number of ways available to do the actual file exist checking but this one suited best, This solution definately works on SQL2005 and forwards, although did need a few additionals:</p>
<p>Turn on the setting (potential security issues if this is on 24/7, but you could run it on a vanila ms sql db server elsewhere) &#8211; Worth turning off afterwards.</p>
<blockquote>
<p>exec sp_configure &#8216;show advanced options&#8217;, 1</p>
<p>go</p>
<p>reconfigure</p>
<p>go</p>
<p>exec sp_configure &#8216;xp_cmdshell&#8217;, 1</p>
<p>go</p>
<p>reconfigure</p>
<p>go</p>
</blockquote>
<p>Apply admin rights to the MS SQL Windows service &#8211; by default this will only have local scope, it needs you to go to the services properties, then logon tab and assign it a user which has scope to view the files its checking exist over the network.</p><p>The post <a href="https://blog.woodylabs.com/2009/05/xp_fileexist-network-drive-t-sql-based-file-checking/">xp_fileexist Network Drive – T SQL Based File checking</a> first appeared on <a href="https://blog.woodylabs.com">Woody Hayday | Blog</a>.</p>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
