<?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>TechnoBlogy &#187; SQL Server</title>
	<atom:link href="http://technoblogy.net/category/db/sql-server/feed" rel="self" type="application/rss+xml" />
	<link>http://technoblogy.net</link>
	<description>Technology with a Big difference</description>
	<lastBuildDate>Thu, 09 Sep 2010 08:02:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Percentage of Work completed &#8211; SQL Server</title>
		<link>http://technoblogy.net/percentage-of-work-completed-sql-server/</link>
		<comments>http://technoblogy.net/percentage-of-work-completed-sql-server/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 16:27:06 +0000</pubDate>
		<dc:creator>Nauman</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[DMV]]></category>
		<category><![CDATA[percentage completed]]></category>
		<category><![CDATA[sys.dm_exec_requests]]></category>

		<guid isPermaLink="false">http://technoblogy.net/percentage-of-work-completed-sql-server/</guid>
		<description><![CDATA[Today, I was taking a manual backup of a database through a scheduled Job. Normally this backup job takes about 1 hour to complete, but today it was still executing for almost 3 hours. I started to look up Activity monitor, dbcc commands for any lock against the database, but of no avail. After searching [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I was taking a manual backup of a database through a scheduled Job. Normally this backup job takes about 1 hour to complete, but today it was still executing for almost 3 hours. I started to look up Activity monitor, dbcc commands for any lock against the database, but of no avail.</p>
<blockquote><p>After searching on internet i came across a DMV(Dynamic Management View) provided in SQL Server. This view has almost every detail of a single process executing in SQL Server.</p>
<p><strong>DMV &#8211; sys.dm_exec_requests</strong></p>
<p>Following script returned my desired result of percentage completed of my backup job:</p>
<p>SELECT Session_Id, Reads, Writes, Cpu_Time, Logical_Reads, Total_Elapsed_Time,</p>
<p>Blocking_Session_Id, Percent_Complete, Command,</p>
<p>(select text from sys.dm_exec_sql_text(sql_handle)) as Text FROM</p>
<p>sys.dm_exec_requests(nolock) WHERE session_id = 90</p></blockquote>
<p>Hope this helps.</p>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/btn/button_1305" title="Percentage of Work completed &ndash; SQL Server" url="http://technoblogy.net/percentage-of-work-completed-sql-server/"></script>]]></content:encoded>
			<wfw:commentRss>http://technoblogy.net/percentage-of-work-completed-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get indexes on all tables &#8211; SQL Server</title>
		<link>http://technoblogy.net/get-indexes-on-all-tables-sql-server/</link>
		<comments>http://technoblogy.net/get-indexes-on-all-tables-sql-server/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 16:14:03 +0000</pubDate>
		<dc:creator>Nauman</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[clustered]]></category>
		<category><![CDATA[Indexes]]></category>
		<category><![CDATA[non clustered]]></category>
		<category><![CDATA[tables]]></category>

		<guid isPermaLink="false">http://technoblogy.net/get-indexes-on-all-tables-sql-server/</guid>
		<description><![CDATA[An important ingredient in database designing is creating, maintaining and rebuilding indexes after some specified intervals. One main  aspect of database tuning is to apply indexes. Index must exist in databases otherwise their would be a lot of performance issues. While searching across internet, i came across a script that will list all the tables [...]]]></description>
			<content:encoded><![CDATA[<p>An important ingredient in database designing is creating, maintaining and rebuilding indexes after some specified intervals. One main  aspect of database tuning is to apply indexes. Index must exist in databases otherwise their would be a lot of performance issues.</p>
<p>While searching across internet, i came across a script that will list all the tables in my database and also show how many indexes are created/applied on those table wither clustered or non clustered.</p>
<p>Here’s the script:</p>
<blockquote><p>with cte as<br />
(<br />
select<br />
table_name = o.name,  �<br />
o.[object_id],<br />
i.index_id,<br />
i.type,<br />
i.type_desc<br />
from<br />
sys.indexes i<br />
inner join<br />
sys.objects o on i.[object_id] = o.[object_id]<br />
where<br />
o.type in (&#8216;U&#8217;)<br />
and<br />
o.is_ms_shipped = 0 and i.is_disabled = 0  and i.is_hypothetical = 0<br />
and<br />
i.type &lt;= 2<br />
), cte2 as<br />
(<br />
select<br />
*<br />
from<br />
cte c<br />
pivot<br />
(count(type) for type_desc in ([HEAP], [CLUSTERED], [NONCLUSTERED])) pv<br />
)<br />
select<br />
c2.table_name,<br />
[rows] = max(p.rows),<br />
is_heap = sum([HEAP]),<br />
is_clustered = sum([CLUSTERED]),<br />
num_of_nonclustered = sum([NONCLUSTERED])<br />
from<br />
cte2 c2<br />
inner join<br />
sys.partitions p on c2.[object_id] = p.[object_id] and c2.index_id = p.index_id<br />
group by<br />
table_name</p></blockquote>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/btn/button_1305" title="Get indexes on all tables &ndash; SQL Server" url="http://technoblogy.net/get-indexes-on-all-tables-sql-server/"></script>]]></content:encoded>
			<wfw:commentRss>http://technoblogy.net/get-indexes-on-all-tables-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrate from MySQL to SQL Server</title>
		<link>http://technoblogy.net/migrate-from-mysql-to-sql-server/</link>
		<comments>http://technoblogy.net/migrate-from-mysql-to-sql-server/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 15:35:40 +0000</pubDate>
		<dc:creator>Nauman</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://technoblogy.net/migrate-from-mysql-to-sql-server/</guid>
		<description><![CDATA[Migrate from MySQL to SQL Server with ease. Microsoft has launched a small utility to migrate a database from MySQL to SQL Server. Name of the utility is SQL Server Migration Assistant for MySQL. More details can be found here]]></description>
			<content:encoded><![CDATA[<p>Migrate from MySQL to SQL Server with ease. Microsoft has launched a small utility to migrate a database from MySQL to SQL Server. Name of the utility is SQL Server Migration Assistant for MySQL.</p>
<p>More details can be found <a href="http://blogs.technet.com/b/dataplatforminsider/archive/2010/08/12/microsoft-announces-sql-server-migration-assistant-for-mysql.aspx" target="_blank">here</a></p>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/btn/button_1305" title="Migrate from MySQL to SQL Server" url="http://technoblogy.net/migrate-from-mysql-to-sql-server/"></script>]]></content:encoded>
			<wfw:commentRss>http://technoblogy.net/migrate-from-mysql-to-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove a Stored Procedure in Production Environment</title>
		<link>http://technoblogy.net/remove-a-stored-procedure-in-production-environment/</link>
		<comments>http://technoblogy.net/remove-a-stored-procedure-in-production-environment/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 15:35:13 +0000</pubDate>
		<dc:creator>Nauman</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[production]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[stored procedure]]></category>
		<category><![CDATA[techniques]]></category>

		<guid isPermaLink="false">http://technoblogy.net/remove-a-stored-procedure-in-production-environment/</guid>
		<description><![CDATA[How to remove a Stored Procedure in SQL Server production environment? How can we be so sure that is not being used any more? You need to know every single path from where this procedure is initiating before you can actually remove it from production. Following are some ways to determine the usage of a [...]]]></description>
			<content:encoded><![CDATA[<p>How to remove a Stored Procedure in SQL Server production environment? How can we be so sure that is not being used any more?</p>
<p>You need to know every single path from where this procedure is initiating before you can actually remove it from production. Following are some ways to determine the usage of a procedure in SQL Server.</p>
<ol>
<li>Set up a trace and filter through SQL Server profiler service on procedure name and ID.</li>
<li>Another way is to regularly check procedure plan cache to see if there is a cached plan for the procedure.</li>
<li>Alternatively you can use a 3rd party audit software to retrieve procedure executions. (Most of these soft wares use tracing at the back end)\</li>
</ol>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/btn/button_1305" title="Remove a Stored Procedure in Production Environment" url="http://technoblogy.net/remove-a-stored-procedure-in-production-environment/"></script>]]></content:encoded>
			<wfw:commentRss>http://technoblogy.net/remove-a-stored-procedure-in-production-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieve permissions on SQL Server database</title>
		<link>http://technoblogy.net/retrieve-permissions-on-sql-server-database/</link>
		<comments>http://technoblogy.net/retrieve-permissions-on-sql-server-database/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 17:38:28 +0000</pubDate>
		<dc:creator>Nauman</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[permissions]]></category>

		<guid isPermaLink="false">http://technoblogy.net/retrieve-permissions-on-sql-server-database/</guid>
		<description><![CDATA[SQL Server permissions can be granted to on an object level (schema, database, database objects). In newer versions of SQL Server permissions can be given to user at a more granular level.]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>SQL Server permissions can be granted to on an object level (schema, database, database objects). In newer versions of SQL Server permissions can be given to user at a more granular level.</p>
<p>To retrieve all the permissions granted to a specific user SQL server has a function named: <strong>fn_my_permission.</strong>  This function is only accessible to system administrator. e.g</p>
<p>following query will retrieve all the permissions on server.</p>
<blockquote><p><em>select * From fn_my_permissions(NULL, NULL)  </em></p></blockquote>
<p>following query retrieve all the permissions on a database:</p>
<blockquote><p><em>select * From fn_my_permissions(NULL, ‘database’)</em></p></blockquote>
<p> </p>
<p>following query retrieve all the permissions on a dbo schema:</p>
<blockquote><p><em>select * From fn_my_permissions(’dbo’, ’schema’)</em></p></blockquote>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/btn/button_1305" title="Retrieve permissions on SQL Server database" url="http://technoblogy.net/retrieve-permissions-on-sql-server-database/"></script>]]></content:encoded>
			<wfw:commentRss>http://technoblogy.net/retrieve-permissions-on-sql-server-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Improve I/O performance for SQL Server</title>
		<link>http://technoblogy.net/how-to-improve-io-performance-for-sql-server/</link>
		<comments>http://technoblogy.net/how-to-improve-io-performance-for-sql-server/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 13:23:40 +0000</pubDate>
		<dc:creator>Nauman</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[I/O]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://technoblogy.net/how-to-improve-io-performance-for-sql-server/</guid>
		<description><![CDATA[  If underline I/O architecture system is working properly then every time SQL Server do some transaction (Read/Write) it can do it without waiting. But if load on the system is up, then SQL transaction have to wait for their turns for processing. This can significantly reduce SQL Server performance. There is a much greater [...]]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>If underline I/O architecture system is working properly then every time SQL Server do some transaction (Read/Write) it can do it without waiting. But if load on the system is up, then SQL transaction have to wait for their turns for processing. This can significantly reduce SQL Server performance. There is a much greater issue when you are not in charge of the underlying storage system. For that the main thing is to optimize the queries running by SQL Server.</p>
<p>Following are some tip to monitor and increase I/O performance of SQL Server.</p>
<p><strong>Queries using maximum I/O.</strong></p>
<p>This query will return top 25 queries that were the slowest in processing.</p>
<blockquote>
<pre><em>SELECT TOP 25
    q.[text],
    (total_logical_reads/execution_count) AS avg_logical_reads,
    (total_logical_writes/execution_count) AS avg_logical_writes,
    (total_physical_reads/execution_count) AS avg_phys_reads,
     Execution_count
FROM sys.dm_exec_query_stats
    cross apply sys.dm_exec_sql_text(plan_handle) AS q
ORDER BY
 (total_logical_reads + total_logical_writes) DESC</em></pre>
</blockquote>
<pre> </pre>
<p>Check which queries can be optimized and update them. Execute the above query frequently to check queries that can potentially create I/O bottleneck on system.</p>
<p><strong>Reading un necessary Data.</strong></p>
<p>When you are retrieving data, which is not going to be used than you are also overusing your I/O performance. One great example of this type of query is:</p>
<pre> </pre>
<pre>SELECT * FROM [Table]</pre>
<p> </p>
<p>Always retrieve only those columns that are going to be used. In cases where you want to get all the columns than specifically write all column names on your select clause.</p>
<p>Also use a WHERE clause where applicable because it will filter out rows that will not be used.</p>
<p><strong>Create Covered Indexes</strong></p>
<p>Once you have optimized your queries by using explicit column names and appropriate WHERE clause filtration of records, you can now focus on creating non-clustered covered index for the queries that have excessive read I/O. Covered indexes contain all columns as a part of index that are being used in SQL WHERE clause. You can also determine what columns are in need to be indexed by examining SQL execution plan of the query.</p>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/btn/button_1305" title="How to Improve I/O performance for SQL Server" url="http://technoblogy.net/how-to-improve-io-performance-for-sql-server/"></script>]]></content:encoded>
			<wfw:commentRss>http://technoblogy.net/how-to-improve-io-performance-for-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Import CSV file in SQL Server</title>
		<link>http://technoblogy.net/import-csv-file-in-sql-server/</link>
		<comments>http://technoblogy.net/import-csv-file-in-sql-server/#comments</comments>
		<pubDate>Fri, 28 May 2010 05:45:29 +0000</pubDate>
		<dc:creator>Nauman</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[bulk insert]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[import]]></category>

		<guid isPermaLink="false">http://technoblogy.net/?p=391</guid>
		<description><![CDATA[Importing a CSV(Comma Separated File) in SQL server is a very common task, and most of us use the Import /Export feature of SQL server to do this. Import/Export feature has SSIS (SQL Server Integration Services) as it backbone and works great with most of the Databases, file types etc. But today we are going [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://technoblogy.net/wp-content/uploads/2010/08/SQL-Server.png"></a>Importing a CSV(<strong>C</strong>omma <strong>S</strong>eparated <strong>F</strong>ile) in SQL server is a very common task, and most of us use the Import /Export feature of SQL server to do this. Import/Export feature has SSIS (SQL Server Integration Services) as it backbone and works great with most of the Databases, file types etc.</p>
<p>But today we are going to import a CSV file in SQL server through simple SQL queries. Following are the only two steps to follows for a loading a CSV file in SQL Server:</p>
<ul>
<li>Create a table, with all the columns you need to import from CSV file.</li>
<li>Next use Bulk Insert query to load all the data in SQL Server table create in step 1.</li>
</ul>
<p><strong>Example</strong></p>
<blockquote><p>CREATE TABLE CSV_LOAD</p>
<p>(</p>
<p>ID INT,</p>
<p>NAME VARCHAR(40),</p>
<p>CLASS VARCHAR(40)</p>
<p>)</p></blockquote>
<p>Our CSV file contains these values:</p>
<blockquote><p>1,NAUMAN,BSC</p>
<p>2,RIZWAN,MBA</p>
<p>3,FURQAN,A LEVELS</p></blockquote>
<p>Now the main part for Bulk Insert</p>
<blockquote><p>BULK INSERT CSV_LOAD</p>
<p>FROM &#8216;c:\csvload.csv&#8217;</p>
<p>WITH</p>
<p>(</p>
<p>FIELDTERMINATOR = &#8216;,&#8217;,</p>
<p>ROWTERMINATOR = &#8216;\n&#8217;</p>
<p>)</p></blockquote>
<p>Thats it.</p>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/btn/button_1305" title="Import CSV file in SQL Server" url="http://technoblogy.net/import-csv-file-in-sql-server/"></script>]]></content:encoded>
			<wfw:commentRss>http://technoblogy.net/import-csv-file-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>0x8002801D Library not Registered.. Cannot create any BI project.</title>
		<link>http://technoblogy.net/0x8002801d-library-not-registered-cannot-create-any-bi-project/</link>
		<comments>http://technoblogy.net/0x8002801d-library-not-registered-cannot-create-any-bi-project/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 16:50:06 +0000</pubDate>
		<dc:creator>Nauman</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[0x8002801D]]></category>
		<category><![CDATA[BI]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://technoblogy.net/0x8002801d-library-not-registered-cannot-create-any-bi-project/</guid>
		<description><![CDATA[  An annoying error coming up while creating any Business Intelligence project from SQL studio. Error says that it cannot open a specific temp file. I have deleted all my BI settings but not good enough for creation of a BI project. Reparing SQL server installation also did not work also. Cause: Some installation/uninstallation have [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://technoblogy.net/wp-content/uploads/2010/08/SQL-Server.png"></a> </p>
<p>An annoying error coming up while creating any Business Intelligence project from SQL studio. Error says that it cannot open a specific temp file. I have deleted all my BI settings but not good enough for creation of a BI project. Reparing SQL server installation also did not work also.</p>
<p><strong>Cause: </strong>Some installation/uninstallation have corrupted the msxml dll files and now it cannot read the temp files.</p>
<p><strong>Resolution: </strong>There is very useful utility packed with MS studio names “regsvr32”</p>
<p>In your visual studio command prompt type the following commands:</p>
<blockquote><p> </p>
<p>regsvr32 msxml6.dll<br />
regsvr32 msxml3.dll</p></blockquote>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/btn/button_1305" title="0x8002801D Library not Registered.. Cannot create any BI project." url="http://technoblogy.net/0x8002801d-library-not-registered-cannot-create-any-bi-project/"></script>]]></content:encoded>
			<wfw:commentRss>http://technoblogy.net/0x8002801d-library-not-registered-cannot-create-any-bi-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing Duplicates through SQL Query</title>
		<link>http://technoblogy.net/removing-duplicates-through-sql-query/</link>
		<comments>http://technoblogy.net/removing-duplicates-through-sql-query/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 16:49:52 +0000</pubDate>
		<dc:creator>Nauman</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[duplicate]]></category>
		<category><![CDATA[remove]]></category>

		<guid isPermaLink="false">http://technoblogy.net/removing-duplicates-through-sql-query/</guid>
		<description><![CDATA[Suppose we have a table in SQL Server, that has duplicates in it. CREATE TABLE T1 ( ProductName varchar(50) ) INSERT INTO T1 VALUES (&#8216;Computer&#8217;), (&#8216;Computer&#8217;), (&#8216;Printer&#8217;), (&#8216;Printer&#8217;), (&#8216;Printer&#8217;), (&#8216;Scanner&#8217;), (&#8216;Scanner&#8217;), (&#8216;Scanner&#8217;), (&#8216;Scanner&#8217;), (&#8216;Camera&#8217;), (&#8216;Flash Drive&#8217;), (&#8216;Flash Drive&#8217;) now use the following query, that will remove duplicates in the temporary table that we just created: [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://technoblogy.net/wp-content/uploads/2010/08/SQL-Server.png"></a>Suppose we have a table in SQL Server, that has duplicates in it.</p>
<blockquote><p>CREATE TABLE T1<br />
(<br />
ProductName varchar(50)<br />
)</p>
<p>INSERT INTO T1<br />
VALUES<br />
(&#8216;Computer&#8217;),<br />
(&#8216;Computer&#8217;),<br />
(&#8216;Printer&#8217;),<br />
(&#8216;Printer&#8217;),<br />
(&#8216;Printer&#8217;),<br />
(&#8216;Scanner&#8217;),<br />
(&#8216;Scanner&#8217;),<br />
(&#8216;Scanner&#8217;),<br />
(&#8216;Scanner&#8217;),<br />
(&#8216;Camera&#8217;),<br />
(&#8216;Flash Drive&#8217;),<br />
(&#8216;Flash Drive&#8217;)</p></blockquote>
<p>now use the following query, that will remove duplicates in the temporary table that we just created:</p>
<blockquote><p>DELETE D FROM<br />
(SELECT ProductName,ROW_NUMBER() OVER (ORDER BY ProductName ASC) AS ROWID  FROM T1 ) D,<br />
(SELECT ProductName,ROW_NUMBER() OVER (ORDER BY ProductName ASC) AS ROWID  FROM T1 ) E<br />
where D.ProductName = E.ProductName AND D.ROWID &lt; E.ROWID</p></blockquote>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/btn/button_1305" title="Removing Duplicates through SQL Query" url="http://technoblogy.net/removing-duplicates-through-sql-query/"></script>]]></content:encoded>
			<wfw:commentRss>http://technoblogy.net/removing-duplicates-through-sql-query/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SqlBulkCopy &#8211; Bulk Insertion in SQL Server from .NET</title>
		<link>http://technoblogy.net/sqlbulkcopy-bulk-insertion-in-sql-server-from-net/</link>
		<comments>http://technoblogy.net/sqlbulkcopy-bulk-insertion-in-sql-server-from-net/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 13:27:06 +0000</pubDate>
		<dc:creator>Nauman</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[bulk]]></category>
		<category><![CDATA[insertion]]></category>
		<category><![CDATA[sqlbulkcopy]]></category>

		<guid isPermaLink="false">http://technoblogy.net/sqlbulkcopy-bulk-insertion-in-sql-server-from-net/</guid>
		<description><![CDATA[Many a times there come a scenario when you have to insert large number of records in sql server. There are number of ways to implement this scenario: through looping techniques to call insert statements for one record at a time. Serialize the data in CSV or XML format and send them as a parameter [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://technoblogy.net/wp-content/uploads/2010/08/SQL-Server.png"></a><a href="http://technoblogy.net/wp-content/uploads/2010/08/VS2010Logo.png"></a>Many a times there come a scenario when you have to insert large number of records in sql server. There are number of ways to implement this scenario:</p>
<ul>
<li>through looping techniques to call insert statements for one record at a time.</li>
<li>Serialize the data in CSV or XML format and send them as a parameter to a stored procedure and then through parsing execute insertion statements.</li>
<li>generate a file and load them through a SSIS package.</li>
<li>Use SqlBulkCopy.</li>
</ul>
<p>SqlBulkCopy is way faster than multiple insert statements, serializing/ deserializing the data, or saving the data out to a file system and running an import.  Its also has no limit on the data you can send across and very efficient in the way it handles inserts.</p>
<p>This is how simple it is to use it. In the example we have a function that writes copies are DataTable into a MS SQL database table called “tblInsertion”.</p>
<blockquote><p>using System.Data.SqlClient;<br />
…</p>
<p>Function WriteToDB(DataTable dt)</p>
<p>{</p>
<blockquote><p>SqlBulkCopy sqlBC = new SqlBulkCopy(dbconnectionstring);</p>
<p>sqlBC.BatchSize = 25000;</p>
<p>sqlBC.BulkCopyTimeout = 60;</p>
<p>sqlBC.DestinationTableName = “dbo.tblFooBar” ;</p>
<p>sqlBC.WriteToServer(dt);</p></blockquote>
<p>}</p></blockquote>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/btn/button_1305" title="SqlBulkCopy &ndash; Bulk Insertion in SQL Server from .NET" url="http://technoblogy.net/sqlbulkcopy-bulk-insertion-in-sql-server-from-net/"></script>]]></content:encoded>
			<wfw:commentRss>http://technoblogy.net/sqlbulkcopy-bulk-insertion-in-sql-server-from-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
