<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Le Blog SQL Server d&#039;ElSüket &#187; Utilitaires</title>
	<atom:link href="https://blog.developpez.com/elsuket/pcategory/utilitaires/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/elsuket</link>
	<description>Nicolas Souquet - Expert SQL Server</description>
	<lastBuildDate>Mon, 05 Apr 2021 07:32:41 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>A la recherche du SQL Server 2017 Configuration Manager perdu</title>
		<link>https://blog.developpez.com/elsuket/p13154/utilitaires/a-la-recherche-du-sql-server-2017-configuration-manager-perdu</link>
		<comments>https://blog.developpez.com/elsuket/p13154/utilitaires/a-la-recherche-du-sql-server-2017-configuration-manager-perdu#comments</comments>
		<pubDate>Sun, 22 Oct 2017 17:45:37 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1511</guid>
		<description><![CDATA[La console dédiée à la configuration de l&#8217;ensemble des services de SQL Server ne voit pas un raccourci être ajouté dans le menu démarrer (en tout cas sous Windows 8.1 et Windows 10). Voici comment créer le raccourci : Il &#8230; <a href="https://blog.developpez.com/elsuket/p13154/utilitaires/a-la-recherche-du-sql-server-2017-configuration-manager-perdu">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La console dédiée à la configuration de l&rsquo;ensemble des services de SQL Server ne voit pas un raccourci être ajouté dans le menu démarrer (en tout cas sous Windows 8.1 et Windows 10).</p>
<p>Voici comment créer le raccourci :<br />
<span id="more-1511"></span></p>
<p>Il suffit de créer un nouveau raccourci, et d&rsquo;y coller la ligne suivante, pour SQL Server 2017 :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">C:\Windows\SysWOW64\mmc.exe /32 C:\WINDOWS\SysWOW64\SQLServerManager14.msc</div></td></tr></tbody></table></div>
<p>Pour les versions antécédantes de SQL Server, il suffit de changer le numéro dans SQLServerManager14.msc par celui de la version qui convient :</p>
<ul>
<li>pour SQL Server 2012, c&rsquo;est SQLServerManager11.msc</li>
<li>pour SQL Server 2014, c&rsquo;est SQLServerManager12.msc</li>
<li>pour SQL Server 2016, c&rsquo;est SQLServerManager13.msc</li>
</ul>
<p>Bonne configuration à tous !</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redémarrer la trace par défaut</title>
		<link>https://blog.developpez.com/elsuket/p13143/snippets/redemarrer-la-trace-par-defaut</link>
		<comments>https://blog.developpez.com/elsuket/p13143/snippets/redemarrer-la-trace-par-defaut#comments</comments>
		<pubDate>Thu, 02 Mar 2017 08:00:02 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1377</guid>
		<description><![CDATA[SQL Server fournit de nombreux outils de monitoring d&#8217;arrière-plan par défaut, comme le journal SQL Server, la session d&#8217;événements étendus system_health, mais aussi une trace SQL Profiler. Cette dernière est enregistrée dans un fichier dans le répertoire des journaux, et &#8230; <a href="https://blog.developpez.com/elsuket/p13143/snippets/redemarrer-la-trace-par-defaut">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SQL Server fournit de nombreux outils de monitoring d&rsquo;arrière-plan par défaut, comme le journal SQL Server, la session d&rsquo;événements étendus <em>system_health</em>, mais aussi une trace <em>SQL Profiler</em>. Cette dernière est enregistrée dans un fichier dans le répertoire des journaux, et SQL Server conserve 6 fichiers de cette trace.</p>
<p>Elle capture, entre autres, les événements d&rsquo;échec d&rsquo;authentification, la création d&rsquo;objets dans TempDB, les warnings sur Hash et Sort, les grossissements de fichiers, et de nombreux autres événements. Ceux-ci peuvent aider à comprendre, a posteriori, ce qui a causé une grande consommation de CPU, des latences disque, &#8230;</p>
<p>Comme cette trace est écrite sur disque, il peut malencontreusement arriver que ce dernier devienne plein, provoquant alors l&rsquo;arrêt automatique et forcé de la trace. Ce léger incident (l&rsquo;arrêt de la trace, pas l&rsquo;absence d&rsquo;espace disque libre !) n&rsquo;empêche aucunement l&rsquo;instance de fonctionner, ou au moins d&rsquo;être accessible. Cependant, comment peut-on redémarrer cette trace sans redémarrer l&rsquo;instance SQL Server ?</p>
<p><span id="more-1377"></span></p>
<p>En effet, la documentation nous indique que la trace par défaut n&rsquo;est démarrée que lorsque l&rsquo;instance démarre aussi &#8230; nous allons voir que c&rsquo;est incomplet. Une fois le disque supportant la trace disposant à nouveau d&rsquo;espace disque libre, on constate que la trace par défaut est arrêtée à l&rsquo;aide de l&rsquo;instruction suivante :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">traces</span></div></td></tr></tbody></table></div>
<p>Lorsque la trace par défaut est active, cette requête retourne une ligne, dont la colonne <em>id</em> est à 1. On peut vérifier que c&rsquo;est la trace par défaut à l&rsquo;aide de la valeur de la colonne <em>is_default</em> : 1 si c&rsquo;est le cas, 0 à l&rsquo;inverse :</p>
<p><img src="http://i.imgur.com/msPoxLS.png" alt="" /></p>
<p>Dans la situation de l&rsquo;incident que nous évoquons, cette même requête ne retournera pas de ligne (ou tout du moins aucune dont la colonne <em>is_default</em> est à 1). Pour démarrer la trace par défaut, il suffit de s&rsquo;en remettre à l&rsquo;option de configuration d&rsquo;instance <em>default trace enabled</em> :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">configurations</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; name <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'%trace%'</span></div></td></tr></tbody></table></div>
<p><img src="http://i.imgur.com/swPu4gE.png" alt="" /></p>
<p>On voit que c&rsquo;est une option avancée et dynamique, ce qui signifie qu&rsquo;un redémarrage de l&rsquo;instance SQL Server n&rsquo;est pas nécessaire. Dès lors, pour réactiver la trace par défaut, il suffit de positionner cette option à 0, puis immédiatement ensuite à 1, ce qui est sa valeur par défaut :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">-- Activation de la modification des options d'instance avancées</span><br />
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_configure</span> <span style="color: #FF0000;">'show advanced options'</span>, <span style="color: #000;">1</span><br />
GO<br />
<span style="color: #0000FF;">RECONFIGURE</span><br />
GO<br />
<br />
<span style="color: #008080;">-- Désactivation de la trace par défaut</span><br />
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_configure</span> <span style="color: #FF0000;">'default trace enabled'</span>, <span style="color: #000;">0</span><br />
GO<br />
<span style="color: #0000FF;">RECONFIGURE</span><br />
GO<br />
<br />
<span style="color: #008080;">-- Ré-activation de la trace par défaut</span><br />
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_configure</span> <span style="color: #FF0000;">'default trace enabled'</span>, <span style="color: #000;">1</span><br />
GO<br />
<span style="color: #0000FF;">RECONFIGURE</span><br />
GO<br />
<br />
<span style="color: #008080;">-- Désactivation de la modification des options d'instance avancées</span><br />
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_configure</span> <span style="color: #FF0000;">'show advanced options'</span>, <span style="color: #000;">0</span><br />
GO<br />
<span style="color: #0000FF;">RECONFIGURE</span><br />
GO</div></td></tr></tbody></table></div>
<p>Sur exécution de ce lot, l&rsquo;onglet <em>Messages</em> du panneau de résultats de <em>SQL Server Management Studio</em> affiche :</p>
<p><em>Configuration option &lsquo;show advanced options&rsquo; changed from 0 to 1. Run the RECONFIGURE statement to install.<br />
Configuration option &lsquo;default trace enabled&rsquo; changed from 1 to 0. Run the RECONFIGURE statement to install.<br />
Configuration option &lsquo;default trace enabled&rsquo; changed from 0 to 1. Run the RECONFIGURE statement to install.<br />
Configuration option &lsquo;show advanced options&rsquo; changed from 1 to 0. Run the RECONFIGURE statement to install.</em></p>
<p>Et l&rsquo;on voit alors que la trace a été démarrée, en interrogeant une nouvelle fois la vue <em>sys.traces</em>.<br />
On trouvera aussi dans les journal de SQL Server les lignes suivantes :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">-- Recherche de l'heure de dernier démarrage de l'instance SQL Server</span><br />
<span style="color: #0000FF;">SELECT</span> sqlserver_start_time <span style="color: #0000FF;">FROM</span> sys.<span style="color: #202020;">dm_os_sys_info</span><br />
<br />
<span style="color: #008080;">-- Recherche du démarrage de la trace par défaut</span><br />
<span style="color: #0000FF;">EXEC</span> xp_readerrorlog <span style="color: #000;">0</span>, <span style="color: #000;">1</span>, N<span style="color: #FF0000;">'Trace ID 1'</span></div></td></tr></tbody></table></div>
<p><img src="http://i.imgur.com/e2rFeEt.png" alt="" /></p>
<p>Ici on voit bien que la trace par défaut a été démarré par le système (le SPID est inférieur à 50), quelques millisecondes après le démarrage de celui-ci. Elle a ensuite été redémarrée par nos soins un peu plus tard.</p>
<p>Petite note finale : les fonctionnalités <em>SQL Trace</em> et <em>SQL Profiler</em> sont obsolètes, et remplacées par la fonctionnalité d&#039;<a href="http://blog.developpez.com/elsuket/p11065/moteur-de-base-de-donnees-sql-server/evenements_etendus_sql_server_2008" title="Les Événements Étendus avec SQL Server 2008" target="_blank">événements étendus</a>, plus puissante et performante. Vous pouvez voir comment les utiliser dans <a href="http://blog.developpez.com/elsuket/p13085/moteur-de-base-de-donnees-sql-server/evenements-etendus/troubleshooting-avec-les-evenements-etendus-en-video" title="Troubleshooting avec les événements étendus en vidéo" target="_blank">cette vidéo</a>, en gardant bien à l&rsquo;esprit que dès SQL Server 2012, une interface graphique intégrée à <em>SQL Server Management Studio</em> permet de créer une session sans écrire de code, et de visualiser les événements capturés à la façon de ce que permet SQL Profiler.</p>
<p>Enfin, pour interroger un fichier de trace SQL Profiler, il suffit d&rsquo;utiliser la fonction <a href="https://msdn.microsoft.com/en-us/library/ms188425.aspx"><em>sys.fn_trace_gettable()</em></a>. Donc pour en faire l&rsquo;analyse, on peut utiliser le lot suivant :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DECLARE</span> @events <span style="color: #0000FF;">TABLE</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; event_id <span style="color: #0000FF;">tinyint</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , event_name sysname<br />
<span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">INSERT</span> @events <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">0</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">2</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">3</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">4</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">6</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">7</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">8</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">9</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">10</span>, <span style="color: #FF0000;">'RPC:Completed'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">11</span>, <span style="color: #FF0000;">'RPC:Starting'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">12</span>, <span style="color: #FF0000;">'SQL:BatchCompleted'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">13</span>, <span style="color: #FF0000;">'SQL:BatchStarting'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">14</span>, <span style="color: #FF0000;">'Audit Login'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">15</span>, <span style="color: #FF0000;">'Audit Logout'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">16</span>, <span style="color: #FF0000;">'Attention'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">17</span>, <span style="color: #FF0000;">'ExistingConnection'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">18</span>, <span style="color: #FF0000;">'Audit Server Starts and Stops'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">19</span>, <span style="color: #FF0000;">'DTCTransaction'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">20</span>, <span style="color: #FF0000;">'Audit Login Failed'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">21</span>, <span style="color: #FF0000;">'EventLog'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">22</span>, <span style="color: #FF0000;">'ErrorLog'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">23</span>, <span style="color: #FF0000;">'Lock:Released'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">24</span>, <span style="color: #FF0000;">'Lock:Acquired'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">25</span>, <span style="color: #FF0000;">'Lock:Deadlock'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">26</span>, <span style="color: #FF0000;">'Lock:Cancel'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">27</span>, <span style="color: #FF0000;">'Lock:Timeout'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">28</span>, <span style="color: #FF0000;">'Degree of Parallelism Event (7.0 Insert)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">29</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">30</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">31</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">32</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">33</span>, <span style="color: #FF0000;">'Exception'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">34</span>, <span style="color: #FF0000;">'SP:CacheMiss'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">35</span>, <span style="color: #FF0000;">'SP:CacheInsert'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">36</span>, <span style="color: #FF0000;">'SP:CacheRemove'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">37</span>, <span style="color: #FF0000;">'SP:Recompile'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">38</span>, <span style="color: #FF0000;">'SP:CacheHit'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">39</span>, <span style="color: #FF0000;">'Deprecated'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">40</span>, <span style="color: #FF0000;">'SQL:StmtStarting'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">41</span>, <span style="color: #FF0000;">'SQL:StmtCompleted'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">42</span>, <span style="color: #FF0000;">'SP:Starting'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">43</span>, <span style="color: #FF0000;">'SP:Completed'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">44</span>, <span style="color: #FF0000;">'SP:StmtStarting'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">45</span>, <span style="color: #FF0000;">'SP:StmtCompleted'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">46</span>, <span style="color: #FF0000;">'Object:Created'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">47</span>, <span style="color: #FF0000;">'Object:Deleted'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">48</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">49</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">50</span>, <span style="color: #FF0000;">'SQL Transaction'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">51</span>, <span style="color: #FF0000;">'Scan:Started'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">52</span>, <span style="color: #FF0000;">'Scan:Stopped'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">53</span>, <span style="color: #FF0000;">'CursorOpen'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">54</span>, <span style="color: #FF0000;">'TransactionLog'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">55</span>, <span style="color: #FF0000;">'Hash Warning'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">56</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">57</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">58</span>, <span style="color: #FF0000;">'Auto Stats'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">59</span>, <span style="color: #FF0000;">'Lock:Deadlock Chain'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">60</span>, <span style="color: #FF0000;">'Lock:Escalation'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">61</span>, <span style="color: #FF0000;">'OLE DB Errors'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">62</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">63</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">64</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">65</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">66</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">67</span>, <span style="color: #FF0000;">'Execution Warnings'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">68</span>, <span style="color: #FF0000;">'Showplan Text (Unencoded)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">69</span>, <span style="color: #FF0000;">'Sort Warnings'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">70</span>, <span style="color: #FF0000;">'CursorPrepare'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">71</span>, <span style="color: #FF0000;">'Prepare SQL'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">72</span>, <span style="color: #FF0000;">'Exec Prepared SQL'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">73</span>, <span style="color: #FF0000;">'Unprepare SQL'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">74</span>, <span style="color: #FF0000;">'CursorExecute'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">75</span>, <span style="color: #FF0000;">'CursorRecompile'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">76</span>, <span style="color: #FF0000;">'CursorImplicitConversion'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">77</span>, <span style="color: #FF0000;">'CursorUnprepare'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">78</span>, <span style="color: #FF0000;">'CursorClose'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">79</span>, <span style="color: #FF0000;">'Missing Column Statistics'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">80</span>, <span style="color: #FF0000;">'Missing Join Predicate'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">81</span>, <span style="color: #FF0000;">'Server Memory Change'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">82</span>, <span style="color: #FF0000;">'User Configurable (0-9)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">83</span>, <span style="color: #FF0000;">'User Configurable (0-9)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">84</span>, <span style="color: #FF0000;">'User Configurable (0-9)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">85</span>, <span style="color: #FF0000;">'User Configurable (0-9)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">86</span>, <span style="color: #FF0000;">'User Configurable (0-9)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">87</span>, <span style="color: #FF0000;">'User Configurable (0-9)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">88</span>, <span style="color: #FF0000;">'User Configurable (0-9)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">89</span>, <span style="color: #FF0000;">'User Configurable (0-9)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">90</span>, <span style="color: #FF0000;">'User Configurable (0-9)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">91</span>, <span style="color: #FF0000;">'User Configurable (0-9)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">92</span>, <span style="color: #FF0000;">'Data File Auto Grow'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">93</span>, <span style="color: #FF0000;">'Log File Auto Grow'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">94</span>, <span style="color: #FF0000;">'Data File Auto Shrink'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">95</span>, <span style="color: #FF0000;">'Log File Auto Shrink'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">96</span>, <span style="color: #FF0000;">'Showplan Text'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">97</span>, <span style="color: #FF0000;">'Showplan All'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">98</span>, <span style="color: #FF0000;">'Showplan Statistics Profile'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">99</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">100</span>, <span style="color: #FF0000;">'RPC Output Parameter'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">101</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">102</span>, <span style="color: #FF0000;">'Audit Statement GDR Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">103</span>, <span style="color: #FF0000;">'Audit Object GDR Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">104</span>, <span style="color: #FF0000;">'Audit AddLogin Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">105</span>, <span style="color: #FF0000;">'Audit Login GDR Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">106</span>, <span style="color: #FF0000;">'Audit Login Change Property Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">107</span>, <span style="color: #FF0000;">'Audit Login Change Password Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">108</span>, <span style="color: #FF0000;">'Audit Add Login to Server Role Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">109</span>, <span style="color: #FF0000;">'Audit Add DB User Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">110</span>, <span style="color: #FF0000;">'Audit Add Member to DB Role Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">111</span>, <span style="color: #FF0000;">'Audit Add Role Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">112</span>, <span style="color: #FF0000;">'Audit App Role Change Password Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">113</span>, <span style="color: #FF0000;">'Audit Statement Permission Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">114</span>, <span style="color: #FF0000;">'Audit Schema Object Access Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">115</span>, <span style="color: #FF0000;">'Audit Backup/Restore Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">116</span>, <span style="color: #FF0000;">'Audit DBCC Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">117</span>, <span style="color: #FF0000;">'Audit Change Audit Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">118</span>, <span style="color: #FF0000;">'Audit Object Derived Permission Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">119</span>, <span style="color: #FF0000;">'OLEDB Call Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">120</span>, <span style="color: #FF0000;">'OLEDB QueryInterface Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">121</span>, <span style="color: #FF0000;">'OLEDB DataRead Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">122</span>, <span style="color: #FF0000;">'Showplan XML'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">123</span>, <span style="color: #FF0000;">'SQL:FullTextQuery'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">124</span>, <span style="color: #FF0000;">'Broker:Conversation'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">125</span>, <span style="color: #FF0000;">'Deprecation Announcement'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">126</span>, <span style="color: #FF0000;">'Deprecation Final Support'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">127</span>, <span style="color: #FF0000;">'Exchange Spill Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">128</span>, <span style="color: #FF0000;">'Audit Database Management Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">129</span>, <span style="color: #FF0000;">'Audit Database Object Management Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">130</span>, <span style="color: #FF0000;">'Audit Database Principal Management Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">131</span>, <span style="color: #FF0000;">'Audit Schema Object Management Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">132</span>, <span style="color: #FF0000;">'Audit Server Principal Impersonation Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">133</span>, <span style="color: #FF0000;">'Audit Database Principal Impersonation Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">134</span>, <span style="color: #FF0000;">'Audit Server Object Take Ownership Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">135</span>, <span style="color: #FF0000;">'Audit Database Object Take Ownership Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">136</span>, <span style="color: #FF0000;">'Broker:Conversation Group'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">137</span>, <span style="color: #FF0000;">'Blocked Process Report'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">138</span>, <span style="color: #FF0000;">'Broker:Connection'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">139</span>, <span style="color: #FF0000;">'Broker:Forwarded Message Sent'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">140</span>, <span style="color: #FF0000;">'Broker:Forwarded Message Dropped'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">141</span>, <span style="color: #FF0000;">'Broker:Message Classify'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">142</span>, <span style="color: #FF0000;">'Broker:Transmission'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">143</span>, <span style="color: #FF0000;">'Broker:Queue Disabled'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">144</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">145</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">146</span>, <span style="color: #FF0000;">'Showplan XML Statistics Profile'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">148</span>, <span style="color: #FF0000;">'Deadlock Graph'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">149</span>, <span style="color: #FF0000;">'Broker:Remote Message Acknowledgement'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">150</span>, <span style="color: #FF0000;">'Trace File Close'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">151</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">152</span>, <span style="color: #FF0000;">'Audit Change Database Owner'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">153</span>, <span style="color: #FF0000;">'Audit Schema Object Take Ownership Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">154</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">155</span>, <span style="color: #FF0000;">'FT:Crawl Started'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">156</span>, <span style="color: #FF0000;">'FT:Crawl Stopped'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">157</span>, <span style="color: #FF0000;">'FT:Crawl Aborted'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">158</span>, <span style="color: #FF0000;">'Audit Broker Conversation'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">159</span>, <span style="color: #FF0000;">'Audit Broker Login'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">160</span>, <span style="color: #FF0000;">'Broker:Message Undeliverable'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">161</span>, <span style="color: #FF0000;">'Broker:Corrupted Message'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">162</span>, <span style="color: #FF0000;">'User Error Message'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">163</span>, <span style="color: #FF0000;">'Broker:Activation'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">164</span>, <span style="color: #FF0000;">'Object:Altered'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">165</span>, <span style="color: #FF0000;">'Performance statistics'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">166</span>, <span style="color: #FF0000;">'SQL:StmtRecompile'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">167</span>, <span style="color: #FF0000;">'Database Mirroring State Change'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">168</span>, <span style="color: #FF0000;">'Showplan XML For Query Compile'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">169</span>, <span style="color: #FF0000;">'Showplan All For Query Compile'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">170</span>, <span style="color: #FF0000;">'Audit Server Scope GDR Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">171</span>, <span style="color: #FF0000;">'Audit Server Object GDR Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">172</span>, <span style="color: #FF0000;">'Audit Database Object GDR Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">173</span>, <span style="color: #FF0000;">'Audit Server Operation Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">175</span>, <span style="color: #FF0000;">'Audit Server Alter Trace Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">176</span>, <span style="color: #FF0000;">'Audit Server Object Management Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">177</span>, <span style="color: #FF0000;">'Audit Server Principal Management Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">178</span>, <span style="color: #FF0000;">'Audit Database Operation Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">180</span>, <span style="color: #FF0000;">'Audit Database Object Access Event'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">181</span>, <span style="color: #FF0000;">'TM: Begin Tran starting'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">182</span>, <span style="color: #FF0000;">'TM: Begin Tran completed'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">183</span>, <span style="color: #FF0000;">'TM: Promote Tran starting'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">184</span>, <span style="color: #FF0000;">'TM: Promote Tran completed'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">185</span>, <span style="color: #FF0000;">'TM: Commit Tran starting'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">186</span>, <span style="color: #FF0000;">'TM: Commit Tran completed'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">187</span>, <span style="color: #FF0000;">'TM: Rollback Tran starting'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">188</span>, <span style="color: #FF0000;">'TM: Rollback Tran completed'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">189</span>, <span style="color: #FF0000;">'Lock:Timeout (timeout &amp;gt; 0)'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">190</span>, <span style="color: #FF0000;">'Progress Report: Online Index Operation'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">191</span>, <span style="color: #FF0000;">'TM: Save Tran starting'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">192</span>, <span style="color: #FF0000;">'TM: Save Tran completed'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">193</span>, <span style="color: #FF0000;">'Background Job Error'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">194</span>, <span style="color: #FF0000;">'OLEDB Provider Information'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">195</span>, <span style="color: #FF0000;">'Mount Tape'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">196</span>, <span style="color: #FF0000;">'Assembly Load'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">197</span>, <span style="color: #FF0000;">'Reserved'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">198</span>, <span style="color: #FF0000;">'XQuery Static Type'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">199</span>, <span style="color: #FF0000;">'QN: subscription'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">200</span>, <span style="color: #FF0000;">'QN: parameter table'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">201</span>, <span style="color: #FF0000;">'QN: template'</span><span style="color: #808080;">&#41;</span><br />
, <span style="color: #808080;">&#40;</span><span style="color: #000;">202</span>, <span style="color: #FF0000;">'QN: dynamics'</span><span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FTG.<span style="color: #202020;">DatabaseName</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , E.<span style="color: #202020;">event_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , FTG.<span style="color: #202020;">ApplicationName</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> occurences<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">MIN</span><span style="color: #808080;">&#40;</span>FTG.<span style="color: #202020;">StartTime</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> first_time<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#40;</span>FTG.<span style="color: #202020;">StartTime</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> last_time<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , FTG.<span style="color: #202020;">SessionLoginName</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , E.<span style="color: #202020;">event_id</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #AF0000;">fn_trace_gettable</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">path</span>, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">path</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #FF00FF;">CHARINDEX</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'\'</span>, <span style="color: #FF00FF;">REVERSE</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">path</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'\Log.trc'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">traces</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; is_default <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #000;">6</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> FTG<br />
<span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; @events <span style="color: #0000FF;">AS</span> E<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> E.<span style="color: #202020;">event_id</span> <span style="color: #808080;">=</span> FTG.<span style="color: #202020;">EventClass</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FTG.<span style="color: #202020;">EventClass</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">BETWEEN</span> <span style="color: #000;">65527</span> <span style="color: #808080;">AND</span> <span style="color: #000;">65528</span><br />
<span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span>&nbsp; &nbsp; &nbsp; &nbsp; FTG.<span style="color: #202020;">DatabaseName</span>, E.<span style="color: #202020;">event_name</span>, FTG.<span style="color: #202020;">ApplicationName</span>, E.<span style="color: #202020;">event_id</span>, FTG.<span style="color: #202020;">SessionLoginName</span><br />
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span>&nbsp; &nbsp; &nbsp; &nbsp; first_time</div></td></tr></tbody></table></div>
<p>Alors bon traçage à tous !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installer SQL Server Management Studio 2016</title>
		<link>https://blog.developpez.com/elsuket/p13118/utilitaires/installer-sql-server-management-studio-2016</link>
		<comments>https://blog.developpez.com/elsuket/p13118/utilitaires/installer-sql-server-management-studio-2016#comments</comments>
		<pubDate>Mon, 14 Nov 2016 14:28:49 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1347</guid>
		<description><![CDATA[SSMS 2016 n&#8217;est maintenant plus inclus dans le package d&#8217;installation de SQL Server. Ceci permet à Microsoft d&#8217;effectuer des corrections sur ce logiciel à un rythme plus rapide que jusqu&#8217;à SQL Server 2014. Ceci se confirme lorsqu&#8217;on regarde la liste &#8230; <a href="https://blog.developpez.com/elsuket/p13118/utilitaires/installer-sql-server-management-studio-2016">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SSMS 2016 n&rsquo;est maintenant plus inclus dans le package d&rsquo;installation de SQL Server.<br />
Ceci permet à Microsoft d&rsquo;effectuer des corrections sur ce logiciel à un rythme plus rapide que jusqu&rsquo;à SQL Server 2014.<br />
Ceci se confirme lorsqu&rsquo;on regarde la <a href="https://msdn.microsoft.com/fr-fr/library/mt588477.aspx">liste des corrections</a> : un bon lot de tickets Connect sont adressés.</p>
<p>Pour installer SQL Server Management Studio 2016 v16.5, c&rsquo;est par <a href="https://msdn.microsoft.com/fr-fr/library/mt238290.aspx">ici</a>.<br />
Pour obtenir l&rsquo;installation dans une autre langue, voyez la section <em>Langues disponibles</em>.</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Sentry Plan Explorer Pro maintenant entièrement gratuit</title>
		<link>https://blog.developpez.com/elsuket/p13106/moteur-de-base-de-donnees-sql-server/indexation/sql-sentry-plan-explorer-pro-maintenant-entierement-gratuit</link>
		<comments>https://blog.developpez.com/elsuket/p13106/moteur-de-base-de-donnees-sql-server/indexation/sql-sentry-plan-explorer-pro-maintenant-entierement-gratuit#comments</comments>
		<pubDate>Fri, 09 Sep 2016 08:00:31 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1344</guid>
		<description><![CDATA[On ne présente plus l’incontournable outil SQL Sentry Plan Explorer, que j&#8217;avais introduit ici et détaillé là. SQL Sentry a annoncé hier que le fabuleux outil qui facilite grandement la lecture de plans de requête, SQL Sentry Plan Explorer, est &#8230; <a href="https://blog.developpez.com/elsuket/p13106/moteur-de-base-de-donnees-sql-server/indexation/sql-sentry-plan-explorer-pro-maintenant-entierement-gratuit">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>On ne présente plus l’incontournable outil SQL Sentry Plan Explorer, que j&rsquo;avais introduit <a href="http://blog.developpez.com/elsuket/p10724/utilitaires/sql_sentry_plan_explorer" title="Analyse de plans de requête : SQL Sentry Plan Explorer">ici</a> et détaillé <a href="http://blog.developpez.com/elsuket/p12879/moteur-de-base-de-donnees-sql-server/capture-manuelle-de-plans-de-requete" title="Capture manuelle de plans de requête">là</a>.</p>
<p>SQL Sentry a annoncé hier que le fabuleux outil qui facilite grandement la lecture de plans de requête, SQL Sentry Plan Explorer, est maintenant gratuit dans son édition Pro.<br />
Jusqu&rsquo;ici, l&rsquo;édition Express était déjà un bel outil, qui est maintenant complété par :</p>
<ul>
<li>L&rsquo;ouverture de plusieurs documents de plan de requête (fichiers .sqlplan, .queryanalysis, .pesession)</li>
<li>L&rsquo;historique et ses commentaires au fur et à mesure du processus d&rsquo;optimisation</li>
<li>L&rsquo;ouverture des graphes décrivant un deadlock (fichiers de type .xdl)</li>
<li>La comparaison de l&rsquo;impact des index pour une même requête</li>
<li>L&rsquo;aide à l&rsquo;analyse de la distribution des valeurs dans un objet de statistique</li>
</ul>
<p>Bonne analyse de plans !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vérifier la validité d&#8217;un SIRET &#8211; Algorithme de Luhn</title>
		<link>https://blog.developpez.com/elsuket/p13056/snippets/verifier-la-validite-dun-siret-algorithme-de-luhn</link>
		<comments>https://blog.developpez.com/elsuket/p13056/snippets/verifier-la-validite-dun-siret-algorithme-de-luhn#comments</comments>
		<pubDate>Thu, 23 Jun 2016 18:54:56 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1233</guid>
		<description><![CDATA[Lors d&#8217;un chargement massif de données et/ou d&#8217;une migration, il est possible que la qualité des données soient altérées. Il faut alors tester leur qualité et valider chaque écart. Parmi ceux-ci, on peut trouver les numéro SIRET, qui permet l&#8217;identification &#8230; <a href="https://blog.developpez.com/elsuket/p13056/snippets/verifier-la-validite-dun-siret-algorithme-de-luhn">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Lors d&rsquo;un chargement massif de données et/ou d&rsquo;une migration, il est possible que la qualité des données soient altérées. Il faut alors tester leur qualité et valider chaque écart. Parmi ceux-ci, on peut trouver les numéro SIRET, qui permet l&rsquo;identification d&rsquo;un établissement ou d&rsquo;une entreprise Française.</p>
<p>Cet identifiant numérique est constitué de 14 chiffres, et est articulé en trois parties :</p>
<ul>
<li>le SIREN</li>
<li>le Numéro Interne de Classement, à quatre chiffres : c&rsquo;est l&rsquo;ordre de création de l’établissement par l&rsquo;entreprise Française</li>
<li>une clé de contrôle, constituée d&rsquo;un seul chiffre</li>
</ul>
<p>Ce dernier est calculé à l&rsquo;aide de l&rsquo;<a href="https://fr.wikipedia.org/wiki/Formule_de_Luhn">algorithme de Luhn</a>. Cet algorithme est aussi utilisé pour valider les numéros de carte bleue, et de nombreux identifiants distribués par les administrations de beaucoup de pays. Nous allons nous en servir pour vérifier la validité de SIRETs en l&rsquo;implémentant spécifiquement pour ce type d&rsquo;identifiant.</p>
<p><span id="more-1233"></span></p>
<p>L&rsquo;algorithme est descriptible comme suit :</p>
<ol>
<li>Pour chaque chiffre dont l&rsquo;index dans la chaîne est impair, on le multiplie par 2; si le résultat est supérieur à 9, on additionne les chiffes qui constituent ce résultat. Ceci revient à multiplier par 2 le chiffre, diviser le résultat par 10, puis ajouter la multiplication par 2 de ce même chiffre modulo 10.</li>
<li>On additionne ensuite les chiffres du résultat un à un, avec les chiffres de l&rsquo;identifiant qui n&rsquo;ont pas été traités, c&rsquo;est à dire ceux dont l&rsquo;index dans la chaîne est pair. Ceci inclut le chiffre de l&rsquo;identifiant qui est clé.</li>
<li>Si le résultat obtenu est un multiple de 10, alors l&rsquo;identifiant est valide. Ceci revient à vérifier que le résultat modulo 10 vaut zéro.</li>
</ol>
<p>La traduction en SQL donne :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CASE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> laColonneSIRET <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">THEN</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>laColonneSIRET<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&amp;</span>lt; <span style="color: #000;">14</span> <span style="color: #0000FF;">THEN</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #000;">0</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">bit</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> laColonneSIRET <span style="color: #808080;">LIKE&amp;</span>#039;<span style="color: #808080;">%</span><span style="color: #808080;">&#91;</span><span style="color: #808080;">^</span><span style="color: #000;">0</span><span style="color: #808080;">-</span><span style="color: #000;">9</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">%&amp;</span>#039; <span style="color: #0000FF;">THEN</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #000;">0</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">bit</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">1</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">1</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">%</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">3</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">3</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">%</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">5</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">5</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">%</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">7</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">7</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">%</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">9</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">9</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">%</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">11</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">11</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">%</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">13</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #000;">2</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">13</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">%</span> <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">---</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">2</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">4</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">6</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">8</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">10</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">12</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>laColonneSIRET, <span style="color: #000;">14</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #808080;">%</span> <span style="color: #000;">10</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">bit</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #000;">0</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">bit</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> is_valid_SIRET</div></td></tr></tbody></table></div>
<p>On peut l&#039;utiliser directement dans une vue, comme dans le pseudo code suivant :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE VIEW maVue<br />
AS<br />
SELECT&nbsp; desColonnes<br />
&nbsp; &nbsp; &nbsp; &nbsp; , CASE<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN laColonneSIRET IS NULL THEN NULL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN LEN(laColonneSIRET) &amp;lt; 14 THEN CAST(0 AS bit)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN laColonneSIRET LIKE&amp;#039;%[^0-9]%&amp;#039; THEN CAST(0 AS bit)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 * CAST(SUBSTRING(laColonneSIRET, 1, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 1, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 3, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 3, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 5, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 5, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 7, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 7, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 9, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 9, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 11, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 11, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 13, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(laColonneSIRET, 13, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ---<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(laColonneSIRET, 2, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(laColonneSIRET, 4, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(laColonneSIRET, 6, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(laColonneSIRET, 8, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(laColonneSIRET, 10, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(laColonneSIRET, 12, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(laColonneSIRET, 14, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) % 10 = 0 THEN CAST(1 AS bit) ELSE CAST(0 AS bit)<br />
&nbsp; &nbsp; &nbsp; &nbsp; END AS is_valid_SIRET<br />
FROM&nbsp; &nbsp; dbo.maTable</div></td></tr></tbody></table></div>
<p>Si l&#039;on souhaite l&#039;utiliser en colonne calculée, on peut utiliser ce CASE directement dans la définition de ladite colonne, ou bien définir une fonction scalaire comme suit :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE FUNCTION fn_scl_is_valid_SIRET<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@_siret char(14)<br />
&nbsp; &nbsp; &nbsp; &nbsp; )<br />
RETURNS bit<br />
WITH SCHEMABINDING<br />
AS<br />
BEGIN<br />
&nbsp; &nbsp; &nbsp; &nbsp; DECLARE @ok bit<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; SELECT&nbsp; @ok = CASE<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN @_siret IS NULL THEN NULL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN LEN(@_siret) &amp;lt; 14 THEN CAST(0 AS bit)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN @_siret LIKE&amp;#039;%[^0-9]%&amp;#039; THEN CAST(0 AS bit)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 * CAST(SUBSTRING(@_siret, 1, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 1, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 3, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 3, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 5, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 5, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 7, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 7, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 9, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 9, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 11, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 11, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 13, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@_siret, 13, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ---<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@_siret, 2, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@_siret, 4, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@_siret, 6, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@_siret, 8, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@_siret, 10, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@_siret, 12, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@_siret, 14, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) % 10 = 0 THEN CAST(1 AS bit) ELSE CAST(0 AS bit)<br />
&nbsp; &nbsp; &nbsp; &nbsp; END<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; RETURN @ok<br />
END</div></td></tr></tbody></table></div>
<p>Et en ce qui concerne la création de la colonne calculée, on peut l&#039;ajouter à l&#039;aide du pseudo-T-SQL suivant :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ALTER TABLE maTable<br />
ADD is_valid_SIRET AS(dbo.fn_scl_is_valid_SIRET(laColonneSIRET))</div></td></tr></tbody></table></div>
<p>Enfin, si l&#039;on souhaite exécuter cette vérification au sein d&#039;une requête, on peut s&#039;en remettre à une fonction de table en ligne. Ce type de fonction n&#039;étant appelé qu&#039;une seule fois, il s&#039;avérera plus performant à l&#039;exécution sur un grand nombre de lignes que l&#039;appel à une fonction scalaire : ces dernières sont appelées autant de fois qu&#039;il y a de lignes de résultat. Ce qui donne :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE FUNCTION fn_it_is_valid_SIRET<br />
&nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @siret char(14)<br />
&nbsp; &nbsp; &nbsp; &nbsp; )<br />
RETURNS TABLE<br />
WITH SCHEMABINDING<br />
AS<br />
RETURN&nbsp; <br />
(<br />
&nbsp; &nbsp; &nbsp; &nbsp; SELECT&nbsp; CASE<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN LEN(COALESCE(@siret,&amp;#039;&amp;#039;)) &amp;lt; 14 THEN CAST(0 AS bit)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN @siret LIKE&amp;#039;%[^0-9]%&amp;#039; THEN CAST(0 AS bit)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN @siret IS NULL THEN CAST(0 AS bit)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 * CAST(SUBSTRING(@siret, 1, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 1, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 3, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 3, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 5, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 5, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 7, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 7, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 9, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 9, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 11, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 11, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 13, 1) AS tinyint) / 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 2 * CAST(SUBSTRING(@siret, 13, 1) AS tinyint) % 10<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ---<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@siret, 2, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@siret, 4, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@siret, 6, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@siret, 8, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@siret, 10, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@siret, 12, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(SUBSTRING(@siret, 14, 1) AS tinyint)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) % 10 = 0 THEN CAST(1 AS bit) ELSE CAST(0 AS bit)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END AS is_valid_SIRET<br />
)</div></td></tr></tbody></table></div>
<p>On peut alors l&#039;utiliser à l&#039;aide de l&#039;opérateur APPLY, comme dans l&#039;exemple suivant :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S.*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , F.is_valid_SIRET<br />
FROM&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.maTableAvecUneColonneSIRET AS S<br />
CROSS APPLY &nbsp; &nbsp; dbo.fn_it_is_valid_SIRET(S.laColonneSIRET) AS F</div></td></tr></tbody></table></div>
<p>Bonne validation de SIRETs !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capture manuelle de plans de requête</title>
		<link>https://blog.developpez.com/elsuket/p12879/moteur-de-base-de-donnees-sql-server/capture-manuelle-de-plans-de-requete</link>
		<comments>https://blog.developpez.com/elsuket/p12879/moteur-de-base-de-donnees-sql-server/capture-manuelle-de-plans-de-requete#comments</comments>
		<pubDate>Fri, 26 Jun 2015 17:03:50 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1134</guid>
		<description><![CDATA[Plusieurs des participants au forum SQL Server de Développez demandent comment optimiser une requête : ce billet leur est particulièrement destiné, puisqu&#8217;une optimisation de requête ne peut réellement se faire sans son plan d&#8217;exécution, le mieux étant aussi d&#8217;avoir la &#8230; <a href="https://blog.developpez.com/elsuket/p12879/moteur-de-base-de-donnees-sql-server/capture-manuelle-de-plans-de-requete">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Plusieurs des participants au forum SQL Server de Développez demandent comment optimiser une requête : ce billet leur est particulièrement destiné, puisqu&rsquo;une optimisation de requête ne peut réellement se faire sans son plan d&rsquo;exécution, le mieux étant aussi d&rsquo;avoir la sortie de l&rsquo;option de session SET STATISTICS IO, TIME ON, et le DDL (ordre CREATE TABLE) de la table et de ses index.<br />
<span id="more-1134"></span></p>
<p>Un plan de requête expose la façon dont l&rsquo;optimiseur de requêtes de SQL Server a calculé la résolution d&rsquo;une requête que nous lui avons soumis. Ce dernier fait un excellent travail dans la très grande majorité des cas, et pour les autres, il a parfois besoin de l&rsquo;aide d&rsquo;un DBA lorsque l&rsquo;indexation n&rsquo;est pas l&rsquo;origine du problème.</p>
<p>SQL Server Management Studio (SSMS) expose les plans de requête estimés et réels.<br />
Le plan de requête estimé expose la suite d&rsquo;opérateurs logiques et physiques que le moteur a trouvé optimale pour résoudre une requête, c&rsquo;est à dire celle qui consommera le moins de ressources. Ce plan est basé sur les statistiques de colonnes et d&rsquo;index. La maintenance et la qualité des statistiques est un un sujet vaste que nous n&rsquo;aborderons pas ici. On peut obtenir le plan de requête estimé sans exécuter celle-ci en pressant CTRL+L, ou en cliquant sur le bouton ci-dessous, après avoir surligné la requête en question s&rsquo;il y en a plusieurs dans la fenêtre de requêtes de SSMS.</p>
<p><img src="http://i.imgur.com/a9Z1vpE.png" alt="" /></p>
<p>Le DBA peut se servir du plan de requête estimé pour comprendre un problème de performances, mais il arrive qu&rsquo;un autre type de plan, dit réel, soit nécessaire. Ce plan peut être généré juste après la fin de l&rsquo;exécution d&rsquo;une requête, et permet d&rsquo;exposer les différences entre le plan estimé et ce qui s&rsquo;est passé lors de son exécution. De façon similaire au plan de requête estimé, on peut obtenir ce plan de requête en pressant CTRL+M, ou en pressant le bouton suivant dans SSMS <strong>avant</strong> l&rsquo;exécution de la requête à étudier.</p>
<p><img src="http://i.imgur.com/P6eGGkx.png" alt="" /></p>
<p>Visuellement, avec SSMS, aussi bien avec le plan de requête estimé que réel, nous obtenons, pour la requête suivante exécutée sur la base de données exemple <em>AdventureWorks2012</em> proposée par Microsoft <a href="http://msftdbprodsamples.codeplex.com/releases/view/55330">ici</a> (voir les détails de l&rsquo;installation <a href="http://blog.developpez.com/elsuket/p11188/moteur-de-base-de-donnees-sql-server/attacher_base_donnees_sans_tran_log" title="Attacher une base de données qui n’a pas de fichier du journal des transactions">ici</a>) :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span><br />
<span style="color: #008080;">-- Expose le nombre de lectures effectué sur chaque table,</span><br />
<span style="color: #008080;">-- ainsi que le temps CPU consommé. On retrouve ces données dans l'onglet</span><br />
<span style="color: #008080;">-- Messages du panneau des résultats de requête, après exécution de celle-ci.</span><br />
<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">STATISTICS</span> IO, <span style="color: #0000FF;">TIME</span> <span style="color: #0000FF;">ON</span> <br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PP.<span style="color: #202020;">LastName</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , PP.<span style="color: #202020;">FirstName</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> sales_count<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Person.<span style="color: #202020;">Person</span> <span style="color: #0000FF;">AS</span> PP<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; HumanResources.<span style="color: #202020;">Employee</span> <span style="color: #0000FF;">AS</span> E<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> PP.<span style="color: #202020;">BusinessEntityID</span> <span style="color: #808080;">=</span> E.<span style="color: #202020;">BusinessEntityID</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; Sales.<span style="color: #202020;">SalesOrderHeader</span> <span style="color: #0000FF;">AS</span> SOH<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> SOH.<span style="color: #202020;">SalesPersonID</span> <span style="color: #808080;">=</span> PP.<span style="color: #202020;">BusinessEntityID</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; Sales.<span style="color: #202020;">SalesOrderDetail</span> <span style="color: #0000FF;">AS</span> SOD<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> SOH.<span style="color: #202020;">SalesOrderID</span> <span style="color: #808080;">=</span> SOD.<span style="color: #202020;">SalesOrderID</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; Production.<span style="color: #202020;">Product</span> <span style="color: #0000FF;">AS</span> P<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> SOD.<span style="color: #202020;">ProductID</span> <span style="color: #808080;">=</span> P.<span style="color: #202020;">ProductID</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; P.<span style="color: #202020;">ProductNumber</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'BK-M18B-44'</span><br />
<span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span>&nbsp; &nbsp; &nbsp; &nbsp; PP.<span style="color: #202020;">LastName</span>, PP.<span style="color: #202020;">FirstName</span><br />
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span>&nbsp; &nbsp; &nbsp; &nbsp; sales_count <span style="color: #0000FF;">DESC</span></div></td></tr></tbody></table></div>
<p><img src="http://i.imgur.com/E0xY7jS.png" alt="" /></p>
<p>Bien qu&rsquo;utile, le fait d&rsquo;avoir à constamment déplacer les curseurs de parcours, surtout lorsque le plan est constitué de nombreux opérateurs, devient vite peu confortable.</p>
<p>Alternativement, SQL Sentry nous offre la possibilité d&rsquo;utiliser la version gratuite de son outil Plan Explorer, que j&rsquo;avais exposé <a href="http://blog.developpez.com/elsuket/p10724/utilitaires/sql_sentry_plan_explorer" title="Analyse de plans de requête : SQL Sentry Plan Explorer" target="_blank">ici</a>, et qui continue d&rsquo;évoluer. On peut télécharger le logiciel <a href="http://www.sqlsentry.com/products/plan-explorer/sql-server-query-view" title="SQL Sentry Plan Explorer">ici</a> (en toute fin de page), et il s&rsquo;intègre automatiquement à SSMS. En effet, il suffit d&rsquo;effectuer un clic-droit dans une zone vierge du plan et de sélectionner l&rsquo;option <em>View in SQL Sentry Plan Explorer</em> &#8230;</p>
<p><img src="http://i.imgur.com/pEuO946.png" alt="" /></p>
<p>&#8230; pour voir l&rsquo;interface de SQL Sentry Plan Explorer s&rsquo;ouvrir, et observer une façon différente de disséquer un plan de requête :</p>
<p><img src="http://i.imgur.com/vHMve4w.png" alt="" /></p>
<p>Le nombre de lignes échangé entre les opérateurs est exposé directement dans le plan, exposé de façon plus compacte. Par ailleurs, le coût relatif des opérateurs est affiché directement au-dessus de ceux-ci, avec une couleur qui s&rsquo;assombrit suivant la dépense de ressources qu&rsquo;ils engendrent. Outre le fait que l&rsquo;on puisse zoomer sur le plan (utile lorsque le plan de requête est tentaculaire, ou en conférence), les divers onglets présents au bas du panneau du plan d&rsquo;exécution graphique décrivent des informations souvent utiles, notamment :</p>
<ul>
<li>le document XML sous-jacent au plan graphique</li>
<li>L&rsquo;arbre du plan, similaire à la sortie que l&rsquo;on obtient avec SSMS lorsque l&rsquo;option de session SHOWPLAN_TEXT est positionnée à ON</li>
<li>Les opérations les plus consommatrices de ressources, comparées à toutes les autres opérations du plan</li>
<li>Les colonnes spécifiées dans la requête, quel opérateur elles subissent et à travers quel index elles sont accédées</li>
<li>Le diagramme de jointure, qui permet bien souvent de se rentre compte d&rsquo;une auto-jointure inopportune</li>
<li>Les paramètres de la requêtes et leur valeur au moment de la compilation et au moment de l&rsquo;exécution</li>
<li>Les expressions (par exemple <em>Expr10NN</em>, où N est un entier, que l&rsquo;on rencontre parfois dans le plan graphique dans SSMS comme substitut à une expression dans la requête, et que l&rsquo;on arrive à comprendre seulement en décortiquant le plan XML. Cela permet aussi de détecter les conversions implicites, parfois néfastes aux performances d&rsquo;exécution d&rsquo;une requête.)</li>
</ul>
<p>Les diverses requêtes sont exposées une à une, avec leur coût relatif au coût total du plan : il suffit de cliquer sur l&rsquo;une des requêtes dans le panneau <em>Results</em> pour les parcourir. Enfin, si l&rsquo;optimiseur suggère d&rsquo;ajouter un index (fonctionnalité de suggestion d&rsquo;<a href="http://blog.developpez.com/elsuket/p6345/moteur-de-base-de-donnees-sql-server/indexation/title_107" title="Recherche d’indexes manquants sous SQL Server 2005">index manquants</a>), il suffit de cliquer sur l&rsquo;opérateur final du plan (le plus en haut et à gauche) pour que l&rsquo;outil ouvre une fenêtre séparée qui donne, comme dans SSMS, l&rsquo;instruction de création de l&rsquo;index.</p>
<p>Passons maintenant au plan d&rsquo;exécution réel :</p>
<p><img src="http://i.imgur.com/IukvKAb.png" alt="" /></p>
<p>Avec la possibilité de montrer l&rsquo;estimation du nombre de lignes (cardinalité) par rapport au nombre de lignes manipulé par les opérateurs lors de l&rsquo;exécution de la requête par un simple clic-droit, on détecte très rapidement les problèmes d&rsquo;estimation de cardinalités : c&rsquo;est bien souvent à cause de cela que la requête étudiée s&rsquo;exécute lentement ou consomme beaucoup de ressources. Dans ce cas, l&rsquo;épaisseur des flèches est largement affectée, et c&rsquo;est l&rsquo;effet visuel généré par le passage d&rsquo;un plan à l&rsquo;autre qui permet la détection visuelle.</p>
<p>Cerise sur le gâteau : SQL Sentry Plan Explorer permet aussi d&rsquo;anonymiser un plan de requête, c&rsquo;est à dire de remplacer le nom réel des tables et autres objets exposés par le plan par un nom générique, et ce en conservant toute la logique du plan. Après un clic sur le bouton suivant, qui se trouve dans la barre d&rsquo;outils de SQL Sentry Plan Explorer &#8230;</p>
<p><img src="http://i.imgur.com/svPkywh.png" alt="" /></p>
<p>&#8230; une autre fenêtre s&rsquo;ouvre, exposant le plan anonymisé : au lieu de trouver le nom des objets réels, on trouve par exemple <em>ObjectN.IndexP</em>, où N et P sont des entiers.</p>
<p><img src="http://i.imgur.com/zYaebnr.png" alt="" /></p>
<p>On peut ensuite sauvegarder un tel plan (qu&rsquo;il soit anonymisé ou non) en vue de le partager sur le <a href="www.developpez.net/forums/f49/bases-donnees/ms-sql-server/" title="Développez.com - Forum SQL Server" target="_blank">forum Développez.com dédié à SQL Server</a> sans exposer d&rsquo;informations sensibles : un clic sur File &gt; Save As ouvre la fenêtre suivante :</p>
<p><img src="http://i.imgur.com/1QQD1wP.png" alt="" /></p>
<ul>
<li>L&rsquo;extension <em>.queryplananalysis</em> est le format propriétaire de SQL Sentry. Si vous sauvegardez sous ce type, assurez-vous que la personne avec qui vous partagez le plan de requête dispose aussi de SQL Sentry Plan Explorer.</li>
<li>L&rsquo;extension <em>.sqlplan</em> est le format propriétaire de SQL Server Management Studio. Après la sauvegarde, si vous double-cliquez sur un tel document, il s&rsquo;ouvrira automatiquement avec ce dernier</li>
<li>L&rsquo;extension <em>.xml</em> est le format générique de description de documents bien connu. Le document résultant est identique à son homologue .sqlplan. On peut l&rsquo;utiliser pour automatiser l&rsquo;extraction de données de plusieurs plans.</li>
</ul>
<p>Bonne capture de plans !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sauvegardes de bases de données et envoi d&#8217;email avec SQL Server Express</title>
		<link>https://blog.developpez.com/elsuket/p12612/snippets/sauvegardes-de-bases-de-donnees-et-envoi-demail-avec-sql-server-express</link>
		<comments>https://blog.developpez.com/elsuket/p12612/snippets/sauvegardes-de-bases-de-donnees-et-envoi-demail-avec-sql-server-express#comments</comments>
		<pubDate>Sun, 11 May 2014 10:01:01 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Utilitaires]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[BACKUP]]></category>
		<category><![CDATA[sauvegarde]]></category>
		<category><![CDATA[SQL Server Express]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1006</guid>
		<description><![CDATA[Windows Server Update Services (WSUS) est une application qui permet de gérer et distribuer les patch que Microsoft publie pour ses produits. Elle est supportée par SQL Server Express (with Adanced Services), et de ce fait : On ne dispose &#8230; <a href="https://blog.developpez.com/elsuket/p12612/snippets/sauvegardes-de-bases-de-donnees-et-envoi-demail-avec-sql-server-express">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><em>Windows Server Update Services</em> (WSUS) est une application qui permet de gérer et distribuer les patch que Microsoft publie pour ses produits. Elle est supportée par SQL Server Express (with Adanced Services), et de ce fait :</p>
<ul>
<li>On ne dispose pas de l&rsquo;Agent SQL Server</li>
<li>On ne peut pas utiliser des plans de maintenance pour gérer les sauvegardes</li>
<li>On ne peut pas envoyer d&rsquo;emails</li>
<li>La compression des fichiers de backup, introduite avec SQL Server 2008, n&rsquo;est pas prise en charge</li>
</ul>
<p>Si donc on souhaite planifier les sauvegardes de base de données, et envoyer un email en cas d&rsquo;échec, on peut :</p>
<ul>
<li>Remplacer un job de l&rsquo;Agent SQL Server par une tâche du Planificateur de Tâches de Windows</li>
<li>Écrire une procédure stockée d&rsquo;assembly pour envoyer des emails</li>
</ul>
<p>Cet article détaille les étapes à suivre pour ce faire.<br />
<span id="more-1006"></span></p>
<p><span style="font-weight:bold;font-family:Verdana;font-size:18px">Une procédure stockée d&rsquo;assembly pour envoyer des emails</span></p>
<p>Si l&rsquo;Agent SQL Server n&rsquo;est pas disponible, l&rsquo;intégration CLR l&rsquo;est. Ainsi en quelques lignes de code C#, on peut envoyer des e-mails de façon assez similaire à ce qu&rsquo;on peut faire sous les éditions non-Express de SQL Server avec la procédure stockée système <em>msdb.dbo.sp_send_dbmail</em>.</p>
<p>Pour créer une procédure stockée d&rsquo;assembly sous Visual Studio 2012 ou ultérieur, il faut tout d&rsquo;abord installer <em>SQL Server Data Tools</em>. Pour ce faire, vous pouvez lire <a href="http://blog.developpez.com/elsuket/p12610/utilitaires/ssdt-bi-et-ssdt-ou-lun-ou-lautre-et-aussi-les-deux" title="SSDT-BI et SSDT : ou l’un, ou l’autre, et aussi les deux !">ce billet</a>. Notez qu&rsquo;il n&rsquo;est pas nécessaire d&rsquo;avoir Visual Studio déjà installé.</p>
<p>Une fois Visual Studio démarré, il suffit de créer un nouveau projet à partir de la page de démarrage, ou bien de suivre <em>File</em> &gt; <em>New</em> &gt; <em>Project</em>, et de choisir un projet SQL Server :</p>
<p><img src="http://i.imgur.com/3Doxf4q.png" alt="" /></p>
<p>Il faut faire attention à la version du framework .NET. Par exemple, si l&rsquo;on souhaite que l&rsquo;assembly soit exécutable par SQL Server 2008, il faut spécifier la version 3.5. Une fois que l&rsquo;on a validé le tout par OK, nous pouvons ajouter une procédure stockée :</p>
<p><img src="http://i.imgur.com/YbADCND.png" alt="" /></p>
<p>Comme je préfère C# à VB.NET, j&rsquo;ai choisi une procédure stockée C#, mais si vous préférez VB.NET, rien ne s&rsquo;y oppose. Notons que par défaut, le langage de la procédure stockée n&rsquo;est pas pré-sélectionné.</p>
<p><img src="http://i.imgur.com/Fb6O7pN.png" alt="" /></p>
<p>Une fois que l&rsquo;on a validé le tout par un clic sur <em>Add</em>, on peut écrire :</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Net</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Net.Mail</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data.SqlClient</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data.SqlTypes</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.SqlServer.Server</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> StoredProcedures<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">SqlServer</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Server</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SqlProcedure</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> spasb_mail_send <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> sender, <span style="color: #6666cc; font-weight: bold;">string</span> recipients, <span style="color: #6666cc; font-weight: bold;">string</span> subject, <span style="color: #6666cc; font-weight: bold;">string</span> body<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SmtpClient mailServer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SmtpClient<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;mail.myCompany.com&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; MailMessage mail <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MailMessage<span style="color: #008000;">&#40;</span>sender, recipients, subject, body<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mail<span style="color: #008000;">.</span><span style="color: #0000FF;">IsBodyHtml</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; mailServer<span style="color: #008000;">.</span><span style="color: #0000FF;">Send</span><span style="color: #008000;">&#40;</span>mail<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Ce qui, même pour l&rsquo;ultra-débutant C# que je suis, est loin d&rsquo;être complexe. Avant de builder le projet, il nous faut configurer l&rsquo;assembly pour lui permettre d&rsquo;accéder à des ressources externes, ce qui se fait après un clic-droit sur le projet, et choisi <em>Properties</em> (ou pour les aficionados du raccourci clavier, ALT + Entrée). Dans la page <em>SQLCLR</em>, nous commutons donc la liste déroulante <em>Permission Level</em> sur EXTERNAL_ACCESS. De la même façon, dans la page <em>SQLCLR Build</em>, nous commutons la liste déroulante <em>Configuration</em> sur <em>Release</em>, ce qui permet un léger gain de performances. Ce n&rsquo;est pas très important dans notre cas, mais si l&rsquo;assembly est plus complexe, cela peut le devenir.</p>
<p><img src="http://i.imgur.com/TW1gYM4.png" alt="" /></p>
<p>Après un clic sur <em>Build</em> &gt; <em>Build Solution</em>, nous pouvons aller chercher le fichier dll dans le dossier de la solution. Dans cet exemple, il s&rsquo;agit de <em>D:\SQLServer\Assemblies\SQLServerExpressDatabaseMail\SQLServerExpressDatabaseMail\bin\Debug</em>, et le fichier est nommé <em>SQLServerExpressDatabaseMail.dll</em>.</p>
<p><img src="http://i.imgur.com/vjePpel.png" alt="" /></p>
<p>De retour dans <em>SQL Server Management Studio</em>, une fois connecté à l&rsquo;instance SQL Server Express, il est tout d&rsquo;abord nécessaire d&rsquo;activer la prise en charge de la CLR par cette dernière. Cela se fait sans redémarrage de l&rsquo;instance, en quelques instruction :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_configure</span> <span style="color: #FF0000;">'clr enabled'</span>, <span style="color: #000;">1</span><br />
GO<br />
<span style="color: #0000FF;">RECONFIGURE</span><br />
GO</div></td></tr></tbody></table></div>
<p>Il est maintenant requis de déclarer la base de données dans laquelle nous allons enregistrer la procédure stockée d&rsquo;assembly comme &laquo;&nbsp;digne de confiance&nbsp;&raquo;. Ceci nous permet d&rsquo;emprunter l&rsquo;identité de SQL Server pour exécuter cette procédure qui va accéder à des ressources en dehors de la base de données : en l’occurrence, un serveur de mails (mais ce peut être le système de fichiers, un webservice, &#8230;). Là encore, une simple commande suffit :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">DATABASE</span> DBA<br />
<span style="color: #0000FF;">SET</span> TRUSTW<span style="color: #808080;">OR</span>THY <span style="color: #0000FF;">ON</span><br />
GO</div></td></tr></tbody></table></div>
<p>Nous devons maintenant enregistrer l&rsquo;assembly dans la base de données, ce que l&rsquo;on peut faire une fois que l&rsquo;on a copié l&rsquo;assembly dans un dossier de notre choix, sur le serveur hébergeant l&rsquo;instance SQL Server Express / WSUS. Dans cet exemple, nous utilisons le dossier C:\SQLServer\.</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">USE</span> DBA<br />
GO<br />
<br />
<span style="color: #0000FF;">CREATE</span> ASSEMBLY SQLServerExpressDatabaseMail<br />
<span style="color: #0000FF;">FROM</span> <span style="color: #FF0000;">'C:\SQLServer\SQLServerExpressDatabaseMail.dll'</span><br />
<span style="color: #0000FF;">WITH</span> PERMISSION_SET <span style="color: #808080;">=</span> EXTERNAL_ACCESS<br />
GO</div></td></tr></tbody></table></div>
<p>On peut vérifier l&rsquo;enregistrement de l&rsquo;assembly en interrogeant la vue système <em>sys.assemblies</em>. En ce point, on n&rsquo;a plus besoin du fichier dll : le binaire de celle-ci est maintenant enregistré dans la base de données (de nom DBA dans cet exemple).<br />
Créons maintenant la procédure stockée :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">PROCEDURE</span> dbo.<span style="color: #202020;">spasb_mail_send</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; @_sender <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">256</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @_recipients <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">256</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @_subject <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">256</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @_body <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">4000</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">EXTERNAL</span> NAME SQLServerExpressDatabaseMail.<span style="color: #202020;">StoredProcedures</span>.<span style="color: #202020;">spasb_mail_send</span><br />
GO</div></td></tr></tbody></table></div>
<p>Et testons enfin :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">EXEC</span> dbo.<span style="color: #202020;">spasb_mail_send</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">'it@myCompany.com'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF0000;">'me@myCompany.com'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF0000;">'Test Mail from Assembly Stored Procedure'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF0000;">'Hey Hey !'</span></div></td></tr></tbody></table></div>
<p><span style="font-weight:bold;font-family:Verdana;font-size:18px">Une procédure stockée pour gérer les sauvegardes</span></p>
<p>Voici une procédure stockée générique qui permet de sauvegarder une base de données en particulier, ou toutes les bases de données hébergées par une instance SQL Server. Dans le second cas, les sauvegardes du fichier du journal des transactions n&rsquo;est pas supportée. En revanche, on peut exécuter cette procédure stockée sur toutes les versions de SQL Server, à partir de 2005. Enfin, le cryptage des sauvegardes, introduit avec SQL Server 2014 n&rsquo;est pas supporté non plus. Cela exige que quelques prérequis soient en place, et ceux-là sortent du cadre de cet article.</p>
<p>La procédure stockée d&rsquo;assembly est référencée dans le bloc CATCH final : pour toute erreur, on envoie un email.</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">PROCEDURE</span> dbo.<span style="color: #202020;">databaseBackup_manage</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; @_backup_type <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">12</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @_database_name <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">128</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @_backup_server_network_path <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">256</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @_print_only <span style="color: #0000FF;">bit</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
<span style="color: #0000FF;">AS</span><br />
<span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DECLARE</span> @<span style="color: #0000FF;">sql</span> <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">4000</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @err_msg <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2048</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @compression <span style="color: #0000FF;">bit</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @checkum <span style="color: #0000FF;">bit</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @mail_subject <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">4000</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">@@SERVERNAME</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' Backups'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- SQL Server 2005 ne supporte pas l'affectation directe de valeurs*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- à des variables lors de la déclaration</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; @compression <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span> TRY<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Gestion de la compression des sauvegardes</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- SQL Server 2008 Enterprise et Developer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SERVERPROPERTY</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'ProductVersion'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">32</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'10.0%'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SERVERPROPERTY</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Edition'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">64</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'Enterprise%'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">OR</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SERVERPROPERTY</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Edition'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">64</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'Developer%'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">OR</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- SQL Server 2008 R2 Enterprise, Standard et Developer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Et toute version après celle-ci</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SERVERPROPERTY</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'ProductVersion'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">32</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'10.50%'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">OR</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SERVERPROPERTY</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'ProductVersion'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">32</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF0000;">'.'</span>, <span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">&amp;</span>gt; <span style="color: #000;">10</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SERVERPROPERTY</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Edition'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">64</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'Enterprise%'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">OR</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SERVERPROPERTY</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Edition'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">64</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'Standard%'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">OR</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SERVERPROPERTY</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Edition'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">64</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'Developer%'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @compression <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Vérifie que le chemin réseau commence par un double anti-slash</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @_backup_server_network_path <span style="color: #808080;">NOT</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'\\%'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @err_msg <span style="color: #808080;">=</span> <span style="color: #FF0000;">'The network path '</span> <span style="color: #808080;">+</span> @_backup_server_network_path <span style="color: #808080;">+</span> <span style="color: #FF0000;">' is not valid.'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">RAISERROR</span><span style="color: #808080;">&#40;</span>@err_msg, <span style="color: #000;">16</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Ajoute l'anti-slash à la fin du chemin réseau, le cas échéant</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> @_backup_server_network_path <span style="color: #808080;">=</span> @_backup_server_network_path <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF00FF;">CHARINDEX</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'\'</span>, <span style="color: #FF00FF;">REVERSE</span><span style="color: #808080;">&#40;</span>@_backup_server_network_path<span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">&amp;</span>gt; <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'\'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @_database_name <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">--------------------------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Sauvegarde d'une base de données en particulier</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">--------------------------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">EXISTS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">databases</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; name <span style="color: #808080;">=</span> @_database_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @err_msg <span style="color: #808080;">=</span> <span style="color: #FF0000;">'La base de données '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> @_database_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">' n'</span><span style="color: #FF0000;">'existe pas.'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">RAISERROR</span><span style="color: #808080;">&#40;</span>@err_msg, <span style="color: #000;">16</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">EXISTS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">databases</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; name <span style="color: #808080;">=</span> @_database_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; state_desc <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ONLINE'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; user_access_desc <span style="color: #808080;">=</span> <span style="color: #FF0000;">'MULTI_USER'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; source_database_id <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span> <span style="color: #008080;">-- La base de données n'est pas un snapshot</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; database_id &nbsp;<span style="color: #000;">2</span> <span style="color: #008080;">-- La base de données n'est pas TempDB</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @err_msg <span style="color: #808080;">=</span> <span style="color: #FF0000;">'La base de données '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> @_database_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">' n'</span><span style="color: #FF0000;">'est pas disponible ou est une capture intantanée.'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">RAISERROR</span><span style="color: #808080;">&#40;</span>@err_msg, <span style="color: #000;">16</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Vérifie le type de backup</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @_backup_type <span style="color: #808080;">NOT</span> <span style="color: #808080;">IN</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'FULL'</span>, <span style="color: #FF0000;">'DIFFERENTIAL'</span>, <span style="color: #FF0000;">'LOG'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @err_msg <span style="color: #808080;">=</span> <span style="color: #FF0000;">'The backup type '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> @_backup_type <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">' is invalid.'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">RAISERROR</span><span style="color: #808080;">&#40;</span>@err_msg, <span style="color: #000;">16</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @<span style="color: #0000FF;">sql</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'BACKUP '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> @_backup_type <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'FULL'</span>, <span style="color: #FF0000;">'DIFFERENTIAL'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'DATABASE '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> @_backup_type <span style="color: #808080;">=</span> <span style="color: #FF0000;">'LOG'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'LOG '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #808080;">+</span> @_database_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">' TO DISK = '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> @_backup_server_network_path <span style="color: #808080;">+</span> <span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">@@SERVERNAME</span>, <span style="color: #FF0000;">'\'</span>, <span style="color: #FF0000;">'_'</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'\'</span> <span style="color: #808080;">+</span> @_database_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'_'</span> <span style="color: #808080;">+</span> @_backup_type <span style="color: #808080;">+</span> <span style="color: #FF0000;">'_'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">19</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">120</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF0000;">':'</span>, <span style="color: #FF0000;">'-'</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF0000;">' '</span>, <span style="color: #FF0000;">'_'</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.bak'</span><span style="color: #FF0000;">''</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">' WITH '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> @_backup_type<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'DIFFERENTIAL'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'DIFFERENTIAL, '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'FULL'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'INIT, '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> @compression <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'COMPRESSION, '</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span> <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">'CHECKSUM'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @_print_only <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> @<span style="color: #0000FF;">sql</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span> TRY<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span> @<span style="color: #0000FF;">sql</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> TRY<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span> CATCH<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @err_msg <span style="color: #808080;">=</span> @_database_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">' | '</span> <span style="color: #808080;">+</span> ERR<span style="color: #808080;">OR</span>_MESSAGE<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">RAISERROR</span><span style="color: #808080;">&#40;</span>@err_msg, <span style="color: #000;">16</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> CATCH<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">--------------------------------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Sauvegarde de toutes les bases de données disponibles</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">--------------------------------------------------------</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @_backup_type <span style="color: #808080;">=</span> <span style="color: #FF0000;">'LOG'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @err_msg <span style="color: #808080;">=</span> <span style="color: #FF0000;">'On ne prend pas une sauvegarde du fichier du journal des transactions de toutes les bases de données.'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">RAISERROR</span><span style="color: #808080;">&#40;</span>@err_msg, <span style="color: #000;">16</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DECLARE</span> @database_list <span style="color: #0000FF;">TABLE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; database_name <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">128</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span>&nbsp; <span style="color: #0000FF;">INTO</span> @database_list<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; database_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>name, <span style="color: #FF0000;">' '</span>, <span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span> <span style="color: #008080;">-- Certaines bases de données ne respectent pas la convention de nommage SQL ANSI.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">databases</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; source_database_id <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span> <span style="color: #008080;">-- La base de données n'est pas un snapshot</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; state_desc <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ONLINE'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; user_access_desc <span style="color: #808080;">=</span> <span style="color: #FF0000;">'MULTI_USER'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; database_id &nbsp;<span style="color: #000;">2</span> <span style="color: #008080;">-- On exclut TempDB</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">EXISTS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; @database_list<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #0000FF;">TOP</span> <span style="color: #000;">1</span> @_database_name <span style="color: #808080;">=</span> database_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; @database_list<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @<span style="color: #0000FF;">sql</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'BACKUP DATABASE '</span> <span style="color: #808080;">+</span> @_database_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">' TO DISK = '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> @_backup_server_network_path <span style="color: #808080;">+</span> <span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">@@SERVERNAME</span>, <span style="color: #FF0000;">'\'</span>, <span style="color: #FF0000;">'_'</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'\'</span> <span style="color: #808080;">+</span> @_database_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'_'</span> <span style="color: #808080;">+</span> @_backup_type <span style="color: #808080;">+</span> <span style="color: #FF0000;">'_'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">19</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">120</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF0000;">':'</span>, <span style="color: #FF0000;">'-'</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF0000;">' '</span>, <span style="color: #FF0000;">'_'</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.bak'</span><span style="color: #FF0000;">''</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">' WITH '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> @_backup_type<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'DIFFERENTIAL'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'DIFFERENTIAL, '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'FULL'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'INIT, '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> @compression <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'COMPRESSION, '</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span> <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">'CHECKSUM'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @_print_only <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">PRINT</span> @<span style="color: #0000FF;">sql</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span> TRY<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_executesql</span> @<span style="color: #0000FF;">sql</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> TRY<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span> CATCH<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @err_msg <span style="color: #808080;">=</span> @_database_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">' | '</span> <span style="color: #808080;">+</span> ERR<span style="color: #808080;">OR</span>_MESSAGE<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">RAISERROR</span><span style="color: #808080;">&#40;</span>@err_msg, <span style="color: #000;">16</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> CATCH<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DELETE</span>&nbsp; <span style="color: #0000FF;">FROM</span> @database_list<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; database_name <span style="color: #808080;">=</span> @_database_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> TRY<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span> CATCH<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Envoie un email en cas d'erreur</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span> dbo.<span style="color: #202020;">spasb_mail_send</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @_sender <span style="color: #808080;">=</span> <span style="color: #FF0000;">'it@myCompany.com'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @_recipients <span style="color: #808080;">=</span> <span style="color: #FF0000;">'it@myCompany.com'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @_subject <span style="color: #808080;">=</span> @mail_subject<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @_body <span style="color: #808080;">=</span> @err_msg<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> CATCH<br />
<span style="color: #0000FF;">END</span></div></td></tr></tbody></table></div>
<p><span style="font-weight:bold;font-family:Verdana;font-size:18px">Remplacer l&rsquo;Agent SQL Server par le Planificateur de Tâches de Windows</span></p>
<p>Nous voilà à l&rsquo;étape finale : prendre des sauvegardes de base de données régulièrement. Pour ce faire, on peut tout à fait utiliser le <em>Planificateur de Tâches de Windows</em> : en effet, on peut appeler l&rsquo;utilitaire en ligne de commandes <em>SQLCMD</em> (la <a href="http://technet.microsoft.com/fr-fr/library/ms162773.aspx">documentation</a>, l&rsquo;<a href="http://technet.microsoft.com/fr-fr/library/ms180944.aspx">utilisation</a>, et un <a href="http://technet.microsoft.com/fr-fr/library/ms170207%28v=sql.105%29.aspx">exemple</a>), qui permet d&rsquo;interagir avec une instance SQL Server. Cet outil permet de passer en paramètre un script, d&rsquo;exécuter une requête, mais surtout d&rsquo;enregistrer la sortie dans un fichier. Cette dernière fonctionnalité facilite la tâche d&rsquo;investigation sur l&rsquo;échec d&rsquo;exécution de code.</p>
<p>Une fois l&rsquo;application <em>Planificateur de Tâches</em> démarrée, on créé une tâche assez simplement :</p>
<p><img src="http://i.imgur.com/ZSHAIHP.png" alt="" /></p>
<p>Une fois passé la première page ou nous nommons la tâche, un clic sur <em>Next</em> nous amène à la planification. Pour <em>Windows Server Update Services</em>, on peut estimer qu&rsquo;une sauvegarde complète par jour est suffisante. Évidemment, cela varie avec la criticité de l&rsquo;application. Nous spécifions donc une exécution quotidienne :</p>
<p><img src="http://i.imgur.com/QdAUdsn.png" alt="" /></p>
<p>Nous planifions l&rsquo;exécution à minuit et une minute :</p>
<p><img src="http://i.imgur.com/JXOESBU.png" alt="" /></p>
<p>Et nous choisissons de démarrer une application :</p>
<p><img src="http://i.imgur.com/ImwrMln.png" alt="" /></p>
<p>Dans la saisie texte <em>Program / Script</em>, nous spécifions l&rsquo;invite de commandes. En ce qui concerne les arguments, nous écrivons :</p>
<ul>
<li>Pour SQL Server 2008 :<br />
<code class="codecolorer dos default"><span class="dos">&quot;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE&quot;</span></code></li>
<li>Pour SQL Server 2012 :<br />
<code class="codecolorer dos default"><span class="dos">&quot;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE&quot;</span></code></li>
<li>Pour SQL Server 2014 :<br />
<code class="codecolorer dos default"><span class="dos">&quot;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\SQLCMD.EXE&quot;</span></code></li>
</ul>
<p>En ce qui concerne les arguments, nous passons :</p>
<p><code class="codecolorer dos default"><span class="dos">sqlcmd -E -S WSUS -i &quot;C:\SQLServer\WSUSBackup.sql&quot; -o &quot;C:\SQLServerBackup\FullBackupLog.txt&quot;</span></code></p>
<p>Attention, la casse des options est importante.</p>
<ul>
<li>-E pour spécifier une connexion approuvée</li>
<li>-S : l&rsquo;instance SQL Server à laquelle on souhaite se connecter</li>
<li>-i : le chemin et le nom du fichier de script T-SQL</li>
<li>-o : le fichier qui capturera les libellés des messages d&rsquo;information, d&rsquo;avertissement ou d&rsquo;erreurs, le cas échéant</li>
</ul>
<p>Ce qui donne :</p>
<p><img src="http://i.imgur.com/6I12ozL.png" alt="" /></p>
<p>Un clic sur <em>Next</em> nous offre une fenêtre de résumé, et on peut valider le tout. Si l&rsquo;on souhaite ajouter des planifications ou modifier d&rsquo;autres options pour cette tâche, il suffit de cocher la case <em>Open the Properties dialog for this task when I click Finish</em>.</p>
<p>Nous créons ensuite un fichier <em>WSUSBackup.sql</em> dans un répertoire <em>C:\SQLServer\</em> sur la machine qui héberge l&rsquo;application WSUS. Ce fichier appelle la procédure stockée <em>DBA.dbo.databaseBackup_manage</em> comme suit :</p>
<p><code class="codecolorer text default"><span class="text">EXEC DBA.dbo.databaseBackup_manage 'FULL', NULL, '\\monPartageDeBackup\', 0</span></code></p>
<p>Et voilà nos sauvegardes de base de données en place.</p>
<p><span style="font-weight:bold;font-family:Verdana;font-size:18px">Utiliser PowerShell pour supprimer les fichiers de sauvegardes trop anciens</span></p>
<p>Dans la liste des actions de la tâche que nous venons de créer, nous pouvons en ajouter une qui aura :</p>
<ul>
<li>Pour programme : <code class="codecolorer text default"><span class="text">powershell</span></code></li>
<li>Pour arguments : <code class="codecolorer text default"><span class="text">-file &quot;C:\SQLServer\DeleteOldBackupFiles.ps1&quot;</span></code></li>
</ul>
<p>Le fichier <em>DeleteOldBackupFiles.ps1</em> contient la commande suivante, qui supprime tous les fichiers créés il y a plus de 7 jours, y compris dans les sous-dossiers du partage de backup (-Recurse) :</p>
<p><code class="codecolorer powershell default"><span class="powershell"><span style="color: #008080; font-weight: bold;">Get-ChildItem</span> <span style="color: #800000;">'\\monPartageDeBackup\'</span> <span style="color: #008080; font-style: italic;">-Recurse</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.CreationTime <span style="color: #FF0000;">-lt</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddDays<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #804000;">7</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Remove-Item</span> <span style="color: #008080; font-style: italic;">-Force</span></span></code></p>
<p>Par défaut, PowerShell ne permet pas l&rsquo;exécution de scripts. Pour l&rsquo;autoriser, il faut démarrer l&rsquo;interface PowerShell, et exécuter <code class="codecolorer powershell default"><span class="powershell"><span style="color: #008080; font-weight: bold;">Set-ExecutionPolicy</span> RemoteSigned</span></code> (en accord avec votre Administrateur Systèmes !).</p>
<p>Retenons également que les statistiques de colonne et d&rsquo;index de la base de données supportant WSUS ne sont pas maintenues. Ce sera probablement suffisant pour générer une lenteur après quelques mois d&rsquo;exploitation, dont votre Administrateur Systèmes vous demandera l&rsquo;origine <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSDT-BI et SSDT : ou l&#8217;un, ou l&#8217;autre, et aussi les deux !</title>
		<link>https://blog.developpez.com/elsuket/p12610/utilitaires/ssdt-bi-et-ssdt-ou-lun-ou-lautre-et-aussi-les-deux</link>
		<comments>https://blog.developpez.com/elsuket/p12610/utilitaires/ssdt-bi-et-ssdt-ou-lun-ou-lautre-et-aussi-les-deux#comments</comments>
		<pubDate>Fri, 09 May 2014 17:40:23 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Assembly & CLR]]></category>
		<category><![CDATA[SQL Server Analysis Services]]></category>
		<category><![CDATA[SQL Server Integration Services]]></category>
		<category><![CDATA[SQL Server Reporting Services]]></category>
		<category><![CDATA[Utilitaires]]></category>
		<category><![CDATA[Business Intelligence]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[SQL Server Data Tools]]></category>
		<category><![CDATA[SSDT]]></category>
		<category><![CDATA[Support Décisionnel]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1000</guid>
		<description><![CDATA[SQL Server Business Intelligence Studio a été remplacé par SQL Server Data Tools (SSDT). SSDT a été mis en ligne pour la première fois pour Visual Studio 2010, qu&#8217;il installait en mode Shell. Cette version n&#8217;est maintenant plus disponible, mais &#8230; <a href="https://blog.developpez.com/elsuket/p12610/utilitaires/ssdt-bi-et-ssdt-ou-lun-ou-lautre-et-aussi-les-deux">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><em>SQL Server Business Intelligence Studio</em> a été remplacé par <a href="http://blog.developpez.com/elsuket/p12489/indexation/pivot-ssdt-attention-ordre" title="La transformation Pivot avec SQL Server Data Tools (ex SSIS) : attention à l’ordre !">SQL Server Data Tools</a> (SSDT).</p>
<p>SSDT a été mis en ligne pour la première fois pour Visual Studio 2010, qu&rsquo;il installait en mode Shell. Cette version n&rsquo;est maintenant plus disponible, mais on la trouve bien entendu pour Visual Studio 2012 (<a href="http://www.microsoft.com/fr-fr/download/details.aspx?id=36843">fr</a>/<a href="http://www.microsoft.com/en-us/download/details.aspx?id=36843">en</a>) et 2013 (<a href="http://www.microsoft.com/fr-fr/download/details.aspx?id=42313">fr</a>/<a href="http://www.microsoft.com/en-us/download/details.aspx?id=42313">en</a>).</p>
<p>Ce dernier est en fait décliné en deux opus, l&rsquo;un dédié à la Business Intelligence, abrévié en SSDT-BI, et l&rsquo;autre SSDT tout court. Les deux versions installent toujours Visual Studio en mode Shell, mais la version BI n&rsquo;installe pas les composants nécessaires au développement d&rsquo;un projet d&rsquo;assembly SQL Server. Et inversement.</p>
<p>J&rsquo;avais donc installé SSDT-BI 2012 sans noter que le projet de type SQL Server n&rsquo;était pas présent. J&rsquo;ai donc installé SSDT 2012 (téléchargeable <a href="http://msdn.microsoft.com/en-us/data/hh297027">ici</a> en version 2012 et 2013), et j&rsquo;ai maintenant ce qui me manquait :</p>
<p><img src="http://i.imgur.com/JNW6bZz.png" alt="" /></p>
<p>Bon développement SQL Server !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Déçu par IntelliSense ? Essayez Devart dbForge SQL Complete !</title>
		<link>https://blog.developpez.com/elsuket/p12156/utilitaires/dbforge-sql-complete</link>
		<comments>https://blog.developpez.com/elsuket/p12156/utilitaires/dbforge-sql-complete#comments</comments>
		<pubDate>Sun, 28 Jul 2013 14:00:10 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=764</guid>
		<description><![CDATA[Si vous utilisez SQL Server Management Studio (SSMS) de façon assez intensive, vous avez probablement trouvé que la fonctionnalité IntelliSense de ce dernier souffre de lacunes pour le moins désagréables à l&#8217;usage. Parmi celles-ci, on trouve l&#8217;impossibilité de chercher une &#8230; <a href="https://blog.developpez.com/elsuket/p12156/utilitaires/dbforge-sql-complete">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Si vous utilisez SQL Server Management Studio (SSMS) de façon assez intensive, vous avez probablement trouvé que la fonctionnalité IntelliSense de ce dernier souffre de lacunes pour le moins désagréables à l&rsquo;usage. Parmi celles-ci, on trouve l&rsquo;impossibilité de chercher une table suivant un mot que son nom contient, ou encore un manque notable sur le scriptage automatique des paramètres d&rsquo;une procédure stockée ou d&rsquo;une instruction DML.</p>
<p>C&rsquo;est ce que à quoi remédie <a href="http://www.devart.com/dbforge/sql/sqlcomplete/" title="dbForge SQL Complete">dbForge SQL Complete</a>, qui remplace allègrement SSMS IntelliSense. Je vous propose ici une revue de l&rsquo;édition Standard de SQL Complete, mais sachez qu&rsquo;il en existe une version gratuite pour un usage non-commercial.<br />
<span id="more-764"></span></p>
<p>L&rsquo;installation du plugin SSMS se fait comme pour toute application. Elle requiert simplement que SSMS ne soit pas en cours d&rsquo;exécution. Sachez néanmoins que SQL Complete s&rsquo;intègre bien sûr à SQL Server Management Studio 2012, mais aussi avec Visual Studio 2012 :</p>
<p><img src="http://img202.imageshack.us/img202/6326/q0ss.png" alt="" /></p>
<p>Le plugin vérifie automatiquement si une nouvelle version est disponible au démarrage de SSMS, et vous permet d&rsquo;effectuer le téléchargement de celle-ci. La progression du téléchargement est affichée à gauche dans la barre d&rsquo;état. Quand celui-ci est terminé, une popup apparait, indiquant l&rsquo;emplacement du fichier. Il est alors nécessaire de fermer SSMS pour poursuivre la mise à jour du plugin.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Aide à l&rsquo;écriture de code</strong></p>
<p>Dès le (re)démarrage de SSMS, on trouve un élément de plus dans la barre de menu, nommé SQL Complete. Avant de développer les options de SQL Complete, voyons ce qu&rsquo;il peut faire. Nous changeons le contexte de bases de données à l&rsquo;aide de l&rsquo;instruction USE AdventureWorks2012 : automatiquement, le cache de SQL Complete charge les métadonnées de la base de données en cours d&rsquo;utilisation, et affiche une barre de progression à droite, dans la barre d&rsquo;état. On trouve alors la liste des bases de données hébergées par l&rsquo;instance SQL Server très simplement :</p>
<p><img src="http://img266.imageshack.us/img266/6965/xw3g.png" alt="" /></p>
<p>Le simple fait de taper &laquo;&nbsp;S&nbsp;&raquo; amène la liste suivante :</p>
<p><img src="http://img856.imageshack.us/img856/5646/um9o.png" alt="" /></p>
<p>Nous avons donc en premier une liste de possibilités T-SQL, suivies par une liste de snippets. Nous verrons plus tard qu&rsquo;il existe un gestionnaire de snippets fort pratique. Supposons que nous voulions écrire SET TRANSACTION ISOLATION LEVEL REPEATABLE. Avec IntelliSence, il faut tout écrire, caractère par caractère. Mais avec SQL Complete, il suffit seulement de taper les premières lettres de chaque mot-clé; les mots-clé qui suivent sont automatiquement pré-filtrés avant l&rsquo;affichage dans l&rsquo;infobulle :</p>
<p><img src="http://img15.imageshack.us/img15/3828/acy.gif" alt="" /></p>
<p>Certes, le gain de temps n&rsquo;est pas énorme, mais cela rend le travail moins pénible en évitant tout simplement les fautes de frappe !</p>
<p>Voyons maintenant comment appeler une procédure stockée sans se fatiguer : on sait que le nom de la procédure stockée contient le mot <em>employee</em>; on tape donc EXEC employee, et on obtient :</p>
<p><img src="http://img855.imageshack.us/img855/903/yp4p.png" alt="" /></p>
<p>Une fois que l&rsquo;on a validé par ENTER, on peut suivre suggestion de l&rsquo;infobulle pour obtenir la liste des paramètres :</p>
<p><img src="http://img819.imageshack.us/img819/3647/lhqk.png" alt="" /></p>
<p>Et nous obtenons alors :</p>
<p><img src="http://img202.imageshack.us/img202/9148/ovp3.png" alt="" /></p>
<p>Avouons que c&rsquo;est moins pénible que de filtrer la liste produite par l&rsquo;Explorateur d&rsquo;Objets de SSMS.<br />
Si nous passons le curseur sur la procédure stockée, nous obtenons une nouvelle fois la liste de ses paramètres dans une infobulle. Si l&rsquo;on souhaite spécifier la valeur des paramètres un à un, là aussi le travail nous est facilité : supposons que nous avons spécifié le premier paramètre, et que nous venons de taper une virgule, qui va introduire le second : automatiquement, l&rsquo;infobulle avec la liste des paramètres apparait, et il n&rsquo;y a plus qu&rsquo;à sélectionner le paramètre souhaité :</p>
<p><img src="http://img14.imageshack.us/img14/7814/9cxc.png" alt="" /></p>
<p>Que l&rsquo;on soit en train d&rsquo;écrire un script ou une procédure stockée, l&rsquo;accès aux variables locales ou aux paramètres d&rsquo;entrée se fait là aussi très aisément, par l&rsquo;affichage automatique de l&rsquo;infobulle :</p>
<p><img src="http://img202.imageshack.us/img202/7991/7lt4.png" alt="" /></p>
<p>Si l&rsquo;on souhaite consulter la définition de la procédure stockée, il suffit de choisir l&rsquo;option <em>Go To Definition</em> dans le menu contextuel :</p>
<p><img src="http://img802.imageshack.us/img802/1060/ma2b.png" alt="" /></p>
<p>L&rsquo;explorateur d&rsquo;objets est immédiatement affecté et a sélectionné la procédure stockée.</p>
<p><img src="http://img208.imageshack.us/img208/3786/9uo.png" alt="" /></p>
<p>Notons que la même option est offerte pour tout objet de base de données.<br />
Voyons d&rsquo;ailleurs comment obtenir la définition d&rsquo;une table sans pour autant avoir affaire avec l&rsquo;Explorateur d&rsquo;Objets de SSMS :</p>
<p><img src="http://img341.imageshack.us/img341/6558/zrhr.png" alt="" /></p>
<p>Bref, SQL Complete nous offre un arsenal d&rsquo;infobulles qui nous permet de gagner du temps en évitant toute faute de frappe, et dans la recherche d&rsquo;objets de code ou de base de données. Ceci permet finalement de n&rsquo;avoir à se concentrer quasiment que sur la logique à implémenter.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Le gestionnaire de snippets</strong></p>
<p>Comme nous l&rsquo;avons vu plus haut, SQL Complete est livré avec un ensemble de snippets. Il est en plus possible de les éditer et d&rsquo;en créer de nouveaux, à l&rsquo;aide du gestionnaire, que l&rsquo;on obtient en choisissant l&rsquo;option <em>Snippets Manager</em> du menu <em>SQL Complete</em>, dans la barre de menus. Voici l&rsquo;interface obtenue :</p>
<p><img src="http://img441.imageshack.us/img441/622/bxec.png" alt="" /></p>
<p>L&rsquo;interface est sobre mais bien conçue, puisqu&rsquo;on peut :</p>
<ol>- Consulter la liste des snippets disponibles<br />
&#8211; Éditer les snippets existants, de façon à ce qu&rsquo;ils suivent un formatage particulier<br />
&#8211; Utiliser des variables prédéfinies, comme DATE, TIME, USER, SERVER, DB, ce qui permet par exemple de faciliter l&rsquo;écriture d&rsquo;en-têtes de modules T-SQL, ou de scripts<br />
&#8211; Organiser les snippets par dossier<br />
&#8211; Créer ses propres paramètres fictifs, ou en créer de nouveaux, qui sont attachés à un snippet particulier<br />
&#8211; Partager un snippet sur Devart</ol>
<p>Par ailleurs les snippets fournis par Devart sont très complets, comme l&rsquo;illustre la capture d&rsquo;écran ci-dessus pour le snippet nommé <em>CreateDatabase</em>. Enfin, les snippets sont stockés sous la forme de fichiers XML portant l&rsquo;extension <em>.snippet</em>, dont l&rsquo;emplacement est affiché en bas de l&rsquo;interface : ceci rend le partage de snippets entre collaborateurs très facile.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Aide au formatage</strong></p>
<p>Parmi les options que l&rsquo;on trouve après avoir suivi <em>SQL Complete</em> &gt; <em>Options</em> depuis la barre de menus, on remarque qu&rsquo;il est possible de créer, éditer et partage des profils de formatage :</p>
<p><img src="http://img547.imageshack.us/img547/183/m3so.png" alt="" /></p>
<p>Si l&rsquo;on clique sur le bouton <em>Edit Profile &#8230;</em>, on obtient une interface encore une fois sobre mais efficace, et surtout exhaustive :</p>
<p><img src="http://img33.imageshack.us/img33/668/hj17.png" alt="" /></p>
<p>Tous les aspects de la puissance du langage T-SQL sont abordés, et on peut aller de la place et l&rsquo;alignement des mots-clé aux lignes d&rsquo;intervalle ou indentations entre les instructions. On peut donc paramétrer le formateur pour qu&rsquo;il nous obéisse au doigt et à l’œil. De retour dans une fenêtre, l&rsquo;application du formatage se fait de façon intuitive, par un simple clic-droit sur l&rsquo;ensemble de requêtes à formater :</p>
<p><img src="http://img853.imageshack.us/img853/3282/s6d.png" alt="" /></p>
<p>Et l&rsquo;on obtient immédiatement :</p>
<p><img src="http://img29.imageshack.us/img29/4858/ld2p.png" alt="" /></p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Import et export des paramètres</strong></p>
<p>L’uniformisation de l&rsquo;utilisation d&rsquo;un standard de codage parmi toutes les personnes qui doivent écrire du code T-SQL dans l&rsquo;entreprise est facilité par l&rsquo;export de cet ensemble de paramètres, qui comprend ceux de l&rsquo;interface et ceux de formate, mais pas les snippets. Cependant pour ces derniers, comme nous l&rsquo;avons vu, il est facile de les trouver puisqu&rsquo;ils sont stockés sous la forme de fichiers XML portant l&rsquo;extension <em>.snippet</em> : leur emplacement est affiché en bas de l&rsquo;interface de gestion des snippets.<br />
On accède comme d&rsquo;habitude à cette option en suivant <em>SQL Complete</em> &gt; <em>Import and Export Settings</em></p>
<p><img src="http://img38.imageshack.us/img38/8970/pp3e.png" alt="" /></p>
<p>L&rsquo;utilisation de l&rsquo;interface étant triviale, je passe sur les détails :</p>
<p><img src="http://img713.imageshack.us/img713/9111/9xni.png" alt="" /></p>
<p><img src="http://img850.imageshack.us/img850/3660/agtx.png" alt="" /></p>
<p><img src="http://img405.imageshack.us/img405/8067/xu3p.png" alt="" /></p>
<p>Une fonctionnalité intéressante non seulement pour partager les paramètres avec ses collègues, mais aussi pour en réaliser une sauvegarde et faciliter un changement de PC.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Conclusion</strong></p>
<p>Devart dbForce SQL Complete est un outil extrêmement complet qui, dès qu&rsquo;on commence à l&rsquo;utiliser, fait rapidement oublier les insuffisances de l&rsquo;intégration d&rsquo;IntelliSense à SQL Server Management Studio. En plus de faciliter l&rsquo;écriture de code, il permet de renforcer les standards de codage d&rsquo;une équipe de développement par la possibilité de formater automatiquement et avec une précision chirurgicale du code T-SQL, et d&rsquo;échanger ce formatage de façon aisée par un simple import / export. L&rsquo;utilité des snippets et indiscutable, et la gestion proposée par ce plugin est supérieure encore une fois à ce qu&rsquo;offre SQL Server Management Studio 2012.</p>
<p>On ne peut donc que féliciter Devart pour la qualité irréprochable de ce produit, qui est d&rsquo;ailleurs décliné pour MySQL, Oracle, et bientôt PostGre SQL. Par ailleurs Devart offre d&rsquo;autres produits, comme des pilotes pour l&rsquo;accès aux base de données, et des solutions d&rsquo;aide au développement par ORM ou avec Delphi.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Auditer les processus bloqués : l&#8217;événement blocked process report</title>
		<link>https://blog.developpez.com/elsuket/p12049/snippets/auditer-les-processus-bloques-levenement-blocked-process-report</link>
		<comments>https://blog.developpez.com/elsuket/p12049/snippets/auditer-les-processus-bloques-levenement-blocked-process-report#comments</comments>
		<pubDate>Sat, 15 Jun 2013 10:46:31 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Non documenté]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Utilitaires]]></category>
		<category><![CDATA[%%lockres%%]]></category>
		<category><![CDATA[blocage]]></category>
		<category><![CDATA[blocked process report]]></category>
		<category><![CDATA[blocked process threshold]]></category>
		<category><![CDATA[blocking]]></category>
		<category><![CDATA[deadlock]]></category>
		<category><![CDATA[événements étendus]]></category>
		<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[lock monitor]]></category>
		<category><![CDATA[Profiler]]></category>
		<category><![CDATA[sp_configure]]></category>
		<category><![CDATA[timeout]]></category>
		<category><![CDATA[verrou]]></category>
		<category><![CDATA[waitresource]]></category>
		<category><![CDATA[XE]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=604</guid>
		<description><![CDATA[SQL Server 2005 a introduit un évènement capturable par SQL Profiler et par les Notifications d’évènements, qui permet de retrouver les processus qui ont été bloqués. Avec la sortie de SQL Server 2008 et l&#8217;introduction des Évènements Étendus, il nous &#8230; <a href="https://blog.developpez.com/elsuket/p12049/snippets/auditer-les-processus-bloques-levenement-blocked-process-report">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SQL Server 2005 a introduit un évènement capturable par <em><a href="http://elsuket.developpez.com/tutoriels/sqlserveur/fichier-trace-cote-serveur/">SQL Profiler</a></em> et par les <em>Notifications d’évènements</em>, qui permet de retrouver les processus qui ont été bloqués. Avec la sortie de SQL Server 2008 et l&rsquo;introduction des <em><a href="http://elsuket.developpez.com/tutoriels/sqlserveur/EvenementsEtendusSQLServer2008/">Évènements Étendus</a></em>, il nous est également possible de capturer cet évènement.</p>
<p>Dans cet article, je vous propose de voir comment paramétrer SQL Server pour capturer cet évènement, puis de vous aider à interpréter le document XML qui décrit la situation de blocage.<br />
<span id="more-604"></span><br />
Toute exécution de requête résulte en l&rsquo;acquisition de verrous, dont la granularité (ligne, page, clé, partition, table, base de données, ou encore et plus rarement compilation) et le mode (partagé, exclusif, de mise à jour, ou d&rsquo;intention) varient. Le verrouillage de ressources est une opération de base pour le moteur de stockage de tout moteur de bases de données SQL, qui garantit l&rsquo;intégrité de la base de données à travers toutes les opérations de manipulation de données que celle-ci supporte. Cependant, il arrive que lorsqu&rsquo;un processus a posé un verrou sur une ressource, d&rsquo;autres processus doivent simultanément accéder à cette même ressource : ces processus sont alors bloqués. Comme il est possible que le processus bloquant ne libère ledit verrou qu&rsquo;après une durée relativement longue, les effets possibles d&rsquo;une telle situation sur nos applications peuvent aller de requêtes dont la durée d&rsquo;exécution est élevée jusqu&rsquo;à l&rsquo;expiration du délai d&rsquo;attente d&rsquo;une réponse pour l&rsquo;exécution d&rsquo;un requête : le fameux <em>timeout</em>.</p>
<p>Il est néanmoins possible, à l&rsquo;aide d&rsquo;une trace SQL Profiler ou des Évènements Étendus, de capturer ces situations, qui sont décrites par un document XML.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Configurer l&rsquo;instance SQL Server</strong></p>
<p>Le seuil de durée de blocage à partir de laquelle on souhaite capturer un tel évènement est configurable à l&rsquo;aide de l&rsquo;option d&rsquo;instance <em>blocked process threshold</em>. On accède à ce paramètre :</p>
<p>&#8211; soit à l&rsquo;aide de <em>SQL Server Management Studio</em> (SSMS), après un clic-droit sur l&rsquo;instance dans l&rsquo;Explorateur d&rsquo;Objets (F8), et avoir choisi l&rsquo;option <em>Propriétés</em> :</p>
<p><img src="http://img855.imageshack.us/img855/6901/gq2.png" alt="" /></p>
<p>&#8211; soit à l&rsquo;aide de la procédure stockée système <em>sp_configure</em> :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">configurations</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; name <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'%block%'</span></div></td></tr></tbody></table></div>
<p><img src="http://img836.imageshack.us/img836/9273/zx81.png" alt="" /></p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">-- Activation de la modification d'options d'instance avancées</span><br />
<span style="color: #0000FF;">EXEC</span> sys.<span style="color: #AF0000;">sp_configure</span> <span style="color: #FF0000;">'show advanced options'</span>, <span style="color: #000;">1</span> <br />
GO<br />
<span style="color: #0000FF;">RECONFIGURE</span><br />
GO<br />
<br />
<span style="color: #008080;">-- Configuration du seuil de durée de blocage à 5 secondes</span><br />
<span style="color: #0000FF;">EXEC</span> sys.<span style="color: #AF0000;">sp_configure</span> <span style="color: #FF0000;">'blocked process threshold'</span>, <span style="color: #000;">5</span><br />
GO <br />
<span style="color: #0000FF;">RECONFIGURE</span>; <br />
GO<br />
<br />
<span style="color: #008080;">-- Désactivation de la modification d'options d'instance avancées</span><br />
<span style="color: #0000FF;">EXEC</span> sys.<span style="color: #AF0000;">sp_configure</span> <span style="color: #FF0000;">'show advanced options'</span>, <span style="color: #000;">0</span><br />
GO<br />
<span style="color: #0000FF;">RECONFIGURE</span><br />
GO</div></td></tr></tbody></table></div>
<p>La console de SSMS affiche, à l&rsquo;exécution de ce lot de requêtes :</p>
<p><img src="http://img28.imageshack.us/img28/4259/1ug.png" alt="" /></p>
<p>Veillez à ne pas mettre un seuil trop bas : sans cela, on aurait le processus d&rsquo;arrière plan LOCK MONITOR qui s&rsquo;exécuterait constamment. Or ce dernier, qui est aussi en charge de détecter les deadlocks, est gourmand en ressources CPU. En s&rsquo;exécutant fréquemment, il pourrait donc impacter négativement les performances générales de l&rsquo;instance SQL Server. D&rsquo;un autre côté, 5 secondes est une durée très longue sur une base de données qui supporte une charge de travail OLTP conséquente. On trouve ce processus avec la requête suivante :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; session_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , status<br />
&nbsp; &nbsp; &nbsp; &nbsp; , command<br />
&nbsp; &nbsp; &nbsp; &nbsp; , wait_type<br />
&nbsp; &nbsp; &nbsp; &nbsp; , wait_time<br />
&nbsp; &nbsp; &nbsp; &nbsp; , last_wait_type<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">dm_exec_requests</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; command <span style="color: #808080;">=</span> <span style="color: #FF0000;">'LOCK MONITOR'</span></div></td></tr></tbody></table></div>
<p>Si l&rsquo;on exécute maintenant cette requête de façon répétée, on voit que la valeur de la colonne <em>wait_time</em> croit jusqu&rsquo;à atteindre 5000, mais ne dépasse jamais cette valeur : cette colonne affiche sa valeur en millisecondes, et montre bien que le processus cherche les processus bloqués toutes les 5 secondes.</p>
<p>Il faut aussi noter qu&rsquo;avec cette configuration, si un processus reste bloqué 15 secondes, l’évènement sera généré 3 fois pour la même situation de blocage.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Capture avec SQL Profiler</strong></p>
<p>Une fois cela fait, nous démarrons SQL Profiler, et dans l&rsquo;onglet de sélection des évènements, dans la catégorie <em>Errors and Warnings</em> (et non pas dans la catégorie <em>Locks</em>), nous trouvons l’évènement <em>Blocked process report</em> :</p>
<p><img src="http://img546.imageshack.us/img546/5205/hptk.png" alt="" /></p>
<p>Nous configurons l’évènement comme suit, où le champ <em>TextData</em> contiendra le document XML décrivant la situation de blocage :</p>
<p><img src="http://img19.imageshack.us/img19/2305/n66.png" alt="" /></p>
<p><strong>N.B.</strong> : N&rsquo;oubliez pas le champ <em>Mode</em>, qui procure le type de verrou acquis.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Capture avec les Évènements Étendus (XE)</strong></p>
<p>Pour les lecteurs qui n&rsquo;ont pas encore eu le temps de se familiariser avec cette fonctionnalité, qui est vouée au remplacement futur de SQL Profiler, et dont la puissance en fait mon outil de diagnostic favori, vous pouvez vous aider de l&rsquo;<a href="http://elsuket.developpez.com/tutoriels/sqlserveur/EvenementsEtendusSQLServer2008/">article</a> que j&rsquo;ai publié sur le sujet.</p>
<p>Si l&rsquo;on souhaite capturer en permanence toute situation de blocage, l&rsquo;avantage revient à XE, puisqu&rsquo;on peut stocker ces évènements dans une cible dite anneau de mémoire (ring buffer). Cette structure consomme très peu de mémoire et fonctionne à l&rsquo;image d&rsquo;un FIFO : lorsqu&rsquo;il est plein, la capture d&rsquo;un nouvel évènement donne lieu à l&rsquo;éviction du plus vieil évènement pour le stockage de celui-ci. Avec SQL Profiler, il est nécessaire de mettre en place une trace côté serveur et de gérer le fichier de trace et l&rsquo;espace disque. En revanche, une fois que l&rsquo;on a démarré la session XE, on peut &laquo;&nbsp;l&rsquo;oublier&nbsp;&raquo;.</p>
<p>Pour les lecteurs familiers de XE et de Profiler, sachez que le document XML produit par ces deux fonctionnalités pour un même évènement de blocage est identique, ce qui n&rsquo;est pas le cas avec les deadlocks (XE produit un document XML mal formé, qui rend impossible son enregistrement en document de type .xdl en vue de son interprétation graphique dans SSMS).</p>
<p>La définition d&rsquo;une telle session est simple :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">-- Définition de la session</span><br />
<span style="color: #0000FF;">CREATE</span> EVENT <span style="color: #0000FF;">SESSION</span> blocked_process_report_RB <span style="color: #0000FF;">ON</span> SERVER<br />
<span style="color: #0000FF;">ADD</span> EVENT sqlserver.<span style="color: #202020;">blocked_process_report</span><br />
<span style="color: #0000FF;">ADD</span> TARGET package0.<span style="color: #202020;">ring_buffer</span> <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SET</span> MAX_MEM<span style="color: #808080;">OR</span>Y <span style="color: #808080;">=</span> <span style="color: #000;">4096</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">WITH</span> <span style="color: #808080;">&#40;</span>MAX_DISPATCH_LATENCY <span style="color: #808080;">=</span> <span style="color: #000;">5</span> SECONDS<span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #008080;">-- Démarrage de la session</span><br />
<span style="color: #0000FF;">ALTER</span> EVENT <span style="color: #0000FF;">SESSION</span> blocked_process_report_RB <span style="color: #0000FF;">ON</span> SERVER<br />
<span style="color: #0000FF;">STATE</span> <span style="color: #808080;">=</span> <span style="color: #0000FF;">START</span><br />
<br />
<span style="color: #008080;">-- Vérification</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; name<br />
&nbsp; &nbsp; &nbsp; &nbsp; , create_time<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">dm_xe_sessions</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; name <span style="color: #808080;">=</span> <span style="color: #FF0000;">'blocked_process_report_RB'</span></div></td></tr></tbody></table></div>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Le test</strong></p>
<p>Pour l&rsquo;exemple, nous avons la trace SQL Profiler et la session XE ci-dessus actifs.<br />
Nous créons la table suivante :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> blocked_process_report_test<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; cle <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> UQ_blocked_process_report_test <span style="color: #0000FF;">UNIQUE</span> <span style="color: #0000FF;">CLUSTERED</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , valeur <span style="color: #0000FF;">tinyint</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
<span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>Puis, dans une première fenêtre de requête (A) sous SSMS, nous ajoutons la ligne suivante, sans valider la transaction :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">BEGIN</span> <span style="color: #0000FF;">TRANSACTION</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span>&nbsp; <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">blocked_process_report_test</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cle<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , valeur<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">VALUES</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">'TEST'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #000;">12</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>Dans une seconde fenêtre de requête (B), nous exécutons :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">UPDATE</span>&nbsp; dbo.<span style="color: #202020;">blocked_process_report_test</span><br />
<span style="color: #0000FF;">SET</span> &nbsp; &nbsp; valeur <span style="color: #808080;">=</span> <span style="color: #000;">15</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; cle <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TEST'</span></div></td></tr></tbody></table></div>
<p>Ceci fait que la requête B doit attendre que la requête A soit terminée pour réaliser l&rsquo;UPDATE, ce qui ne peut se faire que si l&rsquo;on valide (COMMIT) ou annule (ROLLBACK) la transaction : nous ne le faisons pas ici, pour l&rsquo;exemple. Nous laissons aussi la requête B s&rsquo;exécuter 10 secondes, de façon à bien voir que l’évènement est capturé deux fois pour la même situation de blocage.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Ce que capture SQL Profiler</strong></p>
<p>L&rsquo;interface affiche bien deux captures de l’évènement :</p>
<p><img src="http://img705.imageshack.us/img705/8171/5kt.png" alt="" /></p>
<p>Notez que les valeurs pour la colonne <em>Duration</em> sont données ici en microsecondes : on voit donc qu&rsquo;il y a un léger décalage entre la détection du blocage et sa capture. Toutes les informations dont nous avons besoin sont donc sous nos yeux: la ressource à la source de la situation de blocage, ainsi que les requêtes impliquées dans celle-ci.</p>
<p>Il est possible de charger le fichier de trace dans une table à l&rsquo;aide de la fonction <a href="http://msdn.microsoft.com/fr-fr/library/ms188425.aspx">sys.fn_trace_gettable()</a>. Cela permet l&rsquo;écriture d&rsquo;une requête utilisant les méthodes SQLXML, qui extrait directement les informations intéressantes de chaque document XML. La requête est similaire à celle que je donne dans la section suivante.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Ce que capture la session XE</strong></p>
<p>Ici il nous est nécessaire d&rsquo;écrire une requête faisant appel aux fonctions SQLXML pour dépouiller le document XML sans se fatiguer :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF00FF;">DATEADD</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">hour</span>, <span style="color: #FF00FF;">DATEDIFF</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">hour</span>, <span style="color: #FF00FF;">GETUTCDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>, doc.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/@timestamp)[1]'</span>, <span style="color: #FF0000;">'datetime'</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> log_date_time<br />
&nbsp; &nbsp; &nbsp; &nbsp; , doc.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data[@name=&quot;transaction_id&quot;]/value)[1]'</span>, <span style="color: #FF0000;">'bigint'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> transaction_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , doc.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data[@name=&quot;database_name&quot;]/value)[1]'</span>, <span style="color: #FF0000;">'nvarchar(128)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> database_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; , doc.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data[@name=&quot;duration&quot;]/value)[1]'</span>, <span style="color: #FF0000;">'int'</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">1000</span> <span style="color: #0000FF;">AS</span> duration_ms<br />
&nbsp; &nbsp; &nbsp; &nbsp; , doc.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data[@name=&quot;resource_owner_type&quot;]/text)[1]'</span>, <span style="color: #FF0000;">'varchar(10)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> resource_owner_type<br />
&nbsp; &nbsp; &nbsp; &nbsp; , doc.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data[@name=&quot;lock_mode&quot;]/text)[1]'</span>, <span style="color: #FF0000;">'varchar(10)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> lock_mode<br />
&nbsp; &nbsp; &nbsp; &nbsp; , doc.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data[@name=&quot;blocked_process&quot;]/value/blocked-process-report/blocked-process/process/@waitresource)[1]'</span>, <span style="color: #FF0000;">'varchar(max)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> wait_resource<br />
&nbsp; &nbsp; &nbsp; &nbsp; , doc.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data[@name=&quot;blocked_process&quot;]/value/blocked-process-report/blocked-process/process/@isolationlevel)[1]'</span>, <span style="color: #FF0000;">'varchar(max)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> blocked_tran_iso_level<br />
&nbsp; &nbsp; &nbsp; &nbsp; , doc.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data[@name=&quot;blocked_process&quot;]/value/blocked-process-report/blocking-process/process/@isolationlevel)[1]'</span>, <span style="color: #FF0000;">'varchar(max)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> blocking_tran_iso_level<br />
&nbsp; &nbsp; &nbsp; &nbsp; , doc.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data[@name=&quot;blocked_process&quot;]/value/blocked-process-report/blocked-process/process/inputbuf)[1]'</span>, <span style="color: #FF0000;">'varchar(max)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> blocked_statement<br />
&nbsp; &nbsp; &nbsp; &nbsp; , doc.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data[@name=&quot;blocked_process&quot;]/value/blocked-process-report/blocking-process/process/inputbuf)[1]'</span>, <span style="color: #FF0000;">'varchar(max)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> blocking_statement<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; <span style="color: #808080;">&#40;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D.<span style="color: #202020;">n</span>.<span style="color: #202020;">query</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'.'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> doc<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>target_data <span style="color: #0000FF;">AS</span> xml<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">data</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_xe_sessions</span> <span style="color: #0000FF;">AS</span> S &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_xe_session_targets</span> <span style="color: #0000FF;">AS</span> ST<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> S.<span style="color: #202020;">address</span> <span style="color: #808080;">=</span> ST.<span style="color: #202020;">event_session_address</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S.<span style="color: #202020;">name</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'blocked_process_report_RB'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ST.<span style="color: #202020;">target_name</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ring_buffer'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> sub<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">CROSS</span> APPLY &nbsp; &nbsp; <span style="color: #0000FF;">data</span>.<span style="color: #202020;">nodes</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'RingBufferTarget/event'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> D<span style="color: #808080;">&#40;</span>n<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> T</div></td></tr></tbody></table></div>
<p>La capture d&rsquo;écran du résultat a été coupée en deux pour faciliter un peu la lecture :</p>
<p><img src="http://img827.imageshack.us/img827/7796/91d.png" alt="" /></p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Interprétation du résultat</strong></p>
<p>Notre intérêt dans l&rsquo;interprétation de ce document se portera sur la propriété waitresource, que l&rsquo;on peut décrypter à l&rsquo;aide de la <a href="http://support.microsoft.com/kb/224453">documentation</a> (Voir la section <strong><em>Waitresource</em></strong>).</p>
<p>Ici, waitresource est : KEY: 5:72057594039107584 (2158b2b5a6d5), ce qui signifie :</p>
<p>&#8211; Database ID : 5<br />
&#8211; Partition ID : 72057594039107584<br />
&#8211; (2158b2b5a6d5) : le hash de la clé d&rsquo;index</p>
<p>Sur ce dernier point, il faut savoir que SQL Server utilise le hash, stocké sur 6 octets, de la clé de l&rsquo;index qui supporte la requête. Ceci conduit SQL Server à générer des valeurs de hash identiques pour des valeurs de clé différentes, ce qui peut causer d&rsquo;autre problèmes de concurrence d&rsquo;accès. C&rsquo;est une raison de plus pour choisir des clés d&rsquo;index les plus &laquo;&nbsp;étroites&nbsp;&raquo; possible, de façon à éviter ce type de collisions.</p>
<p>Voyons comment retrouver la ressource qui a été verrouillée :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">USE</span> ELSUKET<br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; O.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> table_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , I.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> index_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , P.<span style="color: #202020;">partition_number</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , P.<span style="color: #0000FF;">rows</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">partitions</span> <span style="color: #0000FF;">AS</span> p<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">objects</span> <span style="color: #0000FF;">AS</span> O<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> O.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> P.<span style="color: #FF00FF;">object_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">indexes</span> <span style="color: #0000FF;">AS</span> I<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> P.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> I.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> P.<span style="color: #202020;">index_id</span> <span style="color: #808080;">=</span> I.<span style="color: #202020;">index_id</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p.<span style="color: #202020;">partition_id</span> <span style="color: #808080;">=</span> <span style="color: #000;">72057594039107584</span></div></td></tr></tbody></table></div>
<p><img src="http://img818.imageshack.us/img818/5617/zsbe.png" alt="" /></p>
<p>Voyons maintenant comment retrouver la clé qui a été utilisée :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; dbo.<span style="color: #202020;">blocked_process_report_test</span> <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">INDEX</span> <span style="color: #808080;">=</span> UQ_blocked_process_report_test<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; <span style="color: #808080;">%%</span>lockres<span style="color: #808080;">%%</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'(2158b2b5a6d5)'</span></div></td></tr></tbody></table></div>
<p><img src="http://img268.imageshack.us/img268/5628/5xt.png" alt="" /></p>
<p>La fonction %%lockres%% n&rsquo;est pas documentée : il est donc recommandé de l&rsquo;utiliser avec parcimonie. La même méthodologie est utilisable dans le diagnostic des deadlocks.</p>
<p>Bon déblocage à tous !</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reprendre le contrôle d&#8217;une instance SQL Server lorsqu&#8217;on a perdu le mot de passe de la connexion sa ou lorsque tous les DBAs en ont perdu l&#8217;accès</title>
		<link>https://blog.developpez.com/elsuket/p12007/moteur-de-base-de-donnees-sql-server/reprendre-le-controle-dune-instance-sql-server-lorsquon-a-perdu-le-mot-de-passe-de-la-connexion-sa-ou-lorsque-tous-les-dbas-en-ont-perdu-lacces</link>
		<comments>https://blog.developpez.com/elsuket/p12007/moteur-de-base-de-donnees-sql-server/reprendre-le-controle-dune-instance-sql-server-lorsquon-a-perdu-le-mot-de-passe-de-la-connexion-sa-ou-lorsque-tous-les-dbas-en-ont-perdu-lacces#comments</comments>
		<pubDate>Fri, 31 May 2013 00:36:28 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[Utilitaires]]></category>
		<category><![CDATA[instance]]></category>
		<category><![CDATA[mot de passe]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[sa]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=524</guid>
		<description><![CDATA[Comment faire lorsqu&#8217;on a perdu le mot de passe de la connexion sa pour se connecter à l&#8217;instance ? Ou comment est-il possible de prendre le contrôle d&#8217;une instance SQL Server installée par une personne avec son propre compte, et &#8230; <a href="https://blog.developpez.com/elsuket/p12007/moteur-de-base-de-donnees-sql-server/reprendre-le-controle-dune-instance-sql-server-lorsquon-a-perdu-le-mot-de-passe-de-la-connexion-sa-ou-lorsque-tous-les-dbas-en-ont-perdu-lacces">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Comment faire lorsqu&rsquo;on a perdu le mot de passe de la connexion sa pour se connecter à l&rsquo;instance ?<br />
Ou comment est-il possible de prendre le contrôle d&rsquo;une instance SQL Server installée par une personne avec son propre compte, et qui a quitté l&rsquo;entreprise depuis une durée plus grande que celle de l&rsquo;expiration des mots de passe ?<br />
<span id="more-524"></span><br />
Il est pour cela nécessaire d&rsquo;avoir accès à la machine avec un compte d’administrateur local : en effet dans ce cas, le démarrage en mode mono-utilisateur d&rsquo;une instance de SQL Server autorise l&rsquo;accès à un tel compte. Cela permet donc de créer une nouvelle connexion, à laquelle on octroie le privilège et sésame d&rsquo;appartenance au rôle fixe de serveur <em>sysadmin</em>.</p>
<p>Voyons tout d&rsquo;abord quelles sont les connexions qui disposent du privilège d&rsquo;appartenance au rôle <em>sysadmin</em>. La requête suivante liste l&rsquo;ensemble des connexions inscrites aux rôles d&rsquo;instance :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SPR.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> server_role_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , SPM.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> server_role_member_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , SPR.<span style="color: #202020;">type_desc</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">server_role_members</span> <span style="color: #0000FF;">AS</span> SRM<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">server_principals</span> <span style="color: #0000FF;">AS</span> SPR<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> SRM.<span style="color: #202020;">role_principal_id</span> <span style="color: #808080;">=</span> SPR.<span style="color: #202020;">principal_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">server_principals</span> <span style="color: #0000FF;">AS</span> SPM<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> SRM.<span style="color: #202020;">member_principal_id</span> <span style="color: #808080;">=</span> SPM.<span style="color: #202020;">principal_id</span></div></td></tr></tbody></table></div>
<p><img src="http://img689.imageshack.us/img689/5329/restartsqlserversingleu.png" alt="" /></p>
<p>La connexion <em>ELSUKET8\Nicolas</em> est celle d&rsquo;administrateur local de mon PC : je la supprime :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DROP</span> LOG<span style="color: #808080;">IN</span> <span style="color: #808080;">&#91;</span>ELSUKET8\Nicolas<span style="color: #808080;">&#93;</span></div></td></tr></tbody></table></div>
<p>A l&rsquo;ouverture d&rsquo;une nouvelle fenêtre de requête, nous obtenons bien l&rsquo;erreur :</p>
<p><img src="http://img836.imageshack.us/img836/5329/restartsqlserversingleu.png" alt="" /></p>
<p>Rendons-nous maintenant dans le <a href="http://blog.developpez.com/elsuket/p7723/moteur-de-base-de-donnees-sql-server/configurer_les_protocoles_de_connexion_a">gestionnaire de configuration de SQL Server</a>. Si l&rsquo;instance est sous SQL Server 2012 et que l&rsquo;on souhaite ouvrir cette console à partir d&rsquo;une fenêtre de ligne de commandes, il faudra saisir <em>SQLServerManager11.msc</em>. Une fois la console ouverte, on peut double-cliquer sur SQL Server Services dans l&rsquo;un des deux panneaux, et on obtient la liste des services SQL Server installés :</p>
<p><img src="http://img248.imageshack.us/img248/5329/restartsqlserversingleu.png" alt="" /></p>
<p>Un clic-droit sur le service SQL Server nous permet d&rsquo;accéder, en outre, aux paramètres de démarrage du service. Sous SQL Server 2005 et 2008, ils se trouvent dans l&rsquo;onglet <em>Avancé</em>, mais sous SQL Server 2012, l&rsquo;onglet <em>Paramètres de démarrage</em> a fait son apparition :</p>
<p><img src="http://img22.imageshack.us/img22/5329/restartsqlserversingleu.png" alt="" /></p>
<p>Nous ajoutons ici le paramètre l&rsquo;option <em>-m</em>, qui permet de démarrer une instance en mode mono-utilisateur. Sous SQL Server 2005 et 2008, dans l&rsquo;onglet <em>Avancé</em>, il est nécessaire de placer le curseur à la fin de la chaîne du paramètre <em>Paramètres de démarrage</em>, et d&rsquo;ajouter <em>;-m</em> après la fin de cette chaîne. Une fois fait, nous sommes avertis qu&rsquo;il est évidemment nécessaire de redémarrer le service :</p>
<p><img src="http://img545.imageshack.us/img545/5329/restartsqlserversingleu.png" alt="" /></p>
<p>On peut redémarrer le service toujours à partir de la même console, par un clic-droit sur le service. Une fois fait, nous démarrons SQL Server Management Studio (SSMS) <strong>en tant qu&rsquo;administrateur</strong>. Cette option est accessible par un simple clic-droit sur le raccourci. Attention : comme nous sommes en mode mono-utilisateur, il n&rsquo;est pas possible d&rsquo;ouvrir une connexion pour l&rsquo;explorateur d&rsquo;objets. Donc si l&rsquo;on ne ferme pas la connexion de ce dernier (par clic-droit sur le nom de l&rsquo;instance dans celui-ci), il est impossible d&rsquo;ouvrir une fenêtre de requête.</p>
<p>Nous nous octroyons maintenant le droit de connexion et d&rsquo;appartenance au rôle de serveur <em>sysadmin</em> :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> LOG<span style="color: #808080;">IN</span> <span style="color: #808080;">&#91;</span>ELSUKET8\ElSuket<span style="color: #808080;">&#93;</span><br />
<span style="color: #0000FF;">FROM</span> W<span style="color: #808080;">IN</span>DOWS<br />
GO<br />
<br />
<span style="color: #008080;">-- SQL Server 2012</span><br />
<span style="color: #0000FF;">ALTER</span> SERVER <span style="color: #0000FF;">ROLE</span> sysadmin <span style="color: #0000FF;">ADD</span> MEMBER <span style="color: #808080;">&#91;</span>ELSUKET8\ElSuket<span style="color: #808080;">&#93;</span><br />
<br />
<span style="color: #008080;">-- SQL Server 2000, 2005 et 2008</span><br />
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_addsrvrolemember</span> <span style="color: #FF0000;">'ELSUKET8\ElSuket'</span>, <span style="color: #FF0000;">'sysadmin'</span></div></td></tr></tbody></table></div>
<p>Nous devons maintenant retourner dans la console de configuration des services de SQL Server, retirer le paramètre -m, et redémarrer à nouveau le service, de sorte que l&rsquo;instance soit de nouveau accessible par plusieurs connexions. Une fois fait, on peut démarrer SSMS normalement (i.e. pas en tant qu&rsquo;administrateur), et nous pouvons de nouveau accéder à l&rsquo;instance SQL Server :</p>
<p><img src="http://img835.imageshack.us/img835/5329/restartsqlserversingleu.png" alt="" /></p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Changer le mot de passe de la connexion <em>sa</em></strong></p>
<p>Cela se fait de la même façon, en suivant les étapes suivantes :</p>
<p>1. Ajouter le paramètre -m aux paramètres de démarrage du service SQL Server, puis redémarrer le service;<br />
2. Se connecter à l&rsquo;instance SQL Server avec SSMS en tant qu’administrateur;<br />
3. Changer le mot de passe de la connexion <em>sa</em> avec l&rsquo;instruction suivante :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">ALTER</span> LOG<span style="color: #808080;">IN</span> sa <span style="color: #0000FF;">WITH</span> PASSW<span style="color: #808080;">OR</span>D <span style="color: #808080;">=</span> <span style="color: #FF0000;">'unMotDePasseRobuste'</span></div></td></tr></tbody></table></div>
<p>4. Supprimer le paramètre -m des paramètres de démarrage du service SQL Server, puis redémarrer le service une nouvelle fois;<br />
5. Se connecter normalement avec SSMS, le nom de connexion <em>sa</em> et le nouveau mot de passe.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Effectuer ces mêmes opérations en ligne de commande avec l&rsquo;utilitaire SQLCMD</strong></p>
<p>Il est pour cela nécessaire d&rsquo;ouvrir un fenêtre de lignes de commande en tant qu&rsquo;administrateur. On peut tout simplement créer une raccourci qui pointe sur <em>cmd</em>, puis par clic-droit sur celui-ci, choisir de mode :</p>
<p><img src="http://img689.imageshack.us/img689/5316/restartsqlserversingleux.png" alt="" /></p>
<p>Une fois fait, on démarre l&rsquo;utilitaire en lignes de commande SQLCMD très simplement :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sqlcmd <span style="color: #808080;">-</span>S <span style="color: #808080;">&#91;</span>uneInstance<span style="color: #808080;">&#93;</span></div></td></tr></tbody></table></div>
<p><img src="http://img823.imageshack.us/img823/5329/restartsqlserversingleu.png" alt="" /></p>
<p>Puis, par exemple, changer le mot de passe de la connexion <em>sa</em> :</p>
<p><img src="http://img577.imageshack.us/img577/5329/restartsqlserversingleu.png" alt="" /></p>
<p>Après chaque ligne de code tapée sous SQLCMD, si l&rsquo;on appuie sur <em>Entrée</em>, la commande n&rsquo;est pas exécutée : il faut pour cela utiliser la marqueur de fin de lot GO (qui n&rsquo;est pas une instruction SQL ou T-SQL !). Enfin, pour sortir de l&rsquo;utilitaire SQLCMD, il suffit de taper <em>exit</em>.</p>
<p>Bonne récupération d&rsquo;accès à tous !</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Devart : SQL Complete et sql-format.com</title>
		<link>https://blog.developpez.com/elsuket/p11981/utilitaires/devart</link>
		<comments>https://blog.developpez.com/elsuket/p11981/utilitaires/devart#comments</comments>
		<pubDate>Sat, 18 May 2013 04:50:55 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=367</guid>
		<description><![CDATA[Devart est un éditeur Ukrainien de logiciels tournant autour des moteurs de base de données relationnelles SQL. L&#8217;éditeur vient de publier le site sql-format.com, qui permet comme son nom l&#8217;indique de formater du code T-SQL, avec un très grand nombre &#8230; <a href="https://blog.developpez.com/elsuket/p11981/utilitaires/devart">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Devart est un éditeur Ukrainien de logiciels tournant autour des moteurs de base de données relationnelles SQL. L&rsquo;éditeur vient de publier le site <a href="http://www.sql-format.com/">sql-format.com</a>, qui permet comme son nom l&rsquo;indique de formater du code T-SQL, avec un très grand nombre d&rsquo;options disponibles, parmi lesquelles :</p>
<p>&#8211; Paramétrage de la casse et de l&rsquo;indentation<br />
&#8211; La coloration syntaxique<br />
&#8211; La vérification de la syntaxe : les erreurs trouvées sont soulignées<br />
&#8211; La possibilité de formater un fichier de script</p>
<p>Pour me retrouver souvent avec du code qui a été écrit avant que je mette en place un standard de codage, ce type d&rsquo;outil me fait gagner énormément de temps.<br />
<span id="more-367"></span><br />
C&rsquo;est en fait une copie d&rsquo;une fonctionnalité de <em><a href="http://www.devart.com/dbforge/sql/sqlcomplete/">SQL Complete</a></em>. Celui-ci remplace allègrement <em>IntelliSense</em> de <em>SQL Server Management Studio</em>, par le simple fait que les suggestions proposées au fil de l&rsquo;écriture d&rsquo;une requête sont basées sur le contexte.<br />
Il est également possible de trouver un objet à partir d&rsquo;une suite de lettres contenues dans le nom de cet objet.</p>
<p>Il en existe une version gratuite, que j&rsquo;utilise au quotidien, et une version payante, plus complète et riche en fonctionnalités. Enfin, le site fait cadeau du prix de la licence pour les MVP (voir dans le volet droit de chaque page).</p>
<p>Alors bon codage !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reprise d&#8217;activité étape par étapes : le poster de Paul Randal</title>
		<link>https://blog.developpez.com/elsuket/p11773/moteur-de-base-de-donnees-sql-server/reprise-dactivite-etape-par-etapes-le-poster-de-paul-randal</link>
		<comments>https://blog.developpez.com/elsuket/p11773/moteur-de-base-de-donnees-sql-server/reprise-dactivite-etape-par-etapes-le-poster-de-paul-randal#comments</comments>
		<pubDate>Sat, 09 Feb 2013 04:21:00 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>
		<category><![CDATA[disaster recovery]]></category>
		<category><![CDATA[DR]]></category>
		<category><![CDATA[HA]]></category>
		<category><![CDATA[HADR]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=191</guid>
		<description><![CDATA[Paul Randal est très connu dans la communauté SQL Server puisqu&#8217;il publie très régulièrement des détails sur le fonctionnement interne de SQL Server, dont certains ne sont pas documentés, à travers son site SQLSkills.com (son blog et ceux d&#8217;autres experts &#8230; <a href="https://blog.developpez.com/elsuket/p11773/moteur-de-base-de-donnees-sql-server/reprise-dactivite-etape-par-etapes-le-poster-de-paul-randal">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Paul Randal est très connu dans la communauté SQL Server puisqu&rsquo;il publie très régulièrement des détails sur le fonctionnement interne de SQL Server, dont certains ne sont pas documentés, à travers son site <a href="http://www.sqlskills.com/" title="SQLSkills.com" target="_blank">SQLSkills.com</a> (son blog et ceux d&rsquo;autres experts sont référencés en bas à droite de la page).</p>
<p>Paul Randal vient donc de mettre à la disposition de la communauté un <a href="http://www.sqlskills.com/blogs/paul/sql-server-disaster-recovery-poster-now-available/" title="SQL Server Disaster Recovery Poster Now Available" target="_blank">poster</a> qui détaille les étapes de la reprise d&rsquo;activité par un diagramme décisionnel.</p>
<p>Ce diagramme contient certaines étapes qui référencent un numéro, et chaque numéro correspond à un article publié par Paul Randal. Ils sont tous référencés sur <a href="http://www.sqlskills.com/drposter.asp" title="SQL Server Disaster Recovery Poster Steps Details" target="_blank">cette page</a>.</p>
<p>Toujours bon à avoir sous la main !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pourquoi je ne peux pas être supporter de l&#8217;utilisation des plans de maintenance en production</title>
		<link>https://blog.developpez.com/elsuket/p11161/agent-sql-server/supporter_plan_de_maintenance</link>
		<comments>https://blog.developpez.com/elsuket/p11161/agent-sql-server/supporter_plan_de_maintenance#comments</comments>
		<pubDate>Wed, 18 Jul 2012 17:27:08 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Agent SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une énumération des raisons qui font que jusque ici, je n&#8217;ai jamais donné mon aval à la création de plans de maintenance sur des instance SQL Server de production : => Les plans de maintenance ne sont pas portables &#8230; <a href="https://blog.developpez.com/elsuket/p11161/agent-sql-server/supporter_plan_de_maintenance">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une énumération des raisons qui font que jusque ici, je n&rsquo;ai jamais donné mon aval à la création de plans de maintenance sur des instance SQL Server de production :</p>
<p><span id="more-19"></span></p>
<p>=> Les plans de maintenance ne sont pas portables : il est impossible de déployer simplement sur plusieurs instances de SQL Server un même plan de maintenance en une seule fois. D&rsquo;autre part, une fois la copie réalisée, il est nécessaire de mettre à jour la chaîne de connexion qui est dans celui-ci, et qui correspond a l&rsquo;instance sur laquelle celui-ci a été créé. Enfin, on peut se heurter à des problèmes d&rsquo;intégrité des données référentielle dans la base de données système msdb, ce que le DBA (trop) prudent que je suis se refuse catégoriquement à réaliser.</p>
<p>=> Lorsqu&rsquo;on supprime un plan de maintenance, le package SSIS est supprimé, mais pas le travail de l&rsquo;Agent SQL Server qui lui est attaché</p>
<p>=> A chaque fois que quelqu&rsquo;un crée ou modifie un plan de maintenance, il est nécessaire de changer de nouveau le propriétaire de celui-ci et/ou du travail de l&rsquo;Agent SQL Server qui est attaché à ce plan, car celui-ci est écrasé automatiquement par le nom de connexion de l&rsquo;utilisateur qui réalise l&rsquo;édition du plan de maintenance</p>
<p>=> Dans les éditions <em>Enterprise</em> de SQL Server 2005, il est impossible d&rsquo;obtenir l&rsquo;option CHECKSUM lorsqu&rsquo;on souhaite réaliser une sauvegarde de base de données. Sous SQL Server 2008, ce n&rsquo;est pas possible non plus, mais le CHECKSUM est calculé lorsqu&rsquo;on active la compression des sauvegardes de base de données.</p>
<p>=> En ce qui concerne la maintenance des statistiques, il est impossible d&rsquo;indiquer le niveau d&rsquo;échantillonnage par défaut. D&rsquo;autre part, l’échantillonnage est soit annulé (FULL), soit il est identique pour toutes les tables, ce qui n&rsquo;est pas optimal</p>
<p>=> Quand on connaît les dégâts que peuvent causer un rétrécissement de base de données, on comprend qu&rsquo;une telle tâche ne devrait tout simplement pas exister</p>
<p>=> Les tâches de défragmentation et de reconstruction des index ne permettent pas de spécifier des valeurs seuil pour lesquelles il est préférable de défragmenter plutôt que de reconstruire un index, et inversement.</p>
<p>=> La vérification de l&rsquo;intégrité des bases de données ne permet malheureusement pas de spécifier le niveau de vérification avec lequel on souhaite l&rsquo;effectuer.</p>
<p>En revanche les tâches de nettoyage des fichiers, d&rsquo;envoi de notification à un opérateur, d&rsquo;exécution d&rsquo;un travail de l&rsquo;Agent SQL Server, d&rsquo;exécution de script T-SQL ou de l&rsquo;historique sont plutôt bien conçues, même si pour la dernière j&rsquo;aurai préféré pouvoir spécifier une durée de rétention par type d&rsquo;historique.</p>
<p>Pour toutes ces raisons, je proscris pour le moment l&rsquo;utilisation des plans de maintenance sur les serveurs de production, pour lesquels j&rsquo;ai développé un ensemble de procédures stockées qui me permet de réaliser juste le minimum.</p>
<p>Je pense que les plans de maintenance sont un très bon moyen d&rsquo;assurer un niveau minimal de qualité d&rsquo;une base de données avec un minimum d&rsquo;effort, et sont appropriés pour des serveurs de développement ou des test peu importants, mais pas (encore ?) pour des instances de SQL Server qui supportent la production.</p>
<p>Attention donc à ne pas utiliser les plans de maintenance à tors et à travers <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Copier un DTS d&#8217;un serveur à un autre</title>
		<link>https://blog.developpez.com/elsuket/p7298/utilitaires/copier_un_dts_d_un_serveur_a_un_autre</link>
		<comments>https://blog.developpez.com/elsuket/p7298/utilitaires/copier_un_dts_d_un_serveur_a_un_autre#comments</comments>
		<pubDate>Sat, 28 Feb 2009 12:22:49 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Integration Services]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Nous allons voir comment transférer un lot DTS d&#8217;un serveur vers un autre, ce qui peut être intéressant pour copier un DTS développé sur une machine de développement vers une machine de production &#8230; Rappelons que les DTS (Data Transformation &#8230; <a href="https://blog.developpez.com/elsuket/p7298/utilitaires/copier_un_dts_d_un_serveur_a_un_autre">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Nous allons voir comment transférer un lot DTS d&rsquo;un serveur vers un autre, ce qui peut être intéressant pour copier un DTS développé sur une machine de développement vers une machine de production &#8230;</p>
<p><span id="more-151"></span></p>
<p>Rappelons que les <em>DTS</em> (Data Transformation Services) est un outil d&rsquo;ETL (Extraction / Transformation / Load) introuduit avec SQL Server 7 et remplacé dès <em>SQL Server 2005</em> par <em>SSIS</em> (<em>SQL Server Integration Services</em>)</p>
<p><strong>Sur le serveur source</strong>, replongeons nous dans la console d&rsquo;administration de SQL Server 2000 qu&rsquo;est <em>Enterprise Manager</em> pour retrouver nos lots DTS:</p>
<p><img src="http://blog.developpez.com/media/DTS_01.PNG" width="959" height="308" alt="" /></p>
<p>Nous allons maintenant choisir d&rsquo;exporter le DTS dans un fichier structuré, en choisissant l&rsquo;option &laquo;&nbsp;Enregistrer sous&nbsp;&raquo; du menu &laquo;&nbsp;Lot&nbsp;&raquo; :</p>
<p><img src="http://blog.developpez.com/media/DTS_02.PNG" width="222" height="309" alt="" /></p>
<p>Une boîte de dialogue apparaît alors, nous permettant de spécifier le type de sauvegarde à effectuer</p>
<p><img src="http://blog.developpez.com/media/DTS_03.PNG" width="438" height="390" alt="" /></p>
<p>On voit que l&rsquo;on peut effectuer une sauvegarde d&rsquo;un DTS directement sur un autre serveur hébergeant aussi un instance SQL Server 2000, mais il est possible que la machine de développement soit dans l&rsquo;entreprise alors que la machine de production est chez le client.</p>
<p>On peut aussi spécifier un nom de fichier :</p>
<p><img src="http://blog.developpez.com/media/DTS_04.PNG" width="438" height="390" alt="" /></p>
<p><strong>Après le transfert du fichier sur le serveur cible</strong>, ouvrons <em>Enterprise Manager</em> pour enregistrer le lot :</p>
<p><img src="http://blog.developpez.com/media/DTS_05.PNG" width="342" height="342" alt="" /></p>
<p>On obtient la boîte de dialogue classique de spécification d&rsquo;un emplacement de fichier :</p>
<p><img src="http://blog.developpez.com/media/DTS_06.PNG" width="563" height="419" alt="" /></p>
<p>De retour dans <em>Enterprise Manager</em>, nous devons choisir le lot à ouvrir (comme on peut en enregistrer plusieurs dans le même fichier d&rsquo;export) :</p>
<p><img src="http://blog.developpez.com/media/DTS_07.PNG" width="365" height="260" alt="" /></p>
<p>Il suffit maintenant d&rsquo;enregistrer le lot &#8230;</p>
<p><img src="http://blog.developpez.com/media/DTS_08.PNG" width="218" height="309" alt="" /></p>
<p>&#8230; en spécifiant qu&rsquo;il s&rsquo;agit d&rsquo;un instance SQL Server :</p>
<p><img src="http://blog.developpez.com/media/DTS_09.PNG" width="438" height="387" alt="" /></p>
<p>Et l&rsquo;opération est terminée; la console <em>Enterprise Manager</em> affiche :</p>
<p><img src="http://blog.developpez.com/media/DTS_10.PNG" width="500" height="312" alt="" /></p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Connaître la longueur maximale des lignes des tables, et calculs relatifs</title>
		<link>https://blog.developpez.com/elsuket/p8161/moteur-de-base-de-donnees-sql-server/connaitre_la_longueur_maximale_des_ligne</link>
		<comments>https://blog.developpez.com/elsuket/p8161/moteur-de-base-de-donnees-sql-server/connaitre_la_longueur_maximale_des_ligne#comments</comments>
		<pubDate>Tue, 06 Oct 2009 17:10:14 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Agent SQL Server]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Il est intéressant de connaître la longueur maximale qui peut être stockée par une table pour tenter de prévoir la taille d&#8217;une base de données lorsque le système sera arrivé à maturité. Voici une petite requête pour nous y aider &#8230; <a href="https://blog.developpez.com/elsuket/p8161/moteur-de-base-de-donnees-sql-server/connaitre_la_longueur_maximale_des_ligne">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Il est intéressant de connaître la longueur maximale qui peut être stockée par une table pour tenter de prévoir la taille d&rsquo;une base de données lorsque le système sera arrivé à maturité.<br />
Voici une petite requête pour nous y aider sous SQL Server 2005 et 2008&#8230;<br />
<span id="more-90"></span></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas SOUQUET - 06/10/2009 <br />
------------------------------- <br />
SELECT nomTable, <br />
&nbsp; &nbsp; longueurLigne, <br />
&nbsp; &nbsp; 8060 / longueurLigne AS nbLignesParPage, <br />
&nbsp; &nbsp; longueurLigne * (8060 / longueurLigne) AS nbMaxOctetsParPage, <br />
&nbsp; &nbsp; 8060 - (longueurLigne * (8060 / longueurLigne)) nbOctetsPerdusParPage, <br />
&nbsp; &nbsp; (longueurLigne + longueurLigne % 8060) / 8060 AS nbPagesStockeLigne <br />
FROM <br />
( <br />
&nbsp; SELECT T.name AS nomTable, <br />
&nbsp; &nbsp; &nbsp; SUM(C.max_length) AS longueurLigne <br />
&nbsp; FROM sys.tables AS T <br />
&nbsp; JOIN sys.columns AS C <br />
&nbsp; &nbsp; ON T.object_id = C.object_id <br />
&nbsp; JOIN sys.types AS TY <br />
&nbsp; &nbsp; ON C.user_type_id = TY.user_type_id <br />
&nbsp; GROUP BY T.name <br />
) AS TMP (nomTable, longueurLigne)</div></td></tr></tbody></table></div>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connaître les caractéristiques d&#8217;une trace SQL Profiler</title>
		<link>https://blog.developpez.com/elsuket/p9016/moteur-de-base-de-donnees-sql-server/connaitre_les_caracteristiques_d_une_tra</link>
		<comments>https://blog.developpez.com/elsuket/p9016/moteur-de-base-de-donnees-sql-server/connaitre_les_caracteristiques_d_une_tra#comments</comments>
		<pubDate>Wed, 16 Jun 2010 06:27:27 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Sur un serveur à la configuration sous-dimensionnée que je surveille de temps en temps, j&#8217;ai trouvé une trace SQL Profiler en cours d&#8217;exécution. J&#8217;ai voulu en savoir plus sur les caractéristiques de cette trace. Voici la requête : 123456789101112131415------------------------------- -- &#8230; <a href="https://blog.developpez.com/elsuket/p9016/moteur-de-base-de-donnees-sql-server/connaitre_les_caracteristiques_d_une_tra">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Sur un serveur à la configuration sous-dimensionnée que je surveille de temps en temps, j&rsquo;ai trouvé une trace SQL Profiler en cours d&rsquo;exécution.<br />
J&rsquo;ai voulu en savoir plus sur les caractéristiques de cette trace.<br />
Voici la requête :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas SOUQUET - 16/06/2010 <br />
------------------------------- <br />
SELECT &nbsp; &nbsp;C.name <br />
&nbsp; &nbsp; , FI.value <br />
&nbsp; &nbsp; , T.start_time <br />
&nbsp; &nbsp; , T.last_event_time <br />
&nbsp; &nbsp; , T.event_count <br />
&nbsp; &nbsp; , S.login_name <br />
&nbsp; &nbsp; , S.session_id <br />
&nbsp; &nbsp; , 'EXEC sp_trace_setstatus ' + CAST(T.id AS varchar(10)) + ', 0' AS stop_trace_stmt <br />
FROM &nbsp; &nbsp;sys.traces AS T <br />
CROSS APPLY &nbsp;sys.fn_trace_getfilterinfo (T.id) AS FI <br />
INNER JOIN &nbsp;sys.trace_columns AS C ON FI.columnid = C.trace_column_id <br />
INNER JOIN &nbsp;sys.dm_exec_sessions AS S ON S.session_id = T.reader_spid</div></td></tr></tbody></table></div>
<p>On sait tout de suite quel filtres ont été utilisés à l&rsquo;aide des deux premières colonnes.<br />
La dernière colonne contient l&rsquo;instruction qui permet d&rsquo;arrêter la trace : le développeur a donc toujours ses résultats.</p>
<p>Pour savoir comment créer une trace côté serveur, c&rsquo;est par <a href="http://elsuket.developpez.com/tutoriels/sqlserveur/fichier-trace-cote-serveur/">ici</a></p>
<p>Bon traçage !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comment convertir un fichier blg en csv pour l&#8217;intégrer en base rapidement ?</title>
		<link>https://blog.developpez.com/elsuket/p9870/utilitaires/perfmon_blg_en_csv_integration</link>
		<comments>https://blog.developpez.com/elsuket/p9870/utilitaires/perfmon_blg_en_csv_integration#comments</comments>
		<pubDate>Thu, 07 Apr 2011 10:10:52 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Integration Services]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici comment transformer un fichier blg généré par PerfMon en CSV en vue de l&#8217;intégrer dans une table de base de données (et pourquoi pas faire un rapport à partir de là ? ) Pour convertir un fichier blg au &#8230; <a href="https://blog.developpez.com/elsuket/p9870/utilitaires/perfmon_blg_en_csv_integration">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici comment transformer un fichier blg généré par PerfMon en CSV en vue de l&rsquo;intégrer dans une table de base de données (et pourquoi pas faire un rapport à partir de là ? )<br />
<span id="more-133"></span></p>
<p>Pour convertir un fichier blg au format CSV, il suffit d&rsquo;utiliser l&rsquo;instruction relog en ligne de commandes :</p>
<p><code class="codecolorer text default"><span class="text">&gt;relog perfmon_log.blg -f CSV -o perfmon_log.csv</span></code></p>
<p>En quelques secondes un gros fichier blg peut être converti, retournant le nombre de lignes que contient le fichier CSV.</p>
<p>A partir de là, on peut procéder à son intégration en faisant un clic-droit sur la base de données dans laquelle on souhaite charger les données :</p>
<p><img src="http://blog.developpez.com/media/import_perfmon_1.png" /></p>
<p>La fenêtre suivante s&rsquo;ouvre alors :</p>
<p><img src="http://blog.developpez.com/media/import_perfmon_2.png" /></p>
<p>Il suffit simplement de sélectionner <em>Flat file source</em> dans la liste déroulante <em>Data source</em>, puis de cliquer sur <em>Browse</em> :</p>
<p><img src="http://blog.developpez.com/media/import_perfmon_3.png" width="627" height="436" alt="" /></p>
<p>Attention à filtrer sur l&rsquo;extension csv, sinon le fichier n&rsquo;apparaîtra pas <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p><img src="http://blog.developpez.com/media/import_perfmon_4.png" width="566" height="580" alt="" /></p>
<p>Une fois le fichier sélectionné, faites attention à la page de codes : elle doit correspondre à la collation utilisée par votre base de données.<br />
Dans la plupart des cas, la page de codes par défaut fonctionnera.<br />
Dans mon cas, comme la collation de la base de données est Thai_CI_AS, j&rsquo;ai choisi la page de codes 874.</p>
<p>Enfin, comme la première ligne de notre fichier de log PerfMon contient le nom des compteurs, il faut également cocher la case <em>Colmun names in the first data row</em>.</p>
<p>On peut maintenant cliquer sur le bouton <em>Next</em> :</p>
<p><img src="http://blog.developpez.com/media/import_perfmon_5.png" width="634" height="579" alt="" /></p>
<p>Ici il s&rsquo;agit de spécifier l’instance SQL Server (<em>Server name</em>) et la base de données dans laquelle on souhaite importer les données (<em>Database</em>).</p>
<p><img src="http://blog.developpez.com/media/import_perfmon_6.png" width="633" height="597" alt="" /></p>
<p>La table prend alors le même nom que le fichier, par défaut.<br />
Néanmoins on peut tout à fait parcourir et choisir une table de la base de données.</p>
<p>Une fois cela fait, on peut cliquer sur <em>Next</em> : la fenêtre suivante apparaît :</p>
<p><img src="http://blog.developpez.com/media/import_perfmon_7.png" width="634" height="593" alt="" /></p>
<p>On peut alors choisir d&rsquo;exécuter le package SSIS immédiatement, auquel cas il ne sera pas sauvegardé, ou bien choisir de l&rsquo;enregistrer :</p>
<p>1. dans SQL Server (en fait dans la base de données système MSDB)<br />
2. ou dans un fichier</p>
<p>C&rsquo;est pratique puisque :</p>
<p>&#8211; Dans le premier cas, si nous devons réaliser un nouvel import, on n&rsquo;aura plus qu&rsquo;à se connecter avec SQL Server Management Studio à l&rsquo;instance SSIS pour exécuter le package une nouvelle fois,</p>
<p>&#8211; Dans le second cas, il suffit simplement de double-cliquer sur le fichier (que l&rsquo;on peut échanger avec ses collègues) pour exécuter le package</p>
<p>Dans mon cas, comme je n&rsquo;aurai très probablement jamais plus besoin de réimporter des fichiers de log PerfMon ayant une liste de compteurs strictement identique, j&rsquo;ai choisi <em>Run Immediately</em> seulement.</p>
<p>Dans tous les cas, on cliquera sur le bouton <em>Next</em> :</p>
<p><img src="http://blog.developpez.com/media/import_perfmon_8.png" width="633" height="578" alt="" /></p>
<p>Le package s&rsquo;exécute alors &#8230; quand l&rsquo;opération est terminée, on obtient la fenêtre suivante :</p>
<p><img src="http://blog.developpez.com/media/import_perfmon_9.png" width="634" height="578" alt="" /></p>
<p>Il suffit alors de cliquer sur <em>Close</em> pour voir la fenêtre se fermer, puis de faire un <code class="codecolorer text default"><span class="text">SELECT * FROM dbo.perfmon_log</span></code> <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>Dans le cas où il s&rsquo;agit d&rsquo;une opération qui devra être effectuée à répétition, on peut également sauvegarder le package, et le faire exécuter par un job de l&rsquo;Agent SQL Server.<br />
En plus de cela, on peut construire un rapport <em>SQL Server Reporting Services</em> (SSRS) sur la table recevant les lignes du fichier CSV.</p>
<p>Bon chargement de données PerfMon <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Analyse de plans de requête : SQL Sentry Plan Explorer</title>
		<link>https://blog.developpez.com/elsuket/p10724/utilitaires/sql_sentry_plan_explorer</link>
		<comments>https://blog.developpez.com/elsuket/p10724/utilitaires/sql_sentry_plan_explorer#comments</comments>
		<pubDate>Sat, 18 Feb 2012 16:42:56 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Si les plans d&#8217;exécution graphiques sont un bon outil pour faciliter la lecture des plans, l&#8217;outil souffre de quelques lacunes que SQL Sentry Plan Explorer a su combler. Depuis que je l&#8217;ai téléchargé pour la première fois, je ne peux &#8230; <a href="https://blog.developpez.com/elsuket/p10724/utilitaires/sql_sentry_plan_explorer">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Si les plans d&rsquo;exécution graphiques sont un bon outil pour faciliter la lecture des plans, l&rsquo;outil souffre de quelques lacunes que SQL Sentry Plan Explorer a su combler.<br />
Depuis que je l&rsquo;ai téléchargé pour la première fois, je ne peux plus m&rsquo;en passer <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /><br />
<span id="more-124"></span><br />
C&rsquo;est un logiciel qui est gratuitement proposé par SQL Sentry, disponible sur <a href="http://www.sqlsentry.net/plan-explorer/sql-server-query-view.asp">cette page</a>.<br />
N&rsquo;oubliez pas de télécharger le plug-in pour <em>SQL Server Management Studio</em> (SSMS).</p>
<p>Lorsque le plan comporte de nombreuses icônes, dans SSMS, on est obligé de jouer énormément avec les curseurs pour voir où se situe le problème.<br />
Ce n&rsquo;est pas le cas avec <em>Plan Explorer</em>, qui utilise un format plus compact.<br />
Pour le même plan, voici ce que l&rsquo;on voit dans SSMS :</p>
<p><img src="http://blog.developpez.com/media/pe02.png" width="1222" height="720" alt="" /></p>
<p>Et dans <em>Plan Explorer</em> :</p>
<p><img src="http://blog.developpez.com/media/pe01.png" width="1578" height="390" alt="" /></p>
<p>Je suppose qu&rsquo;avec cette première capture d&rsquo;écran vous aurez remarqué d&rsquo;autre différences :</p>
<p>&#8211; Les cardinalités sont affichées sur les flèches<br />
&#8211; Les opérations les plus coûteuses sont mises en évidence. On peut notamment les visualiser par coût E/S et par coût CPU :</p>
<p><img src="http://blog.developpez.com/media/pe03.png" width="862" height="350" alt="" /></p>
<p>Vous le voyez, il est également très simple de comparer les cardinalités estimées et réelles, ce qui permet rapidement de savoir s&rsquo;il s&rsquo;agit d&rsquo;un problème d&rsquo;estimation de ces dernières.<br />
L&rsquo;option <em>Full object names</em> affiche le nom complet de l&rsquo;objet et de l&rsquo;index, ce qui permet de ne pas avoir à passer le curseur sur les icônes pour savoir quel index a été utilisé.</p>
<p>Enfin les infobulles sont toujours présentes, mais mieux présentées parce qu&rsquo;ordonnées.<br />
Voici donc ce que l&rsquo;on voit sans SSMS pour une icône de plan d&rsquo;exécution graphique :</p>
<p><img src="http://blog.developpez.com/media/pe04.png" width="753" height="650" alt="" /></p>
<p>On aurait apprécié de voir par exemple le nombre de lignes estimé précéder directement le nombre de lignes réel, comme c&rsquo;est le cas dans <em>Plan Explorer</em> :</p>
<p><img src="http://blog.developpez.com/media/pe05.png" width="692" height="751" alt="" /></p>
<p>Les onglets situés au-dessus du plan sont assez pratiques également.<br />
Le <em>Plan Tree</em> est similaire au plan d&rsquo;exécution textuel proposé par SSMS, mais présenté beaucoup plus clairement :</p>
<p>Je passe sur <em>Top Operations</em> et <em>Query Columns</em>, dont leurs noms parlent d&rsquo;eux-mêmes, pour passer à <em>Expressions</em> :</p>
<p><img src="http://blog.developpez.com/media/pe07.png" width="1337" height="139" alt="" /></p>
<p>Désormais les <em>Expr10XX</em> sont décryptables sans avoir à se plonger dans le document XML qu&rsquo;interprètent ces deux outils <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p>Autre implémentation intéressante : lorsqu&rsquo;on obtient le plan d’exécution d&rsquo;une procédure stockée ou d&rsquo;un lot de requêtes, le plan est affiché requête par requête dans <em>Plan Explorer</em>, au lieu d&rsquo;avoir tous les plans affichés dans l&rsquo;onglet <em>Plan d&rsquo;exécution</em> de SSMS :</p>
<p><img src="http://img688.imageshack.us/img688/4394/pe09.png" alt="" title="" /></p>
<p>Enfin on peut choisir les colonnes à afficher dans l&rsquo;onglet <em>Statements Tree</em> :</p>
<p><img src="http://blog.developpez.com/media/pe10.png" width="850" height="259" alt="" /></p>
<p><img src="http://img37.imageshack.us/img37/1612/pe11.png" alt="" title="" /></p>
<p>Il est donc simple d&rsquo;ajouter ou supprimer des colonnes.</p>
<p>Alors bonne lecture de plans d&rsquo;exécution !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Attacher une base de données qui n&#8217;a pas de fichier du journal des transactions</title>
		<link>https://blog.developpez.com/elsuket/p11188/moteur-de-base-de-donnees-sql-server/attacher_base_donnees_sans_tran_log</link>
		<comments>https://blog.developpez.com/elsuket/p11188/moteur-de-base-de-donnees-sql-server/attacher_base_donnees_sans_tran_log#comments</comments>
		<pubDate>Sat, 28 Jul 2012 15:18:35 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici comment attacher une base de données SQL Server pour laquelle on dispose seulement des fichiers de données mais pas du fichier du journal des transactions. L&#8217;exemple qui suit est basé sur l&#8217;attachement de la base de données exemple AdventureWorks2012, &#8230; <a href="https://blog.developpez.com/elsuket/p11188/moteur-de-base-de-donnees-sql-server/attacher_base_donnees_sans_tran_log">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici comment attacher une base de données SQL Server pour laquelle on dispose seulement des fichiers de données mais pas du fichier du journal des transactions.</p>
<p><span id="more-123"></span></p>
<p>L&rsquo;exemple qui suit est basé sur l&rsquo;attachement de la base de données exemple <em>AdventureWorks2012</em>, que l&rsquo;on peut télécharger sur le site <a href="http://msftdbprodsamples.codeplex.com/releases/view/55330">CodePlex</a> :</p>
<p><img src="http://blog.developpez.com/media/attach_no_tran_log_file_01.png" width="594" height="619" alt="" /></p>
<p>Une fois le fichier téléchargé, il suffit de le placer dans le dossier où l&rsquo;on souhaite que la base de données réside.<br />
Dans mon cas, il s&rsquo;agit de D:\SQLServer :</p>
<p><img src="http://blog.developpez.com/media/attach_no_tran_log_file_02.png" width="548" height="162" alt="" /></p>
<p>Passons sous <em>SQL Server Management Studio</em>, où l&rsquo;on peut attacher une base de données à une instance SQL Server après un clic-droit sur le nœud <em>Databases</em> > <em>Attach &#8230;</em> :</p>
<p><img src="http://blog.developpez.com/media/attach_no_tran_log_file_03.png" width="382" height="326" alt="" /></p>
<p>Il suffit de cliquer sur le bouton <em>Add &#8230;</em> dans le dialogue qui s&rsquo;ouvre &#8230;</p>
<p><img src="http://blog.developpez.com/media/attach_no_tran_log_file_04.png" width="703" height="624" alt="" /></p>
<p>&#8230; et de référencer le fichier de données :</p>
<p><img src="http://blog.developpez.com/media/attach_no_tran_log_file_05.png" width="440" height="608" alt="" /></p>
<p>Une fois que l&rsquo;on a cliqué sur OK, le dialogue est mis à jour de la façon suivante :</p>
<p><img src="http://blog.developpez.com/media/attach_no_tran_log_file_06.png" width="965" height="637" alt="" /></p>
<p>Il suffit alors de sélectionner le fichier du journal de transaction (qui n&rsquo;existe pas), et de cliquer sur le bouton <em>Remove</em>, puis sur <em>OK</em> :</p>
<p><img src="http://blog.developpez.com/media/attach_no_tran_log_file_08.png" width="642" height="574" alt="" /></p>
<p>Le fichier du journal des transactions est automatiquement recréé, et la base de données est maintenant attachée.</p>
<p>Cela peut aussi se faire par un script, avec l&rsquo;option ATTACH_REBUILD_LOG de l&rsquo;instruction CREATE DATABASE :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE master <br />
GO <br />
&nbsp;<br />
CREATE DATABASE AdventureWorks2012 <br />
ON (FILENAME = N'D:\SQLServer\AdventureWorks2012_Data.mdf') <br />
FOR ATTACH_REBUILD_LOG <br />
GO</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/attach_no_tran_log_file_09.png" width="847" height="297" alt="" /></p>
<p>Bon attachement de bases de données !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Une procédure stockée système pour monitorer les verrous</title>
		<link>https://blog.developpez.com/elsuket/p11135/moteur-de-base-de-donnees-sql-server/procedure_monitor_locks</link>
		<comments>https://blog.developpez.com/elsuket/p11135/moteur-de-base-de-donnees-sql-server/procedure_monitor_locks#comments</comments>
		<pubDate>Thu, 05 Jul 2012 02:01:08 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une procédure stockée qui permet de lister les verrous en cours dans une instance SQL Server 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788USE master GO ------------------------------- -- Nicolas Souquet - 05/07/2012 ------------------------------- CREATE PROCEDURE sp__processes_locks &#160; @_spid int = NULL AS BEGIN &#160; SET NOCOUNT &#8230; <a href="https://blog.developpez.com/elsuket/p11135/moteur-de-base-de-donnees-sql-server/procedure_monitor_locks">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une procédure stockée qui permet de lister les verrous en cours dans une instance SQL Server</p>
<p><span id="more-121"></span></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE master <br />
GO <br />
------------------------------- <br />
-- Nicolas Souquet - 05/07/2012 <br />
------------------------------- <br />
CREATE PROCEDURE sp__processes_locks <br />
&nbsp; @_spid int = NULL <br />
AS <br />
BEGIN <br />
&nbsp; SET NOCOUNT ON &nbsp;<br />
&nbsp; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED <br />
&nbsp;<br />
&nbsp; SELECT &nbsp; &nbsp;S.host_name <br />
&nbsp; &nbsp; &nbsp; , S.login_name <br />
&nbsp; &nbsp; &nbsp; , CASE &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; WHEN S.program_name LIKE 'Microsoft SQL Server Management Studio%' THEN 'SSMS' <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHEN S.program_name LIKE 'LiteSpeed for SQL Server%' THEN 'LiteSpeed' <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHEN S.program_name = 'Microsoft SQL Server Analysis Services' THEN 'SSAS' <br />
&nbsp; &nbsp; &nbsp; &nbsp; ELSE S.program_name <br />
&nbsp; &nbsp; &nbsp; END AS program <br />
&nbsp; &nbsp; &nbsp; , D.name AS database_name <br />
&nbsp; &nbsp; &nbsp; , SQLT.objectid <br />
&nbsp; &nbsp; &nbsp; , TL.request_session_id <br />
&nbsp; &nbsp; &nbsp; , TL.resource_type <br />
&nbsp; &nbsp; &nbsp; , TL.resource_subtype <br />
&nbsp; &nbsp; &nbsp; , TL.request_mode <br />
&nbsp; &nbsp; &nbsp; , TL.request_type <br />
&nbsp; &nbsp; &nbsp; , TL.request_status <br />
&nbsp; &nbsp; &nbsp; , COUNT(*) AS lock_count <br />
&nbsp; &nbsp; &nbsp; , CASE <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHEN TL.resource_type = 'OBJECT' THEN OBJECT_NAME(TL.resource_associated_entity_id) <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHEN TL.resource_type IN ('KEY', 'PAGE', 'RID') <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; THEN <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;OBJECT_NAME(object_id) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp;sys.partitions AS P <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;P.hobt_id = TL.resource_associated_entity_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) <br />
&nbsp; &nbsp; &nbsp; &nbsp; ELSE TL.resource_type &nbsp;<br />
&nbsp; &nbsp; &nbsp; END AS requested_object_name <br />
&nbsp; &nbsp; &nbsp; , R.wait_type <br />
&nbsp; &nbsp; &nbsp; , R.wait_time <br />
&nbsp; &nbsp; &nbsp; , R.last_wait_type <br />
&nbsp; &nbsp; &nbsp; , R.plan_handle <br />
&nbsp; &nbsp; &nbsp; , R.cpu_time / 1000 AS CPU <br />
&nbsp; &nbsp; &nbsp; , R.reads AS reads <br />
&nbsp; &nbsp; &nbsp; , R.writes AS writes <br />
&nbsp; &nbsp; &nbsp; , R.open_transaction_count AS nbtran <br />
&nbsp; FROM &nbsp; &nbsp;sys.dm_tran_locks AS TL <br />
&nbsp; INNER JOIN &nbsp;sys.databases AS D <br />
&nbsp; &nbsp; &nbsp; &nbsp; ON TL.resource_database_id = D.database_id <br />
&nbsp; LEFT JOIN &nbsp;sys.dm_exec_requests AS R <br />
&nbsp; &nbsp; &nbsp; &nbsp; ON TL.request_session_id = R.session_id <br />
&nbsp; INNER JOIN &nbsp;sys.dm_exec_sessions AS S <br />
&nbsp; &nbsp; &nbsp; &nbsp; ON R.session_id = S.session_id <br />
&nbsp; CROSS APPLY &nbsp;sys.dm_exec_sql_text(R.sql_handle) SQLT <br />
&nbsp; WHERE &nbsp; &nbsp;TL.request_session_id &gt;= 50 <br />
&nbsp; AND &nbsp; &nbsp;TL.request_session_id &lt;&gt; @@SPID <br />
&nbsp; AND &nbsp; &nbsp;( <br />
&nbsp; &nbsp; &nbsp; &nbsp; @_spid IS NULL <br />
&nbsp; &nbsp; &nbsp; &nbsp; OR TL.request_session_id = @_spid <br />
&nbsp; &nbsp; &nbsp; ) <br />
&nbsp; GROUP BY &nbsp;S.host_name <br />
&nbsp; &nbsp; &nbsp; , S.login_name <br />
&nbsp; &nbsp; &nbsp; , S.program_name <br />
&nbsp; &nbsp; &nbsp; , D.name <br />
&nbsp; &nbsp; &nbsp; , TL.request_session_id <br />
&nbsp; &nbsp; &nbsp; , TL.resource_type <br />
&nbsp; &nbsp; &nbsp; , TL.resource_subtype <br />
&nbsp; &nbsp; &nbsp; , TL.request_mode <br />
&nbsp; &nbsp; &nbsp; , TL.request_type <br />
&nbsp; &nbsp; &nbsp; , TL.request_status <br />
&nbsp; &nbsp; &nbsp; , TL.resource_type <br />
&nbsp; &nbsp; &nbsp; , SQLT.objectid <br />
&nbsp; &nbsp; &nbsp; , TL.resource_associated_entity_id <br />
&nbsp; &nbsp; &nbsp; , R.wait_type <br />
&nbsp; &nbsp; &nbsp; , R.wait_time <br />
&nbsp; &nbsp; &nbsp; , R.last_wait_type <br />
&nbsp; &nbsp; &nbsp; , R.plan_handle <br />
&nbsp; &nbsp; &nbsp; , R.cpu_time <br />
&nbsp; &nbsp; &nbsp; , R.reads <br />
&nbsp; &nbsp; &nbsp; , R.writes <br />
&nbsp; &nbsp; &nbsp; , R.open_transaction_count <br />
&nbsp; ORDER BY &nbsp;TL.request_session_id <br />
END <br />
GO <br />
&nbsp;<br />
EXEC sp_ms_marksystemobject 'sp__processes_locks'</div></td></tr></tbody></table></div>
<p>Il suffit ensuite d&rsquo;exécuter <code class="codecolorer text default"><span class="text">EXEC sp__processes_locks</span></code> dans n&rsquo;importe quel contexte de base de données, et le tour est joué <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>Bon monitoring !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Les Événements Étendus avec SQL Server 2008</title>
		<link>https://blog.developpez.com/elsuket/p11065/moteur-de-base-de-donnees-sql-server/evenements_etendus_sql_server_2008</link>
		<comments>https://blog.developpez.com/elsuket/p11065/moteur-de-base-de-donnees-sql-server/evenements_etendus_sql_server_2008#comments</comments>
		<pubDate>Sun, 03 Jun 2012 09:13:20 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Je viens de publier un article sur les Événements Étendus avec SQL Server 2008. Je tiens à remercier Mikedavem pour ses encouragements, la relecture et l&#8217;aide à la publication. Je remercie également toute l&#8217;équipe de Développez.com pour la mise à &#8230; <a href="https://blog.developpez.com/elsuket/p11065/moteur-de-base-de-donnees-sql-server/evenements_etendus_sql_server_2008">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Je viens de publier un article sur les <a href="http://elsuket.developpez.com/tutoriels/sqlserveur/EvenementsEtendusSQLServer2008/">Événements Étendus avec SQL Server 2008</a>.</p>
<p>Je tiens à remercier <a href="http://blog.developpez.com/mikedavem/">Mikedavem</a> pour ses encouragements, la relecture et l&rsquo;aide à la publication.</p>
<p>Je remercie également toute l&rsquo;équipe de Développez.com pour la mise à disposition de la plateforme de publication.</p>
<p>Voici le menu :</p>
<p><strong>I. Architecture logique des XE</strong>, où sont décrits ce que sont les packages, les événements, les cibles, les actions, les prédicats, les « maps », et enfin les types</p>
<p><strong>II. Gestion des sessions d&rsquo;XE avec les vues et fonctions de gestion dynamique</strong>, qui donne le détail et les requêtes pour gérer les sessions XE</p>
<p><strong>III. Quelques exemples guidés</strong> (3 au total)</p>
<p><strong>IV. Le futur avec SQL Server 2012</strong> : une brève section sur les améliorations apportées par SQL Server 2012 concernant les XE</p>
<p><strong>V. Avantages et inconvénients de l&rsquo;utilisation des XE</strong> : une liste de ce qu&rsquo;apportent les XE, et de leurs (rares à mon avis) freins à leur adoption</p>
<p>Bonne Lecture à tous et merci de vos commentaires <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Une requête pour connaître l&#8217;utilisation des index (et leur définition) : la DMV sys.dm_db_index_usage_stats</title>
		<link>https://blog.developpez.com/elsuket/p11068/moteur-de-base-de-donnees-sql-server/definition_stat_utilisation_index</link>
		<comments>https://blog.developpez.com/elsuket/p11068/moteur-de-base-de-donnees-sql-server/definition_stat_utilisation_index#comments</comments>
		<pubDate>Mon, 04 Jun 2012 08:32:53 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une requête qui retourne l&#8217;utilisation des index avec leur définition, sur un schéma et/ou une table ou vue indexée et/ou une base de données : 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899------------------------------- -- Nicolas Souquet - 04/06/2012 ------------------------------- &#160; SET NOCOUNT ON SET TRANSACTION ISOLATION &#8230; <a href="https://blog.developpez.com/elsuket/p11068/moteur-de-base-de-donnees-sql-server/definition_stat_utilisation_index">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une requête qui retourne l&rsquo;utilisation des index avec leur définition, sur un schéma et/ou une table ou vue indexée et/ou une base de données :</p>
<p><span id="more-118"></span></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 04/06/2012 <br />
------------------------------- <br />
&nbsp;<br />
SET NOCOUNT ON <br />
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED <br />
GO <br />
&nbsp;<br />
DECLARE &nbsp;@schema_name sysname = 'dbo' <br />
&nbsp; , @table_or_view_name sysname --= 'maTable' -- si NULL, étudie tous les index de toutes les table du schéma <br />
&nbsp; , @index_name sysname = NULL -- si NULL, étudie tous les index de la table <br />
&nbsp; , @separator varchar(2) = ', ' <br />
---------------------------------------------------------------------------------------------------------------------- <br />
SELECT &nbsp; &nbsp;DISTINCT S.name + '.' + O.name AS schema_table_name <br />
&nbsp; &nbsp; , I.name AS index_name <br />
&nbsp; &nbsp; , PS.row_count <br />
&nbsp; &nbsp; , I.type_desc <br />
&nbsp; &nbsp; , LEFT(KC.key_column_list, LEN(KC.key_column_list) - 2) AS key_column_list <br />
&nbsp; &nbsp; , LEFT(KCI.included_key_column_list, LEN(KCI.included_key_column_list) - 1) AS included_key_column_list <br />
&nbsp; &nbsp; , REPLACE(REPLACE(REPLACE(REPLACE(I.filter_definition, '[', ''), ']', ''), '(', ''), ')', '') AS filter_definition <br />
&nbsp; &nbsp; , PS.used_page_count AS pages_count <br />
&nbsp; &nbsp; , STATS_DATE(O.object_id, I.index_id) AS last_stat_update <br />
&nbsp; &nbsp; , IUS.user_seeks <br />
&nbsp; &nbsp; , IUS.user_scans <br />
&nbsp; &nbsp; , IUS.user_lookups <br />
&nbsp; &nbsp; , (IUS.user_seeks + IUS.user_scans + IUS.user_lookups) AS total_user_searches <br />
&nbsp; &nbsp; , IUS.last_user_seek <br />
&nbsp; &nbsp; , IUS.last_user_scan &nbsp;<br />
&nbsp; &nbsp; , IUS.last_user_lookup <br />
&nbsp; &nbsp; , LS.max_last_search_date <br />
&nbsp; &nbsp; , PS.used_page_count / 8 AS index_size_kb <br />
FROM &nbsp; &nbsp;sys.schemas AS S <br />
INNER JOIN &nbsp;sys.objects AS O <br />
&nbsp; &nbsp; &nbsp; ON S.schema_id = O.schema_id <br />
INNER JOIN &nbsp;sys.indexes AS I &nbsp;<br />
&nbsp; &nbsp; &nbsp; ON O.object_id = I.object_id <br />
INNER JOIN &nbsp;sys.index_columns AS IC <br />
&nbsp; &nbsp; &nbsp; ON IC.object_id = I.object_id <br />
&nbsp; &nbsp; &nbsp; AND IC.index_id = I.index_id <br />
INNER JOIN &nbsp;sys.columns AS C <br />
&nbsp; &nbsp; &nbsp; ON IC.object_id = C.object_id <br />
&nbsp; &nbsp; &nbsp; AND IC.column_id = C.column_id <br />
LEFT JOIN &nbsp;sys.dm_db_index_usage_stats AS IUS <br />
&nbsp; &nbsp; &nbsp; ON IUS.object_id = I.object_id <br />
&nbsp; &nbsp; &nbsp; AND IUS.index_id = I.index_id <br />
&nbsp; &nbsp; &nbsp; AND IUS.database_id = DB_ID() <br />
INNER JOIN &nbsp;sys.dm_db_partition_stats AS PS <br />
&nbsp; &nbsp; &nbsp; ON PS.object_id = I.object_id <br />
&nbsp; &nbsp; &nbsp; AND PS.index_id = I.index_id <br />
CROSS APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; SELECT &nbsp; &nbsp;CS.name + @separator <br />
&nbsp; &nbsp; &nbsp; FROM &nbsp; &nbsp;sys.columns AS CS <br />
&nbsp; &nbsp; &nbsp; INNER JOIN &nbsp;sys.index_columns AS ICS <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON CS.object_id = ICS.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND CS.column_id = ICS.column_id <br />
&nbsp; &nbsp; &nbsp; WHERE &nbsp; &nbsp;IC.object_id = ICS.object_id <br />
&nbsp; &nbsp; &nbsp; AND &nbsp; &nbsp;IC.index_id = ICS.index_id <br />
&nbsp; &nbsp; &nbsp; AND &nbsp; &nbsp;ICS.is_included_column = 0 <br />
&nbsp; &nbsp; &nbsp; ORDER BY &nbsp;ICS.index_column_id <br />
&nbsp; &nbsp; &nbsp; FOR XML PATH ('') <br />
&nbsp; &nbsp; ) AS KC (key_column_list) <br />
OUTER APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; SELECT &nbsp; &nbsp;CSI.name + @separator <br />
&nbsp; &nbsp; &nbsp; FROM &nbsp; &nbsp;sys.columns AS CSI <br />
&nbsp; &nbsp; &nbsp; INNER JOIN &nbsp;sys.index_columns AS ICSI <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON CSI.object_id = ICSI.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND CSI.column_id = ICSI.column_id <br />
&nbsp; &nbsp; &nbsp; WHERE &nbsp; &nbsp;IC.object_id = ICSI.object_id <br />
&nbsp; &nbsp; &nbsp; AND &nbsp; &nbsp;IC.index_id = ICSI.index_id <br />
&nbsp; &nbsp; &nbsp; AND &nbsp; &nbsp;ICSI.is_included_column = 1 <br />
&nbsp; &nbsp; &nbsp; ORDER BY &nbsp;ICSI.index_column_id <br />
&nbsp; &nbsp; &nbsp; FOR XML PATH ('') <br />
&nbsp; &nbsp; ) AS KCI (included_key_column_list) <br />
OUTER APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; SELECT &nbsp;MAX(M.last_search_date) <br />
&nbsp; &nbsp; &nbsp; FROM &nbsp;( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;LU_USK.last_user_seek <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp;sys.dm_db_index_usage_stats AS LU_USK <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;IUS.database_id = LU_USK.database_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.object_id = LU_USK.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.index_id = LU_USK.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UNION ALL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;LU_USC.last_user_scan <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp;sys.dm_db_index_usage_stats AS LU_USC <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;IUS.database_id = LU_USC.database_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.object_id = LU_USC.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.index_id = LU_USC.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UNION ALL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;LU_LK.last_user_lookup <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp;sys.dm_db_index_usage_stats AS LU_LK <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;IUS.database_id = LU_LK.database_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.object_id = LU_LK.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.index_id = LU_LK.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; ) AS M (last_search_date) <br />
&nbsp; &nbsp; ) AS LS (max_last_search_date) <br />
WHERE &nbsp; &nbsp;(@schema_name IS NULL OR S.name = @schema_name) <br />
AND &nbsp; &nbsp;(@table_or_view_name IS NULL OR O.name = @table_or_view_name) <br />
AND &nbsp; &nbsp;(@index_name IS NULL OR I.name = @index_name) <br />
ORDER BY &nbsp;I.type_desc</div></td></tr></tbody></table></div>
<p>Cette vue accumule les statistiques tant que le service SQL Server est démarré; un redémarrage du service ou du serveur purge les statistiques exposées par cette DMV.<br />
Si elle permet de détecter les index non-utilisés et donc à supprimer, vérifiez depuis combien de temps le service SQL Server est actif <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p>Bonne utilisation de vos index !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connaître la taille du cache allouée aux bases de données et à leurs tables avec SQL Server 2005 et suivants</title>
		<link>https://blog.developpez.com/elsuket/p11067/moteur-de-base-de-donnees-sql-server/cache_donnees_alloue_bd_tables</link>
		<comments>https://blog.developpez.com/elsuket/p11067/moteur-de-base-de-donnees-sql-server/cache_donnees_alloue_bd_tables#comments</comments>
		<pubDate>Mon, 04 Jun 2012 07:50:14 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici quelques requêtes qui montrent la taille du cache de données allouée aux tables (et vues indexées) : &#8211; pour toute l&#8217;instance SQL Server, &#8211; par base de données &#8211; par table (ou vue indexée) dans une base de données &#8230; <a href="https://blog.developpez.com/elsuket/p11067/moteur-de-base-de-donnees-sql-server/cache_donnees_alloue_bd_tables">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici quelques requêtes qui montrent la taille du cache de données allouée aux tables (et vues indexées) :</p>
<p>&#8211; pour toute l&rsquo;instance SQL Server,<br />
&#8211; par base de données<br />
&#8211; par table (ou vue indexée) dans une base de données en particulier</p>
<p><span id="more-117"></span></p>
<p>=&gt; <strong>Au niveau de l&rsquo;instance SQL Server</strong></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 04/06/2012 <br />
------------------------------- <br />
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED <br />
GO <br />
&nbsp;<br />
;WITH <br />
&nbsp; CTE AS &nbsp;<br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp;COUNT(*) / 128 AS used_MB <br />
&nbsp; &nbsp; &nbsp; , SUM (CAST (free_space_in_bytes AS float)) / (1024 * 1024) AS empty_MB <br />
&nbsp; &nbsp; FROM &nbsp;sys.dm_os_buffer_descriptors <br />
&nbsp; ) <br />
SELECT &nbsp;used_MB <br />
&nbsp; , CAST(empty_MB AS bigint) AS empty_MB <br />
&nbsp; , CAST((empty_MB / used_MB) * 100 AS decimal(5,2)) AS ratio <br />
FROM &nbsp;CTE <br />
GO</div></td></tr></tbody></table></div>
<p>Cette requête donne l&rsquo;espace alloué au cache de données pour toutes les bases de données d&rsquo;une instance SQL Server.<br />
Elle montre également l&rsquo;espace vide dans les pages, qui quand elle est élevée, est due soit à une fragmentation des index élevée, soit à un modèle de données incorrect qui conduit à ne pouvoir stocker que peu de lignes par page de données.<br />
En effet le taille d&rsquo;une page de données est de 8192 octets, desquels 8060 octets sont dédiés aux données utilisateur.<br />
Si donc la taille d&rsquo;une ligne est de 4031 octets (cas extrême) ou plus, on ne peut stocker qu&rsquo;une seule ligne de données par page, et on gaspille 4029 octets.</p>
<p>=&gt; <strong>Décomposition par base de données</strong></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 04/06/2012 <br />
------------------------------- <br />
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED <br />
GO <br />
&nbsp;<br />
;WITH <br />
&nbsp; CTE AS <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp;CASE <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHEN database_id = 32767 THEN 'RESOURCE DATABASE' <br />
&nbsp; &nbsp; &nbsp; &nbsp; ELSE DB_NAME(database_id) &nbsp;<br />
&nbsp; &nbsp; &nbsp; END AS database_name <br />
&nbsp; &nbsp; &nbsp; , COUNT (*) * 8 / 1024 AS reserved_MB <br />
&nbsp; &nbsp; &nbsp; , SUM(CAST(free_space_in_bytes AS bigint)) / (1024 * 1024) AS empty_MB <br />
&nbsp; &nbsp; FROM &nbsp;sys.dm_os_buffer_descriptors <br />
&nbsp; &nbsp; GROUP &nbsp;BY database_id <br />
&nbsp; ) <br />
SELECT &nbsp;database_name <br />
&nbsp; , reserved_MB <br />
&nbsp; , empty_MB <br />
&nbsp; , CAST(100.0 * empty_MB / CASE reserved_MB WHEN 0 THEN 1 ELSE reserved_MB END AS decimal(5,2))[empty_%] <br />
FROM &nbsp;CTE <br />
--WHERE &nbsp;database_name = 'maBD' <br />
ORDER &nbsp;BY empty_MB DESC</div></td></tr></tbody></table></div>
<p>Même chose ici, mais pour chaque objet de base de données.</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 04/06/2012 <br />
------------------------------- <br />
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED <br />
GO <br />
&nbsp;<br />
;WITH <br />
&nbsp; CTE AS <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp; &nbsp;BD.allocation_unit_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , AU.type_desc AS allocation_type <br />
&nbsp; &nbsp; &nbsp; &nbsp; , P.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , P.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , COUNT_BIG(*) AS page_count <br />
&nbsp; &nbsp; &nbsp; &nbsp; , COUNT_BIG(*) * 8192 AS allocated_space_in_bytes <br />
&nbsp; &nbsp; &nbsp; &nbsp; , SUM(CAST(BD.free_space_in_bytes AS bigint)) AS free_space_in_bytes <br />
&nbsp; &nbsp; FROM &nbsp; &nbsp;sys.dm_os_buffer_descriptors AS BD <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.allocation_units AS AU <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON AU.allocation_unit_id = BD.allocation_unit_id <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.partitions AS P <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON AU.container_id = P.partition_id <br />
&nbsp; &nbsp; WHERE &nbsp; &nbsp;BD.database_id = DB_ID() <br />
&nbsp; &nbsp; GROUP BY &nbsp;BD.allocation_unit_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , AU.type_desc <br />
&nbsp; &nbsp; &nbsp; &nbsp; , P.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , P.index_id <br />
&nbsp; &nbsp; HAVING &nbsp; &nbsp;COUNT_BIG(*) &amp;gt; 8 <br />
&nbsp; ) <br />
SELECT &nbsp; &nbsp;S.name + '.' + O.name AS table_or_indexed_view_name <br />
&nbsp; &nbsp; , I.name AS index_name <br />
&nbsp; &nbsp; , C.allocation_type <br />
&nbsp; &nbsp; , C.page_count <br />
&nbsp; &nbsp; , C.allocated_space_in_bytes <br />
&nbsp; &nbsp; , C.allocated_space_in_bytes - C.free_space_in_bytes AS used_space_in_bytes <br />
&nbsp; &nbsp; , C.free_space_in_bytes <br />
&nbsp; &nbsp; , CAST((CAST(C.free_space_in_bytes AS decimal(20,2)) / C.allocated_space_in_bytes) * 100 AS decimal(5,2)) AS [free_space_in_%] <br />
FROM &nbsp; &nbsp;CTE AS C <br />
INNER JOIN &nbsp;sys.indexes AS I <br />
&nbsp; &nbsp; &nbsp; ON I.index_id = C.index_id <br />
&nbsp; &nbsp; &nbsp; AND I.object_id = C.object_id <br />
INNER JOIN &nbsp;sys.objects AS O <br />
&nbsp; &nbsp; &nbsp; ON C.object_id = O.object_id <br />
INNER JOIN &nbsp;sys.schemas AS S <br />
&nbsp; &nbsp; &nbsp; ON S.schema_id = O.schema_id <br />
INNER JOIN &nbsp;sys.database_principals AS DP <br />
&nbsp; &nbsp; &nbsp; ON S.principal_id = DP.principal_id <br />
WHERE &nbsp; &nbsp;DP.type = 'S' -- schema <br />
AND &nbsp; &nbsp;DP.default_schema_name IS NOT NULL <br />
ORDER BY &nbsp;C.page_count DESC</div></td></tr></tbody></table></div>
<p>Cette requête nécessite de changer le contexte de base de données à la base de données que l&rsquo;on souhaite étudier.<br />
En effet, elle retourne la liste des tables (et vues indexées) qui sont présentes dans le cache de données, ainsi que la taille qu&rsquo;elles y occupent, avec les index.</p>
<p>En exécutant cette dernière requête à intervalles de temps réguliers à l&rsquo;aide d&rsquo;un job de l&rsquo;Agent SQL Server, et en enregistrant le résultat dans une table, on peut étudier la taille du cache allouée aux objets, de façon à faire une projection sur la quantité de RAM nécessaire au bon fonctionnement de la base de données.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Consulter ou télécharger les documentations de SQL Server</title>
		<link>https://blog.developpez.com/elsuket/p10996/utilitaires/telecharger_documentation_sql_server</link>
		<comments>https://blog.developpez.com/elsuket/p10996/utilitaires/telecharger_documentation_sql_server#comments</comments>
		<pubDate>Sun, 29 Apr 2012 08:56:12 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Ma signature étant devenue trop longue pour référencer les liens vers la documentation de SQL Server pour ses dernières versions, je les regroupe donc dans ce billet => Page d&#8217;accueil des documentation de SQL Server sur Internet SQL Server 2000 &#8230; <a href="https://blog.developpez.com/elsuket/p10996/utilitaires/telecharger_documentation_sql_server">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Ma signature étant devenue trop longue pour référencer les liens vers la documentation de SQL Server pour ses dernières versions, je les regroupe donc dans ce billet<br />
<span id="more-137"></span></p>
<p>=> <strong>Page d&rsquo;accueil des documentation de SQL Server sur Internet</strong><br />
<a href="http://msdn.microsoft.com/en-us/library/ms950404.aspx"><br />
SQL Server 2000</a><br />
<a href="http://msdn.microsoft.com/fr-fr/library/ms130214%28SQL.90%29.aspx">SQL Server 2005</a><br />
<a href="http://msdn.microsoft.com/fr-fr/library/ms130214%28v=sql.100%29.aspx">SQL Server 2008</a><br />
<a href="http://msdn.microsoft.com/fr-fr/library/ms130214%28v=sql.105%29.aspx">SQL Server 2008 R2</a><br />
<a href="http://msdn.microsoft.com/fr-fr/library/ms130214%28v=sql.110%29.aspx">SQL Server 2012<br />
</a></p>
<p>=> <strong>Télécharger la documentation de SQL Server pour installation locale</strong></p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?familyid=a6f79cb1-a420-445f-8a4b-bd77a7da194b&amp;displaylang=fr">SQL Server 2000</a><br />
<a href="http://www.microsoft.com/downloads/details.aspx?familyid=BE6A2C5D-00DF-4220-B133-29C1E0B6585F&amp;displaylang=fr">SQL Server 2005</a><br />
<a href="http://www.microsoft.com/downloads/details.aspx?familyid=765433F7-0983-4D7A-B628-0A98145BCB97&amp;displaylang=fr">SQL Server 2008</a><br />
<a href="http://www.microsoft.com/downloads/fr-fr/details.aspx?FamilyID=c18bad82-0e5f-4e82-812b-5b23e5d52b9c">SQL Server 2008 R2</a><br />
<a href="http://blog.developpez.com/elsuket/p10966/sql-server-2012/installer-aid-sql-server-2012-local/">SQL Server 2012</a></p>
<p>Bonne documentation à tous !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>5 nouvelles DMV dans SQL Server 2008 R2 SP1 (et donc SQL Server 2012)</title>
		<link>https://blog.developpez.com/elsuket/p10828/moteur-de-base-de-donnees-sql-server/5_dmv_dans_sql_2008_r2_sp1_sql_2012</link>
		<comments>https://blog.developpez.com/elsuket/p10828/moteur-de-base-de-donnees-sql-server/5_dmv_dans_sql_2008_r2_sp1_sql_2012#comments</comments>
		<pubDate>Tue, 13 Mar 2012 12:53:59 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Le service pack 1 de SQL Server 2008 R2 a introduit quelques nouvelles vues de gestion dynamique fort intéressantes, surtout quand il s&#8217;agit de communiquer avec les administrateurs système. => sys.dm_os_volume_stats permet d&#8217;obtenir quelques informations sur les volumes sur lesquels &#8230; <a href="https://blog.developpez.com/elsuket/p10828/moteur-de-base-de-donnees-sql-server/5_dmv_dans_sql_2008_r2_sp1_sql_2012">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Le service pack 1 de SQL Server 2008 R2 a introduit quelques nouvelles vues de gestion dynamique fort intéressantes, surtout quand il s&rsquo;agit de communiquer avec les administrateurs système.<br />
<span id="more-114"></span></p>
<p>=> <strong>sys.dm_os_volume_stats</strong> permet d&rsquo;obtenir quelques informations sur les volumes sur lesquels sont stockés les fichiers des bases de données hébergées par le serveur. On obtient la liste des volumes avec leurs caractéristiques avec la requête suivante :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 13/03/2012 <br />
------------------------------- <br />
SELECT &nbsp; &nbsp;DISTINCT VS.volume_mount_point <br />
&nbsp; &nbsp; , VS.volume_id <br />
&nbsp; &nbsp; , VS.logical_volume_name <br />
&nbsp; &nbsp; , VS.file_system_type <br />
&nbsp; &nbsp; , VS.total_bytes / 1024 / 1024 AS volume_size_MB <br />
&nbsp; &nbsp; , VS.available_bytes / 1024 / 1024 AS volumn_free_space_MB <br />
&nbsp; &nbsp; , VS.supports_compression <br />
&nbsp; &nbsp; , VS.supports_alternate_streams <br />
&nbsp; &nbsp; , VS.supports_sparse_files <br />
&nbsp; &nbsp; , VS.is_read_only <br />
&nbsp; &nbsp; , VS.is_compressed <br />
FROM &nbsp; &nbsp;sys.master_files AS MF <br />
CROSS APPLY &nbsp;sys.dm_os_volume_stats(MF.database_id, MF.file_id) AS VS</div></td></tr></tbody></table></div>
<p>Et un requête avec la carte des fichiers, pour toutes les bases de données :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 13/03/2012 <br />
------------------------------- <br />
SELECT &nbsp; &nbsp;D.name AS database_name <br />
&nbsp; &nbsp; , MF.name AS file_logical_name <br />
&nbsp; &nbsp; , MF.physical_name AS file_physical_name <br />
&nbsp; &nbsp; , MF.type_desc AS file_type <br />
&nbsp; &nbsp; , VS.volume_mount_point <br />
&nbsp; &nbsp; , VS.volume_id <br />
&nbsp; &nbsp; , VS.logical_volume_name <br />
&nbsp; &nbsp; , VS.file_system_type <br />
&nbsp; &nbsp; , VS.total_bytes / 1024 / 1024 AS volume_size_MB <br />
&nbsp; &nbsp; , VS.available_bytes / 1024 / 1024 AS volumn_free_space_MB <br />
&nbsp; &nbsp; , VS.supports_compression <br />
&nbsp; &nbsp; , VS.supports_alternate_streams <br />
&nbsp; &nbsp; , VS.supports_sparse_files <br />
&nbsp; &nbsp; , VS.is_read_only <br />
&nbsp; &nbsp; , VS.is_compressed <br />
FROM &nbsp; &nbsp;sys.master_files AS MF <br />
CROSS APPLY &nbsp;sys.dm_os_volume_stats(MF.database_id, MF.file_id) AS VS <br />
INNER JOIN &nbsp;sys.databases AS D <br />
&nbsp; &nbsp; &nbsp; ON D.database_id = MF.database_id <br />
-- WHERE &nbsp;D.name = 'maBD'</div></td></tr></tbody></table></div>
<p>La documentation de cette DMV pour <a href="http://msdn.microsoft.com/fr-fr/library/hh223223.aspx">SQL Server 2008 R2</a> et <a href="http://msdn.microsoft.com/fr-fr/library/hh223223%28v=sql.110%29.aspx">SQL Server 2012</a></p>
<p>=> <strong>sys.dm_os_windows_info</strong></p>
<p>Cette DMV retourne quelques informations intéressantes à propos de l&rsquo;installation de Windows qui héberge SQL Server.<br />
En l&rsquo;interrogeant sur mon PC sous Windows 7 SP1 en Français, j&rsquo;obtiens :</p>
<p><img src="http://blog.developpez.com/media/sys.dm_os_windows_info.PNG" width="516" height="158" alt="" /></p>
<p>La documentation de cette DMV pour <a href="http://msdn.microsoft.com/fr-fr/library/hh204565.aspx">SQL Server 2008 R2</a> et <a href="http://msdn.microsoft.com/fr-fr/library/hh204565%28v=sql.110%29.aspx">SQL Server 2012</a></p>
<p>=> <strong>sys.dm_server_registry</strong></p>
<p>Cette DMV retourne toutes les valeurs stockées dans le registre pour SQL Server, en ce qui concerne les options de démarrage du service, et la configuration des <a href="http://blog.developpez.com/elsuket/p7723/utilitaires/configurer-les-protocoles-de-connexion-a/">protocoles de connexion</a> à l&rsquo;instance interrogée :</p>
<p><img src="http://img440.imageshack.us/img440/612/sysdmserverregistry.png" alt="" title="" /></p>
<p>La documentation de cette DMV pour <a href="http://msdn.microsoft.com/fr-fr/library/hh204561.aspx">SQL Server 2008 R2</a> et <a href="http://msdn.microsoft.com/fr-fr/library/hh204561%28v=sql.110%29.aspx">SQL Server 2012</a></p>
<p>=> <strong>sys.dm_server_services</strong></p>
<p>Comme son nom l&rsquo;indique, cette DMV retourne quelques informations sur les services installés pour l&rsquo;instance SQL Server interrogée :</p>
<p><img src="http://blog.developpez.com/media/sys.dm_server_services.PNG" width="1532" height="184" alt="" /></p>
<p>On notera que sont exposés la date de dernier démarrage du service et l&rsquo;instance est en cluster.</p>
<p>La documentation de cette DMV pour <a href="http://msdn.microsoft.com/fr-fr/library/hh204542.aspx">SQL Server 2008 R2</a> et <a href="http://msdn.microsoft.com/fr-fr/library/hh204542%28v=sql.110%29.aspx">SQL Server 2012</a></p>
<p>=> <strong>sys.dm_server_memory_dumps</strong></p>
<p>Cette DMV retourne l&rsquo;ensemble des vidages mémoire avec le chemin des fichiers, c&rsquo;est-à-dire à chaque fois que SQL Server a rencontré un gros problème.<br />
Malheureusement (ou pas) sur mon installation de SQL Server 2012, l&rsquo;interrogation de cette DMV ne retourne rien <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p>La documentation de cette DMV pour <a href="http://msdn.microsoft.com/fr-fr/library/hh204543%28v=sql.105%29.aspx">SQL Server 2008 R2</a> et <a href="http://msdn.microsoft.com/fr-fr/library/hh204543%28v=SQL.110%29.aspx">SQL Server 2012</a></p>
<p>On le voit donc, Microsoft continue d&rsquo;exposer les données système à travers les <a href="http://msdn.microsoft.com/fr-fr/library/ms188754.aspx">fonctions et vues de gestion dynamique</a> (respectivement DMF et DMV dans la littérature, et plus généralement DMO pour Dynamic Management Object).<br />
Elles ont été introduites avec SQL Server 2005, et facilitent grandement les travail des administrateurs de bases de données et des consultants.</p>
<p>Ces 5 nouvelles DMVs permettent notamment de démarrer une discussion avec les administrateurs système.<br />
En effet en exécutant de telles requêtes sur un ensemble de serveurs hébergeant une instance de SQL Server à travers les possibilités de Central Management Server, elles permettent en outre de comparer et détecter très simplement les différences de configuration entre plusieurs serveurs, et elles sont donc fort bienvenues.</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gestion basée sur des stratégies : importer les stratégies de meilleures pratiques</title>
		<link>https://blog.developpez.com/elsuket/p10243/utilitaires/gestion_basee_sur_des_strategies_importe</link>
		<comments>https://blog.developpez.com/elsuket/p10243/utilitaires/gestion_basee_sur_des_strategies_importe#comments</comments>
		<pubDate>Fri, 02 Sep 2011 02:35:20 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Introduite avec SQL Server 2008, la gestion basée sur les stratégies est une fonctionnalité qui permet d&#8217;évaluer et éventuellement de mettre en conformité des instances de SQL Server. Cela simplifie quelque peu la gestion d&#8217;un nombre important d&#8217;instances SQL Server, &#8230; <a href="https://blog.developpez.com/elsuket/p10243/utilitaires/gestion_basee_sur_des_strategies_importe">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Introduite avec SQL Server 2008, la gestion basée sur les stratégies est une fonctionnalité qui permet d&rsquo;évaluer et éventuellement de mettre en conformité des instances de SQL Server.<br />
Cela simplifie quelque peu la gestion d&rsquo;un nombre important d&rsquo;instances SQL Server, en permettant de s&rsquo;assurer que toutes les instances, bases de données ou objets sont en conformité, et ce de façon extrêmement élémentaire.<br />
Autre avantage : c&rsquo;est compatible avec les versions antérieures de SQL Server.</p>
<p>Cette fonctionnalité est livrée avec 50 stratégies par défaut, qualifiées de &laquo;&nbsp;meilleures pratiques&nbsp;&raquo;, mais qui ne sont pas préinstallées directement. Voici comment les importer &#8230;</p>
<p><span id="more-135"></span></p>
<p>Lorsqu&rsquo;on ouvre l&rsquo;<em>Explorateur d&rsquo;Objets</em> de <em>SQL Server Management Studio</em> (SSMS), que l&rsquo;on obtient par F8, et que l&rsquo;on développe le nœud <em>Gestion</em>, on obtient :</p>
<p><img src="http://blog.developpez.com/media/pbm_import1.png" width="315" height="477" alt="" /></p>
<p>La gestion basée basée sur les stratégies propose une liste assez conséquente de propriétés que l&rsquo;on peut vérifier, et qui sont groupées dans ce qui est appelé une facette.<br />
Ainsi on peut vérifier, par exemple :</p>
<p>&#8211; que la densité de grille de niveau 1 d&rsquo;un index spatial est à MEDIUM<br />
&#8211; que l&rsquo;option de serveur &laquo;&nbsp;max degree of parallelism&nbsp;&raquo; est à 1<br />
&#8211; que la dernière sauvegarde complète d&rsquo;une base de données n&rsquo;est pas plus vieille que 7 jours<br />
&#8211; que toute statistique est automatiquement maintenue par SQL Server<br />
&#8211; que le nom de toutes les procédures stockées commence par &laquo;&nbsp;usp_&nbsp;&raquo;</p>
<p>Ceci n&rsquo;est qu&rsquo;une très courte liste d&rsquo;exemples de ce qu&rsquo;il est possible de vérifier à l&rsquo;aide de la gestion basée sur les stratégies.<br />
Chacun de ces exemples constitue une condition, qui est évaluée par une stratégie, que l&rsquo;on peut soit créer :</p>
<p>&#8211; Manuellement à l&rsquo;aide de SSMS<br />
&#8211; Soit automatique en écrivant les scripts ou modules T-SQL nécessaires<br />
&#8211; Soit importer à partir d&rsquo;un fichier XML</p>
<p>Je passerai dans ce billet sur les deux premiers éléments de cette liste, qui méritent à eux seuls un billet, pour détailler l&rsquo;import, et plus particulièrement l&rsquo;import des stratégies de &laquo;&nbsp;meilleures pratiques&nbsp;&raquo;.</p>
<p>L&rsquo;import se fait très simplement : il suffit de cliquer-droit sur le noeud <em>Stratégies</em> :</p>
<p><img src="http://blog.developpez.com/media/pbm_import2.png" width="355" height="473" alt="" /></p>
<p>Un dialogue s&rsquo;ouvre alors pour la sélection de stratégies à importer :</p>
<p><img src="http://blog.developpez.com/media/pbm_import3.png" width="756" height="472" alt="" /></p>
<p>Au clic sur le bouton de recherche (&#8230;), une fenêtre classique de sélection de fichiers s&rsquo;ouvre, et on remarque que celle-ci est paramétrée pour s&rsquo;ouvrir sur un dossier contenant un raccourci nommé <em>Meilleures pratiques pour SQL Server</em>:</p>
<p><img src="http://blog.developpez.com/media/pbm_import4.png" width="867" height="551" alt="" /></p>
<p>En double cliquant sur le raccourci, on est pointé vers <em>C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Policies</em>, où l&rsquo;on s&rsquo;aperçoit qu&rsquo;il existe des stratégies pour <em>SQL Server Analysis Services</em> et <em>SQL Server Reporting Services</em>.<br />
Ici nous nous intéresserons seulement aux stratégies pour le moteur de bases de données relationnelles, donc nous sélectionnons le répertoire <em>DatabaseEngine</em>, puis le répertoire 1036 (qui est l&rsquo;identifiant de langue pour le Français) :</p>
<p><img src="http://blog.developpez.com/media/pbm_import5.jpg" width="768" height="412" alt="" /></p>
<p>Pour importer toutes les stratégies, il suffit de toutes les sélectionner (CTRL + A) et de cliquer sur <em>Ouvrir</em> :</p>
<p><img src="http://blog.developpez.com/media/pbm_import6.png" width="780" height="470" alt="" /></p>
<p>En cliquant sur OK, on procède à l&rsquo;import :</p>
<p><img src="http://blog.developpez.com/media/pbm_import7.png" width="781" height="471" alt="" /></p>
<p>De retour dans SSMS, on trouve toutes les stratégies importées :</p>
<p><img src="http://blog.developpez.com/media/pbm_import8.png" width="460" height="561" alt="" /></p>
<p>Pour évaluer une stratégie, il suffit de choisir Évaluer dans le menu contextuel de l&rsquo;une d&rsquo;entre-elles :</p>
<p> <img src="http://blog.developpez.com/media/pbm_import9.png" width="746" height="445" alt="" /></p>
<p>En quelques secondes, on obtient :</p>
<p><img src="http://blog.developpez.com/media/pbm_import10.png" width="1189" height="471" alt="" /></p>
<p>Et en cliquant sur le lien <em>Afficher</em>, on obtient tous les détails, avec la description de ce que vérifie la stratégie :</p>
<p><img src="http://blog.developpez.com/media/pbm_import11.png" width="727" height="425" alt="" /></p>
<p>Dans l&rsquo;exemple de ce billet, le lien pointe vers une page de la documentation de SQL Server qui décrit ce que vérifie la stratégie, et comment y remédier si elle n&rsquo;était pas vérifiée.</p>
<p>Bonne gestion d&rsquo;instances SQL Server !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trouver et changer le propriétaire d&#8217;un plan de maintenance</title>
		<link>https://blog.developpez.com/elsuket/p10542/utilitaires/proprietaire_plan_maintenance</link>
		<comments>https://blog.developpez.com/elsuket/p10542/utilitaires/proprietaire_plan_maintenance#comments</comments>
		<pubDate>Sun, 27 Nov 2011 06:16:15 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Bien qu&#8217;incomplets en termes de fonctionnalités par rapport à une procédure stockée qui ferait la même chose, les plans de maintenance s&#8217;avèrent très simple à développer et à déployer dans un temps court. Je pense notamment à l&#8217;impossibilité de compresser &#8230; <a href="https://blog.developpez.com/elsuket/p10542/utilitaires/proprietaire_plan_maintenance">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Bien qu&rsquo;incomplets en termes de fonctionnalités par rapport à une procédure stockée qui ferait la même chose, les plans de maintenance s&rsquo;avèrent très simple à développer et à déployer dans un temps court. Je pense notamment à l&rsquo;impossibilité de compresser des sauvegardes sous SQL Server 2008.</p>
<p>Comme beaucoup de choses effectuées à l&rsquo;aide des interfaces graphiques proposées par SQL Server Management Studio, les effets produits par l&rsquo;exécution d&rsquo;une tâche ne sont pas toujours détaillés. Le propriétaire d&rsquo;un plan de maintenance n&rsquo;y échappe pas et est écrasé à chaque modification du plan.<br />
Voici donc comment le trouver, et le changer.<br />
<span id="more-136"></span></p>
<p>Voici la requête qui permet de trouver le propriétaire de tous les plans de maintenance, avec quelques détails :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 27/11/2011 <br />
------------------------------- <br />
SELECT &nbsp; &nbsp;P.name AS SSIS_package_name <br />
&nbsp; &nbsp; , P.createdate <br />
&nbsp; &nbsp; , P.ownersid <br />
&nbsp; &nbsp; , SP.name AS owner_name <br />
&nbsp; &nbsp; , CASE P.packagetype &nbsp;<br />
&nbsp; &nbsp; &nbsp; WHEN 0 THEN 'Default' <br />
&nbsp; &nbsp; &nbsp; WHEN 1 THEN 'SQL Server Import and Export Wizard' <br />
&nbsp; &nbsp; &nbsp; WHEN 2 THEN 'DTS Designer in SQL Server 2000' <br />
&nbsp; &nbsp; &nbsp; WHEN 3 THEN 'SQL Server Replication' <br />
&nbsp; &nbsp; &nbsp; WHEN 5 THEN 'SSIS Designer' <br />
&nbsp; &nbsp; &nbsp; WHEN 6 THEN 'Maintenance Plan Designer or Wizard' <br />
&nbsp; &nbsp; END AS packagetype <br />
FROM &nbsp; &nbsp;msdb.dbo.sysssispackages AS P <br />
INNER JOIN &nbsp;sys.server_principals AS SP <br />
&nbsp; &nbsp; &nbsp; ON P.ownersid = SP.sid <br />
--WHERE &nbsp; &nbsp;P.name = 'monPlanDeMaintenance'</div></td></tr></tbody></table></div>
<p>En dé-commentant la clause WHERE de cette requête, on peut trouver le propriétaire d&rsquo;un plan de maintenance particulier.</p>
<p>Dès lors on peut changer le propriétaire d&rsquo;un plan de maintenance particulier à l&rsquo;aide de la requête suivante :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 27/11/2011 <br />
------------------------------- <br />
UPDATE &nbsp; &nbsp;msdb.dbo.sysssispackages <br />
SET &nbsp; &nbsp;ownersid = SP.sid <br />
FROM &nbsp; &nbsp;msdb.dbo.sysssispackages AS P <br />
CROSS JOIN &nbsp;sys.server_principals AS SP <br />
WHERE &nbsp; &nbsp;P.name = 'monPlanDeMaintenance' <br />
AND &nbsp; &nbsp;SP.name = 'nomDeLoginDuNouveauPropriétaire'</div></td></tr></tbody></table></div>
<p>Ceci fonctionne sous réserve que <em>nomDeLoginDuNouveauPropriétaire</em> et <em>monPlanDeMaintenance</em> existent <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>Et c&rsquo;est malheureusement à effectuer après chaque modification du plan de maintenance si le login qui le modifie n&rsquo;est pas celui qui l&rsquo;exécute !</p>
<p>Bons plans de maintenance <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Marquer une procédure stockée comme objet système : la procédure stockée sp_MS_marksystemobject</title>
		<link>https://blog.developpez.com/elsuket/p9409/utilitaires/marquer_un_procedure_stockee_comme_objet</link>
		<comments>https://blog.developpez.com/elsuket/p9409/utilitaires/marquer_un_procedure_stockee_comme_objet#comments</comments>
		<pubDate>Tue, 19 Oct 2010 04:55:58 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Non documenté]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Il peut être intéressant de pouvoir utiliser une procédure stockée dans n&#8217;importe quel contexte de base de données (sur la même instance SQL Server). Voyons comment faire cela à l&#8217;aide de la procédure stockée système non documentée sp_MS_marksystemobject Je cherchai &#8230; <a href="https://blog.developpez.com/elsuket/p9409/utilitaires/marquer_un_procedure_stockee_comme_objet">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Il peut être intéressant de pouvoir utiliser une procédure stockée dans n&rsquo;importe quel contexte de base de données (sur la même instance SQL Server).<br />
Voyons comment faire cela à l&rsquo;aide de la procédure stockée système <strong>non documentée <em>sp_MS_marksystemobject</em></strong><br />
<span id="more-130"></span><br />
Je cherchai à fournir à mes collègues développeurs SQL un moyen de générer des instructions CRUD (INSERT, SELECT, UPDATE, DELETE) de façon propre et générique.<br />
Voici donc l&rsquo;exemple de l&rsquo;INSERT (je publierai les autres dans un billet à venir) :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE master <br />
GO <br />
&nbsp;<br />
CREATE PROCEDURE dbo.sp__generate_INSERT <br />
&nbsp; &nbsp; @_table_name sysname, <br />
&nbsp; &nbsp; @_nb_tab tinyint = 0 <br />
AS <br />
BEGIN <br />
&nbsp; &nbsp; SET NOCOUNT ON <br />
&nbsp;<br />
&nbsp; &nbsp; DECLARE @sql varchar(max) <br />
&nbsp; &nbsp; SELECT &nbsp; &nbsp;@sql = CASE <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN @sql IS NULL THEN REPLICATE(CHAR(9), @_nb_tab) + 'INSERT' + CHAR(9) + @_table_name + &nbsp;CHAR(13) + CHAR(10) + REPLICATE(CHAR(9), @_nb_tab) + '(' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CHAR(13) + CHAR(10) + REPLICATE(CHAR(9), @_nb_tab) + CHAR(9) + name <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE @sql + CHAR(13) + CHAR(10) + REPLICATE(CHAR(9), @_nb_tab) + CHAR(9) + ', ' + name <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; FROM &nbsp; &nbsp;sys.columns <br />
&nbsp; &nbsp; WHERE &nbsp; &nbsp;object_id = OBJECT_ID(@_table_name) <br />
&nbsp; &nbsp; AND &nbsp; &nbsp;is_computed = 0 <br />
&nbsp; &nbsp; ORDER &nbsp; &nbsp;BY column_id <br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; SET &nbsp; &nbsp;@sql = @sql + CHAR(13) + CHAR(10) + REPLICATE(CHAR(9), @_nb_tab) + ')' <br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; PRINT &nbsp; &nbsp;@sql <br />
END</div></td></tr></tbody></table></div>
<p>Vous remarquerez que je me place dans le contexte de la base de données système master, qui est la seule dans laquelle vous pouvez marquer des procédures stockées comme objet système.</p>
<p>Un autre requis pour pouvoir utiliser une procédure stockée marquée comme objet système dans n&rsquo;importe quel contexte de base de données de l&rsquo;instance en cours, est de faire commencer le nom de la procédure stockée par &laquo;&nbsp;sp&nbsp;&raquo;.<br />
Rien ne vous empêche de marquer la procédure stockée comme objet système, mais lorsque vous exécuterez une telle procédure stockée (dont le nom ne commence donc pas par &laquo;&nbsp;sp&nbsp;&raquo;), SQL Server &laquo;&nbsp;feindra&nbsp;&raquo; de ne pas trouver celle-ci.</p>
<p><strong>Le marquage se fait de façon extrêmement simple, mais n&rsquo;est pas documenté</strong> :</p>
<p><code class="codecolorer text default"><span class="text">EXEC sp_MS_marksystemobject 'sp__generate_INSERT'</span></code></p>
<p>Et le tour est joué : vous pouvez générer le script d&rsquo;INSERT en exécutant tout simplement :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE maBD <br />
GO <br />
&nbsp;<br />
EXEC sp__generate_INSERT 'maTable'</div></td></tr></tbody></table></div>
<p>Bonne génération !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Quelles sont les requêtes et tâches en cours d&#8217;exécution dans une instance SQL Server ?</title>
		<link>https://blog.developpez.com/elsuket/p9047/moteur-de-base-de-donnees-sql-server/requetes_et_taches_cours_execution</link>
		<comments>https://blog.developpez.com/elsuket/p9047/moteur-de-base-de-donnees-sql-server/requetes_et_taches_cours_execution#comments</comments>
		<pubDate>Fri, 25 Jun 2010 05:08:40 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une requête basée sur les vues et fonctions de gestion dynamiques, introduites avec SQL Server 2005. Elle permet de lister l&#8217;ensemble des requêtes actuellement en cours d&#8217;exécution dans une instance SQL Server, avec quelques statistiques et caractéristiques : &#8211; &#8230; <a href="https://blog.developpez.com/elsuket/p9047/moteur-de-base-de-donnees-sql-server/requetes_et_taches_cours_execution">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une requête basée sur les vues et fonctions de gestion dynamiques, introduites avec SQL Server 2005.</p>
<p>Elle permet de lister l&rsquo;ensemble des requêtes actuellement en cours d&rsquo;exécution dans une instance SQL Server, avec quelques statistiques et caractéristiques :</p>
<p>&#8211; le n° de session (SPID),<br />
&#8211; le nombre de threads mis en place pour résoudre la requête,<br />
&#8211; le nom du serveur,<br />
&#8211; le nom du login,<br />
&#8211; le <a href="http://blog.developpez.com/elsuket/p8122/moteur-de-base-de-donnees-sql-server/connaitre-le-pourcentage-d-avancement-d--2008/">pourcentage</a> d&rsquo;avancement d&rsquo;une instruction,<br />
&#8211; le nom de la base de données,<br />
&#8211; le statut de la session,<br />
&#8211; le temps écoulé depuis le début de l&rsquo;exécution,<br />
&#8211; le temps CPU consommé,<br />
&#8211; le nombre de lectures et d&rsquo;écritures,<br />
&#8211; le type d&rsquo;instruction,<br />
&#8211; le nombre de transactions ouvertes par la session,<br />
&#8211; le nombre de resultsets,<br />
&#8211; le type d&rsquo;attente,<br />
&#8211; le temps d&rsquo;attente pour ce type,<br />
&#8211; le type d&rsquo;attente précédent,<br />
&#8211; la ressource attendue,<br />
&#8211; le nom du programme / job qui exécute la requête,<br />
&#8211; l&rsquo;instruction SQL en cours d&rsquo;exécution dans le lot,<br />
&#8211; le lot SQL complet,<br />
&#8211; le plan de requête,<br />
&#8211; les hashs de requête et de plan,<br />
&#8211; le nombre d&rsquo;exécutions du plan,<br />
&#8211; la date de génération du plan,<br />
&#8211; l&rsquo;adresse IP de la machine exécutant la requête.</p>
<p>Toute suggestion est la bienvenue !</p>
<p><span id="more-102"></span></p>
<p><strong>Mise à jour du 13/05/2011</strong></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas SOUQUET - 13/05/2011 <br />
------------------------------- <br />
SET NOCOUNT ON <br />
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED <br />
&nbsp;<br />
;WITH <br />
&nbsp; CTE AS <br />
&nbsp; ( &nbsp;<br />
&nbsp; &nbsp; SELECT &nbsp; &nbsp;CASE ES.login_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'NT AUTHORITY\SYSTEM' THEN CASE &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ES.program_name LIKE 'SQLAgent%' THEN 'SQLAgent' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE ES.program_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE ES.login_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; END AS Login <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ES.session_id AS SPID <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.blocking_session_id AS BlkBy <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.wait_type <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.wait_time <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.last_wait_type <br />
&nbsp; &nbsp; &nbsp; &nbsp; , COUNT(*) AS Threads <br />
&nbsp; &nbsp; &nbsp; &nbsp; , CAST(ER.percent_complete AS NUMERIC(5,2)) AS percent_complete <br />
&nbsp; &nbsp; &nbsp; &nbsp; , DB_NAME(ER.database_id) AS DB <br />
&nbsp; &nbsp; &nbsp; &nbsp; , UPPER(ER.command) AS Command <br />
&nbsp; &nbsp; &nbsp; &nbsp; , UPPER(ER.status) AS Status <br />
&nbsp; &nbsp; &nbsp; &nbsp; , CASE LEN(CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 3600 AS VARCHAR(4))) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 1 THEN '0' + CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 3600 AS VARCHAR(4)) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 3600 AS VARCHAR(4)) <br />
&nbsp; &nbsp; &nbsp; &nbsp; END + ':' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; CASE LEN(CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 60 % 60 AS VARCHAR(2))) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 1 THEN '0' + CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 60 % 60 AS VARCHAR(2)) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 60 % 60 AS VARCHAR(2)) <br />
&nbsp; &nbsp; &nbsp; &nbsp; END + ':' + &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; CASE LEN(CAST(DATEDIFF(second, ER.start_time, GETDATE()) % 60 AS VARCHAR(2))) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 1 THEN '0' + CAST(DATEDIFF(second, ER.start_time, GETDATE()) % 60 AS VARCHAR(2)) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE CAST(DATEDIFF(second, ER.start_time, GETDATE()) % 60 AS VARCHAR(2)) <br />
&nbsp; &nbsp; &nbsp; &nbsp; END AS Launched <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.cpu_time / 1000 AS CPU <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.reads AS Reads <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.writes AS Writes <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.open_transaction_count AS NbTran <br />
&nbsp; &nbsp; &nbsp; &nbsp; , SUBSTRING <br />
&nbsp; &nbsp; &nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ESQLT.text, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ER.statement_start_offset / 2 + 1, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CASE <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ER.statement_end_offset = - 1 THEN LEN(CAST(ESQLT.text AS nvarchar(max))) * 2 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE ER.statement_end_offset &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END - ER.statement_start_offset <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) / 2 + 1 <br />
&nbsp; &nbsp; &nbsp; &nbsp; ) AS StatementInBatch <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ESQLT.text AS Batch <br />
&nbsp; &nbsp; &nbsp; &nbsp; , CASE <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ER.command = 'UPDATE STATISTIC' THEN 'Updating stats on ' + REPLACE(REPLACE(SUBSTRING(ESQLT.text, CHARINDEX('[dbo]', ESQLT.text), CHARINDEX(' ', ESQLT.text, CHARINDEX('[dbo]', ESQLT.text)) - &nbsp;CHARINDEX('[dbo]', ESQLT.text)), '[', ''), ']', '') <br />
&nbsp; &nbsp; &nbsp; &nbsp; END AS info <br />
&nbsp; &nbsp; &nbsp; &nbsp; , CASE &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ES.program_name LIKE 'SQLAgent - TSQL JobStep%' THEN 'Job : ' + J.name <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ES.program_name LIKE 'Microsoft SQL Server Management Studio%' THEN 'SSMS' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ES.program_name LIKE 'LiteSpeed for SQL Server%' THEN 'LiteSpeed' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ES.program_name = 'Microsoft SQL Server Analysis Services' THEN 'SSAS' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE ES.program_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; END AS Program <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ES.host_name AS Host <br />
&nbsp; &nbsp; &nbsp; &nbsp; , EC.client_net_address AS IP <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.plan_handle <br />
&nbsp; &nbsp; FROM &nbsp; &nbsp;sys.dm_exec_sessions ES (nolock) <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.dm_exec_connections (nolock) EC &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON ES.session_id = EC.session_id <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.dm_exec_requests ER (nolock) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON ES.session_id = ER.session_id <br />
&nbsp; &nbsp; LEFT JOIN &nbsp;msdb.dbo.sysjobs J (nolock) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON REPLACE(SUBSTRING(CAST(J.job_id AS char(36)), CHARINDEX('-', J.job_id, 18) + 1, LEN(J.job_id)), '-', '') = <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RIGHT(LEFT(REPLACE(ES.program_name, 'SQLAgent - TSQL JobStep (Job 0x', ''), 32), 16) <br />
&nbsp; &nbsp; CROSS APPLY &nbsp;sys.dm_exec_sql_text(ER.sql_handle) ESQLT <br />
&nbsp; &nbsp; WHERE &nbsp; &nbsp;ES.session_id &lt;&gt; @@SPID <br />
&nbsp; &nbsp; AND &nbsp; &nbsp;ES.is_user_process = 1 <br />
&nbsp; &nbsp; AND &nbsp; &nbsp;(J.name NOT LIKE 'cdc%' OR J.name IS NULL) <br />
&nbsp; &nbsp; AND &nbsp; &nbsp;ES.is_user_process = 1 <br />
&nbsp; &nbsp; GROUP BY &nbsp;ES.session_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.blocking_session_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ES.host_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ES.login_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.percent_complete <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.database_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.status <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.start_time <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.cpu_time <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.reads <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.writes <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.command <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.open_transaction_count <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.statement_start_offset <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.statement_end_offset <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ESQLT.text <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.wait_type <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.wait_time <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.last_wait_type <br />
&nbsp; &nbsp; &nbsp; &nbsp; , J.name <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ES.program_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; , EC.client_net_address <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ER.plan_handle <br />
&nbsp; ) <br />
SELECT &nbsp; &nbsp;C.Login <br />
&nbsp; &nbsp; , C.SPID <br />
&nbsp; &nbsp; , C.BlkBy <br />
&nbsp; &nbsp; , C.wait_type <br />
&nbsp; &nbsp; , C.wait_time <br />
&nbsp; &nbsp; , C.last_wait_type <br />
&nbsp; &nbsp; , C.Threads <br />
&nbsp; &nbsp; , C.percent_complete AS [%] <br />
&nbsp; &nbsp; , C.DB <br />
&nbsp; &nbsp; , C.Command <br />
&nbsp; &nbsp; , C.Status <br />
&nbsp; &nbsp; , C.Launched <br />
&nbsp; &nbsp; , C.CPU <br />
&nbsp; &nbsp; , C.Reads <br />
&nbsp; &nbsp; , C.Writes <br />
&nbsp; &nbsp; , C.NbTran <br />
&nbsp; &nbsp; , C.StatementInBatch <br />
&nbsp; &nbsp; , C.Batch <br />
&nbsp; &nbsp; , C.info <br />
&nbsp; &nbsp; , C.Program <br />
&nbsp; &nbsp; , C.Host <br />
&nbsp; &nbsp; , C.IP <br />
&nbsp; &nbsp; , C.plan_handle <br />
FROM &nbsp; &nbsp;CTE AS C <br />
ORDER BY &nbsp;C.SPID</div></td></tr></tbody></table></div>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas SOUQUET - 25/06/2010 <br />
------------------------------- <br />
SET NOCOUNT ON <br />
&nbsp;<br />
;WITH <br />
&nbsp; CTE_THREADS AS <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp; &nbsp;session_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , COUNT(*) AS nbThreads <br />
&nbsp; &nbsp; FROM &nbsp; &nbsp;sys.dm_exec_sessions <br />
&nbsp; &nbsp; GROUP BY &nbsp;session_id <br />
&nbsp; ) <br />
SELECT &nbsp; &nbsp;ES.session_id SPID <br />
&nbsp; &nbsp; , CT.nbThreads <br />
&nbsp; &nbsp; , ER.blocking_session_id BlkBy <br />
&nbsp; &nbsp; , ES.host_name AS Host <br />
&nbsp; &nbsp; , CASE ES.login_name <br />
&nbsp; &nbsp; &nbsp; WHEN 'NT AUTHORITY\SYSTEM' THEN CASE &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ES.program_name LIKE 'SQLAgent%' THEN 'SQLAgent' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE ES.program_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; ELSE ES.login_name <br />
&nbsp; &nbsp; END AS Login <br />
&nbsp; &nbsp; , CAST(ER.percent_complete AS NUMERIC(5,2)) AS [%] <br />
&nbsp; &nbsp; , DB_NAME(ER.database_id) AS DB <br />
&nbsp; &nbsp; , UPPER(ER.status) AS Status <br />
&nbsp; &nbsp; , CASE LEN(CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 3600 AS VARCHAR(4))) <br />
&nbsp; &nbsp; &nbsp; WHEN 1 THEN '0' + CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 3600 AS VARCHAR(4)) <br />
&nbsp; &nbsp; &nbsp; ELSE CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 3600 AS VARCHAR(4)) <br />
&nbsp; &nbsp; END + ':' + <br />
&nbsp; &nbsp; CASE LEN(CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 60 % 60 AS VARCHAR(2))) <br />
&nbsp; &nbsp; &nbsp; WHEN 1 THEN '0' + CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 60 % 60 AS VARCHAR(2)) <br />
&nbsp; &nbsp; &nbsp; ELSE CAST(DATEDIFF(second, ER.start_time, GETDATE()) / 60 % 60 AS VARCHAR(2)) <br />
&nbsp; &nbsp; END + ':' + &nbsp;<br />
&nbsp; &nbsp; CASE LEN(CAST(DATEDIFF(second, ER.start_time, GETDATE()) % 60 AS VARCHAR(2))) <br />
&nbsp; &nbsp; &nbsp; WHEN 1 THEN '0' + CAST(DATEDIFF(second, ER.start_time, GETDATE()) % 60 AS VARCHAR(2)) <br />
&nbsp; &nbsp; &nbsp; ELSE CAST(DATEDIFF(second, ER.start_time, GETDATE()) % 60 AS VARCHAR(2)) <br />
&nbsp; &nbsp; END AS Launched <br />
&nbsp; &nbsp; , ER.cpu_time / 1000 AS CPU <br />
&nbsp; &nbsp; , ER.reads AS Reads <br />
&nbsp; &nbsp; , ER.writes AS Writes <br />
&nbsp; &nbsp; , UPPER(ER.command) AS Command <br />
&nbsp; &nbsp; , ER.open_transaction_count NbTran <br />
&nbsp; &nbsp; , ER.open_resultset_count AS NbRsltSet <br />
&nbsp; &nbsp; , ER.wait_type <br />
&nbsp; &nbsp; , ER.wait_time <br />
&nbsp; &nbsp; , ER.last_wait_type <br />
&nbsp; &nbsp; , ER.wait_resource <br />
&nbsp; &nbsp; , CASE <br />
&nbsp; &nbsp; &nbsp; WHEN ES.program_name LIKE 'SQLAgent - TSQL JobStep%' THEN 'Job : ' + J.name <br />
&nbsp; &nbsp; &nbsp; WHEN ES.program_name LIKE 'Microsoft SQL Server Management Studio%' THEN 'SQL Qry' <br />
&nbsp; &nbsp; &nbsp; ELSE ES.program_name <br />
&nbsp; &nbsp; END AS Program <br />
&nbsp; &nbsp; , SUBSTRING( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ESQLT.text, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ER.statement_start_offset / 2 + 1, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CASE <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ER.statement_end_offset = - 1 THEN LEN(CAST(ESQLT.text AS nvarchar(max))) * 2 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE ER.statement_end_offset &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END - ER.statement_start_offset <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) / 2 <br />
&nbsp; &nbsp; ) AS StatementInBatch <br />
&nbsp; &nbsp; , ESQLT.text AS Batch <br />
&nbsp; &nbsp; , QP.query_plan <br />
&nbsp; &nbsp; , ER.query_hash &nbsp;<br />
&nbsp; &nbsp; , ER.query_plan_hash <br />
&nbsp; &nbsp; , QS.execution_count <br />
&nbsp; &nbsp; , QS.creation_time <br />
&nbsp; &nbsp; , EC.client_net_address AS IP <br />
FROM &nbsp; &nbsp;sys.dm_exec_sessions ES (nolock) <br />
INNER JOIN &nbsp;sys.dm_exec_connections (nolock) EC &nbsp;<br />
&nbsp; &nbsp; &nbsp; ON ES.session_id = EC.session_id <br />
INNER JOIN &nbsp;sys.dm_exec_requests ER (nolock) <br />
&nbsp; &nbsp; &nbsp; ON ES.session_id = ER.session_id <br />
INNER JOIN &nbsp;CTE_THREADS AS CT <br />
&nbsp; &nbsp; &nbsp; ON ES.session_id = CT.session_id <br />
LEFT JOIN &nbsp;msdb.dbo.sysjobs J (nolock) <br />
&nbsp; &nbsp; &nbsp; ON REPLACE(SUBSTRING(CAST(J.job_id AS CHAR(36)), CHARINDEX('-', J.job_id, 18) + 1, LEN(J.job_id)), '-', '') = <br />
&nbsp; &nbsp; &nbsp; &nbsp; RIGHT(LEFT(REPLACE(ES.program_name, 'SQLAgent - TSQL JobStep (Job 0x', ''), 32), 16) <br />
CROSS APPLY &nbsp;sys.dm_exec_sql_text(ER.sql_handle) ESQLT <br />
OUTER APPLY &nbsp;sys.dm_exec_query_plan (ER.plan_handle) AS QP <br />
LEFT JOIN &nbsp;sys.dm_exec_query_stats AS QS <br />
&nbsp; &nbsp; &nbsp; ON ER.plan_handle = QS.plan_handle <br />
WHERE &nbsp; &nbsp;ES.session_id &lt;&gt; @@SPID <br />
AND &nbsp; &nbsp;(J.name IS NULL OR J.name NOT LIKE 'cdc.%') <br />
ORDER BY &nbsp;ES.session_id</div></td></tr></tbody></table></div>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Une macro Excel pour dépouiller les statistiques IO</title>
		<link>https://blog.developpez.com/elsuket/p9942/moteur-de-base-de-donnees-sql-server/macro_excel_pour_depouiller_les_stat</link>
		<comments>https://blog.developpez.com/elsuket/p9942/moteur-de-base-de-donnees-sql-server/macro_excel_pour_depouiller_les_stat#comments</comments>
		<pubDate>Wed, 04 May 2011 07:05:25 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[L&#8217;option de session SET STATISTICS IO ON permet de révéler la quantité d&#8217;activité générée sur les disques par une requête. Comme je dépouille assez souvent le résultat qui s&#8217;affiche dans la console de SQL Server Management Studio, j&#8217;en suis venu &#8230; <a href="https://blog.developpez.com/elsuket/p9942/moteur-de-base-de-donnees-sql-server/macro_excel_pour_depouiller_les_stat">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>L&rsquo;option de session SET STATISTICS IO ON permet de révéler la quantité d&rsquo;activité générée sur les disques par une requête.<br />
Comme je dépouille assez souvent le résultat qui s&rsquo;affiche dans la console de SQL Server Management Studio, j&rsquo;en suis venu à écrire une macro qui fait ce travail pour moi en un clin d’œil <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p><span id="more-134"></span></p>
<p>Lorsque j&rsquo;ai trouvé une requête dont je sais que l&rsquo;activité disque est importante, je cherche à savoir pourquoi c&rsquo;est le cas.<br />
Je dois parfois ré-exécuter la requête sur le système pour comprendre ce que fait le moteur de base de données, et analyser quelles sont les tables qui subissent le plus de lectures.</p>
<p>Si l&rsquo;on s&rsquo;en tient à ce que propose SQL Server Management Studio, on obtient :</p>
<p><img src="http://blog.developpez.com/media/stats_io_0.png" width="1188" height="279" alt="" /></p>
<p>Il se peut que la requête contient un grand nombre de tables, et dans ce cas la lecture ce ce résultat peut être longue, surtout si l&rsquo;on fait du tuning à longueur de journée <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /><br />
J&rsquo;ai donc créé la <a href="http://cid-7b2c2e997eda3aa2.office.live.com/self.aspx/.Public/IO%20Stats%20Parser.zip">feuille Excel</a> que vous trouverez compressée.</p>
<p>Il suffit de copier le résultat affiché dans la console dans cette feuille, et d&rsquo;exécuter la macro.<br />
Dans le ruban d&rsquo;Office 2007 ou 2010, après avoir sélectionné <em>View</em>, on peut voir les macros en cliquant sur le bouton du même nom :</p>
<p><img src="http://blog.developpez.com/media/stats_io_1.png" width="1135" height="164" alt="" /></p>
<p>La fenêtre suivante s&rsquo;affiche :</p>
<p><img src="http://blog.developpez.com/media/stats_io_2.png" width="383" height="368" alt="" /></p>
<p>Et il suffit de cliquer sur <em>&laquo;&nbsp;Run&nbsp;&raquo;</em>. Le résultat obtenu pour la même requête est alors :</p>
<p><img src="http://blog.developpez.com/media/stats_io_3.png" width="418" height="450" alt="" /></p>
<p>Bon tuning !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trouver les derniers grossissements automatiques de fichiers</title>
		<link>https://blog.developpez.com/elsuket/p9847/moteur-de-base-de-donnees-sql-server/trouver_les_derniers_grossissements_auto</link>
		<comments>https://blog.developpez.com/elsuket/p9847/moteur-de-base-de-donnees-sql-server/trouver_les_derniers_grossissements_auto#comments</comments>
		<pubDate>Wed, 30 Mar 2011 05:44:12 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[La trace SQL Profiler par défaut permet de retrouver les grossissements automatiques des fichiers de toutes les bases de données hébergées par une instance SQL Server. Voyons comment retrouver ces événements : De nombreux grossissements automatiques des fichiers de la &#8230; <a href="https://blog.developpez.com/elsuket/p9847/moteur-de-base-de-donnees-sql-server/trouver_les_derniers_grossissements_auto">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La trace SQL Profiler par défaut permet de retrouver les grossissements automatiques des fichiers de toutes les bases de données hébergées par une instance SQL Server.</p>
<p>Voyons comment retrouver ces événements :</p>
<p><span id="more-108"></span></p>
<p>De nombreux grossissements automatiques des fichiers de la base de données peuvent indiquer :</p>
<p>&#8211; que les fichiers de la base de données ont été mal taillés lors de la création de la base de données<br />
&#8211; que l&rsquo;incrément choisi pour le grossissement automatique est trop faible (par défaut c&rsquo;est 1MB pour un fichier de données !)<br />
&#8211; que des transactions (comme des recréations d&rsquo;index), ou un changement d&rsquo;un module SQL ou dans l&rsquo;application supportée par la base de données génèrent beaucoup de données, et envisager des corrections.</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 30/03/2011 <br />
------------------------------- <br />
-- Recherche de l'UNC du fichier de trace par défaut <br />
DECLARE &nbsp;@trace_file_path nvarchar(260) &nbsp;<br />
SELECT &nbsp;@trace_file_path = path <br />
FROM &nbsp;sys.traces <br />
WHERE &nbsp;id = 1 -- identifiant de la trace par défaut <br />
&nbsp;<br />
-- Extraction des données <br />
SELECT &nbsp;DatabaseName <br />
&nbsp; , FileName <br />
&nbsp; , HostName <br />
&nbsp; , ApplicationName <br />
&nbsp; , SessionLoginName <br />
&nbsp; , Duration <br />
&nbsp; , StartTime <br />
&nbsp; , EndTime <br />
FROM &nbsp;sys.fn_trace_gettable (@trace_file_path, DEFAULT) <br />
WHERE &nbsp;EventClass IN (92, 93) -- Evénements &quot;Data File Auto Grow&quot; et &quot;Log File Auto Grow&quot; <br />
--AND &nbsp;DatabaseName = DB_NAME() -- Pour retrouver les grossissements automatiques de fichiers pour la base de données courante</div></td></tr></tbody></table></div>
<p>On peut trouver la liste des événements et leur identifiant dans la documentation de la procédure stockée <a href="http://msdn.microsoft.com/fr-fr/library/ms186265.aspx">sp_trace_setevent</a>.</p>
<p>J&rsquo;ai utilisé cette procédure dans le tutoriel <a href="http://elsuket.developpez.com/tutoriels/sqlserveur/fichier-trace-cote-serveur/"><em>Création de fichiers de trace SQL Server Profiler côté serveur</em></a></p>
<p>On pourra <a href="http://blog.developpez.com/elsuket/p8540/moteur-de-base-de-donnees-sql-server/trouver-l-espace-disque-occupe-par-les-f/">trouver l&rsquo;espace disque occupé par les fichiers, et l&rsquo;espace libre dans ceux-ci</a>.</p>
<p>Bonne gestion de fichiers !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Trouver le premier et le dernier jour de la semaine, du mois, du trimestre, et autre calculs</title>
		<link>https://blog.developpez.com/elsuket/p9840/snippets/trouver_le_premier_et_le_dernier_jour_de</link>
		<comments>https://blog.developpez.com/elsuket/p9840/snippets/trouver_le_premier_et_le_dernier_jour_de#comments</comments>
		<pubDate>Tue, 29 Mar 2011 15:04:38 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Beaucoup de participants au forum SQL Server se compliquent la vie avec des calculs bizarres, à trouver le premier ou dernier jour d&#8217;un index temporel, comme celui d&#8217;une semaine, d&#8217;un mois, ou d&#8217;un trimestre. Ces calculs se font souvent à &#8230; <a href="https://blog.developpez.com/elsuket/p9840/snippets/trouver_le_premier_et_le_dernier_jour_de">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Beaucoup de participants au forum SQL Server se compliquent la vie avec des calculs bizarres, à trouver le premier ou dernier jour d&rsquo;un index temporel, comme celui d&rsquo;une semaine, d&rsquo;un mois, ou d&rsquo;un trimestre.</p>
<p>Ces calculs se font souvent à base d&rsquo;extractions de sous-chaînes après avoir converti une date en varchar(n), et on aboutit donc à des choses abominables.</p>
<p>Voici donc une série de calculs de valeurs, uniquement à base de fonctions de date &#8230;<br />
Oui, les dates se manipulent avec des <a href="http://msdn.microsoft.com/fr-fr/library/ms186724.aspx#DateandTimeFunctions">fonctions de date</a>, et non pas avec des <a href="http://msdn.microsoft.com/fr-fr/library/ms181984.aspx">fonctions de chaîne</a> !</p>
<p>J&rsquo;en profite au passage pour rappeler mon billet sur le <a href="http://blog.developpez.com/elsuket/p8233/sql-general/du-choix-des-types-de-donnees/">choix des types de données</a> &#8230;</p>
<p><span id="more-65"></span></p>
<p>La majorité des valeurs calculées ci-dessous repose sur la différence en semaines, mois, trimestres, &#8230;, entre la date courante et le 1er Janvier 1900.<br />
En effet, on peut introduire directement cette date par un zéro dans les fonctions de date, que SQL Server caste automatiquement, et qui donne cette date.</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">------------------------------- </span><br />
<span style="color: #808080; font-style: italic;">-- Nicolas Souquet - 29/03/2011 </span><br />
<span style="color: #808080; font-style: italic;">------------------------------- </span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> &nbsp;<span style="color: #808080; font-style: italic;">--*** Semaine </span><br />
&nbsp; DATEADD<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_de_la_semaine_precedente <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_de_la_semaine_courante <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_de_la_semaine_prochaine <br />
&nbsp; <span style="color: #808080; font-style: italic;">--- </span><br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_de_la_semaine_precedente <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_de_la_semaine_courante <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>week<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_de_la_semaine_prochaine <br />
&nbsp; <span style="color: #808080; font-style: italic;">--*** Mois </span><br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_du_mois_precedent <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_du_mois_courant &nbsp;<br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_du_mois_prochain <br />
&nbsp; <span style="color: #808080; font-style: italic;">--- </span><br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_du_mois_precedent <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_du_mois_courant &nbsp;<br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_du_mois_prochain <br />
&nbsp; <span style="color: #808080; font-style: italic;">--*** Trimestre </span><br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_du_trimestre_precedent <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> permier_jour_du_trimestre_courant <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_du_trimestre_prochain <br />
&nbsp; <span style="color: #808080; font-style: italic;">--- </span><br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_du_trimestre_precedent <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_du_trimestre_courant <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_du_trimestre_prochain <br />
&nbsp; <span style="color: #808080; font-style: italic;">--*** Semestre </span><br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_du_semestre_precedent <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_du_semestre_courant <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_du_semestre_prochain <br />
&nbsp; <span style="color: #808080; font-style: italic;">--- </span><br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_du_semestre_precedent <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_du_semestre_courant <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span>quarter<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">12</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_du_semestre_prochain <br />
&nbsp; <span style="color: #808080; font-style: italic;">--*** Annee </span><br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span> <span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_annee_precedente <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span> <span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_annee_courante <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span> <span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_annee_suivante <br />
&nbsp; <span style="color: #808080; font-style: italic;">--- </span><br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span> <span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_annee_precedente <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span> <span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_annee_courante <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span> <span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_annee_suivante <br />
&nbsp; <span style="color: #808080; font-style: italic;">--*** Siècle </span><br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">&#40;</span>GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> % <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span> <span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> premier_jour_du_siecle_courant <br />
&nbsp; <span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">&#40;</span>GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> % <span style="color: #cc66cc;">100</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span> <span style="color: #66cc66;">,</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dernier_jour_du_siecle_courant</div></td></tr></tbody></table></div>
<p>J&rsquo;ai eu un peu la flemme sur le siècle, et j&rsquo;ai trouvé comme prétexte pour m&rsquo;arrêter que cela ne doit pas présenter grand intérêt <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p>Bon calculs sur les dates !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Générer le script de mise à jour des types de données de colonnes dont le type est déprécié</title>
		<link>https://blog.developpez.com/elsuket/p9824/moteur-de-base-de-donnees-sql-server/generer_le_scrirpt_de_mise_a_jour_des_ty</link>
		<comments>https://blog.developpez.com/elsuket/p9824/moteur-de-base-de-donnees-sql-server/generer_le_scrirpt_de_mise_a_jour_des_ty#comments</comments>
		<pubDate>Mon, 21 Mar 2011 12:26:36 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici plusieurs scripts qui permettent d&#8217;automatiser le changement de types de données dépréciés text, ntext et image depuis SQL Server 2005, qui les a respectivement remplacés par varchar(max), nvarchar(max), et varbinary(max), et a rendu les valeurs stockées sous de tels &#8230; <a href="https://blog.developpez.com/elsuket/p9824/moteur-de-base-de-donnees-sql-server/generer_le_scrirpt_de_mise_a_jour_des_ty">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici plusieurs scripts qui permettent d&rsquo;automatiser le changement de types de données dépréciés <em>text</em>, <em>ntext</em> et <em>image</em> depuis SQL Server 2005, qui les a respectivement remplacés par varchar(max), nvarchar(max), et varbinary(max), et a rendu les valeurs stockées sous de tels types bien plus malléables (utilisations de fonctions de chaîne notamment)<br />
<span id="more-94"></span></p>
<p>Si vous n&rsquo;avez qu&rsquo;un petit nombre de colonnes dont le type est déprécié, et/ou que toutes vos bases de données sont toute a la même version (si on a plusieurs clients par exemple, ce n&rsquo;est pas toujours le cas), il suffit d&rsquo;exécuter :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------ <br />
-- Nicolas Souquet - 21-03-2011 <br />
------------------------------- <br />
SET NOCOUNT ON <br />
GO <br />
&nbsp;<br />
DECLARE @sql varchar(max) <br />
&nbsp; , @cr char(2) = CHAR(13) + CHAR(10) <br />
&nbsp; , @tab char(1) = CHAR(9) <br />
&nbsp;<br />
SELECT &nbsp; &nbsp;@sql = CASE <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHEN @sql IS NULL THEN '-- Number of rows for ' + T.name + ' : ' + CAST(PS.row_count AS varchar(19)) + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 'ALTER TABLE ' + T.name + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 'ALTER COLUMN ' + C.name + ' ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CASE TY.name <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'text' THEN 'varchar(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'ntext' THEN 'nvarchar(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'image' THEN 'varbinary(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CASE C.is_nullable <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 1 THEN ' NULL' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 0 THEN ' NOT NULL' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; &nbsp; ELSE @sql + @cr + '-- Number of rows for ' + T.name + ' : ' + CAST(PS.row_count AS varchar(19)) + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 'ALTER TABLE ' + T.name + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 'ALTER COLUMN ' + C.name + ' ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CASE TY.name <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'text' THEN 'varchar(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'ntext' THEN 'nvarchar(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'image' THEN 'varbinary(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CASE C.is_nullable <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 1 THEN ' NULL' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 0 THEN ' NOT NULL' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; &nbsp; END + @cr + 'GO' + @cr <br />
FROM &nbsp; &nbsp;sys.schemas AS S <br />
INNER JOIN &nbsp;sys.tables AS T <br />
&nbsp; &nbsp; &nbsp; ON S.schema_id = T.schema_id <br />
INNER JOIN &nbsp;sys.dm_db_partition_stats AS PS <br />
&nbsp; &nbsp; &nbsp; ON PS.object_id = T.object_id <br />
INNER JOIN &nbsp;sys.columns AS C &nbsp;<br />
&nbsp; &nbsp; &nbsp; ON C.object_id = T.object_id <br />
INNER JOIN &nbsp;sys.types AS TY <br />
&nbsp; &nbsp; &nbsp; ON TY.system_type_id = C.system_type_id <br />
&nbsp; &nbsp; &nbsp; AND TY.system_type_id = TY.user_type_id <br />
WHERE &nbsp; &nbsp;S.name = 'dbo' <br />
AND &nbsp; &nbsp;TY.name IN ('image', 'text', 'ntext') <br />
AND &nbsp; &nbsp;PS.index_id IN (0, 1) -- Heap or Clustered index <br />
ORDER BY &nbsp;T.name, C.column_id <br />
&nbsp;<br />
PRINT &nbsp;@sql</div></td></tr></tbody></table></div>
<p>Comme PRINT est limité à afficher seulement les 8000 premiers caractères d&rsquo;une chaîne, il se peut que le script que vous obtenez soit incomplet.<br />
Dans ce cas une boucle devient nécessaire, pour n&rsquo;afficher qu&rsquo;une instruction par colonne dont le type est à changer :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------ <br />
-- Nicolas Souquet - 21-03-2011 <br />
------------------------------- <br />
DECLARE @tables_with_deprecated_type TABLE <br />
( <br />
&nbsp; table_name sysname <br />
&nbsp; , column_name sysname <br />
&nbsp; , column_data_type_name sysname <br />
&nbsp; , is_column_nullable bit <br />
&nbsp; , table_row_count bigint <br />
) <br />
&nbsp;<br />
INSERT &nbsp; &nbsp;@tables_with_deprecated_type <br />
SELECT &nbsp; &nbsp;T.name <br />
&nbsp; &nbsp; , C.name <br />
&nbsp; &nbsp; , TY.name <br />
&nbsp; &nbsp; , C.is_nullable <br />
&nbsp; &nbsp; , PS.row_count <br />
FROM &nbsp; &nbsp;sys.schemas AS S <br />
INNER JOIN &nbsp;sys.tables AS T <br />
&nbsp; &nbsp; &nbsp; ON S.schema_id = T.schema_id <br />
INNER JOIN &nbsp;sys.dm_db_partition_stats AS PS <br />
&nbsp; &nbsp; &nbsp; ON PS.object_id = T.object_id <br />
INNER JOIN &nbsp;sys.columns AS C &nbsp;<br />
&nbsp; &nbsp; &nbsp; ON C.object_id = T.object_id <br />
INNER JOIN &nbsp;sys.types AS TY <br />
&nbsp; &nbsp; &nbsp; ON TY.system_type_id = C.system_type_id <br />
&nbsp; &nbsp; &nbsp; AND TY.system_type_id = TY.user_type_id <br />
WHERE &nbsp; &nbsp;S.name = 'dbo' <br />
AND &nbsp; &nbsp;TY.name IN ('image', 'text', 'ntext') <br />
AND &nbsp; &nbsp;PS.index_id IN (0, 1) -- Heap or Clustered index <br />
ORDER BY &nbsp;T.name, C.column_id <br />
&nbsp;<br />
DECLARE &nbsp;@table_name sysname <br />
&nbsp; , @column_name sysname <br />
&nbsp; , @column_data_type_name sysname <br />
&nbsp; , @is_column_nullable bit <br />
&nbsp; , @table_row_count bigint <br />
&nbsp; --- <br />
&nbsp; , @sql varchar(max) <br />
&nbsp; , @cr char(2) = CHAR(13) + CHAR(10) <br />
&nbsp; , @tab char(1) = CHAR(9) <br />
&nbsp;<br />
WHILE EXISTS <br />
( <br />
&nbsp; SELECT &nbsp;* <br />
&nbsp; FROM &nbsp;@tables_with_deprecated_type <br />
) <br />
BEGIN <br />
&nbsp; SELECT &nbsp;TOP (1) @table_name = table_name <br />
&nbsp; &nbsp; , @column_name = column_name <br />
&nbsp; &nbsp; , @column_data_type_name = column_data_type_name <br />
&nbsp; &nbsp; , @is_column_nullable = is_column_nullable <br />
&nbsp; &nbsp; , @table_row_count = table_row_count <br />
&nbsp; FROM &nbsp;@tables_with_deprecated_type <br />
&nbsp; <br />
&nbsp; SET &nbsp;@sql = '-- Number of rows for ' + @table_name + ' : ' + CAST(@table_row_count AS varchar(20)) + @cr <br />
&nbsp; &nbsp; + 'ALTER TABLE ' + @table_name + @cr <br />
&nbsp; &nbsp; + 'ALTER COLUMN ' + @column_name + ' ' <br />
&nbsp; &nbsp; + CASE @column_data_type_name <br />
&nbsp; &nbsp; &nbsp; WHEN 'text' THEN 'varchar(max)' <br />
&nbsp; &nbsp; &nbsp; WHEN 'ntext' THEN 'nvarchar(max)' <br />
&nbsp; &nbsp; &nbsp; WHEN 'image' THEN 'varbinary(max)' <br />
&nbsp; &nbsp; END <br />
&nbsp; &nbsp; + CASE @is_column_nullable <br />
&nbsp; &nbsp; &nbsp; WHEN 1 THEN ' NULL' <br />
&nbsp; &nbsp; &nbsp; WHEN 0 THEN ' NOT NULL' <br />
&nbsp; &nbsp; END + @cr + 'GO' + @cr <br />
&nbsp; &nbsp; <br />
&nbsp; PRINT &nbsp;@sql <br />
&nbsp; <br />
&nbsp; DELETE &nbsp;TOP (1) @tables_with_deprecated_type <br />
END</div></td></tr></tbody></table></div>
<p>Si en revanche on cherche à créer un tel script pour des bases de données dont le schéma est à des stades d&rsquo;évolutions différents (par exemple si l&rsquo;on a des clients qui n&rsquo;utilisent pas tous la même version de l&rsquo;application, et donc de la base de données), on peut alors tester l&rsquo;existence de la colonne et de son type déprécié.<br />
Cela permet d&rsquo;utiliser le script généré sans ce soucier de l&rsquo;existence ou non de la colonne, et/ou de son type.</p>
<p>Comme précédemment, si l&rsquo;on a un petit nombre de colonnes, le script suivant fonctionne (le but étant de ne pas dépasser la limite des 8000 caractères retournés par PRINT, comme décrit plus haut) :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------ <br />
-- Nicolas Souquet - 21-03-2011 <br />
------------------------------- <br />
DECLARE @sql varchar(max) <br />
&nbsp; , @cr char(2) = CHAR(13) + CHAR(10) <br />
&nbsp; , @tab char(1) = CHAR(9) <br />
&nbsp;<br />
SELECT &nbsp; &nbsp;@sql = CASE <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHEN @sql IS NULL THEN '-- Number of rows for ' + T.name + ' : ' + CAST(PS.row_count AS varchar(50)) + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 'IF EXISTS' + @cr + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + '(' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'SELECT' + @tab + @tab + '*' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'FROM' + @tab + @tab + 'sys.tables AS T' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'INNER JOIN' + @tab + 'sys.columns AS C ON T.object_id = C.object_id' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'INNER JOIN' + @tab + 'sys.types AS TY ON TY.system_type_id = C.system_type_id' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'WHERE' + @tab + @tab + 'T.name = ''' + T.name + '''' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'AND' + @tab + @tab + 'C.name = ''' + C.name + '''' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'AND' + @tab + @tab + 'TY.name = ''' + TY.name + '''' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + ')' + @cr + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'ALTER TABLE ' + T.name + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 'ALTER COLUMN ' + C.name + ' ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CASE TY.name <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'text' THEN 'varchar(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'ntext' THEN 'nvarchar(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'image' THEN 'varbinary(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CASE C.is_nullable <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 1 THEN ' NULL' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 0 THEN ' NOT NULL' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; &nbsp; ELSE @sql + @cr + '-- Number of rows for ' + T.name + ' : ' + CAST(PS.row_count AS varchar(50)) + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 'IF EXISTS' + @cr + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + '(' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'SELECT' + @tab + @tab + '*' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'FROM' + @tab + @tab + 'sys.tables AS T' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'INNER JOIN' + @tab + 'sys.columns AS C ON T.object_id = C.object_id' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'INNER JOIN' + @tab + 'sys.types AS TY ON TY.system_type_id = C.system_type_id' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'WHERE' + @tab + @tab + 'T.name = ''' + T.name + '''' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'AND' + @tab + @tab + 'C.name = ''' + C.name + '''' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + @tab + 'AND' + @tab + @tab + 'TY.name = ''' + TY.name + '''' + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + ')' + @cr + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'ALTER TABLE ' + T.name + @cr <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + 'ALTER COLUMN ' + C.name + ' ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CASE TY.name <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'text' THEN 'varchar(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'ntext' THEN 'nvarchar(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 'image' THEN 'varbinary(max)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CASE C.is_nullable <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 1 THEN ' NULL' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 0 THEN ' NOT NULL' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; &nbsp; END + @cr + 'GO' + @cr + @cr <br />
FROM &nbsp; &nbsp;sys.schemas AS S <br />
INNER JOIN &nbsp;sys.tables AS T <br />
&nbsp; &nbsp; &nbsp; ON S.schema_id = T.schema_id <br />
INNER JOIN &nbsp;sys.dm_db_partition_stats AS PS <br />
&nbsp; &nbsp; &nbsp; ON PS.object_id = T.object_id <br />
INNER JOIN &nbsp;sys.columns AS C &nbsp;<br />
&nbsp; &nbsp; &nbsp; ON C.object_id = T.object_id <br />
INNER JOIN &nbsp;sys.types AS TY <br />
&nbsp; &nbsp; &nbsp; ON TY.system_type_id = C.system_type_id <br />
&nbsp; &nbsp; &nbsp; AND TY.system_type_id = TY.user_type_id <br />
WHERE &nbsp; &nbsp;1 = 1 <br />
AND &nbsp; &nbsp;S.name = 'dbo' <br />
AND &nbsp; &nbsp;TY.name IN ('image', 'text', 'ntext') <br />
ORDER BY &nbsp;T.name, C.column_id <br />
GO</div></td></tr></tbody></table></div>
<p>Dans le cas contraire, on peut recourir, de façon similaire, à une boucle :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------ <br />
-- Nicolas Souquet - 21-03-2011 <br />
------------------------------- <br />
SET NOCOUNT ON <br />
GO <br />
&nbsp;<br />
DECLARE @tables_with_deprecated_type TABLE <br />
( <br />
&nbsp; table_name sysname <br />
&nbsp; , column_name sysname <br />
&nbsp; , column_data_type_name sysname <br />
&nbsp; , is_column_nullable bit <br />
&nbsp; , table_row_count bigint <br />
) <br />
&nbsp;<br />
INSERT &nbsp; &nbsp;@tables_with_deprecated_type <br />
SELECT &nbsp; &nbsp;T.name <br />
&nbsp; &nbsp; , C.name <br />
&nbsp; &nbsp; , TY.name <br />
&nbsp; &nbsp; , C.is_nullable <br />
&nbsp; &nbsp; , PS.row_count <br />
FROM &nbsp; &nbsp;sys.schemas AS S <br />
INNER JOIN &nbsp;sys.tables AS T <br />
&nbsp; &nbsp; &nbsp; ON S.schema_id = T.schema_id <br />
INNER JOIN &nbsp;sys.dm_db_partition_stats AS PS <br />
&nbsp; &nbsp; &nbsp; ON PS.object_id = T.object_id <br />
INNER JOIN &nbsp;sys.columns AS C &nbsp;<br />
&nbsp; &nbsp; &nbsp; ON C.object_id = T.object_id <br />
INNER JOIN &nbsp;sys.types AS TY <br />
&nbsp; &nbsp; &nbsp; ON TY.system_type_id = C.system_type_id <br />
&nbsp; &nbsp; &nbsp; AND TY.system_type_id = TY.user_type_id <br />
WHERE &nbsp; &nbsp;1 = 1 <br />
AND &nbsp; &nbsp;S.name = 'dbo' <br />
AND &nbsp; &nbsp;TY.name IN ('image', 'text', 'ntext') <br />
AND &nbsp; &nbsp;PS.index_id IN (0, 1) -- Heap or Clustered index <br />
ORDER BY &nbsp;T.name, C.column_id <br />
&nbsp;<br />
DECLARE &nbsp;@table_name sysname <br />
&nbsp; , @column_name sysname <br />
&nbsp; , @column_data_type_name sysname <br />
&nbsp; , @is_column_nullable bit <br />
&nbsp; , @table_row_count bigint <br />
&nbsp; --- <br />
&nbsp; , @sql varchar(max) <br />
&nbsp; , @cr char(2) = CHAR(13) + CHAR(10) <br />
&nbsp; , @tab char(1) = CHAR(9) <br />
&nbsp;<br />
WHILE EXISTS <br />
( <br />
&nbsp; SELECT &nbsp;* <br />
&nbsp; FROM &nbsp;@tables_with_deprecated_type <br />
) <br />
BEGIN <br />
&nbsp; SELECT &nbsp;TOP (1) @table_name = table_name <br />
&nbsp; &nbsp; , @column_name = column_name <br />
&nbsp; &nbsp; , @column_data_type_name = column_data_type_name <br />
&nbsp; &nbsp; , @is_column_nullable = is_column_nullable <br />
&nbsp; &nbsp; , @table_row_count = table_row_count <br />
&nbsp; FROM &nbsp;@tables_with_deprecated_type <br />
&nbsp; <br />
&nbsp; SET &nbsp;@sql = '-- Number of rows for ' + @table_name + ' : ' + CAST(@table_row_count AS varchar(20)) + @cr <br />
&nbsp; &nbsp; + 'IF EXISTS' + @cr + <br />
&nbsp; &nbsp; + '(' + @cr <br />
&nbsp; &nbsp; + @tab + 'SELECT' + @tab + @tab + '*' + @cr <br />
&nbsp; &nbsp; + @tab + 'FROM' + @tab + @tab + 'sys.tables AS T' + @cr <br />
&nbsp; &nbsp; + @tab + 'INNER JOIN' + @tab + 'sys.columns AS C ON T.object_id = C.object_id' + @cr <br />
&nbsp; &nbsp; + @tab + 'INNER JOIN' + @tab + 'sys.types AS TY ON TY.system_type_id = C.system_type_id' + @cr <br />
&nbsp; &nbsp; + @tab + 'WHERE' + @tab + @tab + 'T.name = ''' +@table_name + '''' + @cr <br />
&nbsp; &nbsp; + @tab + 'AND' + @tab + @tab + 'C.name = ''' + @column_name + '''' + @cr <br />
&nbsp; &nbsp; + @tab + 'AND' + @tab + @tab + 'TY.name = ''' + @column_data_type_name + '''' + @cr <br />
&nbsp; &nbsp; + ')' + @cr + <br />
&nbsp; &nbsp; 'ALTER TABLE ' + @table_name + @cr <br />
&nbsp; &nbsp; + 'ALTER COLUMN ' + @column_name + ' ' <br />
&nbsp; &nbsp; + CASE @column_data_type_name <br />
&nbsp; &nbsp; &nbsp; WHEN 'text' THEN 'varchar(max)' <br />
&nbsp; &nbsp; &nbsp; WHEN 'ntext' THEN 'nvarchar(max)' <br />
&nbsp; &nbsp; &nbsp; WHEN 'image' THEN 'varbinary(max)' <br />
&nbsp; &nbsp; END <br />
&nbsp; &nbsp; + CASE @is_column_nullable <br />
&nbsp; &nbsp; &nbsp; WHEN 1 THEN ' NULL' <br />
&nbsp; &nbsp; &nbsp; WHEN 0 THEN ' NOT NULL' <br />
&nbsp; &nbsp; END + @cr + 'GO' + @cr <br />
&nbsp; &nbsp; <br />
&nbsp; PRINT &nbsp;@sql <br />
&nbsp; <br />
&nbsp; DELETE &nbsp;TOP (1) @tables_with_deprecated_type <br />
END <br />
GO</div></td></tr></tbody></table></div>
<p>Le nombre de lignes de la table est imprimé dans tous les cas, et pour les tables volumineuses, on exécutera la changement de type avec précaution !</p>
<p>Bonne mise à jour !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Retrouver le dossier par défaut des sauvegardes des bases de données sous SQL Server 2005 et suivants</title>
		<link>https://blog.developpez.com/elsuket/p9782/moteur-de-base-de-donnees-sql-server/retrouver_le_dossier_par_defaut_des_sauv</link>
		<comments>https://blog.developpez.com/elsuket/p9782/moteur-de-base-de-donnees-sql-server/retrouver_le_dossier_par_defaut_des_sauv#comments</comments>
		<pubDate>Wed, 02 Mar 2011 16:24:39 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voyons comment retrouver le dossier dans lequel sont stockés par défaut les sauvegardes de vos bases de données de deux façons : &#8211; Avec SQL Server Management Studio &#8211; Avec procédure stockée étendue non documentée xp_instance_regread En effet avec SQL &#8230; <a href="https://blog.developpez.com/elsuket/p9782/moteur-de-base-de-donnees-sql-server/retrouver_le_dossier_par_defaut_des_sauv">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voyons comment retrouver le dossier dans lequel sont stockés par défaut les sauvegardes de vos bases de données de deux façons :</p>
<p>&#8211; Avec <em>SQL Server Management Studio</em><br />
&#8211; Avec procédure stockée étendue non documentée <em>xp_instance_regread</em><br />
<span id="more-132"></span></p>
<p>En effet avec <em>SQL Server Management Studio</em>, on peut bien retrouver où seront, par défaut, stockés les fichiers de la base de données, mais pas leurs sauvegardes :</p>
<p>Si nous regardons dans les <em>Propriétés</em>/<em>Properties</em> de l&rsquo;instance :</p>
<p><img src="http://blog.developpez.com/media/backup_default_directory_1.jpg" width="334" height="583" alt="" /></p>
<p>en ouvrant la page &laquo;&nbsp;Database Settings&nbsp;&raquo;/&nbsp;&raquo;Options&nbsp;&raquo;, nous obtenons :</p>
<p><img src="http://blog.developpez.com/media/backup_default_directory_20_01.png" width="922" height="632" alt="" /></p>
<p>C&rsquo;est en fait dans ce dossier que les fichiers de sauvegarde seront stockés par défaut.<br />
Un petit manque de précision de Microsoft !</p>
<p>Le chemin du dossier est également stocké dans la base de registres, sous la clé suivante :</p>
<p><em>HKEY_LOCAL_MACHINE\Software\Microsoft\MSSQLServer\MSSQLServer</em> pour la valeur <em>BackupDirectory</em>.</p>
<p>On peut donc s&rsquo;amuser à la rechercher à l&rsquo;aide du bien connu <em>Regedit</em>, mais on peut aussi l&rsquo;obtenir à l&rsquo;aide d&rsquo;une procédure étendue système non documentée qui permet de lire les valeurs stockées dans la base de registres : <em>xp_instance_regread</em></p>
<p><font face="Courier New" size="2"><br />
<font color = "blue">EXEC</font> <font color = "black">master.dbo.xp_instance_regread</font><br />
    <font color = "red">N&rsquo;HKEY_LOCAL_MACHINE&rsquo;</font><font color = "silver">,</font><br />
    <font color = "red">N&rsquo;Software\Microsoft\MSSQLServer\MSSQLServer&rsquo;</font><font color = "silver">,</font><br />
    <font color = "red">N&rsquo;BackupDirectory&rsquo;</font><br />
</font></p>
<p>Nous retourne également :</p>
<p><img src="http://blog.developpez.com/media/backup_default_directory_3.jpg" width="266" height="67" alt="" /></p>
<p>En effet si vous exécutons l&rsquo;instruction suivante :</p>
<p><font face="Courier New" size="2"><br />
<font color = "blue">BACKUP</font> <font color = "blue">DATABASE</font> <font color = "maroon">ELSUKET</font> <font color = "blue"><br />TO</font> <font color = "maroon">DISK</font> <font color = "silver">=</font> <font color = "red">&lsquo;ELSUKET.bak&rsquo;</font> </font>*</p>
<p>Et que nous explorons le système de gestion de fichiers :</p>
<p><img src="http://blog.developpez.com/media/backup_default_directory_4.jpg" width="546" height="309" alt="" /></p>
<p>Malheureusement pour changer de dossier, nous n&rsquo;avons que les deux solutions suivantes :</p>
<p>&#8211; Spécifier dans l&rsquo;instruction BACKUP, le chemin complet du dossier qui recevra les fichiers de sauvegardes de bases de données<br />
&#8211; Modifier la valeur de la clé de registre citée plus haut</p>
<p>Bonnes sauvegardes !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Utiliser le séparateur &#171;&#160;pipe&#160;&#187; avec l&#8217;utilitaire BCP</title>
		<link>https://blog.developpez.com/elsuket/p9598/utilitaires/utiliser_le_separateur_pipe_avec_l_utili</link>
		<comments>https://blog.developpez.com/elsuket/p9598/utilitaires/utiliser_le_separateur_pipe_avec_l_utili#comments</comments>
		<pubDate>Wed, 22 Dec 2010 11:23:00 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Si l&#8217;on tente d&#8217;exécuter l&#8217;instruction suivante : bcp &#171;&#160;SELECT query_plan FROM ELSUKET.dbo.unTable&#160;&#187; queryout &#171;&#160;C:\toto.txt&#160;&#187; -c -t&#124; -T -S ELSUKET dans une fenêtre d&#8217;invite de commandes ou bien à l&#8217;aide de la procédure stockée xp_cmdshell, nous obtenons l&#8217;erreur : &#8216;-T&#8217; is &#8230; <a href="https://blog.developpez.com/elsuket/p9598/utilitaires/utiliser_le_separateur_pipe_avec_l_utili">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Si l&rsquo;on tente d&rsquo;exécuter l&rsquo;instruction suivante :</p>
<p><font face="Courier New" size="2">bcp &laquo;&nbsp;SELECT query_plan FROM ELSUKET.dbo.unTable&nbsp;&raquo; queryout &laquo;&nbsp;C:\toto.txt&nbsp;&raquo; -c -t| -T -S ELSUKET</font></p>
<p>dans une fenêtre d&rsquo;invite de commandes ou bien à l&rsquo;aide de la procédure stockée xp_cmdshell, nous obtenons l&rsquo;erreur :</p>
<p><font face="Courier New" size="2">&lsquo;-T&rsquo; is not recognized as an internal or external command, operable program or batch file.</font></p>
<p>Comment faire pour éviter cela ? C&rsquo;est très simple :<span id="more-131"></span></p>
<p>Il suffit en fait de précéder le pipe par un accent circonflexe, ce qui dans notre cas donnerait la commande :</p>
<p><font face="Courier New" size="2">BCP &laquo;&nbsp;SELECT query_plan FROM ELSUKET.dbo.unTable&nbsp;&raquo; queryout &laquo;&nbsp;C:\toto.txt&nbsp;&raquo; -c -t<strong>^</strong>| -T -S ELSUKET</font></p>
<p>Le résultat ne se fait pas attendre :</p>
<p><font face="Courier New" size="2">Starting copy&#8230;</p>
<p>27 rows copied.<br />
Network packet size (bytes): 4096<br />
Clock Time (ms.) Total     : 172    Average : (156.98 rows per sec.)</font></p>
<p>Bon BCP !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Obtenir la liste des deadlocks rétrospectivement</title>
		<link>https://blog.developpez.com/elsuket/p9234/moteur-de-base-de-donnees-sql-server/obtenir_la_liste_des_deadlocks_retrospec</link>
		<comments>https://blog.developpez.com/elsuket/p9234/moteur-de-base-de-donnees-sql-server/obtenir_la_liste_des_deadlocks_retrospec#comments</comments>
		<pubDate>Wed, 25 Aug 2010 13:20:43 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une requête qui permet de retrouver la liste des deadlocks qui ont eu lieu dans une instance SQL Server. Elle se base sur la session d&#8217;événements étendus par défaut de SQL Server 2008&#8230; Les événements étendus sont une nouvelle &#8230; <a href="https://blog.developpez.com/elsuket/p9234/moteur-de-base-de-donnees-sql-server/obtenir_la_liste_des_deadlocks_retrospec">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une requête qui permet de retrouver la liste des deadlocks qui ont eu lieu dans une instance SQL Server.<br />
Elle se base sur la session d&rsquo;événements étendus par défaut de SQL Server 2008&#8230;<br />
<span id="more-103"></span></p>
<p>Les événements étendus sont une nouvelle fonctionnalité introduite avec SQL Server, qui permet de tracer des événements suivant les paramètres de la session.<br />
Les données peuvent ensuite être dépouillées à l&rsquo;aide des données exposées de façon structurée sous la forme de documents XML.</p>
<p>Mais il en existe une, démarrée par défaut, qui trace certains événements assez sévères, et qui permet en outre de retrouver les deadlocks et les requêtes qui y ont participé de façon rétrospective, à l&rsquo;aide de la requête suivante :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">;WITH <br />
&nbsp; -- Récupération des documents XML capturés par la session <br />
&nbsp; xml_event_payload AS <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp; &nbsp;CAST(T.target_data AS xml) AS data <br />
&nbsp; &nbsp; FROM &nbsp; &nbsp;sys.dm_xe_session_targets AS T <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.dm_xe_sessions AS S <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON S.address = T.event_session_address <br />
&nbsp; &nbsp; WHERE &nbsp; &nbsp;S.name = 'system_health' <br />
&nbsp; ), <br />
&nbsp; prepare AS -- Extraction des événements de deadlock <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp; &nbsp;ED.event_xml.value('(./data/value)[1]', 'varchar(max)') AS deadlock_data <br />
&nbsp; &nbsp; FROM &nbsp; &nbsp;xml_event_payload AS XEP <br />
&nbsp; &nbsp; CROSS APPLY &nbsp;data.nodes('/RingBufferTarget/event') AS ED (event_xml) <br />
&nbsp; &nbsp; WHERE &nbsp; &nbsp;ED.event_xml.value('./@name', 'varchar(32)') = 'xml_deadlock_report' <br />
&nbsp; ), <br />
&nbsp; well_form_xml_doc AS -- Formation correcte du document XML (mal formé par défaut) <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp;REPLACE(REPLACE(deadlock_data, '&lt;victim-list&gt;', '&lt;deadlock&gt;&lt;victim-list&gt;'), '&lt;process-list&gt;','&lt;/victim-list&gt;&lt;process-list&gt;') AS deadlock_data <br />
&nbsp; &nbsp; FROM &nbsp;prepare <br />
&nbsp; ), <br />
&nbsp; del_victim_list AS -- Formation correcte du document XML (mal formé par défaut) <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp;CAST(STUFF(deadlock_data, PATINDEX('%&lt;victim-list&gt;%', deadlock_data), PATINDEX('%&lt;/victim-list&gt;%', deadlock_data) + 14 - PATINDEX('%&lt;victim-list&gt;%', deadlock_data), '') AS xml) AS deadlock_data <br />
&nbsp; &nbsp; &nbsp; , ROW_NUMBER() OVER(ORDER BY deadlock_data) AS n <br />
&nbsp; &nbsp; FROM &nbsp;well_form_xml_doc <br />
&nbsp; ) &nbsp; &nbsp;<br />
SELECT &nbsp; &nbsp;n <br />
&nbsp; &nbsp; , D.name AS database_name <br />
&nbsp; &nbsp; , DC.deadlock_characteristics.value('./@lasttranstarted', 'datetime') AS occurence_date_time <br />
&nbsp; &nbsp; , DC.deadlock_characteristics.value('(./inputbuf)[1]', 'varchar(max)') AS query <br />
&nbsp; &nbsp; , deadlock_data <br />
FROM &nbsp; &nbsp;del_victim_list <br />
CROSS APPLY &nbsp;deadlock_data.nodes('/deadlock-list/deadlock/process-list/process') AS DC (deadlock_characteristics) <br />
INNER JOIN &nbsp;sys.databases AS D ON D.database_id = DC.deadlock_characteristics.value('./@currentdb', 'int') <br />
WHERE &nbsp; &nbsp;DC.deadlock_characteristics.value('./@lasttranstarted', 'datetime') &gt; '20100823 00:00:00.000' <br />
ORDER BY &nbsp;del_victim_list.n</div></td></tr></tbody></table></div>
<p>Chaque événement capturé par la session consiste en un document XML.<br />
La requête triture les données XML retournées par la session, car ceux-ci sont mal formés pour les deadlocks.</p>
<p>La colonne <strong>n</strong> retourne une numéro arbitraire qui correspond à une occurence de deadlock.<br />
Dès lors toute les requêtes ayant le même numéro ont participé au deadlock.</p>
<p><img src="http://img265.imageshack.us/img265/3803/deadlocksfromxe.png" alt="" title="" /></p>
<p>En cliquant dans la colonne <strong>deadlock_data</strong>, on obtient le document XML généré par l&rsquo;occurence d&rsquo;un deadlock, avec quelques informations en plus, comme le niveau d&rsquo;isolation, le nom de l&rsquo;application et de la transaction, &#8230;</p>
<p>Bon backtrack !</p>
<p>ElSuket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configurer les protocoles de connexion réseau à SQL Server : l&#8217;utilitaire SQL Server Configuration Manager</title>
		<link>https://blog.developpez.com/elsuket/p7723/moteur-de-base-de-donnees-sql-server/configurer_les_protocoles_de_connexion_a</link>
		<comments>https://blog.developpez.com/elsuket/p7723/moteur-de-base-de-donnees-sql-server/configurer_les_protocoles_de_connexion_a#comments</comments>
		<pubDate>Mon, 08 Jun 2009 23:03:43 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[SQL Server 2005 a introduit l&#8217;outil SQL Server Configuration Manager, qui permet de gérer les fonctionnalités des instances SQL Server hébergées par un serveur, mais aussi la configuration du réseau. Ces problèmes sont souvent abordés sur le forum, et sont &#8230; <a href="https://blog.developpez.com/elsuket/p7723/moteur-de-base-de-donnees-sql-server/configurer_les_protocoles_de_connexion_a">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SQL Server 2005 a introduit l&rsquo;outil <em>SQL Server Configuration Manager</em>, qui permet de gérer les fonctionnalités des instances SQL Server hébergées par un serveur, mais aussi la configuration du réseau.<br />
Ces problèmes sont souvent abordés sur le <a href="http://www.developpez.net/forums/f49/bases-donnees/ms-sql-server/">forum</a>, et sont souvent résolus par une description des manipulations à effectuer sous cet utilitaire.</p>
<p>Les voici ici &#8230;</p>
<p><span id="more-127"></span></p>
<p>L&rsquo;outil <em>SQL Server Configuration Manager</em> sert à configurer les instances de SQL Server seulement sur la machine qui le supporte (pas d&rsquo;accès distant possible).<br />
On peut accéder à celui-ci de deux façons :</p>
<p>&#8211; Soit par le menu <em>Démarrer</em>, en choisissant successivement <em>Programmes</em>|<em>Microsoft SQL Server 2008</em>|<em>Outils de configuration</em>|<em>Gestionnaire de configuration SQL Server</em></p>
<p>&#8211; Soit par la commande <em>Exécuter</em> du menu <em>Démarrer</em>, en saisissant :</p>
<pre>
	- pour SQL Server 2005 : SQLServerManager.msc
	- pour SQL Server 2008 : SQLServerManager10.msc
</pre>
<p>Dans les deux cas, l&rsquo;interface affichée est :</p>
<p><img src="http://blog.developpez.com/media/sscm.PNG" width="561" height="223" alt="" /></p>
<p>Pour configurer les protocoles d&rsquo;accès réseau à l&rsquo;instance SQL Server, il suffit, dans le volet de gauche, de double-cliquer sur &laquo;&nbsp;<em>Configuration du réseau SQL Server</em>&laquo;&nbsp;, puis de faire de même sur &laquo;&nbsp;<em>Protocoles pour monInstanceDeSQLServer</em>&laquo;&nbsp;.</p>
<p>Après une installation fraîche de SQL Server, on obtient l&rsquo;affichage suivant :</p>
<p><img src="http://blog.developpez.com/media/sscmprotocoles.PNG" width="529" height="180" alt="" /></p>
<p>Une boite de dialogue différente s&rsquo;affiche pour chacun des protocoles.<br />
Nous ne verrons ici que la boîte de dialogue &laquo;&nbsp;TCP/IP&nbsp;&raquo;, qui s&rsquo;affiche par un double-clic sur le protocole de même nom :</p>
<p><img src="http://blog.developpez.com/media/sscmtcpip.PNG" width="395" height="440" alt="" /></p>
<p>Il suffit de cliquer dans la liste déroulante sur &laquo;&nbsp;oui&nbsp;&raquo; pour activer le protocole TCP/IP.</p>
<p>Passons à l&rsquo;onglet &laquo;&nbsp;<em>Adresses IP</em>&nbsp;&raquo; :</p>
<p><img src="http://blog.developpez.com/media/sscmadressesip.PNG" width="395" height="440" alt="" /></p>
<p>Ici vous devez choisir oui dans la liste déroulante de l&rsquo;option &laquo;&nbsp;Actif&nbsp;&raquo;, puis vous pouvez configurer trois adresses IP et leurs ports (le port par défaut d&rsquo;écoute d&rsquo;une instance SQL Server, si elle est la seule hébergé sur le serveur, est 1433.<br />
Notez que le port 1434 est également utilisé par défaut pour les connexions d&rsquo;administration dédiées).</p>
<p>Dès que vous avez terminé la configuration, après validation de la configuration, vous obtenez la boîte de dialogue suivante :</p>
<p><img src="http://blog.developpez.com/media/sscmredemarre.PNG" width="744" height="126" alt="" /></p>
<p>Vous pouvez redémarrer le service SQL Server toujours dans cet utilitaire : dans le volet de gauche de la console, choisissez &laquo;&nbsp;Service SQL Server&nbsp;&raquo;, puis choisissez le service de l&rsquo;instance que vous venez de configurer en effectuant un clic-droit :</p>
<p><img src="http://blog.developpez.com/media/sscmredemarre2.PNG" width="590" height="266" alt="" /></p>
<p>Deux options s&rsquo;offrent à vous pour redémarrer le service : le bouton de la barre d&rsquo;outils, ou l&rsquo;option &laquo;&nbsp;<em>Redémarrer</em>&laquo;&nbsp;.<br />
Il est important de configurer cela dès l&rsquo;installation d&rsquo;une nouvelle instance de SQL Server, car tout redémarrage du service entraîne la perte des caches de procédure et de données du moteur de base de données &#8230;</p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Compresser tous les backups sans modifier du code ou un plan de maintnenance avec SQL Server 2008</title>
		<link>https://blog.developpez.com/elsuket/p9040/moteur-de-base-de-donnees-sql-server/compresser_tous_les_backups_sans_modifie_2008</link>
		<comments>https://blog.developpez.com/elsuket/p9040/moteur-de-base-de-donnees-sql-server/compresser_tous_les_backups_sans_modifie_2008#comments</comments>
		<pubDate>Wed, 23 Jun 2010 09:44:49 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[SQL Server 2008 a introduit la compression des sauvegardes, qui, bien que consommatrice de CPU, permet de gagner en temps d&#8217;exécution et en espace disque. Si l&#8217;on a porté une procédure stockée de gestion des sauvegardes ou un plan de &#8230; <a href="https://blog.developpez.com/elsuket/p9040/moteur-de-base-de-donnees-sql-server/compresser_tous_les_backups_sans_modifie_2008">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SQL Server 2008 a introduit la compression des sauvegardes, qui, bien que consommatrice de CPU, permet de gagner en temps d&rsquo;exécution et en espace disque.<br />
Si l&rsquo;on a porté une procédure stockée de gestion des sauvegardes ou un plan de maintenance, on peut s&rsquo;éviter de modifier leur code pour les compression à l&rsquo;aide d&rsquo;une option de serveur : <em>backup compression default</em></p>
<p>Il suffit pour cela d&rsquo;exécuter :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">EXEC sp_configure 'backup compression default', '1'<br />
GO<br />
RECONFIGURE<br />
GO</div></td></tr></tbody></table></div>
<p>pour activer la compression de toutes les sauvegardes.</p>
<p>Et bon backups <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Administrer les services SQL Server à distance</title>
		<link>https://blog.developpez.com/elsuket/p8943/moteur-de-base-de-donnees-sql-server/administrer_les_services_sql_server_a_di</link>
		<comments>https://blog.developpez.com/elsuket/p8943/moteur-de-base-de-donnees-sql-server/administrer_les_services_sql_server_a_di#comments</comments>
		<pubDate>Fri, 28 May 2010 05:15:59 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Jour férié, je jette un œil à mes e-mails car l&#8217;entreprise dans laquelle je travaille a plusieurs sites de développement à travers le monde et qu&#8217;aujourd&#8217;hui n&#8217;est donc pas férié pour tout le monde. Un développeur me précise qu&#8217;il ne &#8230; <a href="https://blog.developpez.com/elsuket/p8943/moteur-de-base-de-donnees-sql-server/administrer_les_services_sql_server_a_di">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Jour férié, je jette un œil à mes e-mails car l&rsquo;entreprise dans laquelle je travaille a plusieurs sites de développement à travers le monde et qu&rsquo;aujourd&rsquo;hui n&rsquo;est donc pas férié pour tout le monde.<br />
Un développeur me précise qu&rsquo;il ne peut plus accéder à l&rsquo;instance SQL Server Analysis Services.<br />
Je m&rsquo;empresse donc d&rsquo;établir une connexion VPN pour prendre le contrôle du serveur et voir ce qui s&rsquo;y passe, et là surprise : erreur de protocole.<br />
Je me penche donc vers la console de services sur ma machine pour voir si je peux gérer les services du serveur à distance, et la réponse est &#8230; oui !<br />
Voyons comment faire :<br />
<span id="more-100"></span><br />
Le étapes décrites ici ont été exécutées sous Windows 7, mais je pense qu&rsquo;on peut facilement les reproduire sur les versions antérieures.</p>
<p>Dans le menu démarrer, rechercher services.msc :</p>
<p><img src="http://blog.developpez.com/media/1.png" width="468" height="489" alt="" /></p>
<p>En cliquant sur le résultat, la console d&rsquo;administration des services s&rsquo;ouvre, et on peut alors choisir d&rsquo;administrer les services d&rsquo;une autre machine :</p>
<p><img src="http://blog.developpez.com/media/2.png" width="396" height="281" alt="" /></p>
<p>Le nom de la machine nous est immédiatement demandé :</p>
<p><img src="http://blog.developpez.com/media/3.png" width="525" height="253" alt="" /></p>
<p>Et après quelques secondes, nous obtenons la liste des services de la machine :</p>
<p><img src="http://blog.developpez.com/media/4.png" width="809" height="571" alt="" /></p>
<p>On peut alors gérer le service (démarrer, arrêter, redémarrer, &#8230;), changer son compte d&rsquo;exécution, le désactiver, &#8230;</p>
<p><strong>Attention à ne pas arrêter ou redémarrer le service SQL Server d&rsquo;une machine de production</strong> : la coupure de service est quasiment immédiate et peut conduire à des défauts d&rsquo;intégrité des bases de données au redémarrage du service, en plus de la <a href="http://blog.developpez.com/elsuket/p6630/indexation/purge-du-cache-de-plans/">perte des caches</a> et de la réinitialisation de données de performance collectées jusque-là &#8230;</p>
<p>Bonne administration !</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Trouver l&#8217;espace disque occupé par les fichiers, et l&#8217;espace libre dans ceux-ci</title>
		<link>https://blog.developpez.com/elsuket/p8540/moteur-de-base-de-donnees-sql-server/trouver_l_espace_disque_occupe_par_les_f</link>
		<comments>https://blog.developpez.com/elsuket/p8540/moteur-de-base-de-donnees-sql-server/trouver_l_espace_disque_occupe_par_les_f#comments</comments>
		<pubDate>Wed, 12 May 2010 09:08:49 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Non documenté]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici quelques requêtes pour vous permettre d&#8217;auditer vos fichiers de base de données : => Par une requête 12345678910111213141516171819202122232425------------------------------- -- Nicolas SOUQUET - 26/01/2010 ------------------------------- ;WITH &#160; &#160; CTE AS &#160; &#160; ( &#160; &#160; &#160; SELECT name AS nomLogique, &#8230; <a href="https://blog.developpez.com/elsuket/p8540/moteur-de-base-de-donnees-sql-server/trouver_l_espace_disque_occupe_par_les_f">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici quelques requêtes pour vous permettre d&rsquo;auditer vos fichiers de base de données :<br />
<span id="more-96"></span><br />
=> <strong>Par une requête</strong></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas SOUQUET - 26/01/2010 <br />
------------------------------- <br />
;WITH &nbsp; <br />
&nbsp; CTE AS &nbsp; <br />
&nbsp; ( &nbsp; <br />
&nbsp; &nbsp; SELECT name AS nomLogique, &nbsp;<br />
&nbsp; &nbsp; &nbsp; physical_name AS nomPhysique, &nbsp;<br />
&nbsp; &nbsp; &nbsp; CASE is_percent_growth <br />
&nbsp; WHEN 0 THEN CAST(growth * 8 / 1024 AS VARCHAR(8)) + ' MB' <br />
&nbsp; ELSE CAST(growth AS VARCHAR(3)) + ' %' <br />
&nbsp; &nbsp; &nbsp; END AS accroissement, &nbsp;<br />
&nbsp; &nbsp; &nbsp; CAST((size * 8) / CAST(1024 AS NUMERIC(14, 2)) AS NUMERIC(14, 2)) AS tailleFichier_MB, &nbsp;<br />
&nbsp; &nbsp; &nbsp; CAST((FILEPROPERTY(name, 'SpaceUsed') * 8) / CAST(1024 AS NUMERIC(14, 2)) AS NUMERIC(14, 2)) AS espaceOccupe &nbsp;<br />
&nbsp; &nbsp; FROM sys.database_files &nbsp;<br />
&nbsp; ) &nbsp;<br />
SELECT nomLogique, &nbsp;<br />
&nbsp; nomPhysique, &nbsp;<br />
&nbsp; tailleFichier_MB, &nbsp;<br />
&nbsp; accroissement, &nbsp;<br />
&nbsp; espaceOccupe AS espaceOccupe_MB, &nbsp;<br />
&nbsp; tailleFichier_MB - espaceOccupe AS espaceLibre_MB, &nbsp;<br />
&nbsp; CAST((CAST(espaceOccupe AS NUMERIC(14, 2)) / tailleFichier_MB) * 100 AS NUMERIC(14, 2)) AS [%occupe], &nbsp;<br />
&nbsp; CAST((CAST(tailleFichier_MB - espaceOccupe AS NUMERIC(14, 2)) / tailleFichier_MB) * 100 AS NUMERIC(14, 2)) AS [%libre] &nbsp;<br />
FROM CTE</div></td></tr></tbody></table></div>
<p>=> <strong>Avec l&rsquo;instruction DBCC SHOWFILESTATS</strong> (<strong>non documentée</strong>):</p>
<p>Elle donne le nombre d&rsquo;étendues (extents) occupées et le nombre total d&rsquo;étendues allouées pour le fichier.<br />
Une étendue étant constituée de 8 pages, et une page faisant 8192 octets, il vous faudra donc multiplier les nombres obtenus par 64Ko.</p>
<p>=> <strong>Avec la procédure stockée système sp_spaceused</strong> :</p>
<p>Elle retourne deux ensemble de résultats :<br />
&#8211; l&rsquo;espace occupé pour toute la base de données, mais attention seulement l&rsquo;espace libre dans le fichier de données.<br />
&#8211; le nombre de Ko réservés (= taille du fichier), utilisés (colonne data), dédiés aux index et inutilisés.</p>
<p>=> <strong>Avec l&rsquo;instruction DBCC SQLPERF(logspace)</strong></p>
<p>Celle-ci ne procure que la taille totale du fichier du journal des transactions, ainsi que son pourcentage d&rsquo;occupation.</p>
<p>Bonne gestion d&rsquo;espace disque <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>ElSuket.</p>
<p>=>=>=> <strong>12/05/2010 : MAJ :  un script pour connaître l&rsquo;espace occupé par et dans les fichiers, pour toutes les bases de données d&rsquo;une instance SQL Server :</strong></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- 12/05/2010 - Nicolas SOUQUET <br />
------------------------------- <br />
SET NOCOUNT ON <br />
GO <br />
&nbsp;<br />
DECLARE @sql varchar(1024) <br />
SET @sql = 'SELECT name AS file_logical_name,' + CHAR(13) + CHAR(10) + CHAR(9) + <br />
&nbsp; 'physical_name AS file_physical_name,' + CHAR(13) + CHAR(10) + CHAR(9) + <br />
&nbsp; 'CASE is_percent_growth' + CHAR(13) + CHAR(10) + CHAR(9) + CHAR(9) + <br />
&nbsp; 'WHEN 0 THEN CAST(growth * 8 / 1024 AS varchar(8)) + '''' MB''''' + CHAR(13) + CHAR(10) + CHAR(9) + CHAR(9) + <br />
&nbsp; 'ELSE CAST(growth AS varchar(3)) + '''' %''''' + CHAR(13) + CHAR(10) + CHAR(9) + <br />
&nbsp; 'END AS file_growth,' + CHAR(13) + CHAR(10) + CHAR(9) + <br />
&nbsp; 'CAST((size * 8) / CAST(1024 AS numeric(14, 2)) AS numeric(14, 2)) AS file_size_MB,' + CHAR(13) + CHAR(10) + CHAR(9) + <br />
&nbsp; 'CAST((FILEPROPERTY(name, ''''SpaceUsed'''') * 8) / CAST(1024 AS numeric(14, 2)) AS numeric(14, 2)) AS file_used_space_MB' + CHAR(13) + CHAR(10) + <br />
&nbsp; 'FROM sys.database_files''' + CHAR(13) + CHAR(10) <br />
&nbsp; <br />
DECLARE @exec_sql varchar(1024) <br />
&nbsp;<br />
DECLARE @instance_database_file_space TABLE <br />
( <br />
&nbsp; database_name sysname <br />
&nbsp; , file_logical_name sysname <br />
&nbsp; , file_physical_name nvarchar(260) &nbsp;<br />
&nbsp; , file_growth varchar(8) <br />
&nbsp; , file_size_MB numeric(14,2) <br />
&nbsp; , file_used_space_MB numeric(14,2) <br />
&nbsp; , file_free_space_MB numeric(14,2) <br />
&nbsp; , file_used_space_percent numeric(5,2) <br />
&nbsp; , file_free_space_percent numeric(5,2) <br />
) <br />
&nbsp;<br />
DECLARE @database_file_space TABLE <br />
( <br />
&nbsp; file_logical_name sysname <br />
&nbsp; , file_physical_name nvarchar(260) &nbsp;<br />
&nbsp; , file_growth varchar(8) <br />
&nbsp; , file_size_MB numeric(14,2) <br />
&nbsp; , file_used_space_MB numeric(14,2) <br />
) <br />
&nbsp;<br />
DECLARE db_cur CURSOR LOCAL FAST_FORWARD FOR <br />
&nbsp; SELECT &nbsp;name <br />
&nbsp; FROM &nbsp;sys.databases <br />
&nbsp; WHERE &nbsp;source_database_id IS NULL <br />
FOR READ ONLY <br />
&nbsp;<br />
DECLARE @database_name sysname <br />
&nbsp;<br />
OPEN db_cur <br />
FETCH NEXT FROM db_cur INTO @database_name <br />
WHILE @@fetch_status = 0 <br />
BEGIN <br />
&nbsp; DELETE &nbsp;@database_file_space <br />
&nbsp;<br />
&nbsp; SET @exec_sql = 'EXEC ' + @database_name + '.dbo.sp_executeSQL N''' + @sql + '' <br />
&nbsp;<br />
&nbsp; BEGIN TRY <br />
&nbsp; &nbsp; INSERT &nbsp;@database_file_space <br />
&nbsp; &nbsp; EXEC &nbsp;(@exec_sql) <br />
&nbsp; END TRY <br />
&nbsp; BEGIN CATCH <br />
&nbsp; &nbsp; PRINT @database_name + ' : ' + ERROR_MESSAGE() <br />
&nbsp; END CATCH <br />
&nbsp; <br />
&nbsp; INSERT &nbsp;@instance_database_file_space <br />
&nbsp; SELECT &nbsp;@database_name <br />
&nbsp; &nbsp; , file_logical_name <br />
&nbsp; &nbsp; , file_physical_name <br />
&nbsp; &nbsp; , file_growth <br />
&nbsp; &nbsp; , file_size_MB <br />
&nbsp; &nbsp; , file_used_space_MB <br />
&nbsp; &nbsp; , file_size_MB - file_used_space_MB AS file_free_space_MB <br />
&nbsp; &nbsp; , CAST((CAST(file_used_space_MB AS numeric(14, 2)) / file_size_MB) * 100 AS numeric(14, 2)) AS file_used_space_percent <br />
&nbsp; &nbsp; , CAST((CAST(file_size_MB - file_used_space_MB AS numeric(14, 2)) / file_size_MB) * 100 AS numeric(14, 2)) AS file_free_space_percent <br />
&nbsp; FROM &nbsp;@database_file_space <br />
&nbsp; <br />
&nbsp; FETCH NEXT FROM db_cur INTO @database_name <br />
END <br />
CLOSE db_cur <br />
DEALLOCATE db_cur <br />
&nbsp;<br />
SELECT &nbsp;* <br />
FROM &nbsp;@instance_database_file_space</div></td></tr></tbody></table></div>
<p>Il arrive que la procédure stockée système sp_executeSQL ne soit pas trouvée dans la base de données.<br />
Quand tel est le cas, la liste des bases de données est affichée dans la console de SSMS.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Emplacement du fichier des favoris de la documentation en ligne de SQL Server 2005 et 2008</title>
		<link>https://blog.developpez.com/elsuket/p7464/utilitaires/emplacement_du_fichier_des_favoris_de_la_2005</link>
		<comments>https://blog.developpez.com/elsuket/p7464/utilitaires/emplacement_du_fichier_des_favoris_de_la_2005#comments</comments>
		<pubDate>Thu, 09 Apr 2009 18:53:09 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Il n&#8217;est pas possible dans la documentation en ligne de modifier facilement l&#8217;ordre des favoris, sauf en étant un maniaque du clic. Voyons comment on peut faire avec un simple éditeur texte comme le bloc-notes &#8230; Le fichier qui contient &#8230; <a href="https://blog.developpez.com/elsuket/p7464/utilitaires/emplacement_du_fichier_des_favoris_de_la_2005">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Il n&rsquo;est pas possible dans la documentation en ligne de modifier facilement l&rsquo;ordre des favoris, sauf en étant un maniaque du clic.<br />
Voyons comment on peut faire avec un simple éditeur texte comme le bloc-notes &#8230;<br />
<span id="more-126"></span><br />
Le fichier qui contient les favoris est situé pour une installation par défaut de l&rsquo;aide en ligne dans le répertoire suivant :</p>
<p>=><strong> Sous Windows XP :</strong> </p>
<blockquote><p>C:\Documents and Settings\nomUtilisateur\Application Data\Microsoft\Microsoft SQL Server\90\Tools\Shell\vs help data\Favorites.xml</p></blockquote>
<p>=><strong> Sous Windows Vista et Windows 7 :</strong></p>
<blockquote><p>C:\Users\nomUtilisateur\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\vs help data\Favorites.xml</p></blockquote>
<p>Comme il s&rsquo;agit d&rsquo;un fichier XML, on peut le modifier à sa guise avec le bloc-notes, changer les noms de favoris, &#8230; mais on ne peut toujours pas créer de catégories pour les grouper &#8230;.<br />
En revanche on peut sauver ce fichier avant de changer de PC, ou encore échanger des rubriques avec un collègue.</p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Créer des règles de gestion de base de données avec SSMS 2008</title>
		<link>https://blog.developpez.com/elsuket/p7809/utilitaires/creer_des_regles_de_gestion_de_base_de_d_2008</link>
		<comments>https://blog.developpez.com/elsuket/p7809/utilitaires/creer_des_regles_de_gestion_de_base_de_d_2008#comments</comments>
		<pubDate>Sun, 28 Jun 2009 18:42:28 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Une nouvelle fonctionnalité introduite avec SQL Server 2008 est la gestion d&#8217;instances de SQL Server 2008 basée sur des &#171;&#160;stratégies&#160;&#187; (que l&#8217;on peut voir comme des polices de gestion), Elle permet de normaliser de nombreuses entités de l&#8217;instance SQL Server &#8230; <a href="https://blog.developpez.com/elsuket/p7809/utilitaires/creer_des_regles_de_gestion_de_base_de_d_2008">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Une nouvelle fonctionnalité introduite avec SQL Server 2008 est la gestion d&rsquo;instances de SQL Server 2008 basée sur des &laquo;&nbsp;stratégies&nbsp;&raquo; (que l&rsquo;on peut voir comme des polices de gestion),</p>
<p>Elle permet de normaliser de nombreuses entités de l&rsquo;instance SQL Server 2008, allant de l&rsquo;instance elle même jusqu&rsquo;au nom des objets, en passant les bases de données ou les entités de sécurité, et bien d&rsquo;autres encore.</p>
<p>Il est de plus possible de propager les règles ainsi créées avec la fonctionnalité d&rsquo;import / export de stratégies de gestion.<br />
Je vous propose d&rsquo;en voir une application &#8230;</p>
<p><span id="more-141"></span><br />
Nous avons vu apparaître avec <em>SQL Server Management Studio 2008</em> (SSMS) la nouvelle node &laquo;&nbsp;Gestion de la stratégie&nbsp;&raquo; sous la node &laquo;&nbsp;Gestion&nbsp;&raquo; que l&rsquo;on trouvait sous SSMS 2005.<br />
Ouvrons cette node, et voyons les possibilités qu&rsquo;elle nous offre :</p>
<p><img src="http://blog.developpez.com/media/gesStrat1.PNG" width="371" height="434" alt="" /></p>
<p>On peut ici définir une nouvelle stratégie, c&rsquo;est-à-dire un jeu de régles suivant la multitude de &laquo;&nbsp;Facettes&nbsp;&raquo; qui nous sont proposées :</p>
<p><img src="http://blog.developpez.com/media/gesStrat2.PNG" width="441" height="601" alt="" /></p>
<p>En double-cliquant sur une facette, on peut voir tous les paramètres pour lesquels ont peut vérifier une contrainte :</p>
<p><img src="http://blog.developpez.com/media/gesStrat6.PNG" width="819" height="574" alt="" /></p>
<p>Nous allons maintenant créer un jeu de règles pour les options de bases de données, en choisissant l&rsquo;option &laquo;&nbsp;Nouvelle stratégie &#8230;&nbsp;&raquo; du clic-droit sur la node &laquo;&nbsp;Stratégies&nbsp;&raquo; :</p>
<p><img src="http://blog.developpez.com/media/gesStrat3.PNG" width="760" height="598" alt="" /></p>
<p>Après avoir saisi le nom de la stratégie, l&rsquo;interface offre le choix de créer une nouvelle condition:</p>
<p><img src="http://blog.developpez.com/media/gesStrat4.PNG" width="759" height="595" alt="" /></p>
<p>Nous allons vérifier, par exemple, que toutes les bases de données de l&rsquo;instance :</p>
<p>&#8211; ont bien l&rsquo;option AUTO_CLOSE à OFF<br />
&#8211; ont le niveau de compatibilité 100</p>
<p>Après avoir donné un nom à la condition, on retrouve dans une liste déroulante la liste de toutes les facettes que nous avons vue plus haut:</p>
<p><img src="http://blog.developpez.com/media/gesStrat5.PNG" width="747" height="530" alt="" /></p>
<p>Et pour chacune d&rsquo;elle la liste des valeurs d&rsquo;options pour lesquelles on peut vérifier une condition :</p>
<p><img src="http://blog.developpez.com/media/gesStrat7.PNG" width="747" height="530" alt="" /></p>
<p>Notez que vous pouvez spécifier plusieurs vérifications au sein de la même condition, et spécifier l&rsquo;opérateur :</p>
<p><img src="http://blog.developpez.com/media/gesStrat8.PNG" width="818" height="529" alt="" /></p>
<p>On peut ainsi créer le jeu de vérifications suivant :</p>
<p><img src="http://blog.developpez.com/media/gesStrat9.PNG" width="746" height="529" alt="" /></p>
<p>Après validation, on peut créer un autre jeu de conditions et les grouper dans la même stratégie :</p>
<p><img src="http://blog.developpez.com/media/gesStrat10.PNG" width="759" height="597" alt="" /></p>
<p>on peut choisir d&rsquo;évaluer ces règles à la demande ou sur planification :</p>
<p><img src="http://blog.developpez.com/media/gesStrat11.PNG" width="759" height="595" alt="" /></p>
<p>Il est dommage que l&rsquo;on ne puisse pas créer d&rsquo;autres planifications que celles qui sont proposées &#8230;</p>
<p>Nous ne posons pas de restriction de serveur, mais on peut en mettre une pour ne pas appliquer ces règles suivant le serveur, en définissant suivant le même modèle des règles de restrictions.</p>
<p>Après validation, nous retrouvons ce que nous venons de créer :</p>
<p><img src="http://blog.developpez.com/media/gesStrat12.PNG" width="375" height="452" alt="" /></p>
<p>Nous pouvons évaluer ce jeu de règles, et comme vous le voyez, visualiser l&rsquo;historique de cette stratégie dans le cas où nous l&rsquo;aurions planifiée :</p>
<p><img src="http://blog.developpez.com/media/grStrat13.PNG" width="567" height="564" alt="" /></p>
<p>Évaluons donc la stratégie immédiatement :</p>
<p><img src="http://blog.developpez.com/media/grStrat14.PNG" width="1079" height="677" alt="" /></p>
<p>Nous voyons tout de suite quelle stratégie n&rsquo;est pas respectée, et en cochant les cases correpondantes aux stratégies et conditions que nous voulons voir validées, on peut appliquer directement les changement adéquats.<br />
La boîte de dialogue suivante apparaît après avoir choisi &laquo;&nbsp;Appliquer&nbsp;&raquo; :</p>
<p><img src="http://blog.developpez.com/media/grStrat15.PNG" width="611" height="156" alt="" /></p>
<p>Les changements sont alors appliqués, et les conditions immédiatement réévaluées :</p>
<p><img src="http://blog.developpez.com/media/grStrat16.PNG" width="1078" height="678" alt="" /></p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Générer le script complet des objets d&#8217;une base de données</title>
		<link>https://blog.developpez.com/elsuket/p7945/utilitaires/generer_le_script_complet_des_objets_d_u</link>
		<comments>https://blog.developpez.com/elsuket/p7945/utilitaires/generer_le_script_complet_des_objets_d_u#comments</comments>
		<pubDate>Tue, 11 Aug 2009 22:37:43 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici comment générer le script des objets de base de données (tables, vues, procédures stockées, fonctions, &#8230;) sans ses données, à l&#8217;aide de SQL Server Management Studio. Commençons par un clic-droit sur la base de données à scripter : Immédiatement &#8230; <a href="https://blog.developpez.com/elsuket/p7945/utilitaires/generer_le_script_complet_des_objets_d_u">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici comment générer le script des objets de base de données (tables, vues, procédures stockées, fonctions, &#8230;) sans ses données, à l&rsquo;aide de <em>SQL Server Management Studio.</em></p>
<p><span id="more-128"></span></p>
<p>Commençons par un clic-droit sur la base de données à scripter :</p>
<p><img src="http://blog.developpez.com/media/scriptDB1.png" width="839" height="648" alt="" /></p>
<p>Immédiatement l&rsquo;<em>Assistant Génération de Scripts SQL Server</em> démarre :</p>
<p><img src="http://blog.developpez.com/media/scriptDB3.png" width="493" height="449" alt="" /></p>
<p>Après avoir cliqué sur <em>Suivant</em>, nous pouvons choisir la base de données de l&rsquo;instance SQL Server courante que nous voulons scripter.<br />
Comme nous voulons recréer toute l&rsquo;organisation logique qu&rsquo;abrite la base de données, il nous suffit de cocher &laquo;&nbsp;<em>Générer un script pour tous les objets dans la base de données</em>&nbsp;&raquo;</p>
<p><img src="http://blog.developpez.com/media/scriptDB4.png" width="493" height="449" alt="" /></p>
<p>Ici nous pouvons choisir quelques options pour la génération du script, notamment dès SQL Server 2008, la génération des instructions INSERT pour disposer également des <a href="http://blog.developpez.com/elsuket/p7902/sql-server-management-studio/generer-le-script-de-tables-et-des-donne-2008/">données</a></p>
<p><img src="http://blog.developpez.com/media/scriptDB5.png" width="493" height="447" alt="" /></p>
<p>Généralement c&rsquo;est une étape que l&rsquo;on peut sauter, car les options de script sont correctement configurées.</p>
<p>Ici nous pouvons choisir vers quel support nous allons générer le script, l&rsquo;option &laquo;&nbsp;<em>Générer un script dans une nouvelle fenêtre de requête</em>&nbsp;&raquo; étant sélectionnée par défaut :</p>
<p><img src="http://blog.developpez.com/media/scriptDB6.png" width="679" height="448" alt="" /></p>
<p>Cliquons sur suivant : nous obtenons un résumé du paramétrage du script</p>
<p><img src="http://blog.developpez.com/media/scriptDB7.png" width="680" height="449" alt="" /></p>
<p>En cliquant sur &laquo;&nbsp;<em>Terminer</em>&laquo;&nbsp;, la génération débute :</p>
<p><img src="http://blog.developpez.com/media/scriptDB8.png" width="680" height="449" alt="" /></p>
<p>Et dès la fin de la génération, une nouvelle fenêtre de requête est ouverte, et donne le script :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE [ELSUKET] <br />
GO <br />
/****** Object: &nbsp;Table [dbo].[TbParametres] &nbsp; &nbsp;Script Date: 08/11/2009 23:25:27 ******/ <br />
SET ANSI_NULLS ON <br />
GO <br />
SET QUOTED_IDENTIFIER ON <br />
GO <br />
SET ANSI_PADDING ON <br />
GO <br />
CREATE TABLE [dbo].[TbParametres]( <br />
&nbsp; [IDParametre] [int] IDENTITY(1,1) NOT NULL, <br />
&nbsp; [nomParametre] [varchar](20) NOT NULL, <br />
&nbsp;CONSTRAINT [PK_TbParametres_IDParametre] PRIMARY KEY CLUSTERED &nbsp;<br />
( <br />
&nbsp; [IDParametre] ASC <br />
)WITH (PAD_INDEX &nbsp;= OFF, STATISTICS_NORECOMPUTE &nbsp;= OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS &nbsp;= ON, ALLOW_PAGE_LOCKS &nbsp;= ON) ON [PRIMARY], <br />
&nbsp;CONSTRAINT [UQ_TbParametres_nomParametre] UNIQUE NONCLUSTERED &nbsp;<br />
( <br />
&nbsp; [nomParametre] ASC <br />
)WITH (PAD_INDEX &nbsp;= OFF, STATISTICS_NORECOMPUTE &nbsp;= OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS &nbsp;= ON, ALLOW_PAGE_LOCKS &nbsp;= ON) ON [PRIMARY] <br />
) ON [PRIMARY] <br />
GO <br />
SET ANSI_PADDING OFF <br />
GO <br />
/****** Object: &nbsp;UserDefinedFunction [dbo].[FnGetLastSuccessfulJobExecution] &nbsp; &nbsp;Script Date: 08/11/2009 23:25:30 ******/ <br />
SET ANSI_NULLS ON <br />
GO <br />
SET QUOTED_IDENTIFIER ON <br />
GO <br />
---------------------------------------------------------------------------------------- <br />
-- Nicolas SOUQUET - 04/08/2009 - Recherche la dernière date de bonne exécution d'un job <br />
---------------------------------------------------------------------------------------- <br />
CREATE FUNCTION [dbo].[FnGetLastSuccessfulJobExecution] <br />
&nbsp; (@nomJob SYSNAME) <br />
&nbsp; RETURNS DATETIME <br />
AS <br />
BEGIN <br />
&nbsp; RETURN <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT DateTimeExec + 1 <br />
&nbsp; &nbsp; FROM <br />
&nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; SELECT MAX(CAST(STUFF(STUFF(DateExec, 12, 0, ':'), 15, 0, ':') AS DATETIME)) AS DateTimeExec <br />
&nbsp; &nbsp; &nbsp; FROM <br />
&nbsp; &nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; SELECT CAST(H.run_date AS CHAR(8)) + ' ' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CASE LEN(CAST(H.run_time AS VARCHAR(6))) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 5 THEN '0' + CAST(H.run_time AS CHAR(5)) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE CAST(H.run_time AS CHAR(6)) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END AS DateExec <br />
&nbsp; &nbsp; &nbsp; &nbsp; FROM msdb.dbo.sysjobs AS J <br />
&nbsp; &nbsp; &nbsp; &nbsp; JOIN msdb.dbo.sysjobhistory AS H <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON J.job_id = H.job_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHERE J.name = @nomJob <br />
&nbsp; &nbsp; &nbsp; &nbsp; AND H.run_status = 1 <br />
&nbsp; &nbsp; &nbsp; &nbsp; AND H.step_id = 1 <br />
&nbsp; &nbsp; &nbsp; ) AS EXEC_JOB_TEST <br />
&nbsp; &nbsp; ) AS DER_EXEC_JOB_TEST_OK <br />
&nbsp; ) <br />
END <br />
GO</div></td></tr></tbody></table></div>
<p>Comme on le voit, il n&rsquo;y a pas l&rsquo;instruction CREATE DATABASE.<br />
Qu&rsquo;à cela ne tienne, il nous suffit de la générer aussi :</p>
<p><img src="http://blog.developpez.com/media/scriptDB9.png" width="894" height="496" alt="" /></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE [master] <br />
GO <br />
&nbsp;<br />
/****** Object: &nbsp;Database [ELSUKET] &nbsp; &nbsp;Script Date: 08/11/2009 23:34:04 ******/ <br />
CREATE DATABASE [ELSUKET] ON &nbsp;PRIMARY &nbsp;<br />
( NAME = N'ELSUKET', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\ELSUKET.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) <br />
&nbsp;LOG ON &nbsp;<br />
( NAME = N'ELSUKET_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\ELSUKET_log.LDF' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 5MB) <br />
GO <br />
&nbsp;<br />
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) <br />
begin <br />
EXEC [ELSUKET].[dbo].[sp_fulltext_database] @action = 'enable' <br />
end <br />
GO <br />
&nbsp;<br />
... <br />
&nbsp;<br />
ALTER DATABASE [ELSUKET] SET DB_CHAINING OFF &nbsp;<br />
GO</div></td></tr></tbody></table></div>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installation de SQL Server 2008</title>
		<link>https://blog.developpez.com/elsuket/p7891/moteur-de-base-de-donnees-sql-server/installation_de_sql_server_2008</link>
		<comments>https://blog.developpez.com/elsuket/p7891/moteur-de-base-de-donnees-sql-server/installation_de_sql_server_2008#comments</comments>
		<pubDate>Wed, 22 Jul 2009 22:25:28 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voyons en quelques étapes comment se déroule l&#8217;installation de SQL Server 2008 sur une machine sur laquelle on vient d&#8217;installer un OS tout frais Dès l&#8217;exécution de l&#8217;autorun du DVD, nous obtenons la boîte suivante : Là, Microsoft a bien &#8230; <a href="https://blog.developpez.com/elsuket/p7891/moteur-de-base-de-donnees-sql-server/installation_de_sql_server_2008">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voyons en quelques étapes comment se déroule l&rsquo;installation de SQL Server 2008 sur une machine sur laquelle on vient d&rsquo;installer un OS tout frais <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p><span id="more-83"></span></p>
<p>Dès l&rsquo;exécution de l&rsquo;autorun du DVD, nous obtenons la boîte suivante :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-01.JPG" width="798" height="146" alt="" /></p>
<p>Là, Microsoft a bien fait les choses en incluant dans la paquetage d&rsquo;installation le téléchargement du <em>.NET Framework</em> 3.5 : il n&rsquo;y a donc pas besoin de reprendre l&rsquo;installation.</p>
<p>Après avoir cliqué sur OK, on obtient donc la boîte de dialogue suivante :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-02.JPG" width="508" height="477" alt="" /></p>
<p>Et peu après avoir cliqué sur installer, le téléchargement débute :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-03.JPG" width="508" height="478" alt="" /></p>
<p>Elle est poursuivie par l&rsquo;installation du <em>.NET Framework</em> 3.5</p>
<p>Il n&rsquo;en va pas de même avec Windows Installer 4.5, qu&rsquo;il vous faut télécharger et installer : à faire avant de démarrer le processus d&rsquo;installation de SQL Server 2008 !</p>
<p>Pour le trouver facilement, vous pouvez vous rendre sur <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=fr&amp;FamilyID=5a58b56f-60b6-4412-95b9-54d056d6f9f4">cette page</a></p>
<p>L&rsquo;installation se fait ensuite de façon très classique :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-05.JPG" width="505" height="394" alt="" /></p>
<p>Et il suffit d&rsquo;aceepter la CLUF pour voir l&rsquo;installation de Windows Installer 4.5 s&rsquo;effectuer et se terminer :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-06.JPG" width="507" height="395" alt="" /></p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-07.JPG" width="505" height="394" alt="" /></p>
<p>Reprenons donc l&rsquo;installation de SQL Server 2008 : nous obtenons maintenant la boîte suivante :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-08.JPG" width="584" height="113" alt="" /></p>
<p>Et après quelques secondes, le <em>Centre d&rsquo;installation SQL Server</em> s&rsquo;ouvre :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-09.JPG" width="800" height="497" alt="" /></p>
<p>Si tout cela paraît lourd de premier abord, il n&rsquo;en est en fait rien puisque cette interface vous permet de paramétrer presque totalement l&rsquo;instance de SQL Server.<br />
Voyons le détail des pages qui nous sont proposées.</p>
<p>Ici on peut vérifier que le serveur supportera bien SQL Server 2008 avec l&rsquo;item <em>Configuration matérielle et logicielle requise</em> et contrôler qu&rsquo;aucun paramètre système n&rsquo;empêchera le bon déroulement de l&rsquo;installation à l&rsquo;aide de l&rsquo;<em>outil d&rsquo;analyse de configuration</em>, qui s&rsquo;exécute rapidement et affiche un compte rendu clair :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-10.JPG" width="697" height="573" alt="" /></p>
<p>Passons aux éléments d&rsquo;installation à proprement parler :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-11.JPG" width="803" height="472" alt="" /></p>
<p>On peut réaliser tout les types d&rsquo;opérations d&rsquo;installation de SQL Server de l&rsquo;installation simple à la mise en place d&rsquo;un nouveau cluster, en passant par les mises à niveau d&rsquo;instances s&rsquo;exécutant sous SQL Server 2000 ou 2005 : tout est groupé au même endroit.</p>
<p>La page <em>Maintenance</em> permet de supprimer un cluster SQL Server, de tenter une réparation d&rsquo;une installation de SQL Server 2008 ou encore d&rsquo;effectuer une mise à niveau, mais dans ce cas pour changer d&rsquo;édition de SQL Server (pas de version):</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-12.JPG" width="802" height="471" alt="" /></p>
<p>Les outils vous permettent de faire un état de ce qui est installé sur la machine, ou de mettre à niveau des packages SSIS 2005 vers 2008 (donc impossible de migrer un DTS 2000 vers un package SSIS 2008 directement).<br />
On retrouve l&rsquo;<em>outil d&rsquo;analyse de la configuration système</em> que nous avons exécuté précédemment :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-13.JPG" width="802" height="471" alt="" /></p>
<p>La page <em>Ressources</em> permet d&rsquo;accéder à tout le contenu web de Microsoft concernant SQL Server 2008:</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-14.JPG" width="721" height="589" alt="" /></p>
<p>Enfin il est possible de réaliser une installation avancée basée sur un fichier de configuration, et de préparer / activer un cluster de basculement SQL Server :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-15.JPG" width="800" height="351" alt="" /></p>
<p>La suite des étapes de préparation de l&rsquo;installation parle d&rsquo;elle-même :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-16.JPG" width="800" height="351" alt="" /></p>
<p>Une nouvelle vérification des éléments qui peuvent entraver le déroulement correct de l&rsquo;installation est effectuée :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-17.JPG" width="822" height="617" alt="" /></p>
<p>Il est possible de choisir une édition de SQL Server, elles sont toutes regroupées dans ce package :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-18_01.JPG" width="823" height="616" alt="" /></p>
<p>La CLUF SQL Server 2008 :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-19.JPG" width="823" height="615" alt="" /></p>
<p>Les fichier nécessaires à l&rsquo;installation sont ensuite copiés sur un des disques durs de la machine hôté, comme spécifié dans la page &laquo;&nbsp;<em>Options</em>&nbsp;&raquo;</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-20.JPG" width="821" height="615" alt="" /></p>
<p>Ici nous voyons un avertissement apparaître :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-21.JPG" width="729" height="546" alt="" /></p>
<p>Rien de bien méchant :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-22.JPG" width="801" height="145" alt="" /></p>
<p>Le lien référencé pointe vers la <a href="http://msdn.microsoft.com/fr-fr/library/cc646023.aspx">cette page</a> qui donne la liste des ports à ouvrir dans le pare-feu suivant les fonctionnalités que l&rsquo;on va installer.<br />
Si l&rsquo;on installe que le moteur de base de données SQL Server 2008, il faudra ouvrir le port 1433.</p>
<p>Ensuite, il suffit de sélectionner toutes les fonctionnalités et composants à installer.<br />
N&rsquo;oubliez pas les &laquo;&nbsp;outils de gestion&nbsp;&raquo; : il s&rsquo;agit en fait de <em>SQL Server Management Studio</em> <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-23.JPG" width="807" height="602" alt="" /></p>
<p>On peut choisir d&rsquo;installer une instance par défaut ou nommée, et une liste des instances SQL Server installées sur la machine est affichée :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-24.JPG" width="850" height="635" alt="" /></p>
<p>Un aperçu de l&rsquo;espace disque est calculé :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-25.JPG" width="850" height="634" alt="" /></p>
<p>Une bonne nouveauté : il est possible de configurer les services relatifs aux fonctionnalités choisies à l&rsquo;installation, ainsi que le service SQL Browser &#8230;</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-26.JPG" width="849" height="635" alt="" /></p>
<p>Mais aussi la collation pour l&rsquo;instance du moteur de base de données comme pour SSAS &#8230;</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-27.JPG" width="850" height="634" alt="" /></p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-28.JPG" width="520" height="417" alt="" /></p>
<p>de choisir le mode d&rsquo;authentification (ici pas de nouveauté par rapport à l&rsquo;installation de SQL Server 2005) :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-29.JPG" width="848" height="633" alt="" /></p>
<p>De configurer l&rsquo;emplacement des divers fichiers de base de données (enfin !)</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-30.JPG" width="880" height="551" alt="" /></p>
<p>Comme SQL Server 2008 introduit la fonctionnalité FILESTREAM, il est possible de la configurer ici :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-31.JPG" width="1002" height="629" alt="" /></p>
<p>De configurer directement une instance de Reporting Services, ce qui est également bienvenu :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-32.JPG" width="900" height="565" alt="" /></p>
<p>Vous pouvez également préciser si vous souhaitez envoyer des rapports d&rsquo;erreur à Microsoft :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-33.JPG" width="850" height="532" alt="" /></p>
<p>Nouvelle vérification :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-34.JPG" width="850" height="532" alt="" /></p>
<p>Un résumé des modules qui vont être installés vous est affiché :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-35.JPG" width="849" height="533" alt="" /></p>
<p>Le processus d&rsquo;installation à proprement parler commence alors :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-36.JPG" width="1000" height="627" alt="" /></p>
<p>Un court résumé de l&rsquo;installation s&rsquo;affiche dès la fin de celle-ci &#8230;</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-37.JPG" width="999" height="628" alt="" /></p>
<p>&#8230; et vous pouvez accéder au journal d&rsquo;installation :</p>
<p><img src="http://blog.developpez.com/media/installSQLServer2008-38_01.JPG" width="849" height="532" alt="" /></p>
<p>On regrettera que les protocoles réseau doivent toujours être configurés manuellement à l&rsquo;aide du <em>Gestionnaire de configuration SQL Server</em>, nécessitant le redémarrage du service SQL Server &#8230;</p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Générer le script de tables et des données qu&#8217;elles contiennent avec SSMS 2008</title>
		<link>https://blog.developpez.com/elsuket/p7902/utilitaires/generer_le_script_de_tables_et_des_donne_2008</link>
		<comments>https://blog.developpez.com/elsuket/p7902/utilitaires/generer_le_script_de_tables_et_des_donne_2008#comments</comments>
		<pubDate>Sun, 26 Jul 2009 11:34:35 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[SQL Server Management Studio 2008 introduit le scriptage des données des tables. Le scriptage se fait toujours à l&#8217;aide de l&#8217;Assistant Script, mais il faut aller chercher l&#8217;option pour en scripter également les données Pour cet exemple, nous prenons la &#8230; <a href="https://blog.developpez.com/elsuket/p7902/utilitaires/generer_le_script_de_tables_et_des_donne_2008">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SQL Server Management Studio 2008 introduit le scriptage des données des tables.<br />
Le scriptage se fait toujours à l&rsquo;aide de l&rsquo;<em>Assistant Script</em>, mais il faut aller chercher l&rsquo;option pour en scripter également les données</p>
<p><span id="more-142"></span></p>
<p>Pour cet exemple, nous prenons la petite table suivante :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--------------------------------- <br />
-- Nicolas SOUQUET - 26/07/2009 - <br />
--------------------------------- <br />
CREATE TABLE TbParametres <br />
( <br />
&nbsp; IDParametre INT NOT NULL IDENTITY CONSTRAINT PK_TbParametres_IDParametre PRIMARY KEY, <br />
&nbsp; nomParametre VARCHAR(20) NOT NULL CONSTRAINT UQ_TbParametres_nomParametre UNIQUE <br />
) <br />
GO <br />
&nbsp;<br />
INSERT INTO dbo.TbParametres(nomParametre) <br />
VALUES ('Parametre1'), <br />
&nbsp; &nbsp; ('Parametre2'), <br />
&nbsp; &nbsp; ('Parametre3') <br />
GO <br />
&nbsp;<br />
SELECT IDParametre, nomParametre <br />
FROM dbo.TbParametres</div></td></tr></tbody></table></div>
<p>Nous voulons maintenant scripter le DDL de cette table ainsi que les données stockées par celle-ci.<br />
Nous choisissons l&rsquo;option &laquo;&nbsp;Générer des scripts&nbsp;&raquo; du menu &laquo;&nbsp;Tâches&nbsp;&raquo; que l&rsquo;on trouve dans menu contextuel de la base de données contenant la table TbParametres, en l&rsquo;occurence ELSUKET.</p>
<p><img src="http://blog.developpez.com/media/GenererScriptDonneesTables1.png" width="809" height="640" alt="" /></p>
<p>Nous obtenons la boîte suivante :</p>
<p><img src="http://blog.developpez.com/media/GenererScriptDonneesTables2.png" width="491" height="448" alt="" /></p>
<p>En cliquant sur &laquo;&nbsp;<em>Suivant</em>&laquo;&nbsp;, nous obtenons, comme avec SSMS 2005, la liste des options de script, et l&rsquo;on voit que l&rsquo;option &laquo;&nbsp;<em>Générer le script des données</em>&nbsp;&raquo; a été ajoutée :</p>
<p><img src="http://blog.developpez.com/media/GenererScriptDonneesTables3.png" width="684" height="730" alt="" /></p>
<p>Il suffit bien sûr de la positionner à &laquo;&nbsp;<em>True</em>&nbsp;&raquo; pour obtenir le script des INSERT de toutes les lignes des tables que nous allons choisir :</p>
<p><img src="http://blog.developpez.com/media/GenererScriptDonneesTables4.png" width="493" height="449" alt="" /></p>
<p><img src="http://blog.developpez.com/media/GenererScriptDonneesTables5.png" width="493" height="449" alt="" /></p>
<p>L&rsquo;option &laquo;&nbsp;<em>Générer un script dans une nouvelle fenêtre de requête</em>&nbsp;&raquo; est sélectionnée par défaut.</p>
<p><img src="http://blog.developpez.com/media/GenererScriptDonneesTables6.png" width="493" height="449" alt="" /></p>
<p>Comme d&rsquo;habitude, nous obtenons un résumé des scripts à générer :</p>
<p><img src="http://blog.developpez.com/media/GenererScriptDonneesTables7.png" width="492" height="449" alt="" /></p>
<p>Et peu après avoir cliqué sur &laquo;&nbsp;Terminer&nbsp;&raquo;, nous obtenons le script suivant :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE [ELSUKET] <br />
GO <br />
/****** Object: &nbsp;Table [dbo].[TbParametres] &nbsp; &nbsp;Script Date: 07/26/2009 12:10:22 ******/ <br />
SET ANSI_NULLS ON <br />
GO <br />
SET QUOTED_IDENTIFIER ON <br />
GO <br />
SET ANSI_PADDING ON <br />
GO <br />
CREATE TABLE [dbo].[TbParametres]( <br />
&nbsp; [IDParametre] [int] IDENTITY(1,1) NOT NULL, <br />
&nbsp; [nomParametre] [varchar](20) NOT NULL, <br />
&nbsp;CONSTRAINT [PK_TbParametres_IDParametre] PRIMARY KEY CLUSTERED &nbsp;<br />
( <br />
&nbsp; [IDParametre] ASC <br />
)WITH (PAD_INDEX &nbsp;= OFF, STATISTICS_NORECOMPUTE &nbsp;= OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS &nbsp;= ON, ALLOW_PAGE_LOCKS &nbsp;= ON) ON [PRIMARY], <br />
&nbsp;CONSTRAINT [UQ_TbParametres_nomParametre] UNIQUE NONCLUSTERED &nbsp;<br />
( <br />
&nbsp; [nomParametre] ASC <br />
)WITH (PAD_INDEX &nbsp;= OFF, STATISTICS_NORECOMPUTE &nbsp;= OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS &nbsp;= ON, ALLOW_PAGE_LOCKS &nbsp;= ON) ON [PRIMARY] <br />
) ON [PRIMARY] <br />
GO <br />
SET ANSI_PADDING OFF <br />
GO <br />
&nbsp;<br />
SET IDENTITY_INSERT [dbo].[TbParametres] ON <br />
INSERT [dbo].[TbParametres] ([IDParametre], [nomParametre]) VALUES (1, N'Parametre1') <br />
INSERT [dbo].[TbParametres] ([IDParametre], [nomParametre]) VALUES (2, N'Parametre2') <br />
INSERT [dbo].[TbParametres] ([IDParametre], [nomParametre]) VALUES (3, N'Parametre3') <br />
SET IDENTITY_INSERT [dbo].[TbParametres] OFF</div></td></tr></tbody></table></div>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Exporter le code de vues, procédures stockées, triggers, fonctions SQL vers un fichier</title>
		<link>https://blog.developpez.com/elsuket/p7798/snippets/exporter_le_code_de_vues_procedures_stoc</link>
		<comments>https://blog.developpez.com/elsuket/p7798/snippets/exporter_le_code_de_vues_procedures_stoc#comments</comments>
		<pubDate>Thu, 25 Jun 2009 21:59:43 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Pour effectuer une revue de code ou pour gérer des versions de code en phase de développement, il peut être intéressant d&#8217;exporter les codes des modules SQL vers un fichier. Voyons comment réaliser cela, à l&#8217;aide de l&#8217;utilitaire en ligne &#8230; <a href="https://blog.developpez.com/elsuket/p7798/snippets/exporter_le_code_de_vues_procedures_stoc">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Pour effectuer une revue de code ou pour gérer des versions de code en phase de développement, il peut être intéressant d&rsquo;exporter les codes des modules SQL vers un fichier.<br />
Voyons comment réaliser cela, à l&rsquo;aide de l&rsquo;utilitaire en ligne de commande BCP &#8230;</p>
<p><span id="more-46"></span></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">-------------------------------------------------------------------------------------- <br />
-- Nicolas SOUQUET - 25/06/2009 - Exporter le code de modules dans un fichier unique - <br />
-------------------------------------------------------------------------------------- <br />
SELECT SQL.definition + CHAR(10) + CHAR(13) + 'GO' AS CodeModule <br />
INTO ##MODULES <br />
FROM sys.objects AS OBJETS <br />
JOIN sys.sql_modules AS SQL ON SQL.object_id = OBJETS.object_id <br />
WHERE OBJETS.type IN ('P', 'V', 'TR', 'FN', 'IF', 'TF') <br />
AND OBJETS.name NOT LIKE 'dt%' AND OBJETS.name NOT LIKE 'sp%' <br />
ORDER BY OBJETS.object_id <br />
&nbsp;<br />
DECLARE @szBCP VARCHAR(256); <br />
SET @szBCP = 'bcp &quot;SELECT CodeModule FROM ##MODULES&quot; queryout C:\ModulesSQL.sql -T -c'; <br />
EXEC master.dbo.xp_cmdshell @szBCP; <br />
&nbsp;<br />
DROP TABLE ##MODULES; <br />
&nbsp;<br />
---------------------------------------------------------------------------------------------------- <br />
-- Nicolas SOUQUET - 25/06/2009 - Exporter le code de plusieurs modules avec un fichier par module - <br />
---------------------------------------------------------------------------------------------------- <br />
--&gt;&gt;&gt;&gt; A EXECUTER DANS LE CONTEXTE DE LA BD DEPUIS LAQUELLE ON SOUHAITE RÉALISER L'EXPORT <br />
SET NOCOUNT ON <br />
&nbsp;<br />
DECLARE CUR_MODULES CURSOR FOR <br />
&nbsp; SELECT name <br />
&nbsp; FROM sys.objects <br />
&nbsp; WHERE type IN ('P', 'V', 'TR', 'FN', 'IF', 'TF') <br />
&nbsp; -- AND name LIKE '%blablabla%' <br />
FOR READ ONLY <br />
&nbsp;<br />
DECLARE @szNomModule SYSNAME <br />
OPEN CUR_MODULES <br />
FETCH NEXT FROM CUR_MODULES INTO @szNomModule <br />
WHILE @@FETCH_STATUS = 0 <br />
BEGIN <br />
&nbsp; SELECT definition <br />
&nbsp; INTO ##MODULE_TEXT <br />
&nbsp; FROM sys.sql_modules <br />
&nbsp; WHERE OBJECT_NAME(object_id) = @szNomModule <br />
&nbsp;<br />
&nbsp; DECLARE @szBCP VARCHAR(512); <br />
&nbsp; SET @szBCP = 'bcp &quot;SELECT definition FROM ##PROC_TEXT&quot; queryout C:\' + @szNomModule + '.sql -T -c'; <br />
&nbsp; EXEC master.dbo.xp_cmdshell @szBCP, NO_OUTPUT <br />
&nbsp;<br />
&nbsp; DROP TABLE ##MODULE_TEXT; <br />
&nbsp; FETCH NEXT FROM CUR_MODULES INTO @szNomModule <br />
END <br />
DEALLOCATE CUR_MODULES</div></td></tr></tbody></table></div>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Filtrer l&#8217;affichage des objets d&#8217;une base de données</title>
		<link>https://blog.developpez.com/elsuket/p7720/utilitaires/filtrer_l_affichage_des_objets_d_une_bas</link>
		<comments>https://blog.developpez.com/elsuket/p7720/utilitaires/filtrer_l_affichage_des_objets_d_une_bas#comments</comments>
		<pubDate>Mon, 08 Jun 2009 21:49:18 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Il est possible dans SQL Server Management Studio, sous les nodes regroupant les objets de bases de données (tables, procédures stockées, fonctions et vues) de filtrer l&#8217;affichage des objets suivant plusieurs critères. Cela est très pratique si l&#8217;on a beaucoup &#8230; <a href="https://blog.developpez.com/elsuket/p7720/utilitaires/filtrer_l_affichage_des_objets_d_une_bas">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Il est possible dans SQL Server Management Studio, sous les nodes regroupant les objets de bases de données (tables, procédures stockées, fonctions et vues) de filtrer l&rsquo;affichage des objets suivant plusieurs critères.<br />
Cela est très pratique si l&rsquo;on a beaucoup d&rsquo;objets, et surtout si l&rsquo;on a adopté une convention de nommage stricte&#8230;</p>
<p><span id="more-139"></span></p>
<p>Sous SQL Server 2005 Management Studio, il est permis de filtrer suivant 3 critères :</p>
<p>&#8211; Le nom des objets,<br />
&#8211; Le schéma des objets,<br />
&#8211; la date de création des objets.</p>
<p>SQL Server 2008 Management Studio permet en plus de filtrer sur le propriétaire de l&rsquo;objet.</p>
<p>Voyons comment, sous ces deux interfaces graphiques, réaliser un filtrage.<br />
Nous prendrons pour exemple un filtrage sur le nom des tables, mais le procédé est strictement le même pour tous les autres objets de base de données :</p>
<p>Un clic droit sur la node de type d&rsquo;objet de la base de données produit l&rsquo;affichage suivant :</p>
<p><img src="http://blog.developpez.com/media/filtreclicdroit.PNG" width="500" height="366" alt="" /></p>
<p>En choisissant &laquo;&nbsp;Paramètres de filtre&nbsp;&raquo;, on obtient :</p>
<p><img src="http://blog.developpez.com/media/filtrecriteres.PNG" width="544" height="448" alt="" /></p>
<p>Voici le jeu de tables que la base de données ELSUKET contient :</p>
<p><img src="http://blog.developpez.com/media/filtrelistetables.PNG" width="405" height="532" alt="" /></p>
<p>Supposons que nous ne voulons voir que les tables dont le nom contient la chaîne &laquo;&nbsp;livraison&nbsp;&raquo; :</p>
<p><img src="http://blog.developpez.com/media/filtrelivraison.PNG" width="544" height="448" alt="" /></p>
<p>Voici le résultat obtenu :</p>
<p><img src="http://blog.developpez.com/media/filtrefinal.PNG" width="408" height="499" alt="" /></p>
<p>Pour revenir à l&rsquo;affichage de toutes les tables, il suffit de choisir l&rsquo;option &laquo;&nbsp;Supprimer un filtre&nbsp;&raquo; dans le menu contextuel de filtrage des tables.<br />
On peut aussi changer les critères en retournant dans &laquo;&nbsp;Paramètres de filtre&nbsp;&raquo;.<br />
En revanche on ne peut pas saisir plusieurs critères : une fonctionnalité appréciable aurait été de pouvoir filtrer sur plusieurs chaînes &#8230;</p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SSMS : Tâches sur plusieurs objets de même type à partir des Détails de l&#8217;explorateur d&#8217;objet</title>
		<link>https://blog.developpez.com/elsuket/p7722/utilitaires/ssms_taches_sur_plusieurs_objets_de_meme</link>
		<comments>https://blog.developpez.com/elsuket/p7722/utilitaires/ssms_taches_sur_plusieurs_objets_de_meme#comments</comments>
		<pubDate>Mon, 08 Jun 2009 22:28:03 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Il est possible d&#8217;utiliser l&#8217;explorateur d&#8217;objets pour sélectionner plusieurs objets de même type à la souris, pour ensuite pouvoir les supprimer (comme on le ferait dans l&#8217;explorateur de fichiers de Windows) ou les scripter &#8230; L&#8217;onglet &#171;&#160;Détails de l&#8217;explorateur d&#8217;objet&#160;&#187; &#8230; <a href="https://blog.developpez.com/elsuket/p7722/utilitaires/ssms_taches_sur_plusieurs_objets_de_meme">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Il est possible d&rsquo;utiliser l&rsquo;explorateur d&rsquo;objets pour sélectionner plusieurs objets de même type à la souris, pour ensuite pouvoir les supprimer (comme on le ferait dans l&rsquo;explorateur de fichiers de Windows) ou les scripter &#8230;</p>
<p><span id="more-140"></span></p>
<p>L&rsquo;onglet &laquo;&nbsp;<em>Détails de l&rsquo;explorateur d&rsquo;objet</em>&nbsp;&raquo; est accessible :</p>
<p>&#8211; sous <em>SQL Server Management Studio 2005</em>, en allant dans le menu <em>Affichage</em>, et en choissant l&rsquo;option <em>Détails de l&rsquo;explorateur d&rsquo;objet</em></p>
<p>&#8211; sous <em>SQL Server Management Studio 2008</em>, de la même façon, ou en utilisant le raccourci clavier F7</p>
<p>Voyons maintenant comment un peut se servir de celui-ci.<br />
Supposons que je veux scripter la structure de plusieurs tables, procédures stockées ou jobs : ci-dessous je donne l&rsquo;exemple pour des tables, mais le principe demeure le même pour les objets cités :</p>
<p>Pour effectuer la sélection des objets, il suffit d&rsquo;accéder directement aux <em>Détails de l&rsquo;explorateur d&rsquo;objet</em> comme décrit précédemment, puis de naviguer jusqu&rsquo;au type d&rsquo;objet pour lequel on veut effectuer des tâches :</p>
<p><img src="http://blog.developpez.com/media/details.PNG" width="595" height="277" alt="" /></p>
<p>En choisissant successivement les &laquo;&nbsp;dossiers&nbsp;&raquo; : </p>
<p>&#8211; Bases de données,<br />
&#8211; maBaseDeDonnées<br />
&#8211; Tables</p>
<p>Nous obtenons :</p>
<p><img src="http://blog.developpez.com/media/detailtables.PNG" width="901" height="263" alt="" /></p>
<p>De la même façon que nous sélectionnons plusieurs fichiers ou dossiers dans l&rsquo;explorateur de fichiers de Windows (MAJ + clic gauche), nous pouvons sélectionner, en l&rsquo;occurence, plusieurs tables :</p>
<p><img src="http://blog.developpez.com/media/detailselection.PNG" width="906" height="261" alt="" /></p>
<p>Par un clic droit sur l&rsquo;un des objets sélectionnés, voyons les tâches dont nous disposons :</p>
<p><img src="http://blog.developpez.com/media/detailstaches.PNG" width="856" height="393" alt="" /></p>
<p>Le script de création des tables est alors généré :</p>
<p><img src="http://blog.developpez.com/media/detailscript.PNG" width="800" height="598" alt="" /></p>
<p>On peut aussi supprimer directement ces objets en appuyant sur la touche &laquo;&nbsp;Suppr&nbsp;&raquo;.<br />
Notons que si l&rsquo;on choisit l&rsquo;option &laquo;&nbsp;<em>travail de l&rsquo;agent</em>&laquo;&nbsp;, les tables sont scriptées dans un travail dont vous spécifiez le nom.<br />
Il vous faudra ensuite éditer le travail pour en modifier les propriétés (planification par exemple &#8230;)</p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Utilitaires] Importer et exporter les paramètres de surface d&#8217;exposition : l&#8217;utilitaire SAC</title>
		<link>https://blog.developpez.com/elsuket/p6981/utilitaires/importer_et_exporter_les_parametres_de_s</link>
		<comments>https://blog.developpez.com/elsuket/p6981/utilitaires/importer_et_exporter_les_parametres_de_s#comments</comments>
		<pubDate>Fri, 19 Dec 2008 21:09:50 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Il peut être intéressant entre deux installations de SQL Server de se resservir des mêmes paramètres de surface d&#8217;exposition, plutôt que de passer un moment dans l&#8217;interface graphique proposée. Heureusement, l&#8217;utilitaire en ligne de commande SAC permet d&#8217;exporter et d&#8217;importer &#8230; <a href="https://blog.developpez.com/elsuket/p6981/utilitaires/importer_et_exporter_les_parametres_de_s">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Il peut être intéressant entre deux installations de SQL Server de se resservir des mêmes paramètres de surface d&rsquo;exposition, plutôt que de passer un moment dans l&rsquo;interface graphique proposée.<br />
Heureusement, l&rsquo;utilitaire en ligne de commande SAC permet d&rsquo;exporter et d&rsquo;importer ces paramètres très simplement.<br />
<span id="more-125"></span></p>
<p>Voyons l&rsquo;export dans un fichier ParamSAC.out, et en supposant SQL Server installé dans le répertoire par défaut <em>C:\Program Files\Microsoft SQL Server\</em> :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------ &nbsp;<br />
- Nicolas SOUQUET - 19/12/2008 &nbsp;<br />
------------------------------ &nbsp;<br />
&nbsp;<br />
********** <br />
* Export * <br />
********** <br />
&nbsp;<br />
C:\Program Files\Microsoft SQL Server\90\Shared&gt;SAC out C:\ParamSAC.out -S monServeur -I monInstance -U monUtilisateur -P monMotDePasse</div></td></tr></tbody></table></div>
<p>La console DOS affiche alors le texte suivant en quelques secondes :</p>
<blockquote><p>
Exporting surface area settings for Database Engine instance monInstance&#8230;Started<br />
Exporting surface area settings for Database Engine instance monInstance&#8230;Complete
</p></blockquote>
<p>Voyons maintenant l&rsquo;import :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------ &nbsp;<br />
- Nicolas SOUQUET - 19/12/2008 &nbsp;<br />
------------------------------ &nbsp;<br />
&nbsp;<br />
********** <br />
* Import * <br />
********** <br />
C:\Program Files\Microsoft SQL Server\90\Shared&gt;SAC in C:\ParamSAC.out -S monServeur -U monUtilisateur -P monMotDePasse</div></td></tr></tbody></table></div>
<p>De la même façon, voici ce qu&rsquo;affiche la console DOS après quelques secondes :</p>
<blockquote><p>
Importing surface area settings for Database Engine instance monServeur\monInstance&#8230;Started<br />
Changes to Connection Settings will not take effect until you restart the Database Engine service.<br />
Importing surface area settings for Database Engine instance monServeur\monInstance&#8230;Complete
</p></blockquote>
<p>N&rsquo;oubliez pas de redémarrer le service une fois les paramètres importés :</p>
<p>&#8211; Arrêt : NET STOP MSSQL$monInstance ou NET STOP &laquo;&nbsp;SQLSERVER (monInstance)&nbsp;&raquo;<br />
&#8211; Démarrage : NET START MSSQL$monInstance ou NET START &laquo;&nbsp;SQLSERVER (monInstance)&nbsp;&raquo;</p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
