Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

SQL

SQL Server - Rebuild indexes

1
2
3
4
5
6
select 'ALTER INDEX ['+i.name+'] ON '+ s.name+'.['+ o.name + '] REBUILD WITH (FILLFACTOR ='+ (CASE WHEN i.type=1 THEN '100' ELSE '80' END)  +');'
from sys.indexes i
inner join sys.objects o on i.object_id = o.object_id
inner join sys.schemas s on o.schema_id = s.schema_id
where o.type='u'
order by i.type
https://snipt.net/embed/64bb9f43b05e1307b325908813828a56/
https://snipt.net/raw/64bb9f43b05e1307b325908813828a56/
64bb9f43b05e1307b325908813828a56
sql
SQL
6
2016-12-06T15:18:20
True
False
False
Feb 20, 2014 at 06:59 AM
/api/public/snipt/115422/
sql-server-rebuild-indexes
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">select</span> <span class="s1">&#39;ALTER INDEX [&#39;</span><span class="o">+</span><span class="n">i</span><span class="p">.</span><span class="n">name</span><span class="o">+</span><span class="s1">&#39;] ON &#39;</span><span class="o">+</span> <span class="n">s</span><span class="p">.</span><span class="n">name</span><span class="o">+</span><span class="s1">&#39;.[&#39;</span><span class="o">+</span> <span class="n">o</span><span class="p">.</span><span class="n">name</span> <span class="o">+</span> <span class="s1">&#39;] REBUILD WITH (FILLFACTOR =&#39;</span><span class="o">+</span> <span class="p">(</span><span class="k">CASE</span> <span class="k">WHEN</span> <span class="n">i</span><span class="p">.</span><span class="k">type</span><span class="o">=</span><span class="mi">1</span> <span class="k">THEN</span> <span class="s1">&#39;100&#39;</span> <span class="k">ELSE</span> <span class="s1">&#39;80&#39;</span> <span class="k">END</span><span class="p">)</span> <span class="o">+</span><span class="s1">&#39;);&#39;</span> </span><span id="L-2"><a name="L-2"></a><span class="k">from</span> <span class="n">sys</span><span class="p">.</span><span class="n">indexes</span> <span class="n">i</span> </span><span id="L-3"><a name="L-3"></a><span class="k">inner</span> <span class="k">join</span> <span class="n">sys</span><span class="p">.</span><span class="n">objects</span> <span class="n">o</span> <span class="k">on</span> <span class="n">i</span><span class="p">.</span><span class="n">object_id</span> <span class="o">=</span> <span class="n">o</span><span class="p">.</span><span class="n">object_id</span> </span><span id="L-4"><a name="L-4"></a><span class="k">inner</span> <span class="k">join</span> <span class="n">sys</span><span class="p">.</span><span class="n">schemas</span> <span class="n">s</span> <span class="k">on</span> <span class="n">o</span><span class="p">.</span><span class="n">schema_id</span> <span class="o">=</span> <span class="n">s</span><span class="p">.</span><span class="n">schema_id</span> </span><span id="L-5"><a name="L-5"></a><span class="k">where</span> <span class="n">o</span><span class="p">.</span><span class="k">type</span><span class="o">=</span><span class="s1">&#39;u&#39;</span> </span><span id="L-6"><a name="L-6"></a><span class="k">order</span> <span class="k">by</span> <span class="n">i</span><span class="p">.</span><span class="k">type</span> </span></pre></div> </td></tr></table>
INDEXES, SQL

SQL

ADD Days To Date and Compare to current Date

AND DATE_ADD(date(lastUpdated),INTERVAL 5 DAY) >= CURDATE();
https://snipt.net/embed/0d9e8ddaef6004d7d4b29c08945fb289/
https://snipt.net/raw/0d9e8ddaef6004d7d4b29c08945fb289/
0d9e8ddaef6004d7d4b29c08945fb289
sql
SQL
1
2016-12-06T15:20:04
True
False
False
/api/public/snipt/103411/
add-days-to-date-and-compare-to-current-date
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">AND</span> <span class="n">DATE_ADD</span><span class="p">(</span><span class="nb">date</span><span class="p">(</span><span class="n">lastUpdated</span><span class="p">),</span><span class="nb">INTERVAL</span> <span class="mi">5</span> <span class="k">DAY</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="n">CURDATE</span><span class="p">();</span> </span></pre></div> </td></tr></table>
ADD-DAYS, CURDATE, SQL
Copyrighted, illegal, or inappropriate content? Email [email protected].