<?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>sentient beings &#187; Hacks</title>
	<atom:link href="http://www.sentientbeings.com/category/hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sentientbeings.com</link>
	<description>Adventures in BI</description>
	<lastBuildDate>Mon, 23 Jan 2012 09:12:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>T-SQL: Find any string in any column in any table in a database.</title>
		<link>http://www.sentientbeings.com/2012/01/t-sql-find-any-string-in-any-column-in-any-table-in-a-database/</link>
		<comments>http://www.sentientbeings.com/2012/01/t-sql-find-any-string-in-any-column-in-any-table-in-a-database/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 08:16:43 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Sql]]></category>

		<guid isPermaLink="false">http://www.sentientbeings.com/?p=142</guid>
		<description><![CDATA[Have you ever found yourself in need of finding a certain string in an entire database? As a freelance BI consultant, this happens to me rather frequently when analysing where and how data is stored and how to retrieve it. So I came up with this code. It lets you find a string in any [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever found yourself in need of finding a certain string in an entire database? As a freelance BI consultant, this happens to me rather frequently when analysing where and how data is stored and how to retrieve it.</p>
<p>So I came up with this code. It lets you find a string in any column in any table on your database. It's a pretty length search if you have a lot of data and a lot of columns and tables, but it sure beats searching by hand.</p>
<p>Be warned! This may run a pretty long time on large databases.</p>
<pre class="tsql">&nbsp;
<span style="color: #0000FF;">DECLARE</span> @searchString <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">DECLARE</span> @sqlString <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">DECLARE</span> @processedString <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #008080;">-- Insert your searchstring below</span>
<span style="color: #008080;">-- Use \ as escape character</span>
<span style="color: #008080;">-- examples:</span>
<span style="color: #008080;">--	to search for 'I'm waiting', use 'I\'m waiting'</span>
<span style="color: #008080;">--	to search for '25%' use '25\%'</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span>
	@searchString = <span style="color: #FF0000;">'naar achter'</span>
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @resultTable	<span style="color: #0000FF;">TABLE</span>
<span style="color: #808080;">&#40;</span>
	table_name	<span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	<span style="color: #FF00FF;">COL_NAME</span>	<span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	value_found	<span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span>,
	<span style="color: #FF00FF;">OBJECT_ID</span>	<span style="color: #0000FF;">INT</span>,
	col_id	<span style="color: #0000FF;">INT</span>
<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span>
	@sqlString = <span style="color: #FF0000;">'-- start'</span>,
	@processedString = <span style="color: #FF0000;">''</span>
&nbsp;
<span style="color: #0000FF;">WHILE</span>
	@sqlString &gt; <span style="color: #FF0000;">''</span>
<span style="color: #0000FF;">BEGIN</span>
&nbsp;
	<span style="color: #0000FF;">SELECT</span>
		@sqlString = <span style="color: #FF0000;">''</span>,
		@processedString = <span style="color: #FF0000;">''</span>
&nbsp;
	<span style="color: #0000FF;">SELECT</span>
		@processedString = @processedString +
		<span style="color: #0000FF;">CASE</span>
			<span style="color: #0000FF;">WHEN</span> DATALENGTH<span style="color: #808080;">&#40;</span>@sqlString<span style="color: #808080;">&#41;</span> &lt; <span style="color: #000;">7500</span> <span style="color: #008080;">-- assume a sql statement will never go beyond 500 characters</span>
			<span style="color: #0000FF;">THEN</span>
		<span style="color: #FF0000;">'
			select
				'</span><span style="color: #FF0000;">''</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span>tbl.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">'.'</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">OBJECT_NAME</span><span style="color: #808080;">&#40;</span>tbl.<span style="color: #FF00FF;">OBJECT_ID</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">''</span><span style="color: #FF0000;">' as table_name,
				'</span><span style="color: #FF0000;">''</span> + col.<span style="color: #202020;">name</span> + <span style="color: #FF0000;">''</span><span style="color: #FF0000;">',
				NULL as value_found,
				'</span> + <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">NVARCHAR</span>,tbl.<span style="color: #FF00FF;">OBJECT_ID</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">' as object_id,
				'</span> + <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">NVARCHAR</span>,col.<span style="color: #202020;">column_id</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">' as col_id
		'</span>
			<span style="color: #0000FF;">ELSE</span>
				<span style="color: #FF0000;">''</span>
		<span style="color: #0000FF;">END</span>,
		@sqlString = @sqlString +
		<span style="color: #0000FF;">CASE</span>
			<span style="color: #0000FF;">WHEN</span> DATALENGTH<span style="color: #808080;">&#40;</span>@sqlString<span style="color: #808080;">&#41;</span> &lt; <span style="color: #000;">7500</span> <span style="color: #008080;">-- assume a sql statement will never go beyond 500 characters</span>
			<span style="color: #0000FF;">THEN</span>
		<span style="color: #FF0000;">'
			select
				top 1
				'</span><span style="color: #FF0000;">''</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span>tbl.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">'.'</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">OBJECT_NAME</span><span style="color: #808080;">&#40;</span>tbl.<span style="color: #FF00FF;">OBJECT_ID</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">''</span><span style="color: #FF0000;">' as table_name,
				'</span><span style="color: #FF0000;">''</span> + col.<span style="color: #202020;">name</span> + <span style="color: #FF0000;">''</span><span style="color: #FF0000;">',
				'</span> + col.<span style="color: #202020;">name</span> + <span style="color: #FF0000;">' as value_found,
				'</span> + <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">NVARCHAR</span>,tbl.<span style="color: #FF00FF;">OBJECT_ID</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">' as object_id,
				'</span> + <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">NVARCHAR</span>,col.<span style="color: #202020;">column_id</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">' as col_id
			from
				'</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span>tbl.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">'.'</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">OBJECT_NAME</span><span style="color: #808080;">&#40;</span>tbl.<span style="color: #FF00FF;">OBJECT_ID</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">'
			where
				'</span> + col.<span style="color: #202020;">name</span> + <span style="color: #FF0000;">' like '</span><span style="color: #FF0000;">'%'</span> + @searchString + <span style="color: #FF0000;">'%'</span><span style="color: #FF0000;">' escape '</span><span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\'</span>'</span>
		<span style="color: #FF0000;">'
			else
				'</span><span style="color: #FF0000;">'
		end
	from
		sys.columns col
			inner join
		sys.tables tbl
			on	col.object_id = tbl.object_id
			and	col.user_type_id in (231, 167, 175, 239)
			 --	nvarchar, varchar, char, nchar
			 --	no text
			left join
		@resultTable rst
			on	col.column_id = rst.col_id
			and	col.object_id = rst.object_id
	where
		rst.table_name is null
&nbsp;
	print	@sqlString
	print	@processedString	
&nbsp;
	insert into
		@resultTable
	exec
		(@sqlString)
&nbsp;
	insert into
		@resultTable
	exec
		(@processedString)
&nbsp;
	print	'</span><span style="color: #008080;">---8&lt;-----------------------------------------------------------------------------------------------'</span>
&nbsp;
<span style="color: #0000FF;">END</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span>
	table_name,
	<span style="color: #FF00FF;">COL_NAME</span>,
	value_found
<span style="color: #0000FF;">FROM</span>
	@resultTable
<span style="color: #0000FF;">WHERE</span>
	value_found <span style="color: #0000FF;">IS</span> not null
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span>
	<span style="color: #000;">1</span>, <span style="color: #000;">2</span>, <span style="color: #000;">3</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sentientbeings.com/2012/01/t-sql-find-any-string-in-any-column-in-any-table-in-a-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drop all foreign keys on a database and optionally drop all tables</title>
		<link>http://www.sentientbeings.com/2012/01/drop-all-foreign-keys-on-a-database-and-optionally-drop-all-tables/</link>
		<comments>http://www.sentientbeings.com/2012/01/drop-all-foreign-keys-on-a-database-and-optionally-drop-all-tables/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 08:48:02 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Sql]]></category>

		<guid isPermaLink="false">http://www.sentientbeings.com/?p=135</guid>
		<description><![CDATA[If you've ever found the need to drop or remove all foreign keys on a database then here's a little script that runs without cursors. &#160; DECLARE @SQL NVARCHAR&#40;MAX&#41; &#160; SELECT @SQL = '-- Start ' &#160; WHILE @SQL &#62; '' BEGIN SELECT @SQL = '' &#160; SELECT @SQL = @SQL + CASE WHEN DATALENGTH&#40;@SQL&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>If you've ever found the need to drop or remove all foreign keys on a database then here's a little script that runs without cursors. </p>
<pre class="tsql">&nbsp;
<span style="color: #0000FF;">DECLARE</span> @<span style="color: #0000FF;">SQL</span> <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span>	
&nbsp;
<span style="color: #0000FF;">SELECT</span>
	@<span style="color: #0000FF;">SQL</span> = <span style="color: #FF0000;">'-- Start '</span>
&nbsp;
<span style="color: #0000FF;">WHILE</span> @<span style="color: #0000FF;">SQL</span> &gt; <span style="color: #FF0000;">''</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">SELECT</span>
		@<span style="color: #0000FF;">SQL</span> = <span style="color: #FF0000;">''</span>
&nbsp;
	<span style="color: #0000FF;">SELECT</span>
		@<span style="color: #0000FF;">SQL</span> = @<span style="color: #0000FF;">SQL</span> +
			<span style="color: #0000FF;">CASE</span>
				<span style="color: #0000FF;">WHEN</span> DATALENGTH<span style="color: #808080;">&#40;</span>@<span style="color: #0000FF;">SQL</span><span style="color: #808080;">&#41;</span> &lt; <span style="color: #000;">7500</span> <span style="color: #0000FF;">THEN</span>
					N<span style="color: #FF0000;">'alter table '</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>schema_name<span style="color: #808080;">&#40;</span>schema_id<span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
					+ N<span style="color: #FF0000;">'.'</span>
					+ <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">OBJECT_NAME</span><span style="color: #808080;">&#40;</span>parent_object_id<span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
					+ N<span style="color: #FF0000;">' drop constraint '</span>
					+ name
					+ <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">13</span><span style="color: #808080;">&#41;</span> + <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">10</span><span style="color: #808080;">&#41;</span> <span style="color: #008080;">--+ 'GO' + CHAR(13) + CHAR(10)</span>
				<span style="color: #0000FF;">ELSE</span>
					<span style="color: #FF0000;">''</span>
			<span style="color: #0000FF;">END</span>
	<span style="color: #0000FF;">FROM</span>
		sys.<span style="color: #202020;">foreign_keys</span>
&nbsp;
	<span style="color: #0000FF;">PRINT</span> @<span style="color: #0000FF;">SQL</span>
	<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_EXECUTESQL</span> @<span style="color: #0000FF;">SQL</span>
	<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'---8&lt;------------------------------------------------------------------------------------------'</span>
<span style="color: #0000FF;">END</span>
&nbsp;
GO
&nbsp;
<span style="color: #008080;">---8&lt;-------------------------------------------------------------</span>
<span style="color: #008080;">-- Uncomment the line below to drop all tables too</span>
&nbsp;
<span style="color: #008080;">--exec sp_msforeachtable 'drop table ?'</span>
&nbsp;
<span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'All done'</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sentientbeings.com/2012/01/drop-all-foreign-keys-on-a-database-and-optionally-drop-all-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>T-SQL List all columns in all tables</title>
		<link>http://www.sentientbeings.com/2012/01/t-sql-list-all-columns-in-all-tables/</link>
		<comments>http://www.sentientbeings.com/2012/01/t-sql-list-all-columns-in-all-tables/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 08:40:01 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Sql]]></category>

		<guid isPermaLink="false">http://www.sentientbeings.com/?p=132</guid>
		<description><![CDATA[If you've ever wanted to get a listing of all the columns in all of the tables in a certain database, here's how. I use this often for writing technical documentation on systems. This little code will list all of your tables, columns, datatypes, nullable option, identity option and will also indicate primary and foreign [...]]]></description>
			<content:encoded><![CDATA[<p>If you've ever wanted to get a listing of all the columns in all of the tables in a certain database, here's how. I use this often for writing technical documentation on systems.</p>
<p>This little code will list all of your tables, columns, datatypes, nullable option, identity option and will also indicate primary and foreign keys and default constraints.</p>
<pre class="tsql">&nbsp;
<span style="color: #0000FF;">SELECT</span>
<span style="color: #008080;">--	distinct</span>
<span style="color: #008080;">--	quotename(schema_name(tbl.schema_id)) + N'.' + quotename(tbl.name) as TableName,</span>
<span style="color: #008080;">--	col.column_id,</span>
	col.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> ColumnName,
	type_name<span style="color: #808080;">&#40;</span>col.<span style="color: #202020;">user_type_id</span><span style="color: #808080;">&#41;</span>+
	<span style="color: #0000FF;">CASE</span>
		<span style="color: #0000FF;">WHEN</span> <span style="color: #FF00FF;">COLUMNPROPERTY</span><span style="color: #808080;">&#40;</span>tbl.<span style="color: #FF00FF;">OBJECT_ID</span>, col.<span style="color: #202020;">name</span>, <span style="color: #FF0000;">'scale'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">IS</span> null <span style="color: #0000FF;">THEN</span>
			<span style="color: #FF0000;">' ('</span> + <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">VARCHAR</span>,<span style="color: #FF00FF;">COLUMNPROPERTY</span><span style="color: #808080;">&#40;</span>tbl.<span style="color: #FF00FF;">OBJECT_ID</span>, col.<span style="color: #202020;">name</span>, <span style="color: #FF0000;">'precision'</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">')'</span> <span style="color: #008080;">--is null --convert(varchar, col.max_length)</span>
		<span style="color: #0000FF;">WHEN</span> col.<span style="color: #202020;">user_type_id</span> in <span style="color: #808080;">&#40;</span><span style="color: #000;">60</span>, <span style="color: #000;">106</span>, <span style="color: #000;">108</span>, <span style="color: #000;">122</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">THEN</span>
			<span style="color: #FF0000;">' ('</span> + <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">VARCHAR</span>,col.<span style="color: #0000FF;">PRECISION</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">','</span> + <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">VARCHAR</span>, col.<span style="color: #202020;">scale</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">')'</span>
		<span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span>
	<span style="color: #0000FF;">END</span>	<span style="color: #0000FF;">AS</span> DataType,
	<span style="color: #0000FF;">CASE</span> col.<span style="color: #202020;">is_nullable</span>
		<span style="color: #0000FF;">WHEN</span> <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'NOT '</span>
		<span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span>
	<span style="color: #0000FF;">END</span>
		+	 <span style="color: #FF0000;">'NULL'</span> <span style="color: #0000FF;">AS</span> Nullable,
	<span style="color: #0000FF;">CASE</span> col.<span style="color: #202020;">is_identity</span>
		<span style="color: #0000FF;">WHEN</span> <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">''</span>
		<span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">'IDENTITY ('</span> + <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">VARCHAR</span>, idc.<span style="color: #202020;">seed_value</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">','</span> + <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">VARCHAR</span>, idc.<span style="color: #202020;">increment_value</span><span style="color: #808080;">&#41;</span> + <span style="color: #FF0000;">')'</span>
	<span style="color: #0000FF;">END</span>	<span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">IDENTITY</span><span style="color: #808080;">&#93;</span>,
	<span style="color: #0000FF;">CASE</span>
		<span style="color: #0000FF;">WHEN</span> ixc.<span style="color: #202020;">column_id</span> <span style="color: #0000FF;">IS</span> not null <span style="color: #0000FF;">THEN</span>
			<span style="color: #FF0000;">'PK'</span>
		<span style="color: #0000FF;">WHEN</span> fkc.<span style="color: #202020;">constraint_object_id</span> <span style="color: #0000FF;">IS</span> not null <span style="color: #0000FF;">THEN</span>
			<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>schema_name<span style="color: #808080;">&#40;</span>tb2.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + N<span style="color: #FF0000;">'.'</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>tb2.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span> + N<span style="color: #FF0000;">'.'</span> + fcl.<span style="color: #202020;">name</span>
		<span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span>
	<span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> Key_Constraint,
	<span style="color: #0000FF;">CASE</span>
		<span style="color: #0000FF;">WHEN</span> dfc.<span style="color: #FF00FF;">OBJECT_ID</span> <span style="color: #0000FF;">IS</span> not null <span style="color: #0000FF;">THEN</span>
			dfc.<span style="color: #202020;">definition</span>
		<span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span>
	<span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DEFAULT</span> <span style="color: #0000FF;">CONSTRAINT</span><span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span>
	sys.<span style="color: #202020;">tables</span> tbl
		<span style="color: #0000FF;">INNER</span> join
	<span style="color: #808080;">&#40;</span>
		<span style="color: #0000FF;">SELECT</span>
			<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>schema_name<span style="color: #808080;">&#40;</span>tbl.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + N<span style="color: #FF0000;">'.'</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>tbl.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> TableName,
			col.<span style="color: #202020;">name</span>,
			col.<span style="color: #202020;">column_id</span>,
			col.<span style="color: #FF00FF;">OBJECT_ID</span>,
			col.<span style="color: #202020;">is_identity</span>,
			col.<span style="color: #202020;">is_nullable</span>,
			col.<span style="color: #0000FF;">PRECISION</span>,
			col.<span style="color: #202020;">scale</span>,
			col.<span style="color: #202020;">user_type_id</span>,
			<span style="color: #000;">1</span> <span style="color: #0000FF;">AS</span> SortKey
		<span style="color: #0000FF;">FROM</span>
			sys.<span style="color: #202020;">columns</span> col
				<span style="color: #0000FF;">INNER</span> join
			sys.<span style="color: #202020;">tables</span> tbl
				<span style="color: #0000FF;">ON</span>	tbl.<span style="color: #FF00FF;">OBJECT_ID</span> = col.<span style="color: #FF00FF;">OBJECT_ID</span>
&nbsp;
		<span style="color: #0000FF;">UNION</span> 
&nbsp;
		<span style="color: #0000FF;">SELECT</span>
			<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>schema_name<span style="color: #808080;">&#40;</span>tbl.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + N<span style="color: #FF0000;">'.'</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>tbl.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> TableName,
			<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>schema_name<span style="color: #808080;">&#40;</span>tbl.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + N<span style="color: #FF0000;">'.'</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>tbl.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> TableName,
			<span style="color: #000;">0</span>,
			tbl.<span style="color: #FF00FF;">OBJECT_ID</span>,
			<span style="color: #000;">0</span>,
			<span style="color: #000;">0</span>,
			<span style="color: #000;">0</span>,
			<span style="color: #000;">0</span>,
			<span style="color: #000;">0</span>,
			<span style="color: #000;">0</span>
		<span style="color: #0000FF;">FROM</span>
			sys.<span style="color: #202020;">tables</span> tbl
&nbsp;
	<span style="color: #808080;">&#41;</span>	col
		<span style="color: #0000FF;">ON</span>	tbl.<span style="color: #FF00FF;">OBJECT_ID</span> = col.<span style="color: #FF00FF;">OBJECT_ID</span>
		<span style="color: #0000FF;">LEFT</span> join
	sys.<span style="color: #202020;">key_constraints</span> pkc
		<span style="color: #0000FF;">ON</span>	pkc.<span style="color: #202020;">parent_object_id</span> = tbl.<span style="color: #FF00FF;">OBJECT_ID</span>
		and	pkc.<span style="color: #202020;">type</span> = <span style="color: #FF0000;">'PK'</span>
		<span style="color: #0000FF;">LEFT</span> join
	sys.<span style="color: #202020;">index_columns</span> ixc
		<span style="color: #0000FF;">ON</span>	ixc.<span style="color: #FF00FF;">OBJECT_ID</span> = tbl.<span style="color: #FF00FF;">OBJECT_ID</span>
		and	ixc.<span style="color: #202020;">index_id</span> = pkc.<span style="color: #202020;">unique_index_id</span>
		and	ixc.<span style="color: #202020;">column_id</span> = col.<span style="color: #202020;">column_id</span>
		<span style="color: #0000FF;">LEFT</span> join
	sys.<span style="color: #202020;">foreign_key_columns</span> fkc
		<span style="color: #0000FF;">ON</span>	fkc.<span style="color: #202020;">parent_object_id</span> = tbl.<span style="color: #FF00FF;">OBJECT_ID</span>
		and	fkc.<span style="color: #202020;">parent_column_id</span> = col.<span style="color: #202020;">column_id</span>
		<span style="color: #0000FF;">LEFT</span> join
	sys.<span style="color: #202020;">columns</span> fcl
		<span style="color: #0000FF;">ON</span>	fkc.<span style="color: #202020;">referenced_column_id</span> = fcl.<span style="color: #202020;">column_id</span>
		and	fkc.<span style="color: #202020;">referenced_object_id</span> = fcl.<span style="color: #FF00FF;">OBJECT_ID</span>
		<span style="color: #0000FF;">LEFT</span> join
	sys.<span style="color: #202020;">tables</span> tb2
		<span style="color: #0000FF;">ON</span>	fcl.<span style="color: #FF00FF;">OBJECT_ID</span> = tb2.<span style="color: #FF00FF;">OBJECT_ID</span>
		<span style="color: #0000FF;">LEFT</span> join
	sys.<span style="color: #202020;">default_constraints</span> dfc
		<span style="color: #0000FF;">ON</span>	dfc.<span style="color: #202020;">parent_object_id</span> = tbl.<span style="color: #FF00FF;">OBJECT_ID</span>
		and	dfc.<span style="color: #202020;">parent_column_id</span> = col.<span style="color: #202020;">column_id</span>
		<span style="color: #0000FF;">LEFT</span> join
	sys.<span style="color: #202020;">identity_columns</span> idc
		<span style="color: #0000FF;">ON</span>	idc.<span style="color: #FF00FF;">OBJECT_ID</span> = tbl.<span style="color: #FF00FF;">OBJECT_ID</span>
		and	idc.<span style="color: #202020;">column_id</span> = col.<span style="color: #202020;">column_id</span>
<span style="color: #0000FF;">WHERE</span>
	tbl.<span style="color: #202020;">type</span> = <span style="color: #FF0000;">'U'</span>
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span>
	<span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>schema_name<span style="color: #808080;">&#40;</span>tbl.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> + N<span style="color: #FF0000;">'.'</span> + <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>tbl.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span>,
	SortKey,
	ColumnName
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sentientbeings.com/2012/01/t-sql-list-all-columns-in-all-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LaCie Internet Space no longer works.</title>
		<link>http://www.sentientbeings.com/2011/11/lacie-internet-space-no-longer-works/</link>
		<comments>http://www.sentientbeings.com/2011/11/lacie-internet-space-no-longer-works/#comments</comments>
		<pubDate>Sat, 26 Nov 2011 12:34:29 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Selfish]]></category>

		<guid isPermaLink="false">http://www.sentientbeings.com/?p=128</guid>
		<description><![CDATA[A few weeks ago, I noticed that my Lacie Internet Space was offline. Not a real problem, since the LaCie Internet Space will go offline every once in a while. A powercycle is usually enough to get it going again. But to my dismay, not this time. I powercycled the LaCie Internet Space and it [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago, I noticed that my Lacie Internet Space was offline. Not a real problem, since the LaCie Internet Space will go offline every once in a while. A powercycle is usually enough to get it going again.</p>
<p>But to my dismay, not this time. I powercycled the LaCie Internet Space and it booted allright, the blue light came on and then ... nothing.</p>
<p>I dismantled the complete thing, took out the drive (Hitachi Deskstar 1TB 7200 RPM) and plugged it into my usb/sata converter and again, nothing happened.</p>
<p>Cue slight panic as my entire music collection was stored on this, as well as my wife's photo portfolio. Since the drive did seem to spin up, I suspected the logic board. I scoured the internet for an exact hard disk and found one. In the meantime, I had also bought a second hand LaCie Internet Space, thinking there would be a Hitachi Deskstar inside but it turned out to be a Samsung HD103SI. I discarded the second LaCie Internet Space and put all my hopes on the spare disc, which, by the way, was rather expensive due to the floods in Thailand.</p>
<p>I switched the logic boards, connected the Hitachi to the usb/sata converter and nothing happened. I replaced the logic boards and in a final act of lucidity decided to put the hard drive into the replacement LaCie Internet Space casing. All of a sudden, the disc sprang back to live, started rattling merrily and I could see the disc once again in my network places.</p>
<p>It seemed that the hard disc wasn't at fault but the original LaCie Internet Sace casing. Go figure. Why the drive wasn't recognised by the usb/sata converter is beyond me. I'm copying 1 TB of data to my other NAS right now and I'm never buying anything from LaCie again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sentientbeings.com/2011/11/lacie-internet-space-no-longer-works/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Windows XP Raw Support for CR2</title>
		<link>http://www.sentientbeings.com/2010/06/windows-xp-raw-support-for-cr2/</link>
		<comments>http://www.sentientbeings.com/2010/06/windows-xp-raw-support-for-cr2/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 08:21:31 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://www.sentientbeings.com/?p=125</guid>
		<description><![CDATA[I thought I had tried about everything to get CR2 RAW support up and running in Windows XP. I installed the Canon Codec and tried to open the files with the regular Windows Fax and Picture viewer. FAIL! I installed Microsoft's Powertoy "Microsoft RAW Image Thumbnailer and Viewer for Windows XP" but that failed with [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I had tried about everything to get CR2 RAW support up and running in Windows XP. I installed the Canon Codec and tried to open the files with the regular Windows Fax and Picture viewer. FAIL!</p>
<p>I installed Microsoft's Powertoy "Microsoft RAW Image Thumbnailer and Viewer for Windows XP" but that failed with a "cannot load image" message. I was at wit's end. Until ...</p>
<p>Finally, I discovered that Microsoft's Live Photo Gallery that is part of Vista and Windows 7 and that does suppot CR2 RAW files was available for Windows XP. Download it here: <a href="http://download.live.com/photogallery">http://download.live.com/photogallery</a> and then uncheck all the vile software you don't need. Et voila, CR2 RAW support from your explorer in Windows XP.</p>
<p>Whew. That only took me about 2 hours to fix.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sentientbeings.com/2010/06/windows-xp-raw-support-for-cr2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Megcos 1182 Hacked</title>
		<link>http://www.sentientbeings.com/2009/01/megcos-1182-hacked/</link>
		<comments>http://www.sentientbeings.com/2009/01/megcos-1182-hacked/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 18:47:38 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Selfish]]></category>

		<guid isPermaLink="false">http://www.sentientbeings.com/?p=64</guid>
		<description><![CDATA[We have the all-new Megcos 1182 at home since we got it from my sister for Christmas. While it may not be the most technologically advanced musical cow, we were able to hack it with a mixture of luck and coincidence. DISCLAIMER: This hack can potentially harm your Megcos 1182. There is NO known reset [...]]]></description>
			<content:encoded><![CDATA[<p>We have the all-new Megcos 1182 at home since we got it from my sister for Christmas. While it may not be the most technologically advanced musical cow, we were able to hack it with a mixture of luck and coincidence.</p>
<p>DISCLAIMER: This hack can potentially harm your Megcos 1182. There is NO known reset procedure should anything go wrong. Hitting the Megcos 1182 HARD is your best bet in case anything goes wrong.</p>
<p>The Megcos 1882 or Musical Cow is able to produce a number of interesting sounds and songs. The nose will generate a "moo" sound and the bell will sound like a cowbell. The A button will sound like a sheep, the B button is reminiscent of a rooster and the C button will sound lilke Zorro's Tornado. The 1 button will make a cellphone-like sound, the 2 button will make you think you're in the London tube (that's the underground for US English afficionados) and the 3 button will make a ticking sound like only a clock can. Each of the A, B, C, 1, 2 and 3 buttons will also play a song. Each of these buttons will alternate between "sound" and "song". The songs themselves will rotate and are the same for all buttons. I can't name all of the songs, but there's 10 of them.</p>
<p>However! There are more possibilities. With a little bit of <del datetime="2009-01-11T18:29:46+00:00">playing around</del> delving into the User Interface, we were able to extract 12 more sounds! These sounds are the following.</p>
<ul>
<li>"A" and "Triangle";</li>
<li>"B" and "Square";</li>
<li>"C" and "Circle";</li>
<li>"1" and "Star";</li>
<li>"2" and "Heart";</li>
<li>"3" and "Hexagon".</li>
</ul>
<p>The way to actually reveal these hidden sounds is to actually slide the "on" button not all the way "on" (or not all the way "off"). Sliding it just far enough will result in the buttons producing the said 12 additional sounds. If you don't slide the button for enough, the normal sounds will continue to sound or you get cut-off versions of the 12 additional sounds.</p>
<p>Also: Hexagon? What 1-year old is going to even reproduce that? HEXAGON! LOLLERSK8Z!</p>
<p><img class="aligncenter size-full wp-image-66" title="koe_560" src="http://www.sentientbeings.com/wp-content/uploads/2009/01/koe_560.jpg" alt="koe_560" width="560" height="420" /></p>
<ul></ul>
]]></content:encoded>
			<wfw:commentRss>http://www.sentientbeings.com/2009/01/megcos-1182-hacked/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

