<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2281334126300451608</id><updated>2012-01-12T00:43:05.504-08:00</updated><category term='Personal'/><category term='Backup and Restore'/><category term='Transaction Logs'/><category term='My Events'/><category term='Trigger'/><category term='Replication'/><category term='Locks'/><category term='XML'/><category term='Data Warehouse'/><category term='Storage'/><category term='Run Dynamic SQL'/><category term='Cursor'/><category term='Security'/><category term='Sequence'/><category term='Programming'/><category term='Maintenance'/><title type='text'>John Huang's Blog on SQL Server and .Net</title><subtitle type='html'>We moved to http://www.sqlnotes.info</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>54</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-7872277929286585059</id><published>2011-09-30T15:51:00.000-07:00</published><updated>2011-09-30T15:59:10.824-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Personal'/><title type='text'>Home, Home, Sweeter New Home</title><summary type='text'>Please visit my new home @ http://www.sqlnotes.info.</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/7872277929286585059/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=7872277929286585059' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7872277929286585059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7872277929286585059'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2011/09/home-home-sweeter-new-home.html' title='Home, Home, Sweeter New Home'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-5943081611343751166</id><published>2011-09-23T10:42:00.000-07:00</published><updated>2011-09-23T11:03:31.947-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='My Events'/><title type='text'>Upcoming Event -- SQL Saturday 92 @ Portland Oct 8th</title><summary type='text'>I am going to have a presentation on "Multi-threading TSQL" in Portland Oct 8th, http://www.sqlsaturday.com/92/eventhome.aspx. This session will tell you how to use pure T-SQL to implement parallel SQL processing with complex ordering, such as how to start 2 threads at beginning, synchrinoze them then start another n threads for the next bunch of SQL processes without having any physically </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/5943081611343751166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=5943081611343751166' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5943081611343751166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5943081611343751166'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2011/09/upcoming-event-sql-saturday-92-portland.html' title='Upcoming Event -- SQL Saturday 92 @ Portland Oct 8th'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-6163750428925875715</id><published>2010-05-05T00:20:00.001-07:00</published><updated>2010-05-09T21:48:55.858-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Transaction Logs'/><title type='text'>SQL Server Transaction Logs</title><summary type='text'>Transaction log is a very important component in SQL Server to keep transaction durable even in an event of system failure. It's generated while a modification taking place in most of data pages in the memory that eventually being written into data files within a database. Inserting, deleting and updating DML operations will generate transaction logs. DDL operations, such as alter table, create </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/6163750428925875715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=6163750428925875715' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6163750428925875715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6163750428925875715'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2010/05/sql-server-transaction-logs.html' title='SQL Server Transaction Logs'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-5895642613103069528</id><published>2009-12-17T23:31:00.001-08:00</published><updated>2009-12-17T23:31:38.548-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming'/><title type='text'>Evaluating a Boolean Expression</title><summary type='text'>When you write a boolean expression, @a = @b or @a/@b = 2, do you think the all the part of express get evaluated by SQL Server. let's have a test below:declare @a int = 1, @b int = 0print 'if @a = @b + 1 or @a/@b = 2'if @a = @b + 1 or @a/@b = 2       print 'No Error'print 'if @a/@b = 2 or @a = @b + 1'if @a/@b = 2 or @a = @b + 1      print '	Error'goThis test illustrates that while SQL Server is </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/5895642613103069528/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=5895642613103069528' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5895642613103069528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5895642613103069528'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/12/evaluating-boolean-expression.html' title='Evaluating a Boolean Expression'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-3634076914007453275</id><published>2009-12-16T17:21:00.001-08:00</published><updated>2009-12-16T17:26:12.195-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming'/><title type='text'>Merge Statement</title><summary type='text'>Merge statement was introduced by Microsoft in SQL Server 2005. It allows user to merge one table to another combining different ways of operation, inserting, deleting and updating,  on the targeting table based upon the condition specified in the merge statement.When Matched: It means when the record in the source table and target table matched by key. In this case, you have option of, update </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/3634076914007453275/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=3634076914007453275' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/3634076914007453275'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/3634076914007453275'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/12/merge-statement.html' title='Merge Statement'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-2576966919869692900</id><published>2009-10-23T23:45:00.001-07:00</published><updated>2009-10-24T00:08:42.524-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Accessing Invisible Tables</title><summary type='text'>In SQL Server, there are two kinds of tables are invisible. One is system protected tables, for instance, sys.sysrscols. You could access them by using Dedicated Administrator Connection (DAC) to connection to the server.Enable DAC: exec sp_configure 'remote admin connections', 1 reconfigureConnect using DAC: specify ADMIN:ServerName in connection string, then you can run select * from </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/2576966919869692900/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=2576966919869692900' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/2576966919869692900'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/2576966919869692900'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/10/accessing-invisible-tables.html' title='Accessing Invisible Tables'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-3571531205901199179</id><published>2009-09-18T22:34:00.001-07:00</published><updated>2009-09-18T22:41:42.751-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sequence'/><title type='text'>Implement Sequence in SQL Server (3)</title><summary type='text'>In my previous post, I introduced supporting procedures and functions of Sequence. In this article, I will post one example for performance testing and another two for generating set of numbers. print '------use temporary table------'if OBJECT_ID('tempdb..#1') is not null drop table #1gocreate table #1(id int identity(1,1) primary key)set nocount ondeclare @i int, @d datetime2(3)select @i = 0, @d</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/3571531205901199179/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=3571531205901199179' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/3571531205901199179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/3571531205901199179'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/09/implement-sequence-in-sql-server-3.html' title='Implement Sequence in SQL Server (3)'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-7964639290842855345</id><published>2009-09-15T00:55:00.001-07:00</published><updated>2009-09-15T01:09:39.173-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming'/><title type='text'>Setup Procedure to Run Automatically When SQL Server Starts</title><summary type='text'>That's simple, setup a job and run the procedure and schedule it runs when SQL Server agent started. See the problem here? My title is "when SQL Server Start", not "When SQL Server Agent". SQL Server can start without agent. Procedure in SQL Server can be started automatically when SQL Server starts. In order to do that, you have to set "scan for startup procs" through sp_configure function, and </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/7964639290842855345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=7964639290842855345' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7964639290842855345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7964639290842855345'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/09/setup-procedure-to-run-automatically.html' title='Setup Procedure to Run Automatically When SQL Server Starts'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-2918646283906126977</id><published>2009-09-15T00:10:00.001-07:00</published><updated>2009-09-15T01:03:49.187-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sequence'/><title type='text'>Implement Sequence in SQL Server (2)</title><summary type='text'>In previous article, I explained the way using identity to implement Sequence object. I also gave the source code of my CLR Sequence which can also be downloaded here. As a continuation of this series, in this article, I will explain how to install Sequence object in SQL Server and how to use it.Download the source code and decompress it.Run &lt;&lt;Sequence\SQL Code\Create Tables.sql&gt;&gt; to create </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/2918646283906126977/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=2918646283906126977' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/2918646283906126977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/2918646283906126977'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/09/implement-sequence-in-sql-server-2.html' title='Implement Sequence in SQL Server (2)'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-7547740873799060643</id><published>2009-09-12T23:45:00.001-07:00</published><updated>2009-09-14T22:48:03.356-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sequence'/><title type='text'>Implement Sequence in SQL Server (1)</title><summary type='text'>Sequence is a type of object in Oracle for generating sequential number. A sequence can be seen from all sessions. Sequence is not transactional. Calling NextVal function to a sequence will always give you a new number. It is a very common use in Oracle to create one sequence object for one table object and use the value coming from it as table's primary key. The counterpart of Oracle sequence in</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/7547740873799060643/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=7547740873799060643' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7547740873799060643'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7547740873799060643'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/09/implementing-sequence-in-sql-server-1.html' title='Implement Sequence in SQL Server (1)'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-6765758274716774108</id><published>2009-08-31T17:45:00.001-07:00</published><updated>2009-09-08T19:52:32.789-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Run Dynamic SQL'/><title type='text'>Run Dynamic T-SQL from a Function with Data Change</title><summary type='text'>This is today's topic – Run Dynamic T-SQL from a function which allows data modification…wait a second…in this post, a point has been laid out  that "You can NOT do any data modifications within a function". Is the rule changed? Answer is no. Microsoft hasn't made any promise yet to make a function to be able to update tables. How can it be implemented? In my experiment, I use SQL CLR to make </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/6765758274716774108/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=6765758274716774108' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6765758274716774108'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6765758274716774108'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/run-dynamic-t-sql-from-function-with.html' title='Run Dynamic T-SQL from a Function with Data Change'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-286053643991113622</id><published>2009-08-27T17:51:00.001-07:00</published><updated>2009-08-27T17:54:04.550-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Locks'/><title type='text'>Restrict Connections for a Process</title><summary type='text'>Application lock in SQL Server is very powerful as I mentioned in my previous post here and here. If you have a process, many clients are calling it, and you want to restrict only 10 requests can be processed simultaneously, other requests wait until any of the running requests finish. How do you do it? – haha, you got it, use application lock! I will have an example to explain who it works. </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/286053643991113622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=286053643991113622' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/286053643991113622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/286053643991113622'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/restrict-connections-for-process.html' title='Restrict Connections for a Process'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-7068594595599242108</id><published>2009-08-16T23:37:00.001-07:00</published><updated>2009-08-16T23:42:25.820-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Backup and Restore'/><title type='text'>Backup and Recovery</title><summary type='text'>In a SQL Server database, whenever a modification happens, there are always 2 operations taking place which are log recording to the log file and data modification to the data file. So a database can be backed up in 2 ways –data backup and log backup. Data backup looks at all data files in database, moves data in the data files to the backup file then copy the logs which could make the data to be</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/7068594595599242108/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=7068594595599242108' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7068594595599242108'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7068594595599242108'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/backup-and-recovery.html' title='Backup and Recovery'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-6269360491895674131</id><published>2009-08-14T00:21:00.001-07:00</published><updated>2009-08-14T00:24:57.012-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming'/><title type='text'>Declare a Variable in a Loop</title><summary type='text'>When a new T-SQL variable is declared, null value will be assigned to it. What if I declare a variable within the loop? Will it be initialized every time when it's being declared? Let's have a test.set nocount onif object_id('tempdb..#1') is not null drop table #1gocreate table #1 (id int primary key, name varchar(10))insert into #1 values(1,'a')insert into #1 values(3,'b')insert into #1 values(4</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/6269360491895674131/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=6269360491895674131' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6269360491895674131'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6269360491895674131'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/declare-variable-in-loop.html' title='Declare a Variable in a Loop'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-3560815557389243094</id><published>2009-08-13T23:58:00.001-07:00</published><updated>2009-08-14T00:04:23.532-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Maintenance'/><title type='text'>Repair a Database with Status Suspect</title><summary type='text'>One of my SQL Server 2000, which hosts a 200GB+ database, was dead today due to the RAID failure. The log shows information below. one of the log:SQL Server has encountered 1 occurrence(s) of IO requests taking longer than 15 seconds to complete on file [d:\Microsoft SQL Server\MSSQL\data\blabla.MDF] in database [blabla] (7).  The OS file handle is 0x00000400.  The offset of the latest long IO is</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/3560815557389243094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=3560815557389243094' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/3560815557389243094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/3560815557389243094'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/repair-database-with-status-suspect.html' title='Repair a Database with Status Suspect'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-9197121651774788581</id><published>2009-08-13T00:23:00.001-07:00</published><updated>2009-08-13T00:33:01.706-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Backup and Restore'/><title type='text'>Full Backup and Restore</title><summary type='text'>Any database systems have chance to suffer from severe system failure and hence causes database corruption, for instance, memory failure, hard drive failure, power failure and so on. Once the database gets corrupted, it's almost hopeless to recover it without backup. So it's very important to backup the databases for any database systems. There are two big categories in backup world – cold backup</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/9197121651774788581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=9197121651774788581' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/9197121651774788581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/9197121651774788581'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/full-backup-and-restore.html' title='Full Backup and Restore'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-2576045600951759306</id><published>2009-08-12T14:34:00.001-07:00</published><updated>2009-08-12T14:37:20.874-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming'/><title type='text'>Generating Random Password by a T-SQL Procedure</title><summary type='text'>For generating a complex password, we should not only get random value from the set of the characters but also guarantee the combination of upper case, lower case, numbers and special characters. In the procedure below, the password generated will include all 4 parts.if object_id('GeneratePassword') is not null drop procedure GeneratePasswordgocreate procedure GeneratePassword(@length int)asbegin</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/2576045600951759306/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=2576045600951759306' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/2576045600951759306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/2576045600951759306'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/generating-random-password-by-t-sql.html' title='Generating Random Password by a T-SQL Procedure'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-5650491115740162372</id><published>2009-08-07T14:42:00.001-07:00</published><updated>2009-08-07T14:45:57.399-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><title type='text'>References Permission</title><summary type='text'>While you are assigning permissions to a table through user interface, permission "Refereneces" could be assigned. That's that for? Answer is if a table has References permission assigned to a user, the user can create a Foreign Key reference to all  the "referencable" column(s) to this table even though he has no access to it. This permission could be assigned to column level as well, this means</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/5650491115740162372/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=5650491115740162372' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5650491115740162372'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5650491115740162372'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/references-permission.html' title='References Permission'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-7593914652591085312</id><published>2009-08-07T09:05:00.001-07:00</published><updated>2009-08-07T09:10:12.782-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming'/><title type='text'>Printing Message to Client without Waiting</title><summary type='text'>While I am writing SQL code, I often use print command to send message to the client application for information. One thing I noticed that this command could not return the message to client immediately due to performance concern over the network. Please see the code below.declare @i intselect @i = 0while @i&lt;5begin print @i select @i = @i + 1 waitfor delay '00:00:01'endIn this example, the code </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/7593914652591085312/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=7593914652591085312' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7593914652591085312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7593914652591085312'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/printing-message-to-client-without.html' title='Printing Message to Client without Waiting'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-2773344283369090107</id><published>2009-08-05T17:37:00.001-07:00</published><updated>2009-09-08T19:01:47.686-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Replication'/><category scheme='http://www.blogger.com/atom/ns#' term='Trigger'/><title type='text'>Bypass Merge Replication Triggers</title><summary type='text'>One of my projects is to replicate tables from central office to Point Of Sales system at branches using merge replication for a financial institution. The customer information is replicated to the branches where the customer has been to. When customer goes to a new location, the new location does not have customer's information so the branch staff has to download them from head office. The </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/2773344283369090107/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=2773344283369090107' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/2773344283369090107'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/2773344283369090107'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/bypass-merge-replication-triggers.html' title='Bypass Merge Replication Triggers'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-2361802272767081144</id><published>2009-08-05T16:51:00.001-07:00</published><updated>2009-08-05T16:52:30.841-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Replication'/><title type='text'>Distinguish Records Entered by Replication</title><summary type='text'>When you write a trigger you may have thought to handle the business on the records shipped by replication differently than the records entered by front-end application. How do you distinguish them? There is a simple way you could do it – check the session property with value "replication_agent", this value is 1 when the DML is issued by replication agent, it is 0 when DML is issued by any </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/2361802272767081144/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=2361802272767081144' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/2361802272767081144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/2361802272767081144'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/distinguish-records-entered-by.html' title='Distinguish Records Entered by Replication'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-1099566917210904036</id><published>2009-08-04T16:33:00.001-07:00</published><updated>2009-08-04T16:46:28.357-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><title type='text'>Generate Formatted Text Through XML Functions</title><summary type='text'>I play around xml functions those days and find out an easy way to aggregate string field(s), generate CSVs and fixed length files. This is not a newer topic over the internet, see an example here. The tricks are concatenate field with comma, and then use for xml path clause to generate xml file and finally use value() to convert the content to string for un-escaping the characters like "&lt;", "&gt;",</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/1099566917210904036/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=1099566917210904036' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/1099566917210904036'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/1099566917210904036'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/generate-formatted-text-through-xml.html' title='Generate Formatted Text Through XML Functions'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-6085105160899722383</id><published>2009-08-01T10:50:00.001-07:00</published><updated>2009-08-01T10:54:06.956-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cursor'/><title type='text'>Cursor (6) – Fetch Multiple Rows at a Time</title><summary type='text'>I have talked about many the properties of a cursor in this series; you may already figure out that T-SQL fetch only supports fetching one record at a time. If you want to have fetch to retrieve more than one record at a time, you will have to use API cursor.  You could get more information at here about API cursor.  See the demo below.use AdventureWorksset nocount ongodeclare @handle int exec </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/6085105160899722383/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=6085105160899722383' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6085105160899722383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6085105160899722383'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/08/cursor-6-fetch-multiple-rows-at-time.html' title='Cursor (6) – Fetch Multiple Rows at a Time'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-7507192573258500741</id><published>2009-07-25T22:34:00.001-07:00</published><updated>2009-07-25T22:36:59.025-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Why Truncating Table (2)</title><summary type='text'>This is a continuation of my prior post. Last time, I compared results from truncating and deleting table. According to the log records, we could clearly see that deleting table goes to every data page and marks every record to be deleted. As we know, while modifying data on a page, the page is read to the memory by buffer manager; database engine modifies the page in the memory and then buffer </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/7507192573258500741/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=7507192573258500741' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7507192573258500741'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7507192573258500741'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/why-truncating-table-2.html' title='Why Truncating Table (2)'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-4311292353900390939</id><published>2009-07-24T15:34:00.001-07:00</published><updated>2009-07-24T16:07:06.662-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Trigger'/><title type='text'>Two ways to Pass “Parameters” to Triggers</title><summary type='text'>Triggers are the codes behind the views and tables (or system for the DDL triggers). It is always being executed as long as the data manipulation statement, insert, delete and update, applied to the table except it's been disabled. In some cases, trigger logic can be applied to the most of circumstances but in some particular condition, you want the same trigger behave differently. There are </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/4311292353900390939/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=4311292353900390939' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/4311292353900390939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/4311292353900390939'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/two-ways-to-passing-parameters-to.html' title='Two ways to Pass “Parameters” to Triggers'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-4997123355908117605</id><published>2009-07-22T13:44:00.001-07:00</published><updated>2009-07-22T13:45:53.847-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Why Truncating Table</title><summary type='text'>There are many differences between truncating table and deleting table.  Truncating table cannot have "where" clause; it reseed the identity column if any; the truncating operation is logged as one operation; whereas deleting table can have "where" clause; it does not reseed the identity column and it log every delete and when a table is big, it will become problematic.  I would not be surprised </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/4997123355908117605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=4997123355908117605' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/4997123355908117605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/4997123355908117605'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/why-truncating-table.html' title='Why Truncating Table'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-7980112498670822481</id><published>2009-07-17T16:30:00.001-07:00</published><updated>2009-07-17T16:43:03.684-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Locks'/><title type='text'>Another Example of SQL Server Application Lock</title><summary type='text'>I have talked about using application lock in previous post -- ensuring a block of code being entered once at a time. I want to give another example of use of application locks. Let's say, you have a process (or many process) running, proc1, they are complicated and not running within a transaction. This process might also be fired up by multiple sessions. Let's say you have another process, </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/7980112498670822481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=7980112498670822481' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7980112498670822481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7980112498670822481'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/another-example-of-sql-server.html' title='Another Example of SQL Server Application Lock'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-6554635262396952598</id><published>2009-07-16T13:20:00.001-07:00</published><updated>2009-07-16T13:27:31.486-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Locks'/><title type='text'>How to Make a Block of SQL Code Enter Once at a Time</title><summary type='text'>As a multi-threading application, SQL Server accepts multiple connections and allows them to run same or different SQL statements simultaneously especially in multi-CPU environment. SQL Server implements lock mechanism to prevent resource from being modified while other processes are not expecting it to be modified, i.e. while one process is modifying one row, if another process wants to modify </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/6554635262396952598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=6554635262396952598' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6554635262396952598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6554635262396952598'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/how-to-make-block-of-sql-code-enter.html' title='How to Make a Block of SQL Code Enter Once at a Time'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-8587113140902815360</id><published>2009-07-14T17:53:00.001-07:00</published><updated>2009-07-14T17:55:44.727-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cursor'/><title type='text'>Cursor (5) – Concurrency</title><summary type='text'>Continue on yesterday's topic, I am going to talk about cursor's concurrency. There are 2 concurrency modes SQL Server cursor provides – "SCROLL_LOCKS" and "OPTIMISTIC". If you don't specified any one of those options, the optimistic is selected automatically which is also called default.  These 2 options could not be applied to read only cursors which include static cursor, cursor with read only</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/8587113140902815360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=8587113140902815360' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/8587113140902815360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/8587113140902815360'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/cursor-5-concurrency.html' title='Cursor (5) – Concurrency'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-9080185766328731574</id><published>2009-07-13T23:55:00.001-07:00</published><updated>2009-07-14T00:04:29.559-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cursor'/><title type='text'>Cursor (4) – Other Properties</title><summary type='text'>I have talked about how to manipulate a cursor and Cursor's storage, let's have a glance on other properties of SQL Server cursor. A static cursor is also called insensitive cursor, which was the name a static cursor being called before having static key word. While opening a static cursor, it grabs all the records to the tempdb as I mentioned in my prior post so that there will be a big or small</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/9080185766328731574/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=9080185766328731574' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/9080185766328731574'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/9080185766328731574'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/cursor-4-other-properties.html' title='Cursor (4) – Other Properties'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-6674786497199902130</id><published>2009-07-11T17:34:00.001-07:00</published><updated>2009-07-11T17:35:07.320-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Personal'/><title type='text'>Microsoft Certified Master – SQL Server 2008</title><summary type='text'>It was my hardest time this year; I attended the training of Microsoft Certified Master – SQL Server 2008 in a rainy season – the middle of March 2009. When I was guided to the small room that I booked in HomeStead, which was the closest hotel to the classroom, I felt I was stepping into a different world as I knew I would have totally different life with those 3 weeks. As everyone knows that </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/6674786497199902130/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=6674786497199902130' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6674786497199902130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6674786497199902130'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/microsoft-certified-master-sql-server.html' title='Microsoft Certified Master – SQL Server 2008'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-5661134062683936516</id><published>2009-07-10T23:55:00.001-07:00</published><updated>2009-09-08T19:06:51.612-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Run Dynamic SQL'/><title type='text'>Implement Multi-threaded T-SQL Application</title><summary type='text'>In addition to Capture Multiple Result Sets within T-SQL Statement, combining this CLR procedure, which could also be downloaded here, and Service Broker together, you could very easily implement multi-threaded T-SQL application.  The goal of it is when you run a dynamic SQL; you can get return immediately without waiting SQL statement to be finished. The session calling this dynamic SQL will not</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/5661134062683936516/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=5661134062683936516' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5661134062683936516'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5661134062683936516'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/implement-multi-threaded-t-sql.html' title='Implement Multi-threaded T-SQL Application'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-4969820165768697104</id><published>2009-07-08T22:26:00.001-07:00</published><updated>2009-07-08T22:37:46.838-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cursor'/><title type='text'>Cursor (3) – Cursor Type</title><summary type='text'>Continue on last post, now we know how to operate a cursor, open, close and fetch. If you are asked to write a C# application to iterate records read from database. How do you do it? There are many approaches you could do it. The most common one is to read all rows from database to you C# application and then build a loop to go through every record. In this way, whatever changes to the set of </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/4969820165768697104/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=4969820165768697104' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/4969820165768697104'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/4969820165768697104'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/cursor-3-cursor-type.html' title='Cursor (3) – Cursor Type'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-8168153894187349645</id><published>2009-07-08T15:20:00.001-07:00</published><updated>2009-07-08T15:24:01.819-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Replication'/><title type='text'>Resume Inactive Transactional Replication Agent in SQL Server 2000</title><summary type='text'>I am creating transactional replication from a production server which is a SQL Server 2000 server acting as a publisher in one city to a development server which is a SQL Server 2008 server working as subscriber in another city. There are about few thousand kilometers between those 2 cities.  The network speed is not so fast about 1mbps. The initial snapshot is about 50 GB. I compressed it in to</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/8168153894187349645/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=8168153894187349645' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/8168153894187349645'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/8168153894187349645'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/resume-inactive-transactional.html' title='Resume Inactive Transactional Replication Agent in SQL Server 2000'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-8585049053535539549</id><published>2009-07-07T22:42:00.001-07:00</published><updated>2009-07-07T23:30:05.370-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cursor'/><title type='text'>Cursor (2) – Operating a Cursor</title><summary type='text'>Before getting into this topic, let's recap some cursor commands from last post and talk few more commands.Command DescriptionDeclare CursorDefine a cursor. The cursor structure will be created, including cursor columns definitions and cursor meta-data.Open CursorOpen a cursor so that data could be retrieved from it. When this statement runs, the SQL specified in Declare Cursor will be </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/8585049053535539549/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=8585049053535539549' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/8585049053535539549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/8585049053535539549'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/cursor-2-operating-cursor.html' title='Cursor (2) – Operating a Cursor'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-1607659477256809598</id><published>2009-07-06T22:52:00.001-07:00</published><updated>2009-07-07T21:19:25.543-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Cursor'/><title type='text'>Cursor (1) – How to Use Cursor</title><summary type='text'>Cursor is a built-in mechanism that SQL Server provides to access a set of records which can be a return set from a table, query, and even a stored procedure. Before using a cursor, the cursor has to be defined with a unique name in a scope, it then could be opened. Once the cursor gets opened against a set of rows, T-SQL code can use fetch command to retrieve one row at a time and put it into a </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/1607659477256809598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=1607659477256809598' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/1607659477256809598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/1607659477256809598'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/cursor-1-how-to-use-cursor.html' title='Cursor (1) – How to Use Cursor'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-9132603112071684630</id><published>2009-07-05T18:24:00.001-07:00</published><updated>2009-07-05T18:51:49.788-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Allocating Pages in a Table</title><summary type='text'>Now, I have finished explanation of all the page types in SQL Server. What will be happening in SQL Server when a table is created and a record is entered? When a table created, SQL Server only create the table meta data in system tables without allocating any space and IAM pages for that table(you will see both root page and IAM page in system internal allocation table). When the first record is</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/9132603112071684630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=9132603112071684630' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/9132603112071684630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/9132603112071684630'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/allocating-pages-in-table.html' title='Allocating Pages in a Table'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-1668758482466062530</id><published>2009-07-05T16:10:00.001-07:00</published><updated>2009-07-05T16:31:04.398-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Storage Internal (7) IAM</title><summary type='text'>I have been lazy those days. After finishing few articles for the topic other than Storage Internal, I would like to go back to this topic little bit more. As a continuation of last post, Storage Internal (6) Other Pages, this article is about IAM – Index Allocation Map. As the name of the page, it's is an allocation map for an "index". In SQL Server, the term index including almost everything – </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/1668758482466062530/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=1668758482466062530' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/1668758482466062530'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/1668758482466062530'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/storage-internal-7-iam.html' title='Storage Internal (7) IAM'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-4586295785230061792</id><published>2009-07-04T00:11:00.001-07:00</published><updated>2009-07-04T00:11:47.667-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data Warehouse'/><title type='text'>Capture Data Changes to Data Warehouse</title><summary type='text'>Currently I am working on a data warehouse project. We have to bring relatively big amount of data from operational database to data warehouse initially and do incremental process frequently afterwards. The data in the operational database is rather volatile. We could not just go back few months and then re-process it due to limited time window. In order to mitigate the load on the operational </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/4586295785230061792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=4586295785230061792' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/4586295785230061792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/4586295785230061792'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/capture-data-changes-to-data-warehouse.html' title='Capture Data Changes to Data Warehouse'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-3368250123075546839</id><published>2009-07-02T23:15:00.001-07:00</published><updated>2009-09-08T19:05:53.561-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Run Dynamic SQL'/><title type='text'>Capture Multiple Result Sets within T-SQL Statement</title><summary type='text'>As I mentioned in my last blog, I am going to give you some examples of using CLRRemoteExecute procedure.  Before the example, let me wrap it up and make it easy of use. In this example I set show detail message on. We can see how the script to be run. create procedure dbo.Ex( @Server varchar(128),  @Database varchar(128), @SQL varchar(max), @ConnectionTimeout int = 30, @CommandTimeout int = 3600</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/3368250123075546839/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=3368250123075546839' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/3368250123075546839'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/3368250123075546839'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/07/capture-multiple-result-sets-within-t.html' title='Capture Multiple Result Sets within T-SQL Statement'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-512261633182184966</id><published>2009-06-30T23:54:00.001-07:00</published><updated>2009-09-08T19:52:51.545-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Run Dynamic SQL'/><title type='text'>Run Your SQL Differently (2)</title><summary type='text'>This is a continuation of previous post. Once you explicitly begin a distributed transaction, user transaction will be enlisted in the MSDTC anyways. There is almost no way to get around that except calling a CLR procedure. I wrote this CLR procedure and figured out that it brings in more features exceed my expectations. Let's see what will be involved in writing a CLR to run a SQL statement </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/512261633182184966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=512261633182184966' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/512261633182184966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/512261633182184966'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/run-your-sql-differently-2.html' title='Run Your SQL Differently (2)'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-5907070613293960259</id><published>2009-06-29T23:30:00.001-07:00</published><updated>2009-09-08T19:03:17.350-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Run Dynamic SQL'/><title type='text'>Run Your SQL Differently (1)</title><summary type='text'>There are a lot of ways you could run a SQL Statement for example Exec() and sp_executesql. If you want to run SQL Statement on a remote server or access data from a remote server, there are many options linkedServer.Database.Schema.sp_executesql, OpenQuery, OpenRowset, OpenDataSource. All mechanisms that SQL Server provided are good; however, you are not able to run a statement with the its own </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/5907070613293960259/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=5907070613293960259' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5907070613293960259'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5907070613293960259'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/run-your-sql-differently-1.html' title='Run Your SQL Differently (1)'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-5967418137700133481</id><published>2009-06-28T19:57:00.001-07:00</published><updated>2009-06-29T02:37:02.966-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Storage Internal (6) Other Pages</title><summary type='text'>The page 4 and 5 that following the first SGAM page, are not used. Page 6 is Differential Changed Map page; page type is 16. It is a bit map that indicates that which extents have been changed since last full backup. Some extents are always marked changed even after a full back, for instance the extent at page 0. The interval of DCM is same as GAM and SGAM. The page address of DCM is always the </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/5967418137700133481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=5967418137700133481' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5967418137700133481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5967418137700133481'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/storage-internal-6-other-pages.html' title='Storage Internal (6) Other Pages'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-7042497636545672815</id><published>2009-06-26T22:21:00.001-07:00</published><updated>2009-06-27T14:13:09.577-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Storage Internal (5) GAM and SGAM</title><summary type='text'>As I mentioned before, the fist page, page 0 in a data file is File Header Page, and the second page, page 1 is PFS page. Now, let's have a glance on next 2 pages, the third page – GAM, Global Allocation Map, page type 8 and the fourth page – SGAM, Shared Global Allocation Map, page type 9. Just as PFS page, GAM and SGAM are used to keep track of state of allocation as well, however, they track </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/7042497636545672815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=7042497636545672815' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7042497636545672815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7042497636545672815'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/storage-internal-5-gam-and-sgam.html' title='Storage Internal (5) GAM and SGAM'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-740451746607435141</id><published>2009-06-26T00:31:00.001-07:00</published><updated>2009-07-11T17:35:31.277-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Personal'/><title type='text'>Code Formatting</title><summary type='text'>I had a very hard time to format the code in my blog. At first, I just copy /paste the code from SQL Server management studio to my Microsoft Word application and then post the blog. I thought it was perfect. I really appreciated the work that the SQL Team and Office programmers have done. However, My blog just looked horrible due to the truncation of the html code from Blogger. After using </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/740451746607435141/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=740451746607435141' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/740451746607435141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/740451746607435141'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/code-formatting.html' title='Code Formatting'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-6437303781687561036</id><published>2009-06-25T23:15:00.001-07:00</published><updated>2009-06-26T00:11:41.935-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Storage Internal (4) Page Free Space</title><summary type='text'>Continue on previous post File Header Page. PFS, Page Free Space, page type 11, consists of an 8088 byte byte-map mainly keeping track of the free space on data file pages. Every byte in this page indicates allocation status of a page. Every PFS page can manage 8088 pages. Each data file is conceptually split into PFS intervals of approximately 64M, starting with page zero in the file. The first </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/6437303781687561036/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=6437303781687561036' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6437303781687561036'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6437303781687561036'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/storage-internal-4-page-free-space.html' title='Storage Internal (4) Page Free Space'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-1335021756808607412</id><published>2009-06-24T22:08:00.001-07:00</published><updated>2009-06-25T10:43:17.338-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Security'/><title type='text'>Transparent Data Encryption</title><summary type='text'>Transparent Data Encryption is a new feature introduced in SQL Server 2008. It is designed for protecting the data on the media such as drives, backups, and tapes from being stolen or being attached / restored on un-trusted servers. It provides the ability to comply with laws, standards, and regulations and so on. However, it could not protect the server from being stolen.Let me borrow the </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/1335021756808607412/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=1335021756808607412' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/1335021756808607412'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/1335021756808607412'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/transparent-data-encryption.html' title='Transparent Data Encryption'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-6063078234599087370</id><published>2009-06-22T22:14:00.001-07:00</published><updated>2009-06-22T22:18:46.931-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Storage Internal (3) - File Header Page</title><summary type='text'>File Header Page is page 0 on every data page (row page) in a database. (I will only focus on data page now. In the later post, I will talk about the logs). It records information about the file, backup status, formatting size, encryption information and so on. Now, let's dump page 0 and have a closer look. (As too many fields I don't know and could not find any articles about it from internet, I</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/6063078234599087370/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=6063078234599087370' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6063078234599087370'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6063078234599087370'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/storage-internal-3-file-header-page.html' title='Storage Internal (3) - File Header Page'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-104814889365008750</id><published>2009-06-22T00:07:00.001-07:00</published><updated>2009-06-22T00:17:48.666-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Storage Internal (2) – Page Structure (2)</title><summary type='text'>Continue on last post, Page Structure (1). A page includes a 96 byte header. What is in it? Before answer this question, I would like to introduce a DBCC command DBCC Page. This command can help print the content of a page.dbcc page ( {'dbname' | dbid}, filenum, pagenum [, printopt={0|1|2|3} ]) [ WITH TABLERESULTS ]{'dbname' | dbid}:Database Name or Database ID.  – Database id can be retrieved by</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/104814889365008750/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=104814889365008750' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/104814889365008750'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/104814889365008750'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/storage-internal-2-page-structure-2_22.html' title='Storage Internal (2) – Page Structure (2)'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-6740936658661856961</id><published>2009-06-21T12:28:00.001-07:00</published><updated>2009-06-21T22:26:17.417-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Storage Internal (2) – Page Structure (1)</title><summary type='text'>In last post of this topic, Storage Internal (1) -- Page and Extent, I talked about the basic concept of page and extent.  In this post, I will focus on the structure of a page. There are different types of pages in SQL Server. No matter what types of pages are, the layout of the page is the same. A data file consists of numbers of 8k-pages. A Page includes 8192 bytes. First 96 bytes are used for</summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/6740936658661856961/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=6740936658661856961' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6740936658661856961'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6740936658661856961'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/storage-internal-2-page-structure-1_21.html' title='Storage Internal (2) – Page Structure (1)'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-7247869587755163836</id><published>2009-06-18T22:02:00.001-07:00</published><updated>2009-09-08T19:52:51.545-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Run Dynamic SQL'/><title type='text'>Run dynamic T-SQL statement from a function</title><summary type='text'>  Are you able to run dynamic SQL from a T-SQL function? Answer is no. Let’s have a quick test.  create function dbo.ExecDynamicSQLTest()  returns int  as  begin        exec('print 1')        return 1  end  go  Msg 443, Level 16, State 14, Procedure ExecDynamicSQLTest, Line 5  Invalid use of a side-effecting operator 'EXECUTE STRING' within a function.  Ok,  let’s have another try then  create </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/7247869587755163836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=7247869587755163836' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7247869587755163836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/7247869587755163836'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/run-dynamic-t-sql-statement-from.html' title='Run dynamic T-SQL statement from a function'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-6606697042553713954</id><published>2009-06-17T22:20:00.001-07:00</published><updated>2009-06-17T22:37:16.144-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Storage Internal (1) -- Page and Extent</title><summary type='text'>  In previous posts, I talked about Database file groups and files. From now on I am going to spend some time to describe storage internal. The first question you may ask is why I need to know internal structures. Well,  it helps to understand the storage engine, troubleshoot problems and make decisions. So, what is in the file and how the data is organized in each database files? This is not a </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/6606697042553713954/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=6606697042553713954' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6606697042553713954'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/6606697042553713954'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/storage-internal1-page-and-extent.html' title='Storage Internal (1) -- Page and Extent'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-822917176204510468</id><published>2009-06-16T23:25:00.001-07:00</published><updated>2009-06-16T23:31:07.873-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming'/><title type='text'>Convert comma separated text to table structure</title><summary type='text'>  I have worked with many customers who need to exchange information between systems. Some of them use csv file as the media for the data exchanging. Usually when we design the system, for auditing purpose, we always save the original message either in the file system or in a table after it’s been parsed and processed. There are many approaches converting a csv file to a table, for instance, BCP </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/822917176204510468/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=822917176204510468' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/822917176204510468'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/822917176204510468'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/convert-comma-separated-text-to-table.html' title='Convert comma separated text to table structure'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2281334126300451608.post-5524194390125584384</id><published>2009-06-15T22:28:00.000-07:00</published><updated>2009-06-17T20:06:15.015-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Storage'/><title type='text'>Database file groups and files</title><summary type='text'>  An SQL Server instance can host maximum 32,768 databases. Every database in a server can have up to 32,767 operating-system files. The maximum size of each file is 16TB. (Click here for more detail). Database files cannot be shared among databases, however, if all the files of a database are set to be read-only by OS, the database can be attached to same or different database names in the same </summary><link rel='replies' type='application/atom+xml' href='http://sqlx.blogspot.com/feeds/5524194390125584384/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2281334126300451608&amp;postID=5524194390125584384' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5524194390125584384'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2281334126300451608/posts/default/5524194390125584384'/><link rel='alternate' type='text/html' href='http://sqlx.blogspot.com/2009/06/database-file-groups-and-files_15.html' title='Database file groups and files'/><author><name>John Huang</name><uri>http://www.blogger.com/profile/16066297837586983950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>
