<?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>I Learnt Today... &#187; SQL Server 2005</title>
	<atom:link href="http://www.ilearnttoday.com/category/information-technology/database/sql-server-2005/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ilearnttoday.com</link>
	<description>This is where I share what I learn day by day...</description>
	<lastBuildDate>Tue, 17 Jan 2012 12:44:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A stored procedure that can auto-genarate SQL queries using exec method</title>
		<link>http://www.ilearnttoday.com/dynamic-stored-procedure</link>
		<comments>http://www.ilearnttoday.com/dynamic-stored-procedure#comments</comments>
		<pubDate>Thu, 06 Oct 2011 13:11:45 +0000</pubDate>
		<dc:creator>Menol</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Menol]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[exec]]></category>
		<category><![CDATA[execute]]></category>
		<category><![CDATA[flexible dynamic stored procedure]]></category>
		<category><![CDATA[parameterize]]></category>

		<guid isPermaLink="false">http://www.ilearnttoday.com/?p=513</guid>
		<description><![CDATA[06-10-2011 Have you ever wanted to write a flexible and dynamic stored procedure that would allow you to send the table<a href="http://www.ilearnttoday.com/dynamic-stored-procedure" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p><span style="color: #c0c0c0;">06-10-2011</span><br />
<script type="text/javascript"><!--
google_ad_client = "ca-pub-5478118713208336";
/* LeadIn */
google_ad_slot = "2638602320";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Have you ever wanted to write a flexible and dynamic stored procedure that would allow you to send the table name as a parameter?</p>
<p>Have you ever wanted to write a flexible and dynamic stored procedure that would allow you to send only the condition but also the column name you want to include in the where clause?</p>
<p>Well I did. I wanted to create a stored procedure that would take Table name, Criteria column name  and the Target criteria value as parameters and create the SQL query dynamically.</p>
<p>Usually, we have to write our SQL code in the stored procedure body where we cannot treat our sql statement as a string.</p>
<p>The way to achieve this, however, is by using the Exec method provided in SQL.</p>
<p>Exec (execute) allows you to execute a command or a character string that contains Transact-SQL command(s).</p>
<p>Without wasting more time, following is the code I used to achieve my goal:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE PROCEDURE GetRowCountByStringColumn

@TableName nvarchar(50),
@CriteriaColumnName nvarchar(50),
@CriteriaValue nvarchar(150)
AS
BEGIN

EXEC('SELECT  Count(*) FROM ' + @TableName
+ ' WHERE ' + @CriteriaColumnName + ' = ''' + @CriteriaValue + '''')

END
GO
</pre>
<p>As you can see the procedure takes three arguments:</p>
<p>TableName<br />
CriteriaColumnName &#8211; the name of the column that should be checked in the where clause<br />
CriteriaValue &#8211; the value the Criteria Column Name should be checked against</p>
<p>The exec command creates the SQL command (at run time) and executes it.</p>
<p>This helped me to create many dynamic stored procedures for my current project and saved me from having to create stored procedures for each table.</p>
<p><span style="color: #008000;">Was this post helpful to you? How can I improve? – Your comment is highly appreciated!</span></p>
<p><span style="color: #c0c0c0;">Cassian Menol Razeek</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ilearnttoday.com/dynamic-stored-procedure/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to auto save the data table in memory into database?</title>
		<link>http://www.ilearnttoday.com/commandbinder</link>
		<comments>http://www.ilearnttoday.com/commandbinder#comments</comments>
		<pubDate>Tue, 04 Oct 2011 13:27:46 +0000</pubDate>
		<dc:creator>Menol</dc:creator>
				<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Auto update]]></category>
		<category><![CDATA[Command Binder]]></category>
		<category><![CDATA[CommandBinder]]></category>
		<category><![CDATA[Data adaptor]]></category>
		<category><![CDATA[data table]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[synchronize]]></category>

		<guid isPermaLink="false">http://www.ilearnttoday.com/?p=479</guid>
		<description><![CDATA[2010-04-01 We frequently get to fetch data from the database, update them and then write them back to the database. Most of<a href="http://www.ilearnttoday.com/commandbinder" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p><span style="color: #c0c0c0;">2010-04-</span><span style="color: #c0c0c0;">01</span></p>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "ca-pub-5478118713208336";
/* LeadIn */
google_ad_slot = "2638602320";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<p>We frequently get to fetch data from the database, update them and then write them back to the database.</p>
<p>Most of the time we only have to write them back as individual records.</p>
<p>How about updating a whole database table in the memory and having to synchronize all changes to the actual data table?</p>
<p>My initial thought was this would be full of complex coding. However, thanks to Microsoft, there&#8217;s nothing much to be done at all.</p>
<p>So how are we gonna do this is&#8230;</p>
<p>We will use a data adaptor to fill our data table as usual.</p>
<p>The only new thing is the use of a Command Binder.</p>
<p>Command Binder: A command binder is capable to detect changes that have occurred to a table (in the memory) and then automatically generate appropriate SQL statements to save those changes into the actual data table (in the database).</p>
<p>Following is a simple example: Scenario: In my application I had to take a database table name and present data in a data grid and then save all changes made by the user.</p>
<p>What we need: a data table an adaptor a connection a command builder I have defined them at the form level so I can use them across the form from different events.</p>
<pre class="brush: csharp; title: ; notranslate">
private DataTable _tbl;

private SqlDataAdapter _adptr;

private SqlConnection _conn;

private SqlCommandBuilder _cbldr;
</pre>
<p>Step1: Initialize connection and retrieve data from the database</p>
<pre class="brush: csharp; title: ; notranslate">
_tbl = new DataTable();
_conn = FetchData.GetOpenConnection();
_adptr = new SqlDataAdapter(&quot;Select * from &quot; + DatabaseTableName, _conn);
_cbldr = new SqlCommandBuilder(_adptr);
_adptr.Fill(_tbl);
</pre>
<p>Step2: Let the user to change data (in here simply bind the table to a grid)</p>
<pre class="brush: csharp; title: ; notranslate">
dgMainGrid.DataSource = _tbl;
</pre>
<p>Step3: Save (synchronize) changes to the actual database table Even though this is a complex process and undoubtedly would take a lot of effort to do manually, Thanks to .net framework all we need is a line of code.</p>
<pre class="brush: csharp; title: ; notranslate">
_adptr.Update(_tbl);
</pre>
<p>Once you call the adaptor to update the table, it will use the command builder attached to it to generate all necessary SQL command building. The database table is now up-to-date!</p>
<p><span style="color: #008000;">Was this post helpful to you? How can I improve? – Your comment is highly appreciated!</span></p>
<p><span style="color: #c0c0c0;">Cassian Menol Razeek</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ilearnttoday.com/commandbinder/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>D LINQ : How to Map Columns Which Auto Generate Values At the Database</title>
		<link>http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database</link>
		<comments>http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database#comments</comments>
		<pubDate>Mon, 11 May 2009 17:37:17 +0000</pubDate>
		<dc:creator>Menol</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Menol]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.NET exception]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[auto-generate]]></category>
		<category><![CDATA[Cannot insert explicit value for identity column in table 'tbl_Process' when IDENTITY_INSERT is set to OFF]]></category>
		<category><![CDATA[DLINQ]]></category>
		<category><![CDATA[IDENTITY_INSERT]]></category>
		<category><![CDATA[IsDbGenerated]]></category>
		<category><![CDATA[IsDbGenerated:=True]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[primary key]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server exception]]></category>
		<category><![CDATA[Windows Application]]></category>

		<guid isPermaLink="false">http://www.ilearnttoday.com/?p=390</guid>
		<description><![CDATA[2009-05-11 I have being working on a software application made on .Net and recently my client asked me to use<a href="http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><!--[endif]--><span style="color: silver;">2009-05-11</span></p>
<p><script type="text/javascript"><!--
google_ad_client = "ca-pub-5478118713208336";
/* LeadIn */
google_ad_slot = "2638602320";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p style="text-align: justify;">I have being working on a software application made on .Net and recently my client asked me to use D LINQ instead of SQL.</p>
<p style="text-align: justify;">D LINQ has great benefits loaded! As I started working with DLINQ I started to know that preventing SQL injection is not a headache anymore and misspelled SQL queries will not trouble agian at run time because DLINQ generates all necessary SQL inside the framework!</p>
<p style="text-align: justify;">I chose to use annotations inside the class instead of using separate xml file. Following is a part of the first class I ported to D LINQ.</p>
<p style="text-align: justify;">
<pre class="brush: vb; title: ; notranslate">&lt;/p&gt;
_
Public Class Process
_
Public ProcessID As Integer
_
Public BusinessProcessID As String
_
Public ProcessText As String
...
...
</pre>
<p style="text-align: justify;">ProcessID column is the primary key of my database table tbl_Process.</p>
<p style="text-align: justify;">Important Point: I use database to auto-generate values for the primary key column (integer value incremented by one).</p>
<p style="text-align: justify;">So when I run the application, It gave me this unexpected error:</p>
<p style="text-align: justify;"><strong><em>Cannot insert explicit value for identity column in table &#8216;tbl_Process&#8217; when IDENTITY_INSERT is set to OFF.</em></strong></p>
<p style="text-align: justify;">Basically, the <strong><em>IDENTITY_INSERT</em></strong> when using the database to auto generate value for a field but when I ran a SQL insert statement at the database end it worked fine!</p>
<p style="text-align: justify;">After some tough time I found out the solution for this problem!</p>
<p style="text-align: justify;">When we use an auto-generate field in a data table we have to specifically mention it in the matching field in the appropriate class.</p>
<p style="text-align: justify;">The code to state this is:</p>
<p style="text-align: justify;"><em>Syntax:</em></p>
<p style="text-align: justify;"><strong><em>IsDbGenerated:=True</em></strong></p>
<p style="text-align: justify;">This has to be added to the annotation added for the specific column like:</p>
<p style="text-align: justify;">
<pre class="brush: vb; title: ; notranslate">&lt;/p&gt;
_
Public ProcessID As Integer
</pre>
<p style="text-align: justify;">Now D LINQ can understand that the field value is auto-generated by the database!</p>
<p style="text-align: justify;"><span style="color: green;">Was this post helpful to you? How can I improve? &#8211; Your comment is highly appreciated!</span></p>
<p style="text-align: justify;"><span style="color: silver;">Cassian Menol Razeek</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to (Full and Transaction Log) backup and restore a database in Microsoft SQL Server 2005</title>
		<link>http://www.ilearnttoday.com/backup-a-database-in-sql-server-2005</link>
		<comments>http://www.ilearnttoday.com/backup-a-database-in-sql-server-2005#comments</comments>
		<pubDate>Thu, 04 Dec 2008 05:22:12 +0000</pubDate>
		<dc:creator>Menol</dc:creator>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Full Backup]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Menol]]></category>
		<category><![CDATA[Restore]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[Transaction Log Backup]]></category>
		<category><![CDATA[Complete manual on SQL Server backup and restore]]></category>
		<category><![CDATA[download manual]]></category>
		<category><![CDATA[recover data]]></category>
		<category><![CDATA[recover transactions]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tail log]]></category>
		<category><![CDATA[Tail log backup]]></category>
		<category><![CDATA[Transaction Log]]></category>

		<guid isPermaLink="false">http://ilearnttoday.wordpress.com/?p=31</guid>
		<description><![CDATA[2008-12-04 In this article I will discus how to backup a database as a FULL backup or with Transaction Log<a href="http://www.ilearnttoday.com/backup-a-database-in-sql-server-2005" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p><span style="color:#c0c0c0;">2</span><span style="color:#c0c0c0;">008-12-04<br />
</span></p>
<p><span style="color:#c0c0c0;"><span style="color:#000000;">In this article I will discus how to backup a database as a FULL backup or with Transaction Log (Tail Log) backup and how to restore the database, how to recover transactions made after you taking the backup, etc.</span></span></p>
<p><span style="color:#c0c0c0;"><span style="color:#000000;">Since it is not easy to use and organize images in the post itself I have uploaded a compiled pdf file of this article.</span></span></p>
<p><span style="color:#c0c0c0;"><span style="color:#000000;">Please download the complete manual from following link:</span></span></p>
<p><span style="color:#c0c0c0;"><span style="color:#000000;"><span style="color:#99cc00;"><a href="http://ilearnttoday.files.wordpress.com/2008/12/how-to-backup-and-restore-a-database-in-microsoft-sql-server-2005.pdf" target="_blank"><span class="wp-caption">How to backup and restore a database in Microsoft SQL Server 2005</span></a></span><br />
</span></span></p>
<p><span style="color:#008000;">Was this post helpful to you? How can I improve? &#8211; <span style="color:#008000;">Your comment is highly appreciated!</span></span></p>
<p><span style="color:#c0c0c0;">Cassian Menol Razeek</span><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ilearnttoday.com/backup-a-database-in-sql-server-2005/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

