<?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 de SQLpro &#187; SQL Server 2017</title>
	<atom:link href="https://blog.developpez.com/sqlpro/pcategory/ms-sql-server/sql-server-2017-ms-sql-server/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/sqlpro</link>
	<description>Le SQL pour SQL Server, PostGreSQL et tous les autres SGBDR</description>
	<lastBuildDate>Thu, 15 Oct 2020 12:59:17 +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>Une peste nommée NOLOCK&#8230; et comment l&#8217;éviter</title>
		<link>https://blog.developpez.com/sqlpro/p13181/langage-sql-norme/une-peste-nommee-nolock-et-comment-leviter</link>
		<comments>https://blog.developpez.com/sqlpro/p13181/langage-sql-norme/une-peste-nommee-nolock-et-comment-leviter#comments</comments>
		<pubDate>Sun, 08 Jul 2018 14:55:07 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[Langage SQL (norme)]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[ISOLATION]]></category>
		<category><![CDATA[NOLOCK]]></category>
		<category><![CDATA[SNAPSHOT]]></category>
		<category><![CDATA[transaction]]></category>
		<category><![CDATA[verrou]]></category>
		<category><![CDATA[verrouilage]]></category>
		<category><![CDATA[verrous]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=818</guid>
		<description><![CDATA[L&#8217;utilisation du tag de table NOLOCK, hélas largement prisé par de nombreux développeurs, est, la plupart du temps, une absurdité conduisant à des résultats potentiellement faux. Est-il possible de faire autrement pour minimiser les blocages induit par les verrouillages dans SQL Server ? Réponse OUI ! À la suite de cette remarque : &#171;&#160;&#8230;je passe [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>L&rsquo;utilisation du tag de table NOLOCK, hélas largement prisé par de nombreux développeurs, est, la plupart du temps, une absurdité conduisant à des résultats potentiellement faux. Est-il possible de faire autrement pour minimiser les blocages induit par les verrouillages dans SQL Server ? Réponse OUI !<br />
<span id="more-818"></span><br />
À la suite de cette remarque :<br />
<em>&laquo;&nbsp;&#8230;je passe aussi sur le NOLOCK qui est une véritable connerie en production et donne des valeurs fausses !&nbsp;&raquo;</em><br />
Publiée ici :<br />
<a href="https://www.developpez.net/forums/d1870299/bases-donnees/ms-sql-server/developpement/utilisation-excessive-structure-conditionnelle-choix-multiples/#post10343427" rel="noopener" target="_blank"></a><br />
Mon interlocuteur me répondais :<br />
<em>&laquo;&nbsp;Merci pour cette précision. Comme vous abordez le sujet du NOLOCK effectivement j&rsquo;ai constaté certaines fois en production on avait des valeurs totalement erronées, mais je n&rsquo;arrivais pas à me l&rsquo;expliquer. J&rsquo;ai maintenant une piste et je vais creuser du côté du NOLOCK que nous utilisons beaucoup en production sur une base de données CRM 2013. Aussi par quoi pouvons nous remplacer le NOLOCK ??&nbsp;&raquo;</em></p>
<p>Je lui donnais donc l&rsquo;explication suivante&#8230;<br />
<strong><br />
Le &laquo;&nbsp;NOLOCK&nbsp;&raquo; peut parfaitement se remplacer par le niveau d&rsquo;isolation SNAPSHOT</strong> par exemple&#8230;</p>
<p>NOLOCK ne signifie pas &laquo;&nbsp;<em>je ne pose pas de verrou</em>&laquo;&nbsp;, mais plus précisément : &laquo;&nbsp;<em>j&rsquo;ignore qu&rsquo;il y a des verrous et je lit ce que je peut</em>&nbsp;&raquo; (ceci est plus connu dans la littérature professionnelle sous le nom de <em><strong>lecture dans le chaos</strong></em>&#8230;). Vous pouvez donc lire plusieurs fois les mêmes données ou encore ne pas lire certaines.</p>
<p><strong>Quid du mode SNAPSHOT ?</strong></p>
<p>SNAPSHOT fait du verrouillage optimiste pour les lectures. Par défaut SQL Server fait du verrouillage pessimiste, c&rsquo;est à dire que les lectures posent des verrous qui permettent d&rsquo;autres lectures concurrentes (verrous partagés, mode &laquo;&nbsp;SHARE&nbsp;&raquo;), mais empêchent les écritures des autres utilisateurs. Conceptuellement, le verrouillage optimiste (donc via le mode d’isolation SNAPSHOT) fait une copie (si besoin) des données avant de permettre leurs lectures. Comme vous travaillez sur une copie, les utilisateurs concurrent peuvent modifier les vraies ligne sans que cela vous concerne. Bien entendu il peut toujours y avoir des conflits, mais cela réduit considérablement le nombre de verrous bloquants tout en gardant l&rsquo;intégrité et la consistante de la base, ce qui n&rsquo;est pas du tout le cas du NOLOCK.</p>
<p><strong>Alors, à quoi sert le NOLOCK ? </strong></p>
<p>Cela peut servir pour certains cas ou l&rsquo;on désire des résultats dont on se fout de l&rsquo;intégrité ou de la précision. Souvent dans le domaine de la statistique.<br />
par exemple si vous voulez savoir combien les français ont d&rsquo;enfant par foyer et scrutez donc, pour ce faire, une table de 60 millions de lignes (population française), je ne suis pas sûr que dans un camembert représentant la chose, on fasse la distinction des quelques pixels de l&rsquo;imprécision de la 6e décimale du résultat liées à quelques mauvaises lectures de lignes !<br />
On utilise d&rsquo;ailleurs très souvent le NOLOCK pour des tâches d&rsquo;administration systèmes dans SQL Server afin d&rsquo;éviter tout blocage au risque de perdre quelques lignes, ce qui n&rsquo;a pas toujours une importance capitale lorsque l&rsquo;on veut remonter quelques informations concernant les 20% de requêtes les moins performantes !</p>
<p><strong>Mais alors, le SNAPSHOT fait la même chose en mieux ? </strong></p>
<p>Oui et non&#8230; Certes il permet de garantir l&rsquo;intégrité, la consistance, etc&#8230; mais son mécanisme est plus lourd (un peu moins rapide) et consomme des ressources pour générer les copies (SNAPSHOT). Rassurez-vous il est assez malin pour ne faire ces copies qui s&rsquo;il a besoin de les faire&#8230; En d&rsquo;autres termes si aucun utilisateur concurrent veut faire des modif sur le jeu de lignes que vous manipulez en mode SNAPSHOT, aucune copie ne sera générée. Mais si, lorsque vous avez démarré une lecture en mode SNAPSHOT, un utilisateur concurrent veut modifier des lignes, et bien la copie sera réalisée au cours de votre lecture sans que vous vous en aperceviez&#8230; En quelque sorte le système fonctionne à l&rsquo;envers&#8230; Bien évidemment il faut un espace de stockage pour ces copies et c&rsquo;est la base tempdb qui s&rsquo;y colle. Il faut donc, la dimensionner correctement&#8230;<br />
Tiens, à nouveau un travail de DBA !</p>
<p><strong>Des conflits ! Quels conflits ?</strong></p>
<p>J&rsquo;ai précédemment parlé de conflits possible avec l&rsquo;utilisation du mode SNAPSHOT. En effet, si vous voulez modifier des données lors d&rsquo;une transaction en mode d’isolation SNAPSHOT, c&rsquo;est possible, mais ces modifications seront faites sur la copie, et non sur la base originale, et seront reportées sur la base originale au moment du COMMIT. Deux hypothèses se font alors jour :<br />
■ soit aucune ligne visée par vos modifications faites en mode SNAPSHOT n&rsquo;a été modifié dans une autre session directement sur la base, alors la mise à jour est appliquée.<br />
Ou alors :<br />
■ s&rsquo;il existe au moins une ligne qui a été modifiée par une autre session entre temps sur la base originale, alors vos modifications ne pourront être appliquées aux données originales et vont êtres abandonnées.<br />
Dans ce dernier cas vous obtiendrez une message d&rsquo;erreur (3960) assez abscons, qui indique :<br />
<em>&laquo;&nbsp;La transaction d&rsquo;isolement d&rsquo;instantané a été abandonnée en raison d&rsquo;un conflit de mise à jour. &#8230;&nbsp;&raquo;</em></p>
<p>Notez qu&rsquo;il existe un autre tag plus intéressant que le NOLOCK&#8230;. Le <strong>READPAST</strong> !&#8230;  Qui fait presque la même chose, mais ignore tout ce qui est verrouillé !</p>
<p><strong>Les modes d&rsquo;isolation selon la norme SQL</strong></p>
<p>Sachez que le mode d’isolation SNAPSHOT ne fait pas partie de la norme SQL qui n&rsquo;autorise que les modes d&rsquo;isolation suivants :<br />
0 &#8211; READ UNCOMMITTED : lecture des données invalides (non &laquo;&nbsp;committées&nbsp;&raquo;)<br />
1 &#8211; READ COMMITTED : lecture de données valides (ce qui n&rsquo;empêche pas certaines anomalies transactionnelles comme la lecture non répétable, ou l&rsquo;apparition de lignes fantômes)<br />
2 &#8211; REPEATABLE READ : lecture répétable de données (ce qui n&rsquo;empêche pas certaines anomalies transactionnelles comme l&rsquo;apparition de lignes fantômes)<br />
3 &#8211; SERIALIZABLE : lecture en mode série (aucun accès concurrent aux tables lors des mises à jour, ce qui empêche toute anomalies)<br />
Évidemment plus on monte le niveau d’isolation, plus le verrouillage est important et moins les accès concurrents peuvent travailler.<br />
La norme SQL considère que les manipulation des données doivent porter sur des valeurs &laquo;&nbsp;vivantes&nbsp;&raquo;. Hors, en utilisant le mode SNAPSHOT et son versionnement des lignes, ont est appelé à lire potentiellement des valeurs antérieurs des données, ce n&rsquo;est donc pas une lecture de l&rsquo;état actuel des valeurs dans la base&#8230;</p>
<p>Pour informations, des SGBRD comme Oracle, ou PostGreSQL fonctionnent nativement en mode d&rsquo;isolation SNAPSHOT, autrement dit utilisent systématiquement le verrouillage optimiste et ne savent pas faire autres choses (verrouillage pessimiste en particulier) voir ne savent même pas utiliser certains autres niveau d&rsquo;isolation. Par exemple PostGreSQL ne permet pas de faires des transaction en mode READ UNCOMMITTED et Oracle ne permettent pas d&rsquo;utiliser le niveau d&rsquo;isolation REPEATABLE READ&#8230;</p>
<p><strong>Activer le mode s&rsquo;isolation SNAPSHOT</strong></p>
<p>Pour permettre ce mode d&rsquo;isolation, vous devez d&rsquo;abord autoriser la base à utiliser le mode SNAPSHOT. Ce paramétrage est à deux niveaux :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ALTER DATABASE { CURRENT | nom_base } SET ALLOW_SNAPSHOT_ISOLATION ON;</div></div>
<p>permet d&rsquo;utiliser à tout moment le mode d’isolation SNAPSHOT qui doit être introduit préalablement par la commande SET TRANSACTION ISOLATION SNAPSHOT ou par un tag de table (SNAPSHOT)<br />
&#8230; et :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ALTER DATABASE { CURRENT | nom_base } SET READ_COMMITTED_SNAPSHOT ON;</div></div>
<p>qui place d&rsquo;office toutes les lectures en mode SNAPSHOT (comme le fait Oracle ou PostGreSQL);<br />
<strong>ATTENTION</strong> : pour assurer le versionnement des lignes, SQL Server rajoute à toutes les lignes de toutes les tables une information de version qui est codé sur 14 octets. Ceci peut prendre du temps à mettre en œuvre, en particulier sur de grosses bases.<br />
<strong></p>
<p>Appendice :</strong></p>
<p>Pour une démonstration des effets du NOLOCK : <a href="http://mssqlserver.fr/les-dangers-du-nolock/" rel="noopener" target="_blank">http://mssqlserver.fr/les-dangers-du-nolock/</a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extraire le code des requêtes d&#8217;un verrou mortel traqué par un graphe &#171;&#160;deadlock&#160;&#187; du profiler</title>
		<link>https://blog.developpez.com/sqlpro/p13176/ms-sql-server/extraire-le-code-des-requetes-dun-verrou-mortel-traque-par-un-graphe-deadlock-du-profiler</link>
		<comments>https://blog.developpez.com/sqlpro/p13176/ms-sql-server/extraire-le-code-des-requetes-dun-verrou-mortel-traque-par-un-graphe-deadlock-du-profiler#comments</comments>
		<pubDate>Thu, 22 Feb 2018 18:26:45 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[capture]]></category>
		<category><![CDATA[deadlock]]></category>
		<category><![CDATA[détection]]></category>
		<category><![CDATA[étreinte fatale]]></category>
		<category><![CDATA[interblocage]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[profiler]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[trace]]></category>
		<category><![CDATA[verrou mortel]]></category>
		<category><![CDATA[victime]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=794</guid>
		<description><![CDATA[L&#8217;outil profiler de SQL Server permet de partir à la chasse au verrous mortel et peut récupérer le graphe du verrouillage des éléments concurrents et notamment les données technique de la victime. Mais ce graphe est en fait un document XML contenant toutes les informations sur les processus en jeu, la victime et les survivants. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>L&rsquo;outil profiler de SQL Server permet de partir à la chasse au verrous mortel et peut récupérer le graphe du verrouillage des éléments concurrents et notamment les données technique de la victime. Mais ce graphe est en fait un document XML contenant toutes les informations sur les processus en jeu, la victime et les survivants. Il est alors intéressant d&rsquo;en extraire les requêtes fautives afin de corriger son code ou d&rsquo;indexer les tables, quelques un des moyens de se débarrasser des interblocages&#8230;<br />
<span id="more-794"></span><br />
Pour détecter les verrous mortels, il suffit de demander au profiler de tracer les événements de type &laquo;&nbsp;deadlock&nbsp;&raquo; de la catégorie &laquo;&nbsp;locks&nbsp;&raquo;, à savoir :</p>
<ul>
<li>Deadlock graph</li>
<li>Lock: Deadlock</li>
<li>Lock Deadlock Chain</li>
</ul>
<div id="attachment_797" style="width: 853px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2018/02/Profiler-Deadlock.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/02/Profiler-Deadlock.jpg" alt="Événements à cocher pour auditer les verrous mortels de SQL Server" width="843" height="540" class="size-full wp-image-797" /></a><p class="wp-caption-text">Événements à cocher pour auditer les verrous mortels de SQL Server</p></div>
<p>Une foi enregistrés, les données du profiler peuvent être vues par le client graphique sous cette forme :<br />
<div id="attachment_798" style="width: 1930px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2018/02/Profiler-SQL-Server-et-Deadlock.png"><img src="http://blog.developpez.com/sqlpro/files/2018/02/Profiler-SQL-Server-et-Deadlock.png" alt="Lecture des informations de verrous mortels dans le client graphique du profiler de SQL Server" width="1920" height="1040" class="size-full wp-image-798" /></a><p class="wp-caption-text">Lecture des informations de verrous mortels dans le client graphique du profiler de SQL Server</p></div></p>
<p>Néanmoins, il faut passer à l&rsquo;aide de sa souris sur chacune des bulles représentant les processus pour obtenir le texte des requêtes en jeu. Les rectangles visualisant les verrous, les pattes formant le graphe, qui lorsqu&rsquo;il présente un cycle contient un interblocage.</p>
<p>Dès lors, on peut récupérer les fichiers générés sous forme SQL via la fonction table sys.fn_trace_gettable dont le premier argument est le chemin de stockage des fichiers de trace du profiler et le second le numéro du fichier concerné. On peut aussi tous les obtenir en mettant le mot clef DEFAULT.<br />
L&rsquo;événement de graphe de verrouillage étant de classe 148, il suffit ensuite de filtrer sur ces lignes.<br />
Exemple :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT *<br />
FROM &nbsp; sys.fn_trace_gettable('C:\SQL_TRACE\20180219_14H30_DEADLOCK_.trc', default)</div></div>
<p>La colonne TextData de cette table virtuelle contient alors le XML donnant toutes les informations sur le verrou mortel. En voici un exemple :<br />
<div id="attachment_799" style="width: 780px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2018/02/Deadlock-XML-SQL-Server.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/02/Deadlock-XML-SQL-Server.jpg" alt="Document XML montrant toutes les informations d&#039;un verrou mortel survenu dans SQL Server" width="770" height="702" class="size-full wp-image-799" /></a><p class="wp-caption-text">Document XML montrant toutes les informations d&rsquo;un verrou mortel survenu dans SQL Server</p></div></p>
<p>Avec une requête mêlant du SQL et du XML via XQuery et XPath, il est possible d&rsquo;extraire ce qui nous intéresse, à savoir, le texte des requêtes en jeu ainsi qu&rsquo;une indication disant quelle est la victime et les survivants. Et comme il n&rsquo;y a pas qu&rsquo;un seul interblocage en général, alors on les identifie par un numéro. la requête au final ressemble à cela :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">WITH</span> <br />
TX <span style="color: #993333; font-weight: bold;">AS</span> <br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> StartTime<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>TextData <span style="color: #993333; font-weight: bold;">AS</span> xml<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TextData <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>fn_trace_gettable<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'C:<span style="color: #000099; font-weight: bold;">\!</span> FB<span style="color: #000099; font-weight: bold;">\R</span>henus<span style="color: #000099; font-weight: bold;">\2</span>018-02-19<span style="color: #000099; font-weight: bold;">\2</span>0180219_14H30_DEADLOCK_.trc'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;EventClass <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">148</span> <br />
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
TVM <span style="color: #993333; font-weight: bold;">AS</span> <br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> StartTime<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;v<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">VALUE</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'(./inputbuf)[1]'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'nvarchar(max)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> Query<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;i<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">VALUE</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'(./deadlock/@victim)[1]'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'varchar(32)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> ProcessVictim<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;v<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">VALUE</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'(./@id)[1]'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'varchar(32)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> ProcessID<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp;TX<br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">CROSS</span> APPLY TextData<span style="color: #66cc66;">.</span>nodes<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/deadlock-list'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> X<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">CROSS</span> APPLY TextData<span style="color: #66cc66;">.</span>nodes<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/deadlock-list/deadlock/process-list/process'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> V<span style="color: #66cc66;">&#40;</span>v<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
TVV <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> DENSE_RANK<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> StartTime<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> ID<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;StartTime<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;Query<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CASE</span> <span style="color: #993333; font-weight: bold;">WHEN</span> ProcessVictim <span style="color: #66cc66;">=</span> ProcessID <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'Victim!'</span> <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #ff0000;">'Alive'</span> <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">AS</span> FinalState<br />
<span style="color: #993333; font-weight: bold;">FROM</span> TVM<br />
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
TQV <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> ID<span style="color: #66cc66;">,</span> Query<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; TVV <br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;FinalState <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Victim!'</span><br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> TVV<span style="color: #66cc66;">.</span>ID<span style="color: #66cc66;">,</span> TVV<span style="color: #66cc66;">.</span>StartTime<span style="color: #66cc66;">,</span> TVV<span style="color: #66cc66;">.</span>Query<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CASE</span> <span style="color: #993333; font-weight: bold;">WHEN</span> TQV<span style="color: #66cc66;">.</span>ID <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'Victim!'</span> <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #ff0000;">'Alive'</span> <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">AS</span> FinalState <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; TVV <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> TQV<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">ON</span> TVV<span style="color: #66cc66;">.</span>ID <span style="color: #66cc66;">=</span> TQV<span style="color: #66cc66;">.</span>ID <span style="color: #993333; font-weight: bold;">AND</span> TVV<span style="color: #66cc66;">.</span>Query <span style="color: #66cc66;">=</span> TQV<span style="color: #66cc66;">.</span>Query<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #cc66cc;">1</span>;</div></div>
<p>Au final une telle requête permet de présenter les informations suivantes :<br />
<div id="attachment_807" style="width: 588px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2018/02/Resultat-requête-deadlock1.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/02/Resultat-requête-deadlock1.jpg" alt="Visualisation des requêtes en jeu dans un verrou mortel" width="578" height="383" class="size-full wp-image-807" /></a><p class="wp-caption-text">Visualisation des requêtes en jeu dans un verrou mortel</p></div><br />
Notez au passage le colonne &laquo;&nbsp;FinalState&nbsp;&raquo; indiquant quelle requête a été victime et celles ayant survécus.</p>
<p><a href="http://sqlpro.developpez.com/_fichierSQL/DEADLOCK-SQL.txt" title="Fichier du code" target="_blank">Le code ! Le code ! Le code ! Le code ! Le code ! Le code ! Le code ! Le code ! Le code ! Le code ! </a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Estimation des IO (ES) en lecture et écriture table par table d&#8217;une base SQL</title>
		<link>https://blog.developpez.com/sqlpro/p13175/ms-sql-server/estimation-des-io-es-en-lecture-et-ecriture-table-par-table-dune-base-sql</link>
		<comments>https://blog.developpez.com/sqlpro/p13175/ms-sql-server/estimation-des-io-es-en-lecture-et-ecriture-table-par-table-dune-base-sql#comments</comments>
		<pubDate>Wed, 21 Feb 2018 18:07:18 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[accès]]></category>
		<category><![CDATA[écriture]]></category>
		<category><![CDATA[ES]]></category>
		<category><![CDATA[IO]]></category>
		<category><![CDATA[lecture]]></category>
		<category><![CDATA[métrique]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[Statistiques]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=791</guid>
		<description><![CDATA[Les deux requêtes que je vous présente permettent d&#8217;estimer le nombres de pages lues et écrites table par table tenant compte de tous les index des tables. Attention : il ne s&#8217;agit pas d&#8217;une mesure exacte. Une telle mesure est impossible mais bien d&#8217;une estimation pour connaître les tables les plus écrites et celles les [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Les deux requêtes que je vous présente permettent d&rsquo;estimer le nombres de pages lues et écrites table par table tenant compte de tous les index des tables. Attention : il ne s&rsquo;agit pas d&rsquo;une mesure exacte. Une telle mesure est impossible mais bien d&rsquo;une estimation pour connaître les tables les plus écrites et celles les plus lues de manières relatives les unes aux autres.<br />
<span id="more-791"></span><br />
Elle se base sur le nombre d&rsquo;opération unitaire d&rsquo;accès effectué sur chaque table et index. En gros, il y a trois types d&rsquo;accès :<br />
1) un accès par balayage de la table ou de l&rsquo;index (scan) appelé &laquo;&nbsp;analyse&nbsp;&raquo; dans les plans de requête en français;<br />
2) un accès pour recherche dichotomique dans l&rsquo;index (seek) appelé &laquo;&nbsp;recherche&nbsp;&raquo; dans les plans de requête en français;<br />
3) un accès multi recherche dans l&rsquo;index (lookup) appelé &laquo;&nbsp;recherche de clés&nbsp;&raquo; dans les plans de requête en français;</p>
<p>Nous avons compter qu&rsquo;un SCAN balayait toutes les pages de l&rsquo;index ou de la table, ce qui est faux dans certains cas particulier (par exemple recherche TOP n)<br />
Nous avons compter qu&rsquo;un SEEK parcourait un nombre de page équivalent à la profondeur de l&rsquo;arbre ce qui n&rsquo;est pas vrai pour les recherches de type &laquo;&nbsp;range&nbsp;&raquo; (par exemple lors d&rsquo;un BETWEEN)<br />
Nous avons compter qu&rsquo;un LOOKUP était l&rsquo;équivalent de 10 seeks. Mais cela peut être plus ou moins et dans certains cas, ce n&rsquo;est même pas réellement l&rsquo;équivalent d&rsquo;un seek.</p>
<p>Ces approximations nous permettent quand même une bonne évaluation de la surface d&rsquo;attaque des données des tables en production, dans un but comparatif, voir les tables les plus accédées en lecture ou en écriture.</p>
<p><strong>La requête pour les lectures :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">WITH</span> <br />
idx_details <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> ius<span style="color: #66cc66;">.</span>object_id<span style="color: #66cc66;">,</span> ius<span style="color: #66cc66;">.</span>index_id<span style="color: #66cc66;">,</span> user_seeks<span style="color: #66cc66;">,</span> user_lookups<span style="color: #66cc66;">,</span> user_scans<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>INDEXPROPERTY<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">.</span>object_id<span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'IndexDepth '</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> index_depth<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>used_page_count<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> pages<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>dm_db_partition_stats <span style="color: #993333; font-weight: bold;">AS</span> s<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;s<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> ius<span style="color: #66cc66;">.</span>object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;s<span style="color: #66cc66;">.</span>index_id &nbsp;<span style="color: #66cc66;">=</span> ius<span style="color: #66cc66;">.</span>index_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> page_count<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>dm_db_index_usage_stats <span style="color: #993333; font-weight: bold;">AS</span> ius<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>indexes <span style="color: #993333; font-weight: bold;">AS</span> i<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> &nbsp;ius<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AND</span> ius<span style="color: #66cc66;">.</span>index_id &nbsp;<span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>index_id<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;database_id <span style="color: #66cc66;">=</span> DB_ID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">AND</span> &nbsp; &nbsp;ius<span style="color: #66cc66;">.</span>index_id &nbsp;<span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">OR</span> user_lookups <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">OR</span> user_scans <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> &nbsp;<br />
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
TOPT <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> s<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> TABLE_SCHEMA<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_seeks <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">*</span> user_lookups <span style="color: #66cc66;">*</span> index_depth<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_scans <span style="color: #66cc66;">*</span> page_count<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> IO_READS_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;">100.0</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_seeks <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">*</span> user_lookups <span style="color: #66cc66;">*</span> index_depth<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_scans <span style="color: #66cc66;">*</span> page_count<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NULLIF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_seeks <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">*</span> user_lookups <span style="color: #66cc66;">*</span> index_depth<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_scans <span style="color: #66cc66;">*</span> page_count<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;">OVER</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #993333; font-weight: bold;">AS</span> PERCENT_READS_ESTIMATE<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; idx_details <span style="color: #993333; font-weight: bold;">AS</span> id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>objects <span style="color: #993333; font-weight: bold;">AS</span> o<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> id<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> o<span style="color: #66cc66;">.</span>object_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>schemas <span style="color: #993333; font-weight: bold;">AS</span> s <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> s<span style="color: #66cc66;">.</span>schema_id <span style="color: #66cc66;">=</span> o<span style="color: #66cc66;">.</span>schema_id<br />
<span style="color: #993333; font-weight: bold;">GROUP</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name<br />
<span style="color: #993333; font-weight: bold;">HAVING</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_seeks <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">*</span> user_lookups <span style="color: #66cc66;">*</span> index_depth<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_scans <span style="color: #66cc66;">*</span> page_count<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> TABLE_SCHEMA<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> IO_READS_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>PERCENT_READS_ESTIMATE <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">DECIMAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> PERCENT_READS_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>PERCENT_READS_ESTIMATE<span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> PERCENT_READS_ESTIMATE <span style="color: #993333; font-weight: bold;">DESC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">DECIMAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> CUMUL_PERCENT<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> sqlserver_start_time <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>dm_os_sys_info<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> datetime2<span style="color: #66cc66;">&#40;</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> SINCE<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; TOPT<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> IO_READS_ESTIMATE <span style="color: #993333; font-weight: bold;">DESC</span>;</div></div>
<p><strong>La requête pour les écritures :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">WITH</span> <br />
idx_details <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> ius<span style="color: #66cc66;">.</span>object_id<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_updates <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> user_updates<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>dm_db_index_usage_stats <span style="color: #993333; font-weight: bold;">AS</span> ius<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>indexes <span style="color: #993333; font-weight: bold;">AS</span> i<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> ius<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>object_id <span style="color: #993333; font-weight: bold;">AND</span> ius<span style="color: #66cc66;">.</span>index_id <span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>index_id<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;database_id <span style="color: #66cc66;">=</span> DB_ID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">AND</span> &nbsp; &nbsp;ius<span style="color: #66cc66;">.</span>index_id &nbsp;<span style="color: #cc66cc;">0</span> <br />
<span style="color: #993333; font-weight: bold;">GROUP</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> ius<span style="color: #66cc66;">.</span>object_id<br />
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
TOPT <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> s<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> TABLE_SCHEMA<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;user_updates <span style="color: #993333; font-weight: bold;">AS</span> IO_WRITES_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;">100.0</span> <span style="color: #66cc66;">*</span> user_updates <span style="color: #66cc66;">/</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_updates<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> PERCENT_WRITES_ESTIMATE<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; idx_details <span style="color: #993333; font-weight: bold;">AS</span> id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>objects <span style="color: #993333; font-weight: bold;">AS</span> o<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> id<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> o<span style="color: #66cc66;">.</span>object_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>schemas <span style="color: #993333; font-weight: bold;">AS</span> s <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> s<span style="color: #66cc66;">.</span>schema_id <span style="color: #66cc66;">=</span> o<span style="color: #66cc66;">.</span>schema_id<br />
<span style="color: #993333; font-weight: bold;">GROUP</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> user_updates<br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> TABLE_SCHEMA<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> IO_WRITES_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>PERCENT_WRITES_ESTIMATE <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">DECIMAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> PERCENT_WRITES_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>PERCENT_WRITES_ESTIMATE<span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> PERCENT_WRITES_ESTIMATE <span style="color: #993333; font-weight: bold;">DESC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">DECIMAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> CUMUL_PERCENT<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> sqlserver_start_time <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>dm_os_sys_info<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> datetime2<span style="color: #66cc66;">&#40;</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> SINCE<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; TOPT<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> PERCENT_WRITES_ESTIMATE <span style="color: #993333; font-weight: bold;">DESC</span>;</div></div>
<p><em>Un exemple de résultat pour la lecture :</em></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">TABLE_SCHEMA &nbsp; TABLE_NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IO_READS_ESTIMATE &nbsp; &nbsp;PERCENT_READS_ESTIMATE &nbsp;CUMUL_PERCENT &nbsp; SINCE<br />
-------------- --------------------------- -------------------- ----------------------- --------------- ---------------------------<br />
S_GEO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;COMMUNE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 748792 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 55.59 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 55.59 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2018-01-16 16:17:28<br />
S_RTE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TRONCON_ROUTE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 520044 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 38.61 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 94.19 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2018-01-16 16:17:28<br />
S_ADR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CODE_INSEE_CODE_POSTAL &nbsp; &nbsp; &nbsp;42147 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3.13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;97.32 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2018-01-16 16:17:28<br />
S_GEO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DEPARTEMENT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 36057 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.68 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;100.00 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2018-01-16 16:17:28</div></div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Métrique de volumétrie du stockage par table, index et partition</title>
		<link>https://blog.developpez.com/sqlpro/p13171/ms-sql-server/metrique-de-volumetrie-du-stockage-par-table-index-et-partition</link>
		<comments>https://blog.developpez.com/sqlpro/p13171/ms-sql-server/metrique-de-volumetrie-du-stockage-par-table-index-et-partition#comments</comments>
		<pubDate>Wed, 07 Feb 2018 09:19:04 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[métrique]]></category>
		<category><![CDATA[partition]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[stockage]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=789</guid>
		<description><![CDATA[Voici une petite requête complémentaire pour mesurer les volumes stockées par partition, index et tables d&#8217;une base : SELECT s.name AS TABLE_SCHEMA, o.name AS TABLE_NAME, i.name AS INDEX_NAME, &#160; &#160; &#160; &#160;fs.name AS FILEGROUP_NAME, f.name AS FILE_NAME, f.physical_name, p.partition_number, &#160; &#160; &#160; &#160;p.ROWS, p.data_compression_desc, au.total_pages * 8 AS SIZE_TOTAL_KO, &#160; &#160; &#160; &#160;SUM&#40;au.total_pages * 8&#41; [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Voici une petite requête complémentaire pour mesurer les volumes stockées par partition, index et tables d&rsquo;une base :<br />
<span id="more-789"></span></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> s<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> TABLE_SCHEMA<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> INDEX_NAME<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;fs<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> FILEGROUP_NAME<span style="color: #66cc66;">,</span> f<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> FILE_NAME<span style="color: #66cc66;">,</span> f<span style="color: #66cc66;">.</span>physical_name<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>partition_number<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;p<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">ROWS</span><span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>data_compression_desc<span style="color: #66cc66;">,</span> au<span style="color: #66cc66;">.</span>total_pages <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">8</span> <span style="color: #993333; font-weight: bold;">AS</span> SIZE_TOTAL_KO<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>au<span style="color: #66cc66;">.</span>total_pages <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span>PARTITION <span style="color: #993333; font-weight: bold;">BY</span> i<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> SIZE_TOTAL_INDEX_KO<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>au<span style="color: #66cc66;">.</span>total_pages <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span>PARTITION <span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> SIZE_TOTAL_TABLE_KO<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>partitions <span style="color: #993333; font-weight: bold;">AS</span> p<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>allocation_units <span style="color: #993333; font-weight: bold;">AS</span> au<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> p<span style="color: #66cc66;">.</span>hobt_id <span style="color: #66cc66;">=</span> au<span style="color: #66cc66;">.</span>container_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>filegroups <span style="color: #993333; font-weight: bold;">AS</span> fs<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> au<span style="color: #66cc66;">.</span>data_space_id <span style="color: #66cc66;">=</span> fs<span style="color: #66cc66;">.</span>data_space_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>database_files <span style="color: #993333; font-weight: bold;">AS</span> f<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> fs<span style="color: #66cc66;">.</span>data_space_id <span style="color: #66cc66;">=</span> f<span style="color: #66cc66;">.</span>file_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>objects <span style="color: #993333; font-weight: bold;">AS</span> o<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> p<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> o<span style="color: #66cc66;">.</span>object_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>schemas <span style="color: #993333; font-weight: bold;">AS</span> s <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> o<span style="color: #66cc66;">.</span>schema_id <span style="color: #66cc66;">=</span> s<span style="color: #66cc66;">.</span>schema_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>indexes <span style="color: #993333; font-weight: bold;">AS</span> i<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> p<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>index_id <span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>index_id;</div></div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vérification de la dernière sauvegarde d&#8217;une base</title>
		<link>https://blog.developpez.com/sqlpro/p13170/ms-sql-server/verification-de-la-derniere-sauvegarde-dune-base</link>
		<comments>https://blog.developpez.com/sqlpro/p13170/ms-sql-server/verification-de-la-derniere-sauvegarde-dune-base#comments</comments>
		<pubDate>Thu, 01 Feb 2018 10:51:55 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[verification]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=787</guid>
		<description><![CDATA[Parmi les opérations importantes à systématiser, la vérification de consistance d&#8217;une sauvegarde est une opération à ne pas négliger. Mais compte tendu qu&#8217;une sauvegarde peut être multi-famille (donc répartie sur plusieurs fichiers), multi-support (donc redondées dans plusieurs destinations) ou intégré dans un &#171;&#160;device&#160;&#187; (donc noyée au milieu de plusieurs sauvegarde dans un fichier), la complexité [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Parmi les opérations importantes à systématiser, la vérification de consistance d&rsquo;une sauvegarde est une opération à ne pas négliger. Mais compte tendu qu&rsquo;une sauvegarde peut être multi-famille (donc répartie sur plusieurs fichiers), multi-support (donc redondées dans plusieurs destinations) ou intégré dans un &laquo;&nbsp;device&nbsp;&raquo; (donc noyée au milieu de plusieurs sauvegarde dans un fichier), la complexité augmente d&rsquo;autant. Voici donc une petite procédure pour ce faire&#8230;<br />
<span id="more-787"></span></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> P_VERIFY_LAST_BACKUP @DB sysname<br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<br />
<span style="color: #993333; font-weight: bold;">SET</span> NOCOUNT <span style="color: #993333; font-weight: bold;">ON</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @<span style="color: #993333; font-weight: bold;">SQL</span> NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">''</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">WITH</span> <br />
T0 <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> TOP <span style="color: #cc66cc;">1</span> media_set_id<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">POSITION</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; msdb<span style="color: #66cc66;">.</span>dbo<span style="color: #66cc66;">.</span>backupset<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;database_name <span style="color: #66cc66;">=</span> @DB<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> backup_start_date <span style="color: #993333; font-weight: bold;">DESC</span><br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'RESTORE VERIFYONLY FROM DISK = '</span><span style="color: #ff0000;">''</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">+</span> physical_device_name <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">''</span><span style="color: #ff0000;">' WITH FILE = '</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">POSITION</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">';'</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; msdb<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>backupmediafamily<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> mf<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> T0 <span style="color: #993333; font-weight: bold;">ON</span> mf<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>media_set_id<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> T0<span style="color: #66cc66;">.</span>media_set_id;<br />
<br />
PRINT @<span style="color: #993333; font-weight: bold;">SQL</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">EXEC</span> <span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<p>Exemple d&rsquo;utilisation :</p>
<p>EXEC P_VERIFY_LAST_BACKUP &lsquo;master';</p>
<p><a href="http://sqlpro.developpez.com/_fichierSQL/SET_STATISTIS_IO_AGGREGATE.txt" title="Fichier du code" target="_blank">Le code !</a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
<div id="attachment_590" style="width: 548px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg"><img src="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg" alt="Développez et administrez pour la performance avec SQL Server 2014" width="538" height="652" class="size-full wp-image-590" /></a><p class="wp-caption-text">Développez et administrez pour la performance avec SQL Server 2014</p></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Agrégation des statistiques d&#8217;IO d&#8217;une requête</title>
		<link>https://blog.developpez.com/sqlpro/p13157/ms-sql-server/agregation-des-statistiques-dio-dune-requete</link>
		<comments>https://blog.developpez.com/sqlpro/p13157/ms-sql-server/agregation-des-statistiques-dio-dune-requete#comments</comments>
		<pubDate>Thu, 28 Dec 2017 18:55:58 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[ES]]></category>
		<category><![CDATA[IO]]></category>
		<category><![CDATA[performance requête]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[STATISTICS IO]]></category>
		<category><![CDATA[statistiques entrées sorties]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=778</guid>
		<description><![CDATA[Si le paramétrage SET STATISTICS IO ON de Microsoft SQL Server permet de savoir, table par table les statistiques d&#8217;entrées/sorties (IO pour Input/Output) des requêtes, il n&#8217;est pas toujours facile de s&#8217;y repérer lorsque la requête est complexe et fait appel à de multiples tables. Voici une procédure qui en effectue la synthèse. Rappelons que [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Si le paramétrage <strong>SET STATISTICS IO ON</strong> de Microsoft SQL Server permet de savoir, table par table les statistiques d&rsquo;entrées/sorties (IO pour Input/Output) des requêtes, il n&rsquo;est pas toujours facile de s&rsquo;y repérer lorsque la requête est complexe et fait appel à de multiples tables. Voici une procédure qui en effectue la synthèse.<br />
<span id="more-778"></span><br />
Rappelons que les statistiques IO sont le nombre de pages lues par le moteur SQL pour exécuter une requête. Le paramètre de session STATISTICS IO peut être mis à ON ou OFF. Par défaut il est à OFF. Mis sur ON, il permet, dans SQL Server Management Studio (SSMS), de voir le nombre de pages accédées pour une requête ou un lot de requête. C&rsquo;est une série de message d&rsquo;une ligne commençant par &laquo;&nbsp;Table&#8230;&nbsp;&raquo; qui suit immédiatement le message indiquant le nombre de lignes affectées par la requête.<br />
<div id="attachment_780" style="width: 530px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO.jpg"><img src="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO.jpg" alt="SQL Server onglet message STATISTICS IO" width="520" height="310" class="size-full wp-image-780" /></a><p class="wp-caption-text">SQL Server onglet message STATISTICS IO</p></div> </p>
<p>Néanmoins il est assez difficile de lire tout cela et d&rsquo;en déduire une tendance globale.<br />
Ne serait-ce pas plus intéressante de les présenter de cette manière :<br />
<div id="attachment_781" style="width: 989px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL.jpg"><img src="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL.jpg" alt="SQL Server STATISTICS IO aggregate" width="979" height="329" class="size-full wp-image-781" /></a><p class="wp-caption-text">Statistiques IO SQL Server avec totaux et agrégation</p></div></p>
<p>La petite procédure que voici permet justement d&rsquo;effectuer cette tâche. Il suffit de lui passer le texte complet des message d&rsquo;IO et elle vous retournera tout cela, formaté, totalisé et agrégé !</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">USE</span> msdb;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">CREATE</span> SCHEMA S_DBA;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> S_DBA<span style="color: #66cc66;">.</span>P_SPLIT_STATS_IO @<span style="color: #993333; font-weight: bold;">DATA</span> NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #993333; font-weight: bold;">SET</span> NOCOUNT <span style="color: #993333; font-weight: bold;">ON</span>;<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @LINE NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">SQL</span> NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">''</span>;<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @L <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#40;</span>LINE NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">800</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @T <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sysname<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SCAN_COUNT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGICAL_READS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PHYSICAL_READS &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; READ_AHEAD_READS &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOB_LOGICAL_READS &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOB_PHYSICAL_READS &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOB_READ_AHEAD_READS &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
WHILE CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">LEFT</span><span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">,</span> CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @L <span style="color: #993333; font-weight: bold;">SELECT</span> @LINE;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @<span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">RIGHT</span><span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">,</span> LEN<span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @L <span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">DATA</span>;<br />
<span style="color: #993333; font-weight: bold;">DELETE</span> @L <span style="color: #993333; font-weight: bold;">WHERE</span> LINE <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">''</span> <span style="color: #993333; font-weight: bold;">OR</span> LINE <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">LIKE</span> N<span style="color: #ff0000;">'%Table %'</span> <span style="color: #993333; font-weight: bold;">COLLATE</span> French_BIN;<br />
<br />
<span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @L <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;LINE <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%Nombre d'</span><span style="color: #ff0000;">'analyses%'</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">--&gt; français</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Table '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">','</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' lectures logiques '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' lectures physiques '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' lectures anticipées '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'de données d'</span><span style="color: #ff0000;">'objets volumineux '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @L <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;LINE <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%Scan count%'</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">--&gt; anglais</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Table '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'. Scan count '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">','</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' logical reads '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' physical reads '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' read-ahead reads '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'lob'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'SELECT '</span> <span style="color: #66cc66;">+</span> LINE <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' UNION ALL '</span> <span style="color: #993333; font-weight: bold;">FROM</span> @L;<br />
<span style="color: #993333; font-weight: bold;">SET</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">LEFT</span><span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">,</span> LEN<span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @T<br />
<span style="color: #993333; font-weight: bold;">EXEC</span> <span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">WITH</span> <br />
T <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @T<br />
<span style="color: #993333; font-weight: bold;">UNION</span> <span style="color: #993333; font-weight: bold;">ALL</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'°°° TOTAL °°°'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>SCAN_COUNT<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOGICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>PHYSICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>READ_AHEAD_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOB_LOGICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOB_PHYSICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOB_READ_AHEAD_READS<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @T<br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
<span style="color: #993333; font-weight: bold;">FROM</span> T<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #993333; font-weight: bold;">CASE</span> <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'°°° TOTAL °°°'</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">END</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LOGICAL_READS <span style="color: #993333; font-weight: bold;">DESC</span>; &nbsp;<br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>SCAN_COUNT<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TOTAL_SCANS<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOGICAL_READS <span style="color: #66cc66;">+</span> LOB_LOGICAL_READS<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TOTAL_LOGICAL_READS<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>PHYSICAL_READS <span style="color: #66cc66;">+</span> READ_AHEAD_READS <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LOB_PHYSICAL_READS <span style="color: #66cc66;">+</span> LOB_READ_AHEAD_READS<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TOTAL_PHYSICAL_READS<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @T;<br />
<br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<p><strong>Exemple d&rsquo;utilisation :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">EXECUTE</span> msdb<span style="color: #66cc66;">.</span>S_DBA<span style="color: #66cc66;">.</span>P_SPLIT_STATS_IO <span style="color: #ff0000;">'Table '</span><span style="color: #ff0000;">'PARAM_EAC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 13, lectures logiques 26, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'Worktable'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 0, lectures logiques 0, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'VAL_PARAM_EAC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 1, lectures logiques 59, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'ESP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 31, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'TL_EXP_COOP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 178, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'UC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 5633, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'TL_PP_UC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 1254, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'PG'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 85289, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'Worktable'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 0, lectures logiques 0, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'PG'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 1, lectures logiques 437, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'PP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 7271, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'EXP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 1996, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'VAR'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 866, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.'</span></div></div>
<p>Le résultat :<br />
<div id="attachment_782" style="width: 986px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL-results.jpg"><img src="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL-results.jpg" alt="Les statistiques d&#039;IO d&#039;une requête, sus forme tabulaire, totalisés et agrégés" width="976" height="337" class="size-full wp-image-782" /></a><p class="wp-caption-text">Les statistiques d&rsquo;IO d&rsquo;une requête, sous forme tabulaire, totalisés et agrégés</p></div></p>
<p><strong>QUELQUES EXPLICATIONS SUR LES MÉTRIQUES</strong></p>
<li><strong>analyses</strong> (scan count) : nombre de fois ou l&rsquo;exécuteur de requête a du pénétrer dans un index de la table ou dans la table (en cas de parallélisme, autant de fois que de threads&#8230;)</li>
<li><strong>lectures logiques</strong> (logical reads) : nombre de pages lues en RAM</li>
<li><strong>lectures physiques</strong> (physical reads) : nombre de pages lues depuis le disque (avec transfert en RAM) en mode aléatoire.</li>
<li><strong>lectures anticipées</strong> (read-ahead physical read) : nombre de pages lues depuis le disque (avec transfert en RAM) en mode continu.</li>
<li>&#8230;<strong>d&rsquo;objets volumineux</strong> (lob &#8230;) : nombre de pages &#8230; pour les &laquo;&nbsp;Large OBjects&nbsp;&raquo;.
</li>
<p><strong>NOTA </strong>: cet outil fonctionne que votre serveur soit en anglais ou français.</p>
<p><strong>LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE</strong><br />
<a href="http://sqlpro.developpez.com/_fichierSQL/SET_STATISTIS_IO_AGGREGATE.txt" title="Fichier du code" target="_blank">Le code !</a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
<div id="attachment_590" style="width: 548px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg"><img src="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg" alt="Développez et administrez pour la performance avec SQL Server 2014" width="538" height="652" class="size-full wp-image-590" /></a><p class="wp-caption-text">Développez et administrez pour la performance avec SQL Server 2014</p></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Une fonction de comptage d&#8217;occurrence</title>
		<link>https://blog.developpez.com/sqlpro/p13156/ms-sql-server/une-fonction-de-comptage-doccurrence</link>
		<comments>https://blog.developpez.com/sqlpro/p13156/ms-sql-server/une-fonction-de-comptage-doccurrence#comments</comments>
		<pubDate>Thu, 16 Nov 2017 17:51:42 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[caractères]]></category>
		<category><![CDATA[comptage]]></category>
		<category><![CDATA[fonction]]></category>
		<category><![CDATA[occurrence]]></category>
		<category><![CDATA[SQL server]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=776</guid>
		<description><![CDATA[La petite fonction qui suit permet de compter le nombre de fois ou un caractère est présent dans une chaine de caractères. CREATE FUNCTION F_COUNT_CHAR&#40;@STR NVARCHAR&#40;MAX&#41;, @CHR NCHAR&#40;1&#41;&#41; RETURNS INT WITH RETURNS NULL ON NULL INPUT AS BEGIN DECLARE @NBR INT, @POS INT; SELECT @NBR = 0, @POS = CHARINDEX&#40;@CHR, @STR&#41;; WHILE @POS &#62; 0 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>La petite fonction qui suit permet de compter le nombre de fois ou un caractère est présent dans une chaine de caractères.</p>
<p><span id="more-776"></span></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span>@STR NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @CHR <span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">RETURNS</span> <span style="color: #993333; font-weight: bold;">INT</span><br />
<span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #993333; font-weight: bold;">RETURNS</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">INPUT</span><br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @NBR <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">,</span> @POS <span style="color: #993333; font-weight: bold;">INT</span>;<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @NBR <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> @POS <span style="color: #66cc66;">=</span> CHARINDEX<span style="color: #66cc66;">&#40;</span>@CHR<span style="color: #66cc66;">,</span> @STR<span style="color: #66cc66;">&#41;</span>;<br />
WHILE @POS <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @NBR <span style="color: #66cc66;">=</span> @NBR <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @POS <span style="color: #66cc66;">=</span> CHARINDEX<span style="color: #66cc66;">&#40;</span>@CHR<span style="color: #66cc66;">,</span> @STR<span style="color: #66cc66;">,</span> @POS <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<span style="color: #993333; font-weight: bold;">RETURN</span> @NBR;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<p>Exemples d&rsquo;utilisation :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><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;">-- exemple &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- résultat</span><br />
<span style="color: #808080; font-style: italic;">------------------------------------------- ------------</span><br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'abracadabra'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'a'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">--&gt; 5</span><br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'a'</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">--&gt; 0</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'a'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">--&gt; 0</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">--&gt; 0</span><br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'a'</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">--&gt; NULL</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'a'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">--&gt; NULL</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">--&gt; NULL</span></div></div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
<div id="attachment_590" style="width: 548px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg"><img src="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg" alt="Développez et administrez pour la performance avec SQL Server 2014" width="538" height="652" class="size-full wp-image-590" /></a><p class="wp-caption-text">Développez et administrez pour la performance avec SQL Server 2014</p></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Métadonnées de l&#8217;utilisation d&#8217;une colonne</title>
		<link>https://blog.developpez.com/sqlpro/p13155/ms-sql-server/metadonnees-de-lutilisation-dune-colonne</link>
		<comments>https://blog.developpez.com/sqlpro/p13155/ms-sql-server/metadonnees-de-lutilisation-dune-colonne#comments</comments>
		<pubDate>Mon, 23 Oct 2017 07:07:13 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[colonne]]></category>
		<category><![CDATA[contrainte]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[métadonnées]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=765</guid>
		<description><![CDATA[Certaines modifications de type de données d&#8217;une colonne nécessitent une suppression préalable des contraintes et index. Pour vous y aider, la procédure suivante indique dans quels objets (index ou contraintes) une colonne d&#8217;une table passée en argument est enrôlée. Dans le cas ou vous voudriez changer le type d&#8217;une telle colonne, il faudrait agir manuellement [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Certaines modifications de type de données d&rsquo;une colonne nécessitent une suppression préalable des contraintes et index. Pour vous y aider, la procédure suivante indique dans quels objets (index ou contraintes) une colonne d&rsquo;une table passée en argument est enrôlée.<br />
<span id="more-765"></span></p>
<p>Dans le cas ou vous voudriez changer le type d&rsquo;une telle colonne, il faudrait agir manuellement avec le scénario suivant :</p>
<p>1)	Scripter la création des contraintes par clic droit sur le nom de chacune des contraintes et les supprimer<br />
2)	Scripter la création des index par clic droit sur le nom de chacun des index et les supprimer<br />
3)	Modifier le type de données de la colonne avec la commande ALTER TABLE … ALTER COLUMN …<br />
4)	Recréer les index<br />
5)	Recréer les contraintes</p>
<p>Cette procédure à été créée pour vous y aider. Elle indique pour un couple d’information table/colonne dans quels index ou contrainte cette dernière est enrôlée&#8230;<br />
Cette procédure est créée en tant que procédure système afin d&rsquo;être exploitable dans n&rsquo;importe quelle base de l&rsquo;instance SQL Server.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">USE</span> master;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>all_objects<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'sp__COLUMN_IS_USED'</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;schema_id <span style="color: #66cc66;">=</span> SCHEMA_ID<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'dbo'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">EXEC</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ROP PROCEDURE dbo.sp__COLUMN_IS_USED;'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #808080; font-style: italic;">--===========================================================================--</span><br />
<span style="color: #808080; font-style: italic;">-- METADONNÉES D'UTILISATION D'UNE COLONNE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --</span><br />
<span style="color: #808080; font-style: italic;">--===========================================================================--</span><br />
<span style="color: #808080; font-style: italic;">-- Fredéric Brouard alias SQLpro &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;http://sqlpro.developpez.com --</span><br />
<span style="color: #808080; font-style: italic;">-- Société SQL SPOT - http://www.sqlspot.com &nbsp; &nbsp; &nbsp; &nbsp;2017-10-13 - version 1.0 --</span><br />
<span style="color: #808080; font-style: italic;">--===========================================================================--</span><br />
<br />
<br />
<span style="color: #808080; font-style: italic;">--▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄--</span><br />
<span style="color: #808080; font-style: italic;">-- PHASE 1 : création de la procédure &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--</span><br />
<span style="color: #808080; font-style: italic;">--▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀--</span><br />
<br />
<br />
<span style="color: #993333; font-weight: bold;">USE</span> master;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> dbo<span style="color: #66cc66;">.</span>sp__COLUMN_IS_USED @OBJ NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">261</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @COL NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">128</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">NULL</span><br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #808080; font-style: italic;">/******************************************************************************<br />
* METADONNÉES D'UTILISATION D'UNE COLONNE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* Procédure listant sous forme de tables dans quels objets est utilisé une &nbsp; &nbsp;*<br />
* colonne d'une table &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; *<br />
******************************************************************************* &nbsp; <br />
* Frédéric Brouard - SQLpro@SQLspot.com - Sté SQL SPOT http://www.sqlspot.com *<br />
* Plus d'info. sur http://sqlpro.developpez.com &nbsp; - &nbsp;2017-10-13 - version 1.0 * &nbsp; <br />
******************************************************************************* &nbsp; <br />
* Cette procédure prend en argument le nom d'une table avec son schéma SQL &nbsp; &nbsp;*<br />
* (sinon le schéma par défaut de l'utilisateur qui la lance) ainsi qu'un nom &nbsp;*<br />
* de colonne et renvoie un jeu de données contenant le descriptif des cas &nbsp; &nbsp; *<br />
* d'utilisation de cette colonne dans les index et les contraintes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
*******************************************************************************<br />
* ATTENTION &nbsp;: procédure système ! Exécutable depuis n'importe quelle base &nbsp; &nbsp;*<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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* Paramètre en entrée : &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; *<br />
* &nbsp; &nbsp;@OBJ type NVARCHAR(261) : nom de table dont on veut connaître les index &nbsp;*<br />
* &nbsp; &nbsp;@COL nom de la colonne dont on veut connaître l'usage &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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* COLONNE de la table en sortie : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;COLUMN_NAME &nbsp; nom de la colonne passée en paramètre &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;OBJECT_TYPE &nbsp; type d'objet (nature de la contrainte ou INDEX) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;OBJECT_NAME &nbsp; nom de la contrainte ou de l'index &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
<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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* EXEMPLE : &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; &nbsp; *<br />
* &nbsp; &nbsp;EXEC dbo.sp__COLUMN_IS_USED 'CC', 'Idx' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;... donne la liste de tous les index et contrainte de la table CC &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp; &nbsp; &nbsp;incluant la colonne Idx &nbsp; &nbsp; &nbsp; &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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
******************************************************************************/</span> <br />
<br />
<span style="color: #993333; font-weight: bold;">SET</span> NOCOUNT <span style="color: #993333; font-weight: bold;">ON</span>;<br />
<span style="color: #993333; font-weight: bold;">WITH</span> T <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> COLUMN_NAME<span style="color: #66cc66;">,</span> CONSTRAINT_TYPE <span style="color: #993333; font-weight: bold;">AS</span> OBJECT_TYPE<span style="color: #66cc66;">,</span> KCU<span style="color: #66cc66;">.</span>CONSTRAINT_NAME <span style="color: #993333; font-weight: bold;">AS</span> OBJECT_NAME <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; INFORMATION_SCHEMA<span style="color: #66cc66;">.</span>KEY_COLUMN_USAGE <span style="color: #993333; font-weight: bold;">AS</span> KCU<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> INFORMATION_SCHEMA<span style="color: #66cc66;">.</span>TABLE_CONSTRAINTS <span style="color: #993333; font-weight: bold;">AS</span> TC<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> KCU<span style="color: #66cc66;">.</span>TABLE_SCHEMA <span style="color: #66cc66;">=</span> TC<span style="color: #66cc66;">.</span>TABLE_SCHEMA &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> KCU<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #66cc66;">=</span> TC<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> KCU<span style="color: #66cc66;">.</span>CONSTRAINT_NAME <span style="color: #66cc66;">=</span> TC<span style="color: #66cc66;">.</span>CONSTRAINT_NAME<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;OBJECT_ID<span style="color: #66cc66;">&#40;</span>KCU<span style="color: #66cc66;">.</span>TABLE_SCHEMA <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'.'</span> <span style="color: #66cc66;">+</span> KCU<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> OBJECT_ID<span style="color: #66cc66;">&#40;</span>@OBJ<span style="color: #66cc66;">&#41;</span> <br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;<span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>RTRIM<span style="color: #66cc66;">&#40;</span>LTRIM<span style="color: #66cc66;">&#40;</span>@COL<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">']'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'['</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> COLUMN_NAME<br />
<span style="color: #993333; font-weight: bold;">UNION</span> <span style="color: #993333; font-weight: bold;">ALL</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>RTRIM<span style="color: #66cc66;">&#40;</span>LTRIM<span style="color: #66cc66;">&#40;</span>@COL<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">']'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'['</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> CONSTRAINT_TYPE <span style="color: #993333; font-weight: bold;">AS</span> OBJECT_TYPE<span style="color: #66cc66;">,</span> CK<span style="color: #66cc66;">.</span>CONSTRAINT_NAME <span style="color: #993333; font-weight: bold;">AS</span> OBJECT_NAME <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; INFORMATION_SCHEMA<span style="color: #66cc66;">.</span>CHECK_CONSTRAINTS <span style="color: #993333; font-weight: bold;">AS</span> CK<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> INFORMATION_SCHEMA<span style="color: #66cc66;">.</span>TABLE_CONSTRAINTS <span style="color: #993333; font-weight: bold;">AS</span> TC<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> CK<span style="color: #66cc66;">.</span>CONSTRAINT_SCHEMA <span style="color: #66cc66;">=</span> TC<span style="color: #66cc66;">.</span>CONSTRAINT_SCHEMA &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> CK<span style="color: #66cc66;">.</span>CONSTRAINT_NAME <span style="color: #66cc66;">=</span> TC<span style="color: #66cc66;">.</span>CONSTRAINT_NAME<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;OBJECT_ID<span style="color: #66cc66;">&#40;</span>TC<span style="color: #66cc66;">.</span>TABLE_SCHEMA <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'.'</span> <span style="color: #66cc66;">+</span> TC<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> OBJECT_ID<span style="color: #66cc66;">&#40;</span>@OBJ<span style="color: #66cc66;">&#41;</span> <br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;CHECK_CLAUSE <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%'</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>RTRIM<span style="color: #66cc66;">&#40;</span>LTRIM<span style="color: #66cc66;">&#40;</span>@COL<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">']'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'['</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'%'</span><br />
<span style="color: #993333; font-weight: bold;">UNION</span> <span style="color: #993333; font-weight: bold;">ALL</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> c<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'INDEX'</span><span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">.</span>name <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>indexes <span style="color: #993333; font-weight: bold;">AS</span> i <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>index_columns <span style="color: #993333; font-weight: bold;">AS</span> ic <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> i<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> ic<span style="color: #66cc66;">.</span>object_id <span style="color: #993333; font-weight: bold;">AND</span> i<span style="color: #66cc66;">.</span>index_id <span style="color: #66cc66;">=</span> ic<span style="color: #66cc66;">.</span>index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">COLUMNS</span> <span style="color: #993333; font-weight: bold;">AS</span> c <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> ic<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>object_id <span style="color: #993333; font-weight: bold;">AND</span> ic<span style="color: #66cc66;">.</span>column_id <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>column_id<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;i<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> OBJECT_ID<span style="color: #66cc66;">&#40;</span>@OBJ<span style="color: #66cc66;">&#41;</span> <br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;<span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>RTRIM<span style="color: #66cc66;">&#40;</span>LTRIM<span style="color: #66cc66;">&#40;</span>@COL<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">']'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'['</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; T<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #993333; font-weight: bold;">CASE</span> OBJECT_TYPE <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #ff0000;">'PRIMARY KEY'</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #ff0000;">'UNIQUE'</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #ff0000;">'FOREIGN KEY'</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #cc66cc;">3</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #ff0000;">'CHECK'</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #cc66cc;">4</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #ff0000;">'INDEX'</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #cc66cc;">5</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #cc66cc;">99</span> <span style="color: #993333; font-weight: bold;">END</span><span style="color: #66cc66;">,</span> OBJECT_NAME; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<br />
<span style="color: #808080; font-style: italic;">--▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄--</span><br />
<span style="color: #808080; font-style: italic;">-- PHASE 2 : traduction en procédure système &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --</span><br />
<span style="color: #808080; font-style: italic;">--▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀--</span><br />
<br />
<span style="color: #993333; font-weight: bold;">EXEC</span> sp_MS_marksystemobject <span style="color: #ff0000;">'sp__COLUMN_IS_USED'</span>;</div></div>
<p>Pour utiliser cette procédure, lancez la avec EXEC et passez le nom de table éventuellement préfixé par son schéma SQL ainsi que le nom de la colonne. Exemple :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">EXEC sp__COLUMN_IS_USED 'matable', 'macolonne';</div></div>
<p><a href="http://sqlpro.developpez.com/_fichierSQL/sp__COLUMN_IS_USED.txt" title="CODE SQL" rel="noopener" target="_blank">LE CODE ! LE CODE ! LE CODE ! LE CODE ! LE CODE ! LE CODE ! LE CODE ! LE CODE ! LE CODE ! LE CODE !</a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
<div id="attachment_590" style="width: 548px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg"><img src="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg" alt="Développez et administrez pour la performance avec SQL Server 2014" width="538" height="652" class="size-full wp-image-590" /></a><p class="wp-caption-text">Développez et administrez pour la performance avec SQL Server 2014</p></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
