<?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:blogger='http://schemas.google.com/blogger/2008' 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-2588235033302682131</id><updated>2024-09-07T18:06:07.734+02:00</updated><title type='text'>NetDevHelp</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://netdevhelp.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2588235033302682131/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://netdevhelp.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Joe Carnish</name><uri>http://www.blogger.com/profile/05941441374978011609</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2588235033302682131.post-5600702884499889682</id><published>2010-11-20T20:29:00.000+01:00</published><updated>2010-11-20T20:28:56.804+01:00</updated><title type='text'>Shrink SQL Server Database</title><content type='html'>&lt;!-- Converted from text/rtf format --&gt;  &lt;P ALIGN=LEFT&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;B&gt;&lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;Background&lt;/FONT&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;  &lt;P ALIGN=LEFT&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;Database tend to grow in size the more you use them even if the amount of data&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt; &lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;stored stays the same. This is mainly due to transaction log size constantly increasing. Also database engine tends to reserve more space for a database than it is in the given moment&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt; &lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;necessary. All this extra storage space can be retrieved which is especially useful in the event of sending the database files&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt; to some external device for backup purposes or such.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt; &lt;/SPAN&gt;&lt;/P&gt;  &lt;P ALIGN=LEFT&gt;&lt;B&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;Solution&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;B&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;  &lt;P ALIGN=LEFT&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;The commands to shrink the database that I&#39;ve found most&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt; &lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;useful&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt; &lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;are:&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;/SPAN&gt;&lt;/P&gt;  &lt;P ALIGN=LEFT&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt; &lt;FONT SIZE=2 FACE=&quot;Courier New&quot;&gt;BACKUP LOG&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;I&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;I&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt; &lt;FONT SIZE=2 FACE=&quot;Courier New&quot;&gt;database_name&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;FONT SIZE=2 FACE=&quot;Courier New&quot;&gt; WITH TRUNCATE_ONLY&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;  &lt;P ALIGN=LEFT&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt; &lt;FONT SIZE=2 FACE=&quot;Courier New&quot;&gt;DBCC SHRINKDATABASE (&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;I&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;I&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;FONT SIZE=2 FACE=&quot;Courier New&quot;&gt;database_name&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;FONT SIZE=2 FACE=&quot;Courier New&quot;&gt;)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;/SPAN&gt;&lt;/P&gt;  &lt;P ALIGN=LEFT&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;The&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;I&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;I&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;I&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt; &lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;database_name&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt; in the above commands needs to be replaced with the actual database name.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;/SPAN&gt;&lt;/P&gt;  &lt;P ALIGN=LEFT&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;You can also try the shrink database commands available in the SQL Server Management studio UI.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt; &lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;However they not always&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt; &lt;FONT SIZE=2 FACE=&quot;Arial&quot;&gt;succeed to free as much space as it is technically possible.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;pl&quot;&gt;&lt;/SPAN&gt;&lt;SPAN LANG=&quot;en-us&quot;&gt;&lt;/SPAN&gt;&lt;/P&gt;  </content><link rel='replies' type='application/atom+xml' href='http://netdevhelp.blogspot.com/feeds/5600702884499889682/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://netdevhelp.blogspot.com/2010/11/shrink-sql-server-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2588235033302682131/posts/default/5600702884499889682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2588235033302682131/posts/default/5600702884499889682'/><link rel='alternate' type='text/html' href='http://netdevhelp.blogspot.com/2010/11/shrink-sql-server-database.html' title='Shrink SQL Server Database'/><author><name>Joe Carnish</name><uri>http://www.blogger.com/profile/05941441374978011609</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2588235033302682131.post-3677230638728218227</id><published>2010-11-20T19:21:00.001+01:00</published><updated>2010-11-20T20:32:16.216+01:00</updated><title type='text'>Insert values into identity column in SQL Server</title><content type='html'>&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;b&gt;Background&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Identity column with auto increment in SQL Server data table does not allow for overriding its value. While in most cases it is the desired&amp;nbsp;behavior&amp;nbsp;sometimes there is a&amp;nbsp;necessity&amp;nbsp;to do things differently. For example while copying data from your development database to the production you may want to make sure all the IDs are exactly the same in both sets.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;b&gt;Solution&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;To enable&amp;nbsp;overriding identity column it is required to run following command before executing the overriding script:&lt;/div&gt;&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;SET IDENTITY_INSERT &lt;i&gt;table_name &lt;/i&gt;ON&lt;/span&gt;&lt;/blockquote&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;You will need to replace &lt;i&gt;table_name &lt;/i&gt;with the actual table name you want the identity insert enabled on.&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;After executing your command you may want to switch back to original settings, which you can achieve running:&lt;/div&gt;&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;SET IDENTITY_INSERT&amp;nbsp;&lt;i&gt;table_name&amp;nbsp;&lt;/i&gt;OFF&lt;/span&gt;&lt;/blockquote&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;To&amp;nbsp;summarize, the whole SQL query overriding identity column should have following structure:&amp;nbsp;&lt;/div&gt;&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;SET IDENTITY_INSERT&amp;nbsp;&lt;i&gt;table_name&amp;nbsp;&lt;/i&gt;ON&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;UPDATE&amp;nbsp;table_name&amp;nbsp;SET&lt;/span&gt; ... &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #6aa84f;&quot;&gt;--here goes your query&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;SET IDENTITY_INSERT&amp;nbsp;&lt;i&gt;table_name&amp;nbsp;&lt;/i&gt;OFF&lt;/span&gt;&lt;/blockquote&gt;</content><link rel='replies' type='application/atom+xml' href='http://netdevhelp.blogspot.com/feeds/3677230638728218227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://netdevhelp.blogspot.com/2010/11/insert-values-into-identity-column-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2588235033302682131/posts/default/3677230638728218227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2588235033302682131/posts/default/3677230638728218227'/><link rel='alternate' type='text/html' href='http://netdevhelp.blogspot.com/2010/11/insert-values-into-identity-column-in.html' title='Insert values into identity column in SQL Server'/><author><name>Joe Carnish</name><uri>http://www.blogger.com/profile/05941441374978011609</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2588235033302682131.post-5324433711637114271</id><published>2010-11-20T18:57:00.000+01:00</published><updated>2010-11-20T18:57:45.263+01:00</updated><title type='text'>Reset identity column index in SQL Server</title><content type='html'>&lt;b&gt;Background&lt;/b&gt;&lt;br /&gt;
When you set a column in your SQL table to auto increment every inserted record will have a value of this column one number higher than the previous one - which is what we want in general. However even after you delete some or all of the records in the table the next inserted record will not have the next-higher-free-ID. It will be one higher than the last inserted one. Reseting this index is fortunately very easy and requires firing single command of a format:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution&lt;/b&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;DBCC CHECKIDENT (&#39;table_name&#39;, RESEED, 0)&lt;/span&gt;&lt;/blockquote&gt;Where &lt;i&gt;table_name&lt;/i&gt; is the name of the table you want to reset the auto increment ID on. The above command will reset the seed to the original value &#39;0&#39;. So the next inserted record will have the ID equal 1. Though you can replace the last parameter with a different number if you wish the numbering to start from a different position.</content><link rel='replies' type='application/atom+xml' href='http://netdevhelp.blogspot.com/feeds/5324433711637114271/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://netdevhelp.blogspot.com/2010/11/reset-identity-column-index-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2588235033302682131/posts/default/5324433711637114271'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2588235033302682131/posts/default/5324433711637114271'/><link rel='alternate' type='text/html' href='http://netdevhelp.blogspot.com/2010/11/reset-identity-column-index-in-sql.html' title='Reset identity column index in SQL Server'/><author><name>Joe Carnish</name><uri>http://www.blogger.com/profile/05941441374978011609</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>