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

<channel>
	<title>Le Blog SQL Server d&#039;ElSüket</title>
	<atom:link href="https://blog.developpez.com/elsuket/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/elsuket</link>
	<description>Nicolas Souquet - Expert SQL Server</description>
	<lastBuildDate>Mon, 05 Apr 2021 07:32:41 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Vidéos des sessions Data Frogs</title>
		<link>https://blog.developpez.com/elsuket/p13206/moteur-de-base-de-donnees-sql-server/indexation/videos-des-sessions-data-frogs</link>
		<comments>https://blog.developpez.com/elsuket/p13206/moteur-de-base-de-donnees-sql-server/indexation/videos-des-sessions-data-frogs#comments</comments>
		<pubDate>Mon, 05 Apr 2021 07:32:41 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1527</guid>
		<description><![CDATA[Après un long moment d&#8217;absence, je suis revenu en animant une session parmi d&#8217;autres, sur le Query Store. Voici le menu : David Barbarin – Maintenance des statistiques avec SQL Server Nicolas Souquet – Tout savoir sur le Query Store &#8230; <a href="https://blog.developpez.com/elsuket/p13206/moteur-de-base-de-donnees-sql-server/indexation/videos-des-sessions-data-frogs">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Après un long moment d&rsquo;absence, je suis revenu en animant une session parmi d&rsquo;autres, sur le Query Store. Voici le menu :</p>
<p>David Barbarin – Maintenance des statistiques avec SQL Server<br />
Nicolas Souquet – Tout savoir sur le Query Store<br />
Amar Adghar – Azure, quelle architecture pour moi ?<br />
Arian Papillon and Julien Pierre – Les fausses bonnes idées SQL Server<br />
Christophe Laporte – Configurer SQL Server pour un dépannage efficace<br />
Hugo Kornelis – T-SQL User-Defined Functions, or: How to kill performance in one, easy step<br />
Frédéric Brouard – Passer de SQL Server à PostGreSQL &#8230; ou l&rsquo;inverse ?</p>
<p>Les vidéos sont disponibles <a href="https://www.youtube.com/channel/UCd1tirBk4XtjQ_hWZ0uAFrw">ici</a>.<br />
Retrouvez également les scripts que j&rsquo;ai utilisés pour les démos <a href="https://1drv.ms/u/s!Akx83zoei9Kzc4rPEi-GIFYf088?e=Z70fYe">ici</a>.</p>
<p>Bonne visualisation <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A la recherche du SQL Server 2017 Configuration Manager perdu</title>
		<link>https://blog.developpez.com/elsuket/p13154/utilitaires/a-la-recherche-du-sql-server-2017-configuration-manager-perdu</link>
		<comments>https://blog.developpez.com/elsuket/p13154/utilitaires/a-la-recherche-du-sql-server-2017-configuration-manager-perdu#comments</comments>
		<pubDate>Sun, 22 Oct 2017 17:45:37 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1481</guid>
		<description><![CDATA[La sortie de SQL Server 2017 marque un tournant majeur pour Microsoft, puisque SQL Server est maintenant disponible sous Linux. Jusqu&#8217;ici, ce n&#8217;était pas le cas, et c&#8217;était très probablement le dernier rempart à l&#8217;adoption de SQL Server dans les &#8230; <a href="https://blog.developpez.com/elsuket/p13153/moteur-de-base-de-donnees-sql-server/indexation/sortie-de-sql-server-2017-installation">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La sortie de SQL Server 2017 marque un tournant majeur pour Microsoft, puisque SQL Server est maintenant disponible sous Linux. Jusqu&rsquo;ici, ce n&rsquo;était pas le cas, et c&rsquo;était très probablement le dernier rempart à l&rsquo;adoption de SQL Server dans les entreprises où l&rsquo;infrastructure logicielle de Linux/Unix est prépondérante.</p>
<p>Il y a bien d&rsquo;autres éléments qui ont été ajoutés aux fonctionnalités de SQL Server avec ce nouvel opus, que l&rsquo;on peut télécharger à partir de <a href="https://www.microsoft.com/en-us/sql-server/sql-server-downloads">cette page</a>.  Plus bas dans celle-ci, on trouve également les téléchargements de SQL Server Management Studio 2017, SQL Server Data Tools, et les connecteurs pour faire interagir une application avec SQL Server en .NET, Java, mais aussi Python et Ruby.</p>
<p>Notons que depuis SQL Server 2014, l&rsquo;édition <em>Developer</em> de SQL Server est gratuite, ce qui fait qu&rsquo;on peut la télécharger sur nos PCs et commencer à bricoler après quelques minutes d&rsquo;installation, en faisant appel à toutes les possibilités et fonctionnalités du moteur de base de données : l&rsquo;édition Developer, est, en termes de fonctionnalités, équivalente à l&rsquo;édition Enterprise, qui les offre toutes.</p>
<p>Voyons donc ce qu&rsquo;il en est :<br />
<span id="more-1481"></span></p>
<p>A partir de la page, on obtient un petit installeur de 5Mo, et lors de sont exécution, on obtient la fenêtre suivante :</p>
<p><img src="https://i.imgur.com/bG7f0Rh.png" alt="" /></p>
<p>Ici j&rsquo;ai choisi <em>Download Media</em>, puisque c&rsquo;est l&rsquo;option qui me permettra d&rsquo;installer au besoin, avec seulement les fonctionnalités que je souhaite. Nous obtenons alors l&rsquo;écran suivant :</p>
<p><img src="https://i.imgur.com/evxbSsT.png" alt="" /></p>
<p>Plus besoin donc de se soucier du langage, et on peut télécharger selon son envie et l&rsquo;OS, soit sous le format ISO, soit en CAB. Un lien nous permet aussi créer une instance SQL Server dans Azure.</p>
<p>Une fois le tout validé, le téléchargement débute &#8230; et se termine par :</p>
<p><img src="https://i.imgur.com/lasY6a0.png" alt="" /></p>
<p>Un clic sur le bouton <em>Open folder</em> nous amène directement sur le fichier ISO fraîchement téléchargé. A l’exécution de ce dernier, on obtient la fenêtre suivante :</p>
<p><img src="https://i.imgur.com/n6WGnAD.png" alt="" /></p>
<p>A partir de la page <em>Installation</em>, on peut bien sûr démarrer l&rsquo;installation d&rsquo;une instance SQL Server 2017, et ici encore accéder aux pages qui permettent de télécharger la dernière version de SQL Server Management Studio (SSMS) et SQL Server Data Tools (SSDT). Depuis SQL Server 2016, ces outils ne sont en effet plus contenus dans l&rsquo;installeur de SQL Server : ceci permet à l&rsquo;installeur de garder une taille relativement raisonnable (1.4 Go), étant donné que l&rsquo;installeur de SSMS pèse à lui seul près de 800 Mo. </p>
<p>Les différences avec l&rsquo;installation de SQL Server 2016 sont peu nombreuses, mais valent qu&rsquo;on s&rsquo;y arrête : alors que SQL Server 2016 supportait l’apprentissage automatisé avec le langage R, on pouvait installer en plus de SQL Server une instance de <em>R Server</em>. Comme SQL Server 2017 supporte en plus Python pour servir ce même besoin, l&rsquo;installation de <em>R Server</em> a été remplacée dans ce nouvel opus par un <em>Machine Learning Server</em> :</p>
<p><img src="https://i.imgur.com/n6WGnAD.png" alt="" /></p>
<p>Les écrans de clé de produit et de licence demeurent inchangés :</p>
<p><img src="https://i.imgur.com/5vsyssv.png" alt="" /></p>
<p><img src="https://imgur.com/sl2wJEc.png" alt="" /></p>
<p>Idem pour le calcul des règles d&rsquo;installation :</p>
<p><img src="https://imgur.com/IdOmSm4.png" alt="" /></p>
<p><img src="https://imgur.com/qTtZjNJ.png" alt="" /></p>
<p>Nous voici maintenant à la sélection des fonctionnalités à installer : comme vu précédemment, nous pouvons ajouter les fonctionnalités d&rsquo;Apprentissage Automatisé, soit en support de script (<em>Machine-Learning Services (In-Database)</em>), soit en instance dédiée (<em>Machine-Learning Services (Standalone)</em>) et choisir d&rsquo;installer seulement R ou Python. Cocher la case de l&rsquo;une de ces deux fonctionnalités génère une nouvelle page dans la liste à gauche : <em>Consent to install Microsoft R Server/Python</em></p>
<p><img src="https://imgur.com/oAFrYvT.png" alt="" /></p>
<p>L&rsquo;écran de nommage de l&rsquo;instance reste inchangé :</p>
<p><img src="https://imgur.com/2WT9Nd8.png" alt="" /></p>
<p>De même que celui de configuration des services de l&rsquo;instance :</p>
<p><img src="https://imgur.com/8dxreKG.png" alt="" /></p>
<p>L&rsquo;octroi du droit <em>Perform Volume Maintenance Task</em> au compte de service qui exécute SQL Server, introduite avec SQL Server 2016, est toujours bienvenu, et sa description est limpide.</p>
<p>En ce qui concerne la configuration du moteur de base de données, pas de surprise non plus &#8230;</p>
<p><img src="https://imgur.com/Dkzhkbj.png" alt="" /></p>
<p>&#8230; mais on apprécie toujours l&rsquo;onglet qui permet de configurer plusieurs fichiers pour TempDB, introduite avec SQL Server 2016 :</p>
<p><img src="https://imgur.com/SdpqPAO.png" alt="" /></p>
<p>Comme nous l&rsquo;avons vu, l&rsquo;acceptation de la licence pour R Server et Python est requise :</p>
<p><img src="https://imgur.com/tBjZ6gh.png" alt="" /></p>
<p><img src="https://imgur.com/32VFNJS.png" alt="" /></p>
<p>Comme d&rsquo;habitude, un résumé des éléments qui vont être installés s&rsquo;affiche, permettant de revoir le tout avant de cliquer sur le bouton <em>Install</em></p>
<p><img src="https://imgur.com/LpymZlU.png" alt="" /></p>
<p>Et bien sûr, on peut récupérer l&rsquo;emplacement du fichier de configuration de cette installation juste en-dessous du résumé, pour le passer en paramètre à une installation scriptée et silencieuse de SQL Server. Il se trouve toujours dans le répertoire <em>C:\Program Files\Microsoft SQL Server\140\Setup Bootstrap\Log\AAAAMMJJ_HHmmss\ConfigurationFile.ini</em>.</p>
<p>L&rsquo;installation démarre alors, et, si nous avions choisi d&rsquo;installer les fonctionnalités de Machine-Learning, on observera le téléchargement des éléments nécessaires à celles-ci par l&rsquo;utilisation de la bande passante réseau/Internet. Une fois terminée, on peut démarrer <a href="http://blog.developpez.com/elsuket/p13152/sql-server-management-studio/telecharger-sql-server-management-studio-2017-v17-2" title="Télécharger SQL Server Management Studio 2017 (v17.2)"><em>SQL Server Management Studio 17.2</em></a>, et obtenir alors :</p>
<p><img src="https://imgur.com/h3SNsrK.png" alt="" /></p>
<p>Il ne nous reste plus qu&rsquo;à nous amuser avec les nouvelles fonctionnalités de cette version, listées sur <a href="https://docs.microsoft.com/en-us/sql/sql-server/what-s-new-in-sql-server-2017">cette page</a>, et dont les plus marquantes à mon sens sont :</p>
<ul>
<li>Reprise de reconstruction d&rsquo;index en ligne, ce qui permet de la mettre en pause pour la reprendre plus tard</li>
<li>Exécution adaptative des requêtes : adaptation de l&rsquo;algorithme de jointure et feedback sur l&rsquo;octroi de mémoire à l&rsquo;exécution d&rsquo;une requête</li>
<li>Tuning automatisé : détection et correction automatique de régression de performance pour un plan de requête, et création/suppression de doublons d&rsquo;index dans Azure</li>
<li>Ajout du type de données graphe</li>
<li>Groupes de disponibilité AlwaysOn sans cluster</li>
<li>Nouvelles DMVs : sys.dm_db_log_stats, sys.dm_tran_version_store_space_usage, sys.dm_db_log_info et sys.dm_db_stats_histogram</li>
<li>Amélioration du support In-Memory  : colonnes calculées, JSON, CASE et CROSS APPLY</li>
<li>Fonctions de chaîne : CONCAT_WS et TRIM (enfin !)</li>
<li>Et bien sûr le niveau de compatibilité de base de données 140</li>
</ul>
<p>Pour voir les fonctionnalités devenues dépréciées, et notamment celles qui ne seront plus supportées dans la prochaine version de SQL Server (2018 ou 2019 ? les paris sont ouverts ! :)), c&rsquo;est par <a href="https://docs.microsoft.com/en-us/sql/database-engine/deprecated-database-engine-features-in-sql-server-2017">ici</a>.</p>
<p>Bon SQL Server 2017 à tous !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Télécharger SQL Server Management Studio 2017 (v17.2)</title>
		<link>https://blog.developpez.com/elsuket/p13152/sql-server-management-studio/telecharger-sql-server-management-studio-2017-v17-2</link>
		<comments>https://blog.developpez.com/elsuket/p13152/sql-server-management-studio/telecharger-sql-server-management-studio-2017-v17-2#comments</comments>
		<pubDate>Sun, 17 Sep 2017 16:50:58 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Management Studio]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1463</guid>
		<description><![CDATA[Voici la dernière version de SQL Server Management Studio : https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms Je donne le lien car il arrive qu&#8217;on obtienne la version 17.0 RC par exemple, alors que la version la plus actuelle est la 17.2. Cela évite d&#8217;avoir à &#8230; <a href="https://blog.developpez.com/elsuket/p13152/sql-server-management-studio/telecharger-sql-server-management-studio-2017-v17-2">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici la dernière version de SQL Server Management Studio :</p>
<p>https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms</p>
<p>Je donne le lien car il arrive qu&rsquo;on obtienne la version 17.0 RC par exemple, alors que la version la plus actuelle est la 17.2. Cela évite d&rsquo;avoir à télécharger 350 Mo en plus de 680 de la 17.0 <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_biggrin.gif" alt=":D" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Variables de type table, statistiques et drapeau de trace 2453</title>
		<link>https://blog.developpez.com/elsuket/p13151/moteur-de-base-de-donnees-sql-server/variables-de-type-table-statistiques-et-drapeau-de-trace-2453</link>
		<comments>https://blog.developpez.com/elsuket/p13151/moteur-de-base-de-donnees-sql-server/variables-de-type-table-statistiques-et-drapeau-de-trace-2453#comments</comments>
		<pubDate>Sun, 30 Jul 2017 21:39:01 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[drapeau de trace]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[trace flag]]></category>
		<category><![CDATA[variable de type table]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1409</guid>
		<description><![CDATA[M&#8217;étant arrêté d&#8217;écrire pendant un certain temps, mais certainement pas de lire, me voilà de retour au clavier pour partager sur mon sujet préféré : l&#8217;optimiseur de requêtes, et plus particulièrement l&#8217;estimation de cardinalités. En butinant des billets de blog &#8230; <a href="https://blog.developpez.com/elsuket/p13151/moteur-de-base-de-donnees-sql-server/variables-de-type-table-statistiques-et-drapeau-de-trace-2453">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>M&rsquo;étant arrêté d&rsquo;écrire pendant un certain temps, mais certainement pas de lire, me voilà de retour au clavier pour partager sur mon sujet préféré : l&rsquo;optimiseur de requêtes, et plus particulièrement l&rsquo;estimation de cardinalités. En butinant des billets de blog ici et là à propos de SQL Server, je trouvais un billet détaillant le comportement des requêtes spécifiant des variables de type TABLE.</p>
<p>Qu&rsquo;est-ce que l&rsquo;estimation de cardinalités ? Pour faire très court, c&rsquo;est l&rsquo;ensemble des règles mathématiques qui permettent à SQL Server d&rsquo;avoir une idée assez précise du nombre de lignes qu&rsquo;il aura à traiter lors de l&rsquo;exécution d&rsquo;une requête. C&rsquo;est avec ce calcul-là qu&rsquo;il sélectionne les algorithmes de jointure, de regroupement, l&rsquo;ordre et la façon d&rsquo;accéder aux tables, et bien d&rsquo;autres choses encore. Bien sûr, ces choix varient suivant le volume de données à traiter. On le comprend donc, c&rsquo;est un sujet très important, puisqu&rsquo;il impacte directement les performances de l&rsquo;exécution de nos chères (parfois en IO et temps CPU !) requêtes.</p>
<p>Alors vous allez me dire, crevant d&rsquo;impatience : &laquo;&nbsp;bon d&rsquo;accord, mais il le sort de son chapeau magique ce calcul ?&nbsp;&raquo; : au risque de vous décevoir, non. Dès lors qu&rsquo;on soumet une requête qui filtre une table par une colonne, ou l&rsquo;utilise dans une jointure, un regroupement, alors par défaut, le moteur crée automatiquement des objets de statistique. C&rsquo;est à dire qu&rsquo;il va échantillonner les données des colonnes des tables participant à la requête pour évaluer la distribution des données dans les colonnes (et index) de ces tables. Fort de ces informations, il peut alors réaliser le fameux calcul. Bref, ce sont des mathématiques <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p>L&rsquo;auteur du billet en question partageait sur le fait que par défaut, SQL Server estime qu&rsquo;il n&rsquo;y a qu&rsquo;une seule ligne dans une variable de type TABLE. Ceci s&rsquo;explique par le fait que SQL Server ne maintient pas d&rsquo;objet de statistique sur les variables de type TABLE (pour les curieux, il le fait néanmoins sur les <a href="http://blog.developpez.com/elsuket/p7739/moteur-de-base-de-donnees-sql-server/variable_table_temporaire_performance" title="Utilisation des variables de type table ou des tables temporaires, et performances">tables temporaires</a>). Quand on sait l&rsquo;usage qui est fait des variables de type TABLE dans les applications, il est évident qu&rsquo;il arrive rarement que ces tables ne soient en charge que d&rsquo;une seule ligne; de là des performances qui ne sont pas toujours en adéquation avec le volume de données à traiter.</p>
<p>Voyons le comportement par défaut du moteur à l&rsquo;aide de la base de données AdventureWorks2012 :<br />
<span id="more-1409"></span></p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span><br />
GO<br />
<br />
<span style="color: #0000FF;">USE</span> AdventureWorks2012<br />
GO<br />
<br />
<span style="color: #0000FF;">DECLARE</span> @BusinessEntityId <span style="color: #0000FF;">TABLE</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; BusinessEntityID <span style="color: #0000FF;">INT</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
<span style="color: #808080;">&#41;</span>;<br />
&nbsp;<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @BusinessEntityId<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; BusinessEntityID<br />
<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; BusinessEntityID<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; Person.<span style="color: #202020;">Person</span>;<br />
&nbsp;<br />
<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">STATISTICS</span> IO, <span style="color: #0000FF;">TIME</span>, XML <span style="color: #0000FF;">ON</span><br />
&nbsp;<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @BusinessEntityId b<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; Person.<span style="color: #202020;">Person</span> p<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> b.<span style="color: #202020;">BusinessEntityID</span> <span style="color: #808080;">=</span> p.<span style="color: #202020;">BusinessEntityID</span>;<br />
<br />
<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">STATISTICS</span> IO, <span style="color: #0000FF;">TIME</span>, XML <span style="color: #0000FF;">OFF</span></div></td></tr></tbody></table></div>
<p>L&rsquo;option de session SET STATISTICS nous permet de collecter des métriques IO, temps CPU et durée en millisecondes de la requête. Son option XML expose le <a href="http://blog.developpez.com/elsuket/p12879/moteur-de-base-de-donnees-sql-server/capture-manuelle-de-plans-de-requete" title="Capture manuelle de plans de requête">plan réel de requête</a> en plus du résultat de la requête.  La sortie de ce lot est, tronquée des lectures &laquo;&nbsp;physiques&nbsp;&raquo; (i.e. sur disque et pas en RAM), et des lectures LOB, puisqu&rsquo;il n&rsquo;y en a pas :</p>
<p><em>Table &lsquo;Person&rsquo;. Scan count 0, logical reads 59916<br />
Table &lsquo;#BEF1AB90&prime;. Scan count 1, logical reads 33</p>
<p> SQL Server Execution Times:<br />
   CPU time = 47 ms,  elapsed time = 56 ms.</em></p>
<p>Si l&rsquo;on étudie le plan de requête, voici ce que l&rsquo;on trouve pour notre variable de type TABLE :</p>
<p><img src="http://imgur.com/IyPj2KC.png" alt="" /></p>
<p>Pour voir sur quelle base le moteur a réalisé ses calculs, il suffit de survoler l&rsquo;opérateur <em>Table Scan</em> avec le curseur de la souris :</p>
<p><img src="http://imgur.com/CPy7CtN.png" alt="" /></p>
<p>Le moteur a donc estimé qu&rsquo;il n&rsquo;y qu&rsquo;une seule ligne dans la variable de type TABLE, puis il a exécuté le plan de cette requête. D&rsquo;une certaine manière, il nous avoue s&rsquo;être un peu trompé, puisqu&rsquo;il nous indique qu&rsquo;en réalité, il a lu 19972 lignes.</p>
<p>Mais, à la lecture du résumé l&rsquo;article <a href="https://support.microsoft.com/en-us/help/2952444">2952444</a>, on voit que ce comportement a été corrigé à l&rsquo;aide d&rsquo;un correctif dès SQL Server 2012 SP2 et le CU3 de SQL Server 2014, ce qui fait qu&rsquo;il est dans les RTM des versions suivantes de SQL Server, à ce jour SQL Server 2016 et 2017 (bientôt !) :</p>
<p><em>When you populate a table variable with many rows and then join it with other tables, the query optimizer may choose an inefficient query plan, which may lead to slow query performance.<br />
</em></p>
<p>Voyons donc ce qu&rsquo;il en est : nous rejouons le même lot de requête, mais avec le drapeau de trace activé cette fois :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">-- Activation du drapeau de trace 2453 pour toutes</span><br />
<span style="color: #008080;">-- les bases de données que l'instance héberge</span><br />
<span style="color: #0000FF;">DBCC</span> TRACEON <span style="color: #808080;">&#40;</span><span style="color: #000;">2453</span>, <span style="color: #808080;">-</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span><br />
GO<br />
<br />
<span style="color: #0000FF;">USE</span> AdventureWorks2012<br />
GO<br />
<br />
<span style="color: #0000FF;">DECLARE</span> @BusinessEntityId <span style="color: #0000FF;">TABLE</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; BusinessEntityID <span style="color: #0000FF;">INT</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
<span style="color: #808080;">&#41;</span>;<br />
&nbsp;<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @BusinessEntityId<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; BusinessEntityID<br />
<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span> &nbsp;BusinessEntityID<br />
<span style="color: #0000FF;">FROM</span> &nbsp; &nbsp;Person.<span style="color: #202020;">Person</span>;<br />
&nbsp;<br />
<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">STATISTICS</span> IO, <span style="color: #0000FF;">TIME</span>, XML <span style="color: #0000FF;">ON</span><br />
&nbsp;<br />
<span style="color: #0000FF;">SELECT</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">FROM</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@BusinessEntityId b<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp;Person.<span style="color: #202020;">Person</span> p<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> b.<span style="color: #202020;">BusinessEntityID</span> <span style="color: #808080;">=</span> p.<span style="color: #202020;">BusinessEntityID</span>;<br />
<br />
<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">STATISTICS</span> IO, <span style="color: #0000FF;">TIME</span>, XML <span style="color: #0000FF;">OFF</span></div></td></tr></tbody></table></div>
<p>La sortie est :</p>
<p><em>Table &lsquo;Workfile&rsquo;. Scan count 7, logical reads 64, physical reads 0, read-ahead reads 64<br />
Table &lsquo;Worktable&rsquo;. Scan count 0, logical reads 0<br />
Table &lsquo;Person&rsquo;. Scan count 1, logical reads 67<br />
Table &lsquo;#A96F2843&prime;. Scan count 1, logical reads 33</p>
<p> SQL Server Execution Times:<br />
   CPU time = 31 ms,  elapsed time = 39 ms.</em></p>
<p>Le gain de temps pour une requête aussi simple n&rsquo;est pas négligeable, mais c&rsquo;est surtout le gain en IOs qui est très intéressant ! Voyons ce que nous dit le plan de requête :</p>
<p><img src="http://imgur.com/suEqrcd.png" alt="" /></p>
<p>L&rsquo;ordre d&rsquo;accès aux tables est le même, mais on voit bien que la façon de les traiter a changé : les jointures et agrégats sont exécutés par hachage. On note aussi les avertissements (petit point d&rsquo;exclamation noir dans un triangle jaune) sur ces deux opérateurs : ils ont du accéder à TempDB pour exécuter la jointure et l&rsquo;agrégat, d&rsquo;où les <em>Workfile</em> et <em>Worktable</em> dans la sortie de SET STATISTICS : ce sont des structures créées à la volée dans TempDB, souvent à défaut d&rsquo;index pouvant supporter la requête efficacement.</p>
<p>Voyons ce que nous indique l&rsquo;opérateur <em>Table Scan</em> :</p>
<p><img src="http://imgur.com/JuxVHGM.png" alt="" /></p>
<p>Ici on voit bien que l&rsquo;estimation du nombre de lignes s&rsquo;est faite correctement, et c&rsquo;est donc bien cela qui a conduit le moteur à changer les algorithmes de jointure et de calcul de l&rsquo;agrégat.</p>
<p>Pour ma part, la grande majorité des instances SQL Server que j&rsquo;administre actuellement sont de version 2014, et j&rsquo;ai activé ce drapeau de trace sur toutes celles-ci. En effet, l&rsquo;application qui repose sur cette base de données fait souvent appel à des <em>Tabled-Valued Parameters</em>, qui sont des variables de type table que l&rsquo;on peut passer en paramètre à une procédure stockée ou un appel à la procédure stockée système <em>sp_executesql</em>. Les performances générales de l&rsquo;application s&rsquo;en sont immédiatement ressenti positivement.</p>
<p>Je n&rsquo;irai pas jusqu&rsquo;à écrire qu&rsquo;il faudrait que ce drapeau de trace soit activé sur toute les instances de production, car :</p>
<ol>
<li>toutes les applications et leurs charges de travail sont différentes</li>
<li>il est toujours primordial de tester et de mesurer avant d&rsquo;effectuer un quelconque changement de configuration sur une instance de production</li>
</ol>
<p>Je vous engage vivement donc à tester pour en observer l&rsquo;effet :</p>
<ul>
<li>Pour savoir quels sont les drapeaux de trace actifs, il suffit d&rsquo;exécuter DBCC TRACESTATUS seul, ou si l&rsquo;on veut être plus spécifique : DBCC TRACESTATUS (2453, -1)</li>
<li>Pour désactiver un drapeau de trace, il faut exécuter : DBCC TRACEOFF ({traceFlag}, -1), soit dans le cadre de ce billet : DBCC TRACEOFF (2453, -1)</li>
</ul>
<p>N&rsquo;hésitez pas à me laisser un petit commentaire !</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Résoudre les problèmes les plus communs de connexion à SQL Server</title>
		<link>https://blog.developpez.com/elsuket/p13147/moteur-de-base-de-donnees-sql-server/indexation/resoudre-problemes-communs-connexion-a-sql-server</link>
		<comments>https://blog.developpez.com/elsuket/p13147/moteur-de-base-de-donnees-sql-server/indexation/resoudre-problemes-communs-connexion-a-sql-server#comments</comments>
		<pubDate>Wed, 22 Mar 2017 20:23:23 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1396</guid>
		<description><![CDATA[Qui n&#8217;a jamais eu le message d&#8217;erreur suivant ? A network-related or instance-specific error occurred while establishing a connection to SQL Server Login failed for user DOMAIN\user Microsoft vient de publier un guide de résolution de ces erreurs, qui indique &#8230; <a href="https://blog.developpez.com/elsuket/p13147/moteur-de-base-de-donnees-sql-server/indexation/resoudre-problemes-communs-connexion-a-sql-server">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Qui n&rsquo;a jamais eu le message d&rsquo;erreur suivant ?</p>
<ul>
<li>A network-related or instance-specific error occurred while establishing a connection to SQL Server</li>
<li>Login failed for user DOMAIN\user</li>
</ul>
<p>Microsoft vient de publier un <a href="https://support.microsoft.com/fr-fr/help/4009936/solving-connectivity-errors-to-sql-server">guide de résolution</a> de ces erreurs, qui indique les sources du problème et les étapes de résolution.</p>
<p>Bonne connexion(s) !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redémarrer la trace par défaut</title>
		<link>https://blog.developpez.com/elsuket/p13143/snippets/redemarrer-la-trace-par-defaut</link>
		<comments>https://blog.developpez.com/elsuket/p13143/snippets/redemarrer-la-trace-par-defaut#comments</comments>
		<pubDate>Thu, 02 Mar 2017 08:00:02 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1369</guid>
		<description><![CDATA[SQL Server 2012 a introduit les objets SEQUENCE. Ils permettent, en outre, de spécifier des contraintes de valeur par défaut. Ils vont aussi remplacer la propriété d&#8217;auto-incrémentation typiquement utilisée pour les colonnes supportant des contraintes de clé primaire subrogée. Dès &#8230; <a href="https://blog.developpez.com/elsuket/p13120/moteur-de-base-de-donnees-sql-server/indexation/retrouver-les-sequences-attachees-a-des-contraintes-de-valeur-par-defaut">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SQL Server 2012 a introduit <a href="http://blog.developpez.com/elsuket/p11008/t-sql/sql_server_2012_sequence" title="Tout savoir sur SEQUENCE avec SQL Server 2012" target="_blank">les objets SEQUENCE</a>.<br />
Ils permettent, en outre, de spécifier des contraintes de valeur par défaut. Ils vont aussi remplacer la propriété d&rsquo;auto-incrémentation typiquement utilisée pour les colonnes supportant des contraintes de clé primaire subrogée.</p>
<p>Dès lors, comment retrouver les séquences référencées par de telles contraintes ? Voici un exemple et une petite requête pour nous y aider &#8230;<br />
<span id="more-1369"></span></p>
<p>Pour l&rsquo;exemple, supposons la séquence et la table suivantes :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">USE</span> ELSUKET<br />
GO<br />
<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">SEQUENCE</span> dbo.<span style="color: #202020;">seq_user</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">int</span><br />
<span style="color: #0000FF;">START</span> <span style="color: #0000FF;">WITH</span> <span style="color: #808080;">-</span><span style="color: #000;">2147483648</span> <span style="color: #808080;">IN</span>CREMENT <span style="color: #0000FF;">BY</span> <span style="color: #000;">1</span> ;<br />
GO<br />
&nbsp;<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> t_user<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; id <span style="color: #0000FF;">int</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> PK_t_user <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> DF_t_user__id <span style="color: #0000FF;">DEFAULT</span> <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">VALUE</span> <span style="color: #0000FF;">FOR</span> dbo.<span style="color: #202020;">seq_user</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , name <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">32</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> UQ_t_user__name <span style="color: #0000FF;">UNIQUE</span><br />
<span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>Il est nécessaire d&rsquo;utiliser la fonction de gestion dynamique <em>sys.dm_sql_referencing_entities()</em> pour retrouver les caractéristiques de la contrainte :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span>T.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.'</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>T.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> table_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>DC.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> default_constraint_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span>SQ.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.'</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SQ.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> sequence_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF0000;">'ALTER TABLE '</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span>T.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.'</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>T.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">' DROP CONSTRAINT '</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>DC.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> sql_drop_constraint<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">sequences</span> <span style="color: #0000FF;">AS</span> SQ<br />
<span style="color: #808080;">CROSS</span> APPLY &nbsp; &nbsp; sys.<span style="color: #202020;">dm_sql_referencing_entities</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SCHEMA_NAME<span style="color: #808080;">&#40;</span>SQ.<span style="color: #202020;">schema_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.'</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">QUOTENAME</span><span style="color: #808080;">&#40;</span>SQ.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF0000;">'OBJECT'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> RE<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">default_constraints</span> <span style="color: #0000FF;">AS</span> DC<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> RE.<span style="color: #202020;">referencing_id</span> <span style="color: #808080;">=</span> DC.<span style="color: #FF00FF;">object_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">tables</span> <span style="color: #0000FF;">AS</span> T<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> T.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> DC.<span style="color: #202020;">parent_object_id</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T.<span style="color: #202020;">name</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'t_user'</span></div></td></tr></tbody></table></div>
<p>ce qui donne :</p>
<p><img src="http://i.imgur.com/0zS4TTc.png" alt="" /></p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server 2016 Service Pack 1 : monumentale mise à jour !</title>
		<link>https://blog.developpez.com/elsuket/p13119/moteur-de-base-de-donnees-sql-server/sql-server-2016-service-pack-1-monumentale-mise-a-jour</link>
		<comments>https://blog.developpez.com/elsuket/p13119/moteur-de-base-de-donnees-sql-server/sql-server-2016-service-pack-1-monumentale-mise-a-jour#comments</comments>
		<pubDate>Wed, 23 Nov 2016 08:00:47 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[SQL Server 2016]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1351</guid>
		<description><![CDATA[La sortie du Service Pack 1 pour SQL Server 2016 est venue avec une annonce pour le moins inattendue : de nombreuses fonctionnalités jusqu&#8217;ici réservées à l&#8217;édition Enterprise le sont maintenant dans les éditions Standard, Express, et même LocalDB. La &#8230; <a href="https://blog.developpez.com/elsuket/p13119/moteur-de-base-de-donnees-sql-server/sql-server-2016-service-pack-1-monumentale-mise-a-jour">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La sortie du Service Pack 1 pour SQL Server 2016 est venue avec une annonce pour le moins inattendue : de nombreuses fonctionnalités jusqu&rsquo;ici réservées à l&rsquo;édition <em>Enterprise</em> le sont maintenant dans les éditions <em>Standard</em>, <em>Express</em>, et même <em>LocalDB</em>.</p>
<p><span id="more-1351"></span></p>
<p>La table suivante décrit ce changement de façon plus visuelle : le moins qu&rsquo;on puisse dire, c&rsquo;est qu&rsquo;elle s&rsquo;est éclairci avec ce Service Pack !</p>
<p><img src="http://i.imgur.com/Viyy4ne.png" alt="" /></p>
<p>Mêmes les fonctionnalités introduites avec SQL Server 2016 RTM <em>Enterprise</em> ont été élargies aux autres éditions. Ceci permet bien sûr de programmer de façon plus uniforme, en ayant moins recours à la vérification de l&rsquo;édition. C&rsquo;est tout à fait avantageux pour les éditeurs de logiciels, mais aussi pour les scripts de maintenance, notamment PowerShell, qui devraient donc compter moins de <em>if</em> une fois toutes les bases de données migrées vers cette version (ce qui n&rsquo;est pas une mince affaire :)). Mon seul regret ira peut-être à la reconstruction d&rsquo;index en ligne, mais c&rsquo;est un choix qui se justifie si l&rsquo;on se place de l&rsquo;autre côté du comptoir.</p>
<p>Pour avoir une vue plus complète, voici <a href="https://www.microsoft.com/en-us/sql-server/sql-server-editions">la page de comparaison des éditions de SQL Server 2016 SP1</a>.</p>
<p>Ceci étant, c&rsquo;est d&rsquo;abord une excellente nouvelle, quoique la littérature actuelle sur ce sujet en dise du fait des limitations suivantes pour les index ColumnStore et les tables optimisées en mémoire (InMemory OLTP) :</p>
<ul>
<li>un quart de la quantité de RAM allouée à SQL Server</li>
<li>degré de parallélisation maximal : 2 cores</li>
</ul>
<p>Mais ne serait-ce que pour la sécurité des données, les fonctionnalités introduites avec SQL Server 2016 RTM sont bienvenues dans l&rsquo;édition <em>Standard</em> en SP1. Ensuite ces deux fonctionnalités limitées couvrent des cas d&rsquo;utilisation très courants, comme l&rsquo;analytique simple que l&rsquo;on développe pour une application OLTP, ou encore les variables de type TABLE et autres tables temporaires que l&rsquo;on peut tenter de déplacer en InMemory pour alléger la charge d&rsquo;IOs disque de TempDB.</p>
<p>Mais bien sûr ce n&rsquo;est pas Black Friday tous les jours, donc il faut aussi voir ce qui justifie toujours l&rsquo;achat d&rsquo;une édition <em>Enterprise</em> ou <em>Standard</em> de SQL Server 2016 SP1 :</p>
<ul>
<li>L&rsquo;Agent SQL Server n&rsquo;est pas porté aux éditions <em>Express</em> et <em>LocalDB</em>;</li>
<li>La parallélisation n&rsquo;est pas disponible dans ces deux mêmes éditions;</li>
<li>ALTER INDEX &#8230; REBUILD WITH (ONLINE = ON) est toujours réservé à l&rsquo;édition <em>Enterprise</em>;</li>
<li>Les groupes de disponibilité AlwaysOn prennent tout leur sens sous l&rsquo;édition <em>Enterprise</em>; autrement, cela s&rsquo;apparente à de la mise en mirroir;</li>
<li>La prise en compte à chaud de CPU et de RAM additionnels est réservé à l&rsquo;édition <em>Enterprise</em>;</li>
<li>Le cryptage (<em>Transparent Data Encryption</em>) avec ou sans EKM (<em>Extensible Key Management</em>, qui permet de déplacer la gestion des clés à un petit serveur spécialisé (<em>Hardware Security Module</em>)) reste une fonctionnalité <em>Enterprise</em>;</li>
<li>Le cryptage et la compression des sauvegardes n&rsquo;est pas disponible en édition <em>Express</em> ou <em>LocalDB</em>;</li>
<li>La quantité de RAM est toujours limitée à 128Go pour une édition <em>Standard</em>, quand l&rsquo;<em>Enterprise</em> est à 24 To (!!!);</li>
</ul>
<p>Pas grand chose de choquant donc, si ce n&rsquo;est peut-être le dernier élément de cette liste : l&rsquo;écart entre <em>Enterprise</em> et <em>Standard</em> frise le gouffre. Ceci est accentué lorsqu&rsquo;on trouve des PC portables disposant de 32 voire 64Go de RAM. On peut donc avoir bonne espérance que cette limite sera repoussée dans un avenir relativement proche.</p>
<p>Dès lors il est simple de voir que le volume de licences <em>Standard</em> de SQL Server 2016 va forcément augmenter, sans pour autant marcher sur les plates-bandes de celui de l&rsquo;édition <em>Enterprise</em>.</p>
<p>En ce qui concerne la consolidation du code à travers les éditions, nous les verrons dans un prochain billet.</p>
<p>Bonne migration vers SQL Server 2016 SP1 à tous !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installer SQL Server Management Studio 2016</title>
		<link>https://blog.developpez.com/elsuket/p13118/utilitaires/installer-sql-server-management-studio-2016</link>
		<comments>https://blog.developpez.com/elsuket/p13118/utilitaires/installer-sql-server-management-studio-2016#comments</comments>
		<pubDate>Mon, 14 Nov 2016 14:28:49 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

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

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1336</guid>
		<description><![CDATA[Avec la sortie de SQL Server 2016, Microsoft avait annoncé découpler l&#8217;installation de SQL Server Management Studio (SSMS) de celle de SQL Server. Ceci sert deux buts : On n&#8217;est plus tenté d&#8217;installer SSMS en même temps que SQL Server &#8230; <a href="https://blog.developpez.com/elsuket/p13094/sql-server-management-studio/sql-server-management-studio-2016-v16-3-vient-de-sortir">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Avec la sortie de SQL Server 2016, Microsoft avait annoncé découpler l&rsquo;installation de SQL Server Management Studio (SSMS) de celle de SQL Server. Ceci sert deux buts :</p>
<ul>
<li>On n&rsquo;est plus tenté d&rsquo;installer SSMS en même temps que SQL Server sur une machine : ceci fait donc moins d&rsquo;ouvertures aux potentielles failles de sécurité et élimine de possibles instabilités de la machine. Cela oblige les acteurs de l&rsquo;entreprise à se connecter une l&rsquo;instance SQL Server directement depuis leur station de travail, ou mieux depuis une machine &laquo;&nbsp;de rebond&nbsp;&raquo; qui peut être monitorée très strictement en ce qui concerne la sécurité d&rsquo;accès et l&rsquo;audit des actions de l&rsquo;utilisateur (par exemple enregistrement vidéo de la session bureau à distance)</li>
<p><span id="more-1336"></span></p>
<li>Les corrections et améliorations que SSMS mérite se feront plus fréquemment que le cycle de versionnement de SQL Server, qui est tous les deux ans depuis quelques opus.</li>
</ul>
<p>Voici donc le lien de téléchargement : en <a href="https://msdn.microsoft.com/fr-fr/library/mt238290.aspx">Français</a> et en <a href="https://msdn.microsoft.com/en-us/library/mt238290.aspx">Anglais</a></p>
<p>Bon upgrade SSMS !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sys.dm_exec_query_profiles : la DMV qui détaille les noeuds d&#8217;un plan d&#8217;exécution réel</title>
		<link>https://blog.developpez.com/elsuket/p13089/moteur-de-base-de-donnees-sql-server/indexation/sys-dm_exec_query_profiles-la-dmv-qui-detaille-les-noeuds-dun-plan-dexecution-reel</link>
		<comments>https://blog.developpez.com/elsuket/p13089/moteur-de-base-de-donnees-sql-server/indexation/sys-dm_exec_query_profiles-la-dmv-qui-detaille-les-noeuds-dun-plan-dexecution-reel#comments</comments>
		<pubDate>Tue, 09 Aug 2016 08:00:57 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[SQL Server 2014]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1266</guid>
		<description><![CDATA[La lecture du plan d&#8217;exécution réel peut s&#8217;avérer être une tâche laborieuse, surtout lorsque le plan contient de nombreux opérateurs ou nœuds. Introduite avec SQL Server 2014, la vue de gestion dynamique sys.dm_exec_query_profiles nous permet de voir quel(s) nœud(s) d&#8217;un &#8230; <a href="https://blog.developpez.com/elsuket/p13089/moteur-de-base-de-donnees-sql-server/indexation/sys-dm_exec_query_profiles-la-dmv-qui-detaille-les-noeuds-dun-plan-dexecution-reel">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La lecture du plan d&rsquo;exécution réel peut s&rsquo;avérer être une tâche laborieuse, surtout lorsque le plan contient de nombreux opérateurs ou nœuds.</p>
<p>Introduite avec SQL Server 2014, la vue de gestion dynamique <em>sys.dm_exec_query_profiles</em> nous permet de voir quel(s) nœud(s) d&rsquo;un <a href="http://blog.developpez.com/elsuket/p12879/moteur-de-base-de-donnees-sql-server/capture-manuelle-de-plans-de-requete" title="Capture manuelle de plans de requête">plan d&rsquo;exécution réel</a> consomme le plus de ressources et /ou de temps. C&rsquo;est donc un formidable outil qui peut faire largement diminuer la recherche des points noueux d&rsquo;une requête à l&rsquo;étude.</p>
<p><span id="more-1266"></span></p>
<p><a href="https://msdn.microsoft.com/en-us/library/dn223301.aspx">La documentation</a> de cette DMV montre qu&rsquo;elle expose de nombreuses colonnes, qui nous renseignent de façon très précise sur la consommation de ressources physiques de chaque opérateur du plan de requête, notamment avec le nombre de millisecondes après lequel un opérateur s&rsquo;est exécuté pour la première et la dernière fois. Pour simplifier l&rsquo;analyse des requêtes, on peut s&rsquo;en tenir à quelques unes d&rsquo;entre-elles, comme dans la requête suivante :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; physical_operator_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; , node_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , elapsed_time_ms<br />
&nbsp; &nbsp; &nbsp; &nbsp; , cpu_time_ms<br />
&nbsp; &nbsp; &nbsp; &nbsp; , row_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , estimate_row_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , logical_read_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , rewind_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , rebind_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , end_of_scan_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , scan_count<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">dm_exec_query_profiles</span></div></td></tr></tbody></table></div>
<p>La colonne <em>node_id</em> nous donne le numéro de l&rsquo;opérateur dans le plan de requête. Il faut noter que l&rsquo;opérateur racine de l&rsquo;arbre de résolution qu&rsquo;est le plan de requête, et qui se situe en haut et à gauche dans le plan d&rsquo;exécution graphique, est le seul dans tout plan à ne pas porter de <em>NodeID</em>. L&rsquo;opérateur qui le précède porte le <em>NodeID</em> 0, et celui qui précède ce dernier le <em>NodeID</em> 1, et ainsi de suite. Le plus grand numéro de <em>NodeID</em> est à l&rsquo;opérateur qui est le plus à droite et en bas du plan d&rsquo;exécution graphique.</p>
<p>La colonne <em>session_id</em> va nous permettre de spécifier sur quelle session porte notre étude : pour que cette vue expose des lignes, il est nécessaire que l&rsquo;option de session SET STATISTICS XML soit positionnée à ON pour la requête à étudier. Ceci équivaut à l&rsquo;activation de l&rsquo;option d&rsquo;inclusion du plan d&rsquo;exécution réel dans la barre d&rsquo;outil de SQL Server Management Studio (SSMS) avant l&rsquo;exécution d&rsquo;une requête. Ceci est normal, puisque comme pour toutes les tâches de monitoring, elle viennent avec un coût : celui-ci pourrait devenir trop élevé si toutes les requêtes étaient auditées à ce niveau de détail, d&rsquo;autant que ce type d&rsquo;information est utilisé par les DBAs, et pas par les applications qui interagissent avec la base de données.</p>
<p>Supposons que la requête (très simple) que l&rsquo;on souhaite étudier est la suivante :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sales.<span style="color: #202020;">SalesOrderDetail</span> <span style="color: #0000FF;">AS</span> SOD<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; Production.<span style="color: #202020;">Product</span> <span style="color: #0000FF;">AS</span> P<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> SOD.<span style="color: #202020;">ProductID</span> <span style="color: #808080;">=</span> P.<span style="color: #202020;">ProductID</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; P.<span style="color: #202020;">ListPrice</span> <span style="color: #808080;">&amp;</span>gt; <span style="color: #000;">1000</span></div></td></tr></tbody></table></div>
<p>On peut récupérer le session_id de plusieurs manières :</p>
<ul>
<li>Il est indiqué dans la barre d&rsquo;état de toute fenêtre de requête sous SSMS, en bas à droite;</li>
<li>Si l&rsquo;on a conservé les options par défaut de SSMS, il est aussi indiqué sur l&rsquo;onglet de la fenêtre de requête;</li>
<li>On peut exécuter SELECT @@SPID dans la même fenêtre de requête que celle à étudier.</li>
</ul>
<p><img src="http://i.imgur.com/JLFuhns.png" alt="" /></p>
<p>Ne soyez pas perturbé par l&rsquo;option de session <em>SET STATISTICS IO, TIME ON</em> positionné juste avant la requête : je l&rsquo;utilise toujours pour diagnostiquer une requête, car cela expose le temps CPU, la durée totale, et surtout, le nombre d&rsquo;IOs produit par la requête pour chaque table participant à celle-ci. On peut adjoindre l&rsquo;option <em>XML</em> à la liste <em>IO, TIME</em> si on le souhaite.</p>
<p>Les lecteurs aux yeux affûtés auront remarqué que dans la capture d&rsquo;écran ci-dessus, il y a un deuxième onglet ouvert : en effet, on doit utiliser une fenêtre de requête pour celle à étudier, et une autre pour lire la sortie de la vue <em>sys.dm_exec_query_profiles</em> pour cette session. Pour cet exemple, on peut reprendre la première requête, et rajouter la clause WHERE adéquate : la session qui va exécuter la requête à l&rsquo;étude porte le <em>session_id</em> 51 :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; physical_operator_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; , node_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , elapsed_time_ms<br />
&nbsp; &nbsp; &nbsp; &nbsp; , cpu_time_ms<br />
&nbsp; &nbsp; &nbsp; &nbsp; , row_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , estimate_row_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , logical_read_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , rewind_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , rebind_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , end_of_scan_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , scan_count<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">dm_exec_query_profiles</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; session_id <span style="color: #808080;">=</span> <span style="color: #000;">51</span> <span style="color: #008080;">-- session_id de la requête à l'étude</span></div></td></tr></tbody></table></div>
<p>L&rsquo;exercice consiste donc à démarrer l&rsquo;exécution de la requête à l&rsquo;étude, puis à basculer vers la fenêtre de requête qui spécifie la vue <em>sys.dm_exec_query_profiles</em> avant la fin de l&rsquo;exécution de la requête à l&rsquo;étude. Pour la requête de cet exemple, cela nous donne :</p>
<p><img src="http://i.imgur.com/FJozDlw.png" alt="" /></p>
<p>On constate ainsi des écarts importants entre le nombre de lignes estimé et réel pour les opérateurs dont le <em>NodeID</em> est 0 et 4, mais il y a un problème : alors que la somme des valeurs de la colonne <em>elapsed_time_ms</em> nous donne 15, la sortie dans l&rsquo;onglet <em>Messages</em> est la suivante (légèrement écourtée, notamment les IOs physiques et de LOBs, pour les besoins de l&rsquo;article) :</p>
<blockquote><p>(29382 row(s) affected)<br />
Table &lsquo;Workfile&rsquo;. Scan count 0, logical reads 0<br />
Table &lsquo;Worktable&rsquo;. Scan count 0, logical reads 0<br />
Table &lsquo;SalesOrderDetail&rsquo;. Scan count 1, logical reads 1246<br />
Table &lsquo;Product&rsquo;. Scan count 1, logical reads 15</p>
<p> SQL Server Execution Times:<br />
   CPU time = 156 ms,  elapsed time = <strong>1225</strong> ms.</p></blockquote>
<p>Il y a bien sûr le temps de consommation du jeu de lignes de résultat par SSMS. On peut le confirmer en éliminant le résultat une fois la requête exécutée : pour ce faire, il suffit de faire un clic-droit dans un zone vierge de la requête &gt; <em>Query options</em> &#8230; &gt; <em>Results</em> / <em>Grid</em> &gt; et de cocher la case <em>Discard results after execution</em>.</p>
<p>La question qui vient maintenant est : comment faire pour les requêtes dont l&rsquo;exécution est bien plus longue ? Et dans tous les cas, la durée d&rsquo;exécution des requêtes n&rsquo;étant pas précisément prédictible même après une ou deux exécutions, comment capturer les valeurs qu&rsquo;expose cette DMV en s&rsquo;approchant le plus possible de la fin de la requête ? On peut pour cela écrire une boucle qui va stocker le contenu de la DMV à intervalles réguliers et fréquents, et qui vérifie à chaque tour que la requête est toujours en cours d&rsquo;exécution :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span><br />
GO<br />
<br />
<span style="color: #0000FF;">DECLARE</span> @session_id <span style="color: #0000FF;">int</span> <span style="color: #808080;">=</span> <span style="color: #000;">51</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @delay <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">8</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'00:00:00.010'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @i <span style="color: #0000FF;">int</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
<br />
<span style="color: #0000FF;">IF</span> <span style="color: #FF00FF;">OBJECT_ID</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'TempDB.dbo.#query_profile_global'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> #query_profile_global<br />
<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> #query_profile_global<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; physical_operator_name <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">256</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , node_id <span style="color: #0000FF;">int</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , elapsed_time_ms <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , cpu_time_ms <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , row_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , estimate_row_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , logical_read_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , rewind_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , rebind_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , end_of_scan_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">object_name</span> sysname <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , index_name sysname <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , scan_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , time_stamp <span style="color: #0000FF;">datetime</span> <span style="color: #808080;">NULL</span><br />
<span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">DECLARE</span> @query_profile <span style="color: #0000FF;">TABLE</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; physical_operator_name <span style="color: #0000FF;">nvarchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">256</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , node_id <span style="color: #0000FF;">int</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , elapsed_time_ms <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , cpu_time_ms <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , row_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , estimate_row_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , logical_read_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , rewind_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , rebind_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , end_of_scan_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">object_name</span> sysname <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , index_name sysname <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , scan_count <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , time_stamp <span style="color: #0000FF;">datetime</span> <span style="color: #808080;">NULL</span><br />
<span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">EXISTS</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">dm_exec_requests</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; session_id <span style="color: #808080;">=</span> @session_id<br />
<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INTO</span> @query_profile<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QP.<span style="color: #202020;">physical_operator_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , QP.<span style="color: #202020;">node_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , QP.<span style="color: #202020;">elapsed_time_ms</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , QP.<span style="color: #202020;">cpu_time_ms</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , QP.<span style="color: #202020;">row_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , QP.<span style="color: #202020;">estimate_row_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , QP.<span style="color: #202020;">logical_read_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , QP.<span style="color: #202020;">rewind_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , QP.<span style="color: #202020;">rebind_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , QP.<span style="color: #202020;">end_of_scan_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , O.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF00FF;">object_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , I.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> index_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , QP.<span style="color: #202020;">scan_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> time_stamp<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_exec_query_profiles</span> <span style="color: #0000FF;">AS</span> QP<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">objects</span> <span style="color: #0000FF;">AS</span> O<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> QP.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> O.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">indexes</span> <span style="color: #0000FF;">AS</span> I<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> QP.<span style="color: #202020;">index_id</span> <span style="color: #808080;">=</span> I.<span style="color: #202020;">index_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> QP.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> I.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QP.<span style="color: #202020;">session_id</span> <span style="color: #808080;">=</span> @session_id <span style="color: #008080;">-- spid running query</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @i <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span>&nbsp; <span style="color: #0000FF;">INTO</span> #query_profile_global<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; @query_profile<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">UPDATE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #query_profile_global<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; physical_operator_name <span style="color: #808080;">=</span> QP.<span style="color: #202020;">physical_operator_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , node_id <span style="color: #808080;">=</span> QP.<span style="color: #202020;">node_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , elapsed_time_ms <span style="color: #808080;">=</span> QP.<span style="color: #202020;">elapsed_time_ms</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , cpu_time_ms <span style="color: #808080;">=</span> QP.<span style="color: #202020;">cpu_time_ms</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , row_count <span style="color: #808080;">=</span> QP.<span style="color: #202020;">row_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , estimate_row_count <span style="color: #808080;">=</span> QP.<span style="color: #202020;">estimate_row_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , logical_read_count <span style="color: #808080;">=</span> QP.<span style="color: #202020;">logical_read_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , rewind_count <span style="color: #808080;">=</span> QP.<span style="color: #202020;">rewind_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , rebind_count <span style="color: #808080;">=</span> QP.<span style="color: #202020;">rebind_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , end_of_scan_count <span style="color: #808080;">=</span> QP.<span style="color: #202020;">end_of_scan_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">object_name</span> <span style="color: #808080;">=</span> QP.<span style="color: #FF00FF;">object_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , index_name <span style="color: #808080;">=</span> QP.<span style="color: #202020;">index_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , scan_count <span style="color: #808080;">=</span> QP.<span style="color: #202020;">scan_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , time_stamp <span style="color: #808080;">=</span> QP.<span style="color: #202020;">time_stamp</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @query_profile <span style="color: #0000FF;">AS</span> QP<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; #query_profile_global <span style="color: #0000FF;">AS</span> QFG<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> QFG.<span style="color: #202020;">node_id</span> <span style="color: #808080;">=</span> QP.<span style="color: #202020;">node_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WAITFOR</span> DELAY @delay<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DELETE</span> <span style="color: #0000FF;">FROM</span> @query_profile<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @i <span style="color: #808080;">+=</span> <span style="color: #000;">1</span><br />
<span style="color: #0000FF;">END</span><br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #0000FF;">DISTINCT</span> <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; #query_profile_global<br />
<span style="color: #0000FF;">ORDER</span> &nbsp; <span style="color: #0000FF;">BY</span> node_id<br />
<span style="color: #008080;">--ORDER BY elapsed_time_ms DESC</span></div></td></tr></tbody></table></div>
<p>Ici on stocke le contenu de la DMV toutes les 10 ms. Le délai entre chaque boucle peut être adapté : si l&rsquo;on sait que la requête dure environ quart d&rsquo;heure, une récupération du contenu de la vue toutes les secondes est suffisante. Cette valeur peut donc être adaptée suivant la durée d&rsquo;exécution globale de la requête. Il faut aussi veiller à exécuter ce lot de requêtes dans le même contexte de base de données que celui sous lequel on exécute la requête à étudier. En effet, cela permet d&rsquo;obtenir le nom de l&rsquo;objet de base de données accédé :</p>
<p><img src="http://i.imgur.com/vdDfdkK.png" /></p>
<p>On constate dans la sortie du lot de requêtes interrogeant la DMV que, par exemple, l&rsquo;opérateur de <em>NodeID</em> 4 est l&rsquo;accès à l&rsquo;index cluster de la table <em>SalesOrderDetail</em>, et qu&rsquo;il a traité 121317 lignes. Voyons si cela est reflété par le plan d&rsquo;exécution réel graphique de la requête :</p>
<p><img src="http://i.imgur.com/Z6l9xMA.png" alt="" /></p>
<p>Le numéro de <em>NodeID</em> 4 est bien l&rsquo;opérateur exposé par la DMV, et si l&rsquo;on lit la ligne de la bulle dont le libellé est <em>Actual number of rows</em>, on a bien 121317.</p>
<p>Pour l&rsquo;étude des requêtes plus lourdes, la DMV <em>sys.dm_exec_query_profiles</em> nous permettra de repérer immédiatement les opérateurs les plus consommateurs de ressources, et donc de travailler directement sur ceux-ci en se reportant au plan de requête, puis à la requête elle-même pour en revoir l&rsquo;écriture et éventuellement l&rsquo;indexation.</p>
<p>Bonne optimisation !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Les nouveautés de l&#8217;optimiseur de SQL Server 2016</title>
		<link>https://blog.developpez.com/elsuket/p13088/moteur-de-base-de-donnees-sql-server/les-nouveautes-de-loptimiseur-de-sql-server-2016</link>
		<comments>https://blog.developpez.com/elsuket/p13088/moteur-de-base-de-donnees-sql-server/les-nouveautes-de-loptimiseur-de-sql-server-2016#comments</comments>
		<pubDate>Wed, 03 Aug 2016 20:28:29 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1310</guid>
		<description><![CDATA[Avec la sortie de SQL Server 2016, sous le mode de compatibilité des bases de données à 130, les corrections et ajouts sont listés dans ce billet officiel. On notera comme très bienvenues : le fait de ne plus avoir &#8230; <a href="https://blog.developpez.com/elsuket/p13088/moteur-de-base-de-donnees-sql-server/les-nouveautes-de-loptimiseur-de-sql-server-2016">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Avec la sortie de SQL Server 2016, sous le mode de compatibilité des bases de données à 130, les corrections et ajouts sont listés dans ce <a href="https://blogs.msdn.microsoft.com/sqlserverstorageengine/2016/05/23/query-optimizer-additions-in-sql-server/">billet officiel</a>.</p>
<p>On notera comme très bienvenues :</p>
<ul>
<li>le fait de ne plus avoir à activer le drapeau de trace 2371 pour voir le ré-échantillonnage des statistiques de colonnes et d&rsquo;index se faire lorsque la table a subi 20% du nombre de ses lignes en affectation</li>
<li>le drapeau de trace est l&rsquo;un de ceux qu&rsquo;on n&rsquo;ose pas activer, parce qu&rsquo;il peut être bénéfique à certaines requêtes et pas à d&rsquo;autres : sous le mode de compatibilité 130, ce sera le cas par défaut</li>
<li>la parallélisation de la mise à jour des statistiques échantillonnées, qui vient compléter avantageusement celles qui ne l&rsquo;étaient pas (FULLSCAN)</li>
</ul>
<p>Bonne lecture et optimisation de requêtes !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comment voir le contenu complet d&#8217;une colonne de type [n]varchar(max)</title>
		<link>https://blog.developpez.com/elsuket/p13087/moteur-de-base-de-donnees-sql-server/indexation/comment-voir-le-contenu-complet-dune-colonne-de-type-nvarcharmax</link>
		<comments>https://blog.developpez.com/elsuket/p13087/moteur-de-base-de-donnees-sql-server/indexation/comment-voir-le-contenu-complet-dune-colonne-de-type-nvarcharmax#comments</comments>
		<pubDate>Wed, 03 Aug 2016 08:00:33 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>
		<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[contenu]]></category>
		<category><![CDATA[intégral]]></category>
		<category><![CDATA[SLQ Server Management Studio]]></category>
		<category><![CDATA[SMSS]]></category>
		<category><![CDATA[texte]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1287</guid>
		<description><![CDATA[S&#8217;apercevoir, alors que l&#8217;on vient de coller une valeur d&#8217;une colonne du résultat d&#8217;une requête dans SQL Server Management Studio, que le buffer est limité, est quelque peu frustrant. On peut parfois dépasser cette limite en se rendant dans le &#8230; <a href="https://blog.developpez.com/elsuket/p13087/moteur-de-base-de-donnees-sql-server/indexation/comment-voir-le-contenu-complet-dune-colonne-de-type-nvarcharmax">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>S&rsquo;apercevoir, alors que l&rsquo;on vient de coller une valeur d&rsquo;une colonne du résultat d&rsquo;une requête dans SQL Server Management Studio, que le buffer est limité, est quelque peu frustrant.<br />
On peut parfois dépasser cette limite en se rendant dans le menu Tools &gt; Options &gt; Query Results &gt; SLQ Server &gt; Results to Grid :</p>
<p><img src="http://i.imgur.com/E7x5Ysi.png" alt="" /></p>
<p>Mais souvent, cela ne suffit pas. Voyons comment contourner ce petit problème :</p>
<p><span id="more-1287"></span></p>
<p>Pour les besoins de la démonstration, créons une petite table, avec une pile d&rsquo;exécution. C&rsquo;est ce que l&rsquo;on trouve parfois dans les bases de données lorsque celles-ci sont dédiées à une seule application et écrit les erreurs rencontrées directement dans une table :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br />313<br />314<br />315<br />316<br />317<br />318<br />319<br />320<br />321<br />322<br />323<br />324<br />325<br />326<br />327<br />328<br />329<br />330<br />331<br />332<br />333<br />334<br />335<br />336<br />337<br />338<br />339<br />340<br />341<br />342<br />343<br />344<br />345<br />346<br />347<br />348<br />349<br />350<br />351<br />352<br />353<br />354<br />355<br />356<br />357<br />358<br />359<br />360<br />361<br />362<br />363<br />364<br />365<br />366<br />367<br />368<br />369<br />370<br />371<br />372<br />373<br />374<br />375<br />376<br />377<br />378<br />379<br />380<br />381<br />382<br />383<br />384<br />385<br />386<br />387<br />388<br />389<br />390<br />391<br />392<br />393<br />394<br />395<br />396<br />397<br />398<br />399<br />400<br />401<br />402<br />403<br />404<br />405<br />406<br />407<br />408<br />409<br />410<br />411<br />412<br />413<br />414<br />415<br />416<br />417<br />418<br />419<br />420<br />421<br />422<br />423<br />424<br />425<br />426<br />427<br />428<br />429<br />430<br />431<br />432<br />433<br />434<br />435<br />436<br />437<br />438<br />439<br />440<br />441<br />442<br />443<br />444<br />445<br />446<br />447<br />448<br />449<br />450<br />451<br />452<br />453<br />454<br />455<br />456<br />457<br />458<br />459<br />460<br />461<br />462<br />463<br />464<br />465<br />466<br />467<br />468<br />469<br />470<br />471<br />472<br />473<br />474<br />475<br />476<br />477<br />478<br />479<br />480<br />481<br />482<br />483<br />484<br />485<br />486<br />487<br />488<br />489<br />490<br />491<br />492<br />493<br />494<br />495<br />496<br />497<br />498<br />499<br />500<br />501<br />502<br />503<br />504<br />505<br />506<br />507<br />508<br />509<br />510<br />511<br />512<br />513<br />514<br />515<br />516<br />517<br />518<br />519<br />520<br />521<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> dbo.<span style="color: #202020;">application_log</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; log_label <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">application_log</span><br />
<span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'[ERROR] org.springframework.boot.context.embedded.tomcat.TomcatStarter - Error starting Tomcat context: org.springframework.beans.factory.BeanCreationException<br />
[WARN] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt<br />
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) [spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) [spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) [spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at de.sveri.mct.Application.main(Application.java:72) [main/:na]<br />
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:98) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.(TomcatEmbeddedServletContainer.java:75) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:378) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:155) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:157) [spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) [spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 5 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:209) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:165) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:160) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:143) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.(ServletContextInitializerBeans.java:74) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getServletContextInitializerBeans(EmbeddedWebApplicationContext.java:234) [spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:221) [spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access$000(EmbeddedWebApplicationContext.java:84) [spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:206) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:54) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156) ~[tomcat-embed-core-8.0.23.jar:8.0.23]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.0.23.jar:8.0.23]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) ~[tomcat-embed-core-8.0.23.jar:8.0.23]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399) ~[tomcat-embed-core-8.0.23.jar:8.0.23]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_25]<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:649) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 34 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:164) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1365) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:606) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 36 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:523) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:512) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.security.config.annotation.web.configuration.AutowiredWebSecurityConfigurersIgnoreParents.getWebSecurityConfigurers(AutowiredWebSecurityConfigurersIgnoreParents.java:52) ~[spring-security-config-4.0.1.RELEASE.jar:4.0.1.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:112) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:129) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:49) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:342) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:120) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:242) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:161) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 40 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 62 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 64 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 75 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1477) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 77 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:444) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 90 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 98 common frames omitted<br />
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 105 common frames omitted<br />
Caused by: org.hibernate.AnnotationException: Unknown mappedBy in: de.sveri.mct.domain.Topic.topic, referenced property unknown: de.sveri.mct.domain.Topic.topic<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:160) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1697) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 113 common frames omitted<br />
[ERROR] org.springframework.boot.SpringApplication - Application startup failed<br />
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at de.sveri.mct.Application.main(Application.java:72) [main/:na]<br />
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:98) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.(TomcatEmbeddedServletContainer.java:75) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:378) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:155) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:157) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 5 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:209) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:165) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:160) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:143) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.(ServletContextInitializerBeans.java:74) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getServletContextInitializerBeans(EmbeddedWebApplicationContext.java:234) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:221) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access$000(EmbeddedWebApplicationContext.java:84) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:206) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:54) ~[spring-boot-1.2.4.RELEASE.jar:1.2.4.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156) ~[tomcat-embed-core-8.0.23.jar:8.0.23]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.0.23.jar:8.0.23]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) ~[tomcat-embed-core-8.0.23.jar:8.0.23]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399) ~[tomcat-embed-core-8.0.23.jar:8.0.23]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_25]<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:649) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 34 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:164) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1365) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:606) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 36 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:523) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:512) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.security.config.annotation.web.configuration.AutowiredWebSecurityConfigurersIgnoreParents.getWebSecurityConfigurers(AutowiredWebSecurityConfigurersIgnoreParents.java:52) ~[spring-security-config-4.0.1.RELEASE.jar:4.0.1.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:112) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:129) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:49) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:342) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:120) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:242) ~[spring-expression-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:161) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 40 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 62 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 64 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 75 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1477) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 77 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:444) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 90 common frames omitted<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 98 common frames omitted<br />
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 105 common frames omitted<br />
Caused by: org.hibernate.AnnotationException: Unknown mappedBy in: de.sveri.mct.domain.Topic.topic, referenced property unknown: de.sveri.mct.domain.Topic.topic<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:160) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1697) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846) ~[hibernate-core-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 113 common frames omitted<br />
Exception in thread &quot;main&quot; org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at de.sveri.mct.Application.main(Application.java:72)<br />
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:98)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.(TomcatEmbeddedServletContainer.java:75)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:378)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:155)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:157)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 5 more<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:209)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:165)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:160)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:143)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.ServletContextInitializerBeans.(ServletContextInitializerBeans.java:74)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getServletContextInitializerBeans(EmbeddedWebApplicationContext.java:234)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:221)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access$000(EmbeddedWebApplicationContext.java:84)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:206)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.boot.context.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:54)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.util.concurrent.FutureTask.run(FutureTask.java:266)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.lang.Thread.run(Thread.java:745)<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:649)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 34 more<br />
Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:164)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1365)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:606)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 36 more<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'securityConfiguration'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:523)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:512)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.security.config.annotation.web.configuration.AutowiredWebSecurityConfigurersIgnoreParents.getWebSecurityConfigurers(AutowiredWebSecurityConfigurersIgnoreParents.java:52)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at java.lang.reflect.Method.invoke(Method.java:483)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:112)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:129)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:49)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:342)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:120)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:242)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:161)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 40 more<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService de.sveri.mct.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 62 more<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userDetailsService'</span><span style="color: #FF0000;">': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 64 more<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.sveri.mct.repository.UserRepository de.sveri.mct.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 75 more<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'userRepository'</span><span style="color: #FF0000;">': Cannot create inner bean '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property '</span><span style="color: #FF0000;">'entityManager'</span><span style="color: #FF0000;">'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:313)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1477)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 77 more<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'(inner bean)#58e814e6'</span><span style="color: #FF0000;">': Cannot resolve reference to bean '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:444)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:299)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 90 more<br />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '</span><span style="color: #FF0000;">'entityManagerFactory'</span><span style="color: #FF0000;">' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 98 more<br />
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 105 more<br />
Caused by: org.hibernate.AnnotationException: Unknown mappedBy in: de.sveri.mct.domain.Topic.topic, referenced property unknown: de.sveri.mct.domain.Topic.topic<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:160)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1697)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)<br />
&nbsp; &nbsp; &nbsp; &nbsp; at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)<br />
&nbsp; &nbsp; &nbsp; &nbsp; ... 113 more<br />
Disconnected from the target VM, address: '</span><span style="color: #FF0000;">'127.0.0.1:54986'</span><span style="color: #FF0000;">', transport: '</span><span style="color: #FF0000;">'socket'</span><span style="color: #FF0000;">'<br />
<br />
Process finished with exit code 1'</span><span style="color: #808080;">&#41;</span><br />
GO</div></td></tr></tbody></table></div>
<p>Consultons maintenant la longueur de cette chaîne :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; DATALENGTH<span style="color: #808080;">&#40;</span>log_label<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> byte_length<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; dbo.<span style="color: #202020;">application_log</span></div></td></tr></tbody></table></div>
<p>Nous obtenons 111640. Si nous exécutons maintenant :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; log_label<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; dbo.<span style="color: #202020;">application_log</span></div></td></tr></tbody></table></div>
<p>Puis que l&rsquo;on réalise un copier-coller de la valeur dans une nouvelle fenêtre de requête, nous allons voir que nous n&rsquo;obtenons pas l&rsquo;intégralité du texte :</p>
<p><img src="http://i.imgur.com/2OAf2Ps.png" alt="" /></p>
<p>On a remarqué cependant que les documents XML, notamment les plans de requête, sont récupérables dans leur intégralité, alors que ce sont généralement des documents sont relativement longs. Tentons donc :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>log_label <span style="color: #0000FF;">AS</span> XML<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> log_label<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; dbo.<span style="color: #202020;">application_log</span></div></td></tr></tbody></table></div>
<p>Ceci se termine directement avec l&rsquo;erreur suivante affichée dans la console :</p>
<blockquote><p>Msg 9400, Level 16, State 1, Line 526<br />
XML parsing: line 513, character 33, unexpected end of input</p></blockquote>
<p>Si l&rsquo;on en vient cependant à utiliser le marqueur de section texte CDATA, qui échappe l&rsquo;interprétation XML du document considéré, on obtient :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span> <span style="color: #0000FF;">AS</span> xml<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; dbo.<span style="color: #202020;">application_log</span></div></td></tr></tbody></table></div>
<p><img src="http://i.imgur.com/oWoUkuq.png" alt="" /></p>
<p>En cliquant sur le lien proposé, un nouvel onglet s&rsquo;ouvre, dans lequel l&rsquo;intégralité du texte est exposée :</p>
<p><img src="http://i.imgur.com/4Nbl42U.png" alt="" /></p>
<p>Bonne consultation de logs !</p>
<p>@++ <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Les attentes, c&#8217;est quoi au juste ?</title>
		<link>https://blog.developpez.com/elsuket/p13086/moteur-de-base-de-donnees-sql-server/les-attentes-cest-quoi-au-juste</link>
		<comments>https://blog.developpez.com/elsuket/p13086/moteur-de-base-de-donnees-sql-server/les-attentes-cest-quoi-au-juste#comments</comments>
		<pubDate>Tue, 02 Aug 2016 20:27:40 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1239</guid>
		<description><![CDATA[Les attentes sont aux threads SQL Server ce qu&#8217;elles sont aux patients dans une salle d&#8217;attente. Voilà ! Bien entendu ce n&#8217;est pas aussi simple que cela. Démarrons donc une série de billets sur les attentes au sein du moteur &#8230; <a href="https://blog.developpez.com/elsuket/p13086/moteur-de-base-de-donnees-sql-server/les-attentes-cest-quoi-au-juste">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Les attentes sont aux threads SQL Server ce qu&rsquo;elles sont aux patients dans une salle d&rsquo;attente. Voilà !</p>
<p>Bien entendu ce n&rsquo;est pas aussi simple que cela. Démarrons donc une série de billets sur les attentes au sein du moteur de bases de données de SQL Server, en détaillant un peu le mode d&rsquo;exécution des requêtes.</p>
<p><span id="more-1239"></span></p>
<p><strong>Modes d&rsquo;exécution des processus : avant et après SQL Server 2000</strong></p>
<p>Sur les versions antérieures à SQL Server 2005, une grande partie des opérations étaient effectuées par le système d&rsquo;exploitation lui-même. Ceci fait que jusqu&rsquo;à SQL Server 2000, il était difficile de comprendre un problème de performance, c&rsquo;est à dire d&rsquo;obtenir des détails sur le traitement interne des processus par Windows. Cinq ans et une tétra-volée de lignes de code plus tard, Microsoft nous livre un nouvel opus de SQL Server, estampillé 2005, avec un nouveau composant majeur : SQL Operating System (SQLOS). Celui-ci est la fondation du succès actuel du moteur, et il nous permet, à l&rsquo;aide des vues et fonctions de gestion dynamique (DMVs, DMFs, ou DMOs dans la littérature), de mieux comprendre ce qui se passe lorsque l&rsquo;on trouve que l&rsquo;instance, la base de données, ou une requête se comportent anormalement.</p>
<p>Outre le fait que le moteur est, avec cette version, devenu hautement configurable, il implémente un mode d&rsquo;exécution simultané de processus en mode coopératif, à la différence de Windows, qui les exécute par préemption. En effet, le système d&rsquo;exploitation exécute un processus en octroyant à celui-ci un certain temps, qu&rsquo;on appelle quantum, et une priorité par rapport aux autres processus. Cette priorité varie en fonction des ressources matérielles disponibles, de l&rsquo;activité courante, &#8230; Il fait donc s&rsquo;exécuter tour à tour des processus en interrompant l&rsquo;exécution d&rsquo;autres.</p>
<p>On voit donc que cela se pose directement en opposition à la concurrence d&rsquo;accès que doit supporter un moteur de bases de données relationnelles SQL : les interruptions d&rsquo;exécutions peuvent se produire pour plusieurs processus de SQL Server, mais aussi être générés par les processus d&rsquo;autres applications s&rsquo;exécutant sur la même machine (antivirus par exemple, &#8230;). De là le mode coopératif, qui laisse le soin au moteur de gérer ses propres processus, à de rares exceptions près (création des fichiers d&rsquo;une base de données, &#8230;). Ce mode procure un excellent gain de performance observable dès la fin de la migration d&rsquo;une base SQL Server 2000 à 2005, mais pose aussi une nouvelle problématique : la concurrence d&rsquo;accès aux ressources logiques ou physiques que gère le moteur, qui doivent souvent être sérialisées.</p>
<p><strong>Planificateurs, tâches, et unités d&rsquo;exécution</strong><br />
Le mode coopératif d&rsquo;exécution de processus est supporté par un modèle de traitement différent, qui suit le schéma suivant : </p>
<p><img src="http://i.imgur.com/Rs86lka.png" alt="" /></p>
<p><strong>Les sessions</strong><br />
C&rsquo;est la connexion d&rsquo;une application cliente à l&rsquo;instance SQL Server. On peut connaître le détail de chacune des sessions ouvertes sur l&rsquo;instance en interrogeant la vue de gestion dynamique <em>sys.dm_exec_sessions</em>. Les sessions dont la colonne <em>session_id</em> ont une valeur inférieure à 50 sont des sessions ouvertes par le système lui même, pour la gestion de ses processus d&rsquo;arrière-plan. Il est possible que, lorsqu&rsquo;une charge de travail importante s&rsquo;exécute, le moteur ouvre une session dont la valeur de <em>session_id</em> est supérieur à 50. Si on veut donc être sûr de ne requêter que les sessions utilisateur, on peut filtrer par la colonne <em>is_user_process</em>.</p>
<p><strong>Les requêtes</strong><br />
Ce sont, au sens logique, les requêtes en cours d&rsquo;exécution par le moteur. Elles sont elles aussi exposées par une vue de gestion dynamique :  <em>sys.dm_exec_requests</em>. Ici aussi, on retrouve de nombreuses caractéristiques, parmi lesquelles le type et la durée d&rsquo;attente (<em>wait_type</em>, <em>last_wait_type</em>, et <em>wait_time</em>), le numéro de la session qui bloque l&rsquo;exécution de la requête (<em>blocking_session_id</em>). A ce stade du modèle d&rsquo;exécution des requêtes, on voit donc que la gestion des accès concurrentiels aux ressources est au cœur du moteur de base de données.</p>
<p>En suivant le schéma ci-dessus, on peut lier <em>sys.dm_exec_sessions</em> à <em>sys.dm_exec_requests</em> sur la colonne <em>session_id</em>, et cette dernière à <em>sys.dm_os_tasks</em> sur la colonne <em>task_address</em>. Et la colonne <em>task_address</em>, me direz-vous ? voici &#8230;</p>
<p><strong>Les tâches</strong><br />
Elles incarnent le travail qui doit être effectué par SQLOS pour résoudre une requête; à une requête peuvent correspondre plusieurs tâches. Lorsque le moteur soumet une requête à exécution, il crée une série de tâches. On peut en obtenir les détails en interrogeant la vue <em>sys.dm_os_tasks</em>. Même sur une instance où aucune requête n&rsquo;est en cours d&rsquo;exécution, l&rsquo;interrogation de cette vue nous retourne quelques lignes : comme évoqué, SQL Server exécute ses propres processus en arrière-plan; c&rsquo;est d&rsquo;ailleurs ce que l&rsquo;on peut constater en observant la colonne <em>session_id</em> : nombreuses sont les lignes pour lesquelles la valeur est inférieure à 50. Ceci correspond à ce que nous avons observé à l&rsquo;interrogation de <em>sys.dm_exec_sessions</em>. Il en va de même pour la colonne <em>request_id</em> : elle nous permet de réaliser une jointure avec la vue <em>sys.dm_exec_requests</em>. Et la colonne <em>worker_address</em>, me direz-vous ? voici &#8230;</p>
<p><strong>Les unités d&rsquo;exécution</strong><br />
Les unités d&rsquo;exécution effectuent le travail de résolution de la requête que l&rsquo;on vient de soumettre, qui leur est ordonné par les tâches. A une tâche correspond une seule unité d&rsquo;exécution.</p>
<p>Elles sont groupées dans un pool, et à tout instant, on peut (généralement !) les classer en deux catégories : soit elles sont inoccupées (elles bullent, potentiellement en regardant les copines travailler), soit elles exécutent une tâche. Lorsque toutes les unités d&rsquo;exécution sont occupées, la tâche est alors mise en attente jusqu&rsquo;à ce que l&rsquo;une d&rsquo;entre-elles devienne disponible.</p>
<p>Le nombre d&rsquo;unités d&rsquo;exécution est automatiquement calculé par SQL Server durant l&rsquo;installation. Pour connaître le nombre d&rsquo;unités d&rsquo;exécution créées par SQL Server, il suffit de s&rsquo;en remettre à la table exposée sur <a href="https://msdn.microsoft.com/en-us/library/ms190219.aspx">cette page</a> de la documentation.</p>
<p>Le nombre d&rsquo;unités d&rsquo;exécution est configurable, et est par défaut à zéro : c&rsquo;est à dire qu&rsquo;on laisse SQL Server avec la configuration d&rsquo;installation. Dans la très grande majorité des cas, il n&rsquo;y a aucun besoin de modifier le nombre d&rsquo;unités d&rsquo;exécution. Bien sûr, un fil d&rsquo;exécution nécessite un peu de mémoire pour s&rsquo;exécuter : 2 Mo sur les machines dont le CPU fonctionne avec des mots de 64 bits. </p>
<p>On peut en obtenir les détails en interrogeant la vue de gestion dynamique <em>sys.dm_os_workers</em>. Celle-ci expose plusieurs colonnes renseignant sur l&rsquo;état de l&rsquo;unité, avec ses statistiques d&rsquo;exécution, et expose deux colonnes : <em>scheduler_address</em>, qui permet de faire la jointure avec la vue <em>sys.dm_os_schedulers</em>, et <em>task_address</em> avec la vue<em> sys.dm_os_tasks</em>. La colonne la plus intéressante pour le sujet que nous traitons est <em>state</em>, qui peut prendre les valeurs suivantes :</p>
<ul>
<li>INIT : SQLOS prépare l&rsquo;unité d&rsquo;exécution</li>
<li>RUNNING : l&rsquo;unité d&rsquo;exécution exécute actuellement un travail sur un processeur</li>
<li>RUNNABLE : l&rsquo;unité d&rsquo;exécution est en attente d&rsquo;un processeur pour exécuter un travail</li>
<li>SUSPENDED : l&rsquo;unité d&rsquo;exécution est en attente de l&rsquo;accès à une ressource</li>
</ul>
<p>Comme nous le verrons plus loin dans cet article, les unités d&rsquo;exécution passent de l&rsquo;état RUNNING à SUSPENDED, puis à RUNNABLE, et de nouveau à RUNNING jusqu&rsquo;à ce que le travail qu&rsquo;elles ont à exécuter soit terminé.</p>
<p>Et la colonne <em>thread_address</em>, me direz-vous ? voici &#8230;</p>
<p><strong>Les fils d&rsquo;exécution</strong><br />
L&rsquo;unité d&rsquo;exécution ne réalise pas précisément l&rsquo;exécution elle-même : elle demande un fil au système d&rsquo;exploitation. C&rsquo;est ce qu&rsquo;expose la vue de gestion dynamique <em>sys.dm_os_threads</em>.</p>
<p><strong>Les planificateurs</strong><br />
Un planificateur est en charge de gérer les unités d&rsquo;exécution. En ce sens, c&rsquo;est un peu le chef d&rsquo;orchestre de l&rsquo;exécution concurrente des requêtes, qu&rsquo;elles proviennent d&rsquo;applications ou des processus internes à SQL Server. Lorsqu&rsquo;une tâche requiert un core pour s&rsquo;exécuter, c&rsquo;est le planificateur qui assigne la tâche à un des cores disponibles.</p>
<p>C&rsquo;est aussi ce composant qui s&rsquo;assure que les unités d&rsquo;exécution coopèrent en cédant le core auxquels elles sont attachées lorsqu&rsquo;elles atteignent leur quantum. On pourrait alors argumenter que ce mode d&rsquo;exécution n&rsquo;est pas si coopératif que son nom le laisse entendre. Le quantum est en fait en place parce que le planificateur ne permet qu&rsquo;à une seule unité d&rsquo;exécution d&rsquo;occuper un core. S&rsquo;il n&rsquo;existait pas, alors l&rsquo;unité d&rsquo;exécution pourrait occuper un core indéfiniment.</p>
<p>Chaque core de CPU, qu&rsquo;il soit logique ou physique, dispose d&rsquo;un (et d&rsquo;un seul) planificateur. Par exemple, supposons que l&rsquo;on dispose d&rsquo;une machine équipée de deux processeurs à huit cœurs chacun : il y a aura donc 16 planificateurs.</p>
<p>On peut obtenir les détails de chaque planificateur en interrogeant la vue de gestion dynamique <em>sys.dm_os_schedulers</em> :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; parent_node_id <span style="color: #0000FF;">AS</span> NUMA_node_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , scheduler_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , cpu_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , status<br />
&nbsp; &nbsp; &nbsp; &nbsp; , active_worker_address<br />
&nbsp; &nbsp; &nbsp; &nbsp; , quantum_length_us<br />
&nbsp; &nbsp; &nbsp; &nbsp; , total_cpu_usage_ms<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">dm_os_schedulers</span></div></td></tr></tbody></table></div>
<p>On peut y voir à quel core le planificateur est attaché, son statut (VISIBLE ONLINE : utilisé pour les requêtes utilisateur, HIDDEN ONLINE : utilisé par les processus d&rsquo;arrière plan du moteur), le quantum qui lui est attribué (toujours à 4000 µs, et ce n&rsquo;est pas configurable), et le temps CPU consommé par chaque planificateur. Si l&rsquo;on rajoute les colonnes :</p>
<ul>
<li>current_workers_count</li>
<li>active_workers_count</li>
<li>current_tasks_count</li>
<li>runnable_tasks_count</li>
<li>work_queue_count</li>
</ul>
<p>On a alors une idée de la charge que supporte l&rsquo;instance SQL Server étudiée. Par exemple, si la dernière colonne de cette liste montre des nombres élevés, il est probable que SQL Server soit actuellement sous pression CPU.</p>
<p>Vous remarquerez aussi un planificateur dont le statut est VISIBLE ONLINE (DAC) : la fonctionnalité <a href="https://msdn.microsoft.com/fr-fr/library/ms189595.aspx"><em>Dedicated Administrator Connection</em></a> permet de se connecter à une instance SQL Server lorsqu&rsquo;elle ne réagit plus (surcharge CPU par exemple, &#8230;). Ce planificateur lui est dédié.</p>
<p><img src="http://i.imgur.com/yvHkTMI.png" alt="" /></p>
<p>Nous avons vu comment le moteur distribue le travail aux CPUs pour maximiser la concurrence d&rsquo;exécution des requêtes. Voyons ce qui se passe lorsque le planificateur doit placer une requête en attente, que ce soit pour l&rsquo;accès à une ressource, l&rsquo;acquisition d&rsquo;un verrou, ou tout simplement lorsque le quantum est atteint &#8230;</p>
<p><!--more--><br />
<strong>Les attentes</strong></p>
<p>Les fils d&rsquo;exécution suivent les phases et les états suivant les deux graphes suivants, qui sont superposables :</p>
<p><img src="http://i.imgur.com/eQUVIxO.png" alt="" /></p>
<p>Comme nous l&rsquo;avons vu, les unités d&rsquo;exécution passent de l&rsquo;état RUNNING à SUSPENDED à RUNNABLE, dans cet ordre (à de rares exceptions près, notamment lors de l&rsquo;utilisation de la fonctionnalité <em>Resource Governor</em>). Les attentes représentent le temps que les unités d&rsquo;exécution participant à l&rsquo;exécution d&rsquo;une requête on passé entre le passage d&rsquo;un de ces états à un autre. Ce temps est subdivisé en deux catégories :</p>
<ul>
<li>L&rsquo;attente de l&rsquo;accès à une ressource : la ressource peut être un planificateur, le gestionnaire de ressources pour les requêtes parallélisées, un objet de verrouillage (pose d&rsquo;un verrou sur base de données, fichier de base de données, un schéma, une table, une page, une clé, une étendue, les métadonnées, les unités d&rsquo;allocation, la CLR, ou pose de loquets (<em>latch</em> dans la littérature) &#8230; On l&rsquo;appelle compendieusement <strong>attente de ressource.</strong></li>
<li>L&rsquo;attente de la disponibilité d&rsquo;un processeur après que la ressource soit devenue disponible : c&rsquo;est ce qu&rsquo;on appelle de façon plus concise l&rsquo;<strong>attente de signal</strong>.</li>
</ul>
<p>Le temps d&rsquo;attente est la somme de ces deux temps. Forts de cela, votre œil avisé vous a certainement amené à vous demander : Pourquoi avoir utilisé les deux termes <em>Liste</em> et <em>Queue</em> sur le schéma ci-dessus ?</p>
<p><strong>La liste des unités d&rsquo;exécution</strong><br />
Cette liste des unités d&rsquo;exécution à l&rsquo;état SUSPENDED n&rsquo;a pas d&rsquo;ordre ni de priorité de traitement. Toute unité d&rsquo;exécution peut y rester sans limite de temps, et le nombre d’éléments que cette liste peut contenir n&rsquo;a pas non plus de limite. </p>
<p>L&rsquo;unité d&rsquo;exécution est ajoutée à cette liste lorsque son état passe de RUNNING à SUSPENDED.  Elle en est retirée lorsque son état passe de SUSPENDED à RUNNABLE : ceci se produit lorsque cette dernière est notifiée que la ressource qu&rsquo;elle attendait est maintenant disponible, et ce toujours sans ordre ni priorité de traitement.</p>
<p>Ces attentes sont exposées par la vue de gestion dynamique <em>sys.dm_os_waiting_tasks</em>.</p>
<p>Si cela vous a fait penser à l&rsquo;attente de pintes au zinc d&rsquo;un bar bondé, sachez que vous n&rsquo;êtes pas seul !</p>
<p><strong>La queue des unités d&rsquo;exécution en attente d&rsquo;un core</strong><br />
Cette queue contient la liste des unités d&rsquo;exécution dont l&rsquo;état est RUNNABLE, et fonctionne comme un FIFO. L&rsquo;unité d&rsquo;exécution qui se trouve donc être entrée la première dans la queue est la première à être attachée à un core disponible.</p>
<p>Une unité d&rsquo;exécution entre dans cette queue lorsque son état passe de SUSPENDED à RUNNABLE. Ceci se produit par exemple lorsqu&rsquo;une autre unité d&rsquo;exécution en cours de traitement par l&rsquo;un des cores alloués à l&rsquo;instance SQL Server dépasse son quantum, ou que son état devient SUSPENDED.</p>
<p>Le nombre d&rsquo;éléments de cette queue est exposé par la vue de gestion dynamique <em>sys.dm_os_schedulers</em>, à travers la colonne <em>runnable_tasks_count</em>.</p>
<p>Si cela vous a fait penser à l&rsquo;attente pour l&rsquo;accès aux toilettes d&rsquo;un bar bondé, sachez que vous n&rsquo;êtes pas seul !</p>
<p>Pour illustrer tout cela, le schéma plus haut peut être complété par les deux losanges rouges ci-dessous :</p>
<p><img src="http://i.imgur.com/mCSWcDw.png" alt="" /></p>
<p>Voilà pour la description du fonctionnement de l&rsquo;exécution des requêtes.<br />
Dans un billet à venir, nous verrons les types d&rsquo;attentes les plus communs, et comment on peut les interpréter.</p>
<p>A bientôt, et bonne gestion des attentes. N&rsquo;hésitez pas à commenter cet article !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Troubleshooting avec les événements étendus en vidéo</title>
		<link>https://blog.developpez.com/elsuket/p13085/moteur-de-base-de-donnees-sql-server/evenements-etendus/troubleshooting-avec-les-evenements-etendus-en-video</link>
		<comments>https://blog.developpez.com/elsuket/p13085/moteur-de-base-de-donnees-sql-server/evenements-etendus/troubleshooting-avec-les-evenements-etendus-en-video#comments</comments>
		<pubDate>Thu, 28 Jul 2016 08:00:08 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Evénements étendus]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1291</guid>
		<description><![CDATA[Voici la vidéo de la session que j&#8217;ai animé avec David Barbarin sur les événements étendus. Cela recoupe l&#8217;article et la partie du livre sur SQL Server 2014 consacrée à cette fonctionnalité. Bonne visualisation !]]></description>
				<content:encoded><![CDATA[<p>Voici la <a href="https://www.youtube.com/watch?v=gwZ6sD6Xkho">vidéo</a> de la session que j&rsquo;ai animé avec <a href="http://blog.developpez.com/mikedavem/">David Barbarin</a> sur les événements étendus.</p>
<p>Cela recoupe l&rsquo;<a href="http://elsuket.developpez.com/tutoriels/sqlserveur/EvenementsEtendusSQLServer2008/">article</a> et la partie du <a href="http://www.eyrolles.com/Informatique/Livre/sql-server-2014-9782212135923">livre sur SQL Server 2014</a> consacrée à cette fonctionnalité.</p>
<p>Bonne visualisation !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Livre SQL Server 2014 &#8211; chapitres et index à télécharger : les liens</title>
		<link>https://blog.developpez.com/elsuket/p13084/annonces/livre-sql-server-2014-chapitres-et-index-a-telecharger-les-liens</link>
		<comments>https://blog.developpez.com/elsuket/p13084/annonces/livre-sql-server-2014-chapitres-et-index-a-telecharger-les-liens#comments</comments>
		<pubDate>Wed, 27 Jul 2016 19:54:03 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1289</guid>
		<description><![CDATA[Le livre SQL Server 2014 vient avec plusieurs chapitres et l&#8217;index du livre qui sont à télécharger. Voici les liens directs vers celles-ci. Ils sont résumés dans le billet de Frédéric Brouard. Bonne lecture, et merci de vos retours sur &#8230; <a href="https://blog.developpez.com/elsuket/p13084/annonces/livre-sql-server-2014-chapitres-et-index-a-telecharger-les-liens">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Le livre SQL Server 2014 vient avec plusieurs chapitres et l&rsquo;index du livre qui sont à télécharger. Voici les liens directs vers celles-ci.</p>
<p><span id="more-1289"></span></p>
<p>Ils sont résumés dans le <a href="http://blog.developpez.com/sqlpro/p13035/ms-sql-server/sql-server-2014-les-ressources-du-livre">billet</a> de Frédéric Brouard.</p>
<p>Bonne lecture, et merci de vos <a href="http://www.developpez.net/forums/d1491949/bases-donnees/ms-sql-server/livre-sql-server-2014-frederic-brouard-christian-soutou-nicolas-souquet-david-barbarin/">retours</a> sur le forum !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Récompense MVP : Chapitre 2016</title>
		<link>https://blog.developpez.com/elsuket/p13077/annonces/recompense-mvp-chapitre-2016</link>
		<comments>https://blog.developpez.com/elsuket/p13077/annonces/recompense-mvp-chapitre-2016#comments</comments>
		<pubDate>Mon, 11 Jul 2016 21:56:36 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1279</guid>
		<description><![CDATA[Microsoft vient de me remettre cette récompense pour la sixième fois, et à quelques jours près, un an après mon retour en France. Comme toute récompense, elle est le résultat de la cohésion de la communauté SQL Server, et à &#8230; <a href="https://blog.developpez.com/elsuket/p13077/annonces/recompense-mvp-chapitre-2016">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Microsoft vient de me remettre cette récompense pour la sixième fois, et à quelques jours près, un an après mon retour en France.<br />
Comme toute récompense, elle est le résultat de la cohésion de la communauté SQL Server, et à ce titre, je souhaite remercier tout spécialement :</p>
<p>Dans la catégorie base de données :</p>
<ul>
<li><a href="https://sites.google.com/a/pascale-doz.com/sql-server/home">Pascale Doz</a>, experte en bases de données;</li>
<li>Frédéric Brouard, alias <a href="http://blog.developpez.com/sqlpro/">SQLPro</a>, expert en bases de données;</li>
<li>Rudi Bruchez, alias <a href="http://www.babaluga.com/">Babaluga</a>, expert en bases de données;</li>
<li>David Barbarin, alias <a href="http://blog.developpez.com/mikedavem/">Mikedavem</a>, expert SQL Server</li>
</ul>
<p>Dans la catégorie recrutement IT : Clément Bocquentin, consultant indépendant en <a href="http://crescit-consulting.fr/">recrutement</a>;</p>
<p>Dans la catégorie communautés :</p>
<ul>
<li>Toute l&rsquo;équipe de Développez.com, et les participants au forum, sans qui je n&rsquo;aurai pas le plaisir de connaître toutes ces personnes;</li>
<li>Martine Thiphaine, Lead MVP Microsoft France;</li>
<li>Les membres du <a href="http://guss.pro/">Groupe des Utilisateurs de SQL Server</a></li>
</ul>
<p>Last but not least : <a href="http://blog.datafly.pro/">Arian Papillon</a>, <a href="http://www.concatskills.com/">Sarah Bessard</a> et <a href="https://fr.linkedin.com/in/gilles-ducassou-3712b219">Gilles Ducassou</a> (encore des experts SQL Server ! :D)</p>
<p>A très bientôt dans la mécanique interne de SQL Server <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Promotion sur les livres sur Microsoft Press Store</title>
		<link>https://blog.developpez.com/elsuket/p13058/t-sql/promotion-sur-les-livres-sur-microsoft-press-store</link>
		<comments>https://blog.developpez.com/elsuket/p13058/t-sql/promotion-sur-les-livres-sur-microsoft-press-store#comments</comments>
		<pubDate>Tue, 28 Jun 2016 22:04:59 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Lecture]]></category>
		<category><![CDATA[SQL général]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1257</guid>
		<description><![CDATA[Le livre T-SQL Fundamentals d&#8217;Itzik Ben-Gan, avec qui on a la sensation de réapprendre le T-SQL à chaque ouvrage, va bientôt arriver dans son troisième opus. Pour l&#8217;occasion, Microsoft offre jusqu&#8217;à 40% de remise avec le code PREORDER. Ceci est &#8230; <a href="https://blog.developpez.com/elsuket/p13058/t-sql/promotion-sur-les-livres-sur-microsoft-press-store">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Le livre T-SQL Fundamentals d&rsquo;Itzik Ben-Gan, avec qui on a la sensation de réapprendre le T-SQL à chaque ouvrage, va bientôt arriver dans son <a href="https://www.microsoftpressstore.com/cart/buy.aspx?isbn=9781509302000&amp;partner=76&amp;cmd=add">troisième opus</a>. Pour l&rsquo;occasion, Microsoft offre jusqu&rsquo;à 40% de remise avec le code PREORDER. Ceci est valable jusqu&rsquo;au 31 Juillet 2016.</p>
<p>Bonne lecture !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Résumé du SQL Saturday #501 à Paris par la célèbre Sarah Bessard</title>
		<link>https://blog.developpez.com/elsuket/p13057/moteur-de-base-de-donnees-sql-server/resume-du-sql-saturday-501-a-paris-par-la-celebre-sarah-bessard</link>
		<comments>https://blog.developpez.com/elsuket/p13057/moteur-de-base-de-donnees-sql-server/resume-du-sql-saturday-501-a-paris-par-la-celebre-sarah-bessard#comments</comments>
		<pubDate>Sun, 26 Jun 2016 18:16:41 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1237</guid>
		<description><![CDATA[Je me suis rendu hier au SQL Saturdays organisés à Paris par le GUSS, un bel événement, beaucoup de monde, et une vue imprenable sur Paris. J&#8217;ai eu l&#8217;honneur et l&#8217;avantage de faire la rencontre de la très célèbre Sarah &#8230; <a href="https://blog.developpez.com/elsuket/p13057/moteur-de-base-de-donnees-sql-server/resume-du-sql-saturday-501-a-paris-par-la-celebre-sarah-bessard">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Je me suis rendu hier au SQL Saturdays organisés à Paris par le <a href="http://www.concatskills.com/2016/06/26/keyser-soze-au-sqlsat2016/">GUSS</a>, un bel événement, beaucoup de monde, et une vue imprenable sur Paris.</p>
<p>J&rsquo;ai eu l&rsquo;honneur et l&rsquo;avantage de faire la rencontre de la très célèbre Sarah Bessard, dont j&rsquo;entendais régulièrement parler depuis mon rapatriement en France, sans pour autant l&rsquo;avoir encore vue de mes yeux. Elle a résumé avec un humour qui n&rsquo;a d&rsquo;égal que son talent pour l&rsquo;animation par une mise en scène d&rsquo;un excellente session sur le Query Store en compagnie de Philippe Geiger, et d&rsquo;une autre sur le processus de migration d&rsquo;une version à l&rsquo;autre de SQL Server, avec Arian Papillon, en sombrero et collier de fleurs &#8230; Preuve, s&rsquo;il en fallait encore, de la nécessité de femmes dans ce mondes de barbus !</p>
<p>Je vous laisse donc vous délecter de ce <a href="http://www.concatskills.com/2016/06/26/keyser-soze-au-sqlsat2016/">résumé</a>, car je n&rsquo;aurais pas pu l&rsquo;écrire mieux qu&rsquo;elle. Croyez-le ou non, il colle très bien à la réalité !</p>
<p>@++ <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vérifier la validité d&#8217;un SIRET &#8211; Algorithme de Luhn</title>
		<link>https://blog.developpez.com/elsuket/p13056/snippets/verifier-la-validite-dun-siret-algorithme-de-luhn</link>
		<comments>https://blog.developpez.com/elsuket/p13056/snippets/verifier-la-validite-dun-siret-algorithme-de-luhn#comments</comments>
		<pubDate>Thu, 23 Jun 2016 18:54:56 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1229</guid>
		<description><![CDATA[La fragmentation et la défragmentation des index relationnels est un sujet connu sur lequel la littérature ne manque pas. Mais on voit bien moins souvent des lignes sur les index fulltext, donc la fragmentation élevée nuit de la même façon &#8230; <a href="https://blog.developpez.com/elsuket/p13047/moteur-de-base-de-donnees-sql-server/indexation/mesurer-et-remedier-a-la-fragmentation-des-index-fulltext">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La fragmentation et la défragmentation des index relationnels est un sujet connu sur lequel la littérature ne manque pas. Mais on voit bien moins souvent des lignes sur les index fulltext, donc la fragmentation élevée nuit de la même façon aux performances des requêtes que leurs cousins relationnels.</p>
<p>Voici donc une requête qui permet de mesurer la fragmentation des index fulltext, et qui génère l&rsquo;instruction de maintenance adéquate, le cas échéant :</p>
<p><span id="more-1229"></span></p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CTE <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; C.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> catalog_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , I.<span style="color: #202020;">change_tracking_state_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , S.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.'</span> <span style="color: #808080;">+</span> T.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> table_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , F.<span style="color: #202020;">fragment_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , F.<span style="color: #202020;">index_size_MB</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , F.<span style="color: #202020;">largest_fragment_size_MB</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , F.<span style="color: #202020;">avg_fragment_MB</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100.0</span> <span style="color: #808080;">*</span> <span style="color: #808080;">&#40;</span>F.<span style="color: #202020;">index_size_MB</span> <span style="color: #808080;">-</span> F.<span style="color: #202020;">avg_fragment_MB</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #0000FF;">NULLIF</span><span style="color: #808080;">&#40;</span>F.<span style="color: #202020;">index_size_MB</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">decimal</span><span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>,<span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> avg_MB_frag_pct<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span> <span style="color: #808080;">-</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">100.0</span> <span style="color: #808080;">/</span> F.<span style="color: #202020;">fragment_count</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">decimal</span><span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>,<span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> avg_frag_count_pct<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">fulltext_catalogs</span> <span style="color: #0000FF;">AS</span> C<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">fulltext_indexes</span> <span style="color: #0000FF;">AS</span> I<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> I.<span style="color: #202020;">fulltext_catalog_id</span> <span style="color: #808080;">=</span> C.<span style="color: #202020;">fulltext_catalog_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Compute fragment data for each table with a full-text index</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; table_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> fragment_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">SUM</span><span style="color: #808080;">&#40;</span>data_size <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1024.0</span> <span style="color: #808080;">*</span> <span style="color: #000;">1024</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">decimal</span><span style="color: #808080;">&#40;</span><span style="color: #000;">9</span>,<span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> index_size_MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">AVG</span><span style="color: #808080;">&#40;</span>data_size <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1024.0</span> <span style="color: #808080;">*</span> <span style="color: #000;">1024</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">decimal</span><span style="color: #808080;">&#40;</span><span style="color: #000;">9</span>,<span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> avg_fragment_MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#40;</span>data_size <span style="color: #808080;">/</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1024.0</span> <span style="color: #808080;">*</span> <span style="color: #000;">1024</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">decimal</span><span style="color: #808080;">&#40;</span><span style="color: #000;">9</span>,<span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> largest_fragment_size_MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">fulltext_index_fragments</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">GROUP</span> &nbsp; <span style="color: #0000FF;">BY</span> table_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> F<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> F.<span style="color: #202020;">table_id</span> <span style="color: #808080;">=</span> I.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">tables</span> <span style="color: #0000FF;">AS</span> T<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> T.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> I.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">schemas</span> <span style="color: #0000FF;">AS</span> S<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> S.<span style="color: #202020;">schema_id</span> <span style="color: #808080;">=</span> T.<span style="color: #202020;">schema_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF0000;">'ALTER FULLTEXT CATALOG ['</span><span style="color: #808080;">+</span> &nbsp;catalog_name &nbsp;<span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> avg_frag_count_pct <span style="color: #808080;">&amp;</span>gt; <span style="color: #000;">30</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'] REBUILD'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> avg_frag_count_pct <span style="color: #808080;">BETWEEN</span> <span style="color: #000;">10</span> <span style="color: #808080;">AND</span> <span style="color: #000;">30</span> <span style="color: #808080;">AND</span> avg_frag_count_pct <span style="color: #808080;">&amp;</span>gt;<span style="color: #808080;">=</span> <span style="color: #000;">10</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'] REORGANIZE'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> &nbsp;<span style="color: #0000FF;">AS</span> maintenance_sql<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; CTE</div></td></tr></tbody></table></div>
<p>Bonne maintenance d&rsquo;index fulltext !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripter les index fulltext</title>
		<link>https://blog.developpez.com/elsuket/p13046/moteur-de-base-de-donnees-sql-server/indexation/scripter-les-index-fulltext</link>
		<comments>https://blog.developpez.com/elsuket/p13046/moteur-de-base-de-donnees-sql-server/indexation/scripter-les-index-fulltext#comments</comments>
		<pubDate>Mon, 06 Jun 2016 10:52:13 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Full-Text]]></category>
		<category><![CDATA[Indexation]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1226</guid>
		<description><![CDATA[Voici une petite requête qui permet d&#8217;extraire le script de création des index fulltext d&#8217;une base de données. Il génère également l&#8217;instruction de création du catalogue (CREATE FULLTEXT CATALOG) auquel chaque index est lié. Donc si l&#8217;on a plusieurs index &#8230; <a href="https://blog.developpez.com/elsuket/p13046/moteur-de-base-de-donnees-sql-server/indexation/scripter-les-index-fulltext">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une petite requête qui permet d&rsquo;extraire le script de création des index fulltext d&rsquo;une base de données. Il génère également l&rsquo;instruction de création du catalogue (CREATE FULLTEXT CATALOG) auquel chaque index est lié. Donc si l&rsquo;on a plusieurs index attachés au même catalogue, le script teste si le catalogue existe déjà.</p>
<p><span id="more-1226"></span></p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DECLARE</span> @cr <span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">13</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">10</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @tab <span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">9</span><span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">'IF NOT EXISTS (SELECT * FROM sys.fulltext_catalogs WHERE name = '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> FC.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">')'</span> <span style="color: #808080;">+</span> @cr<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">'CREATE FULLTEXT CATALOG ['</span> <span style="color: #808080;">+</span> FC.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> FC.<span style="color: #202020;">is_default</span> <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">' AS DEFAULT'</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span> <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> FC.<span style="color: #202020;">is_accent_sensitivity_on</span> <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">' WITH ACCENT_SENSITIVITY = ON'</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span> <span style="color: #0000FF;">END</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">';'</span> <span style="color: #808080;">+</span> @cr <span style="color: #808080;">+</span> @cr<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">'IF NOT EXISTS(SELECT * FROM sys.fulltext_indexes WHERE object_id = OBJECT_ID('</span><span style="color: #FF0000;">'['</span> <span style="color: #808080;">+</span> S.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'].['</span> <span style="color: #808080;">+</span> T.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span><span style="color: #FF0000;">'))'</span> <span style="color: #808080;">+</span> @cr<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">'CREATE FULLTEXT INDEX ON ['</span> <span style="color: #808080;">+</span> S.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'].['</span> <span style="color: #808080;">+</span> T.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span> <span style="color: #808080;">+</span> @cr <span style="color: #808080;">+</span> <span style="color: #FF0000;">'('</span> <span style="color: #808080;">+</span> @cr <span style="color: #808080;">+</span> @tab <span style="color: #808080;">+</span> <span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>FIS.<span style="color: #202020;">column_list</span>, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>FIS.<span style="color: #202020;">column_list</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF0000;">','</span>, @cr <span style="color: #808080;">+</span> @tab <span style="color: #808080;">+</span> <span style="color: #FF0000;">', '</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> @cr <span style="color: #808080;">+</span> <span style="color: #FF0000;">')'</span> <span style="color: #808080;">+</span> @cr<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">'KEY INDEX ['</span> <span style="color: #808080;">+</span> I.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] ON (['</span> <span style="color: #808080;">+</span> FC.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'], FILEGROUP ['</span> <span style="color: #808080;">+</span> FG.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'])'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>FIO.<span style="color: #202020;">fulltext_index_options</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">&amp;</span>gt; <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'WITH '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">RIGHT</span><span style="color: #808080;">&#40;</span>FIO.<span style="color: #202020;">fulltext_index_options</span>, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>FIO.<span style="color: #202020;">fulltext_index_options</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span> <span style="color: #0000FF;">END</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">';'</span> <span style="color: #808080;">+</span> @cr <span style="color: #808080;">+</span> @cr<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">fulltext_catalogs</span> <span style="color: #0000FF;">AS</span> FC<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">fulltext_indexes</span> <span style="color: #0000FF;">AS</span> FI<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> FI.<span style="color: #202020;">fulltext_catalog_id</span> <span style="color: #808080;">=</span> FC.<span style="color: #202020;">fulltext_catalog_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">indexes</span> <span style="color: #0000FF;">AS</span> I<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> I.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> FI.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> I.<span style="color: #202020;">index_id</span> <span style="color: #808080;">=</span> FI.<span style="color: #202020;">unique_index_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">tables</span> <span style="color: #0000FF;">AS</span> T<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> FI.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> T.<span style="color: #FF00FF;">object_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">schemas</span> <span style="color: #0000FF;">AS</span> S<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> S.<span style="color: #202020;">schema_id</span> <span style="color: #808080;">=</span> T.<span style="color: #202020;">schema_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">filegroups</span> <span style="color: #0000FF;">AS</span> FG<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> FG.<span style="color: #202020;">data_space_id</span> <span style="color: #808080;">=</span> FI.<span style="color: #202020;">data_space_id</span><br />
<span style="color: #808080;">CROSS</span> APPLY &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; C.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' LANGUAGE '</span> <span style="color: #808080;">+</span> FL.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">', '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">fulltext_index_columns</span> <span style="color: #0000FF;">AS</span> FIC<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">columns</span> <span style="color: #0000FF;">AS</span> C<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> FIC.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> C.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> FIC.<span style="color: #202020;">column_id</span> <span style="color: #808080;">=</span> C.<span style="color: #202020;">column_id</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">fulltext_languages</span> <span style="color: #0000FF;">AS</span> FL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> FIC.<span style="color: #202020;">language_id</span> <span style="color: #808080;">=</span> FL.<span style="color: #202020;">lcid</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FI.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> FIC.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> FIS<span style="color: #808080;">&#40;</span>column_list<span style="color: #808080;">&#41;</span><br />
<span style="color: #808080;">CROSS</span> APPLY &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> FI.<span style="color: #202020;">change_tracking_state_desc</span> &nbsp;<span style="color: #FF0000;">'AUTO'</span> <span style="color: #0000FF;">THEN</span> &nbsp;<span style="color: #FF0000;">', CHANGE_TRACKING = '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> FI.<span style="color: #202020;">change_tracking_state_desc</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">''</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span> <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> FI.<span style="color: #202020;">stoplist_id</span> <span style="color: #808080;">&amp;</span>gt; <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">', STOPLIST = '</span> <span style="color: #808080;">+</span> FSL.<span style="color: #202020;">name</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span> <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> FI.<span style="color: #202020;">property_list_id</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">', SEARCH PROPERTY LIST = '</span> <span style="color: #808080;">+</span> FRSPL.<span style="color: #202020;">name</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">''</span> <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">COLLATE</span> database_default<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">fulltext_indexes</span> <span style="color: #0000FF;">AS</span> FIO<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">fulltext_stoplists</span> <span style="color: #0000FF;">AS</span> FSL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> FI.<span style="color: #202020;">stoplist_id</span> <span style="color: #808080;">=</span> FSL.<span style="color: #202020;">stoplist_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">registered_search_property_lists</span> <span style="color: #0000FF;">AS</span> FRSPL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> FI.<span style="color: #202020;">property_list_id</span> <span style="color: #808080;">=</span> FRSPL.<span style="color: #202020;">property_list_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FIO.<span style="color: #202020;">fulltext_catalog_id</span> <span style="color: #808080;">=</span> FI.<span style="color: #202020;">fulltext_catalog_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FIO.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> FI.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XML <span style="color: #0000FF;">PATH</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> FIO<span style="color: #808080;">&#40;</span>fulltext_index_options<span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>Bonne indexation fulltext !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Récupérer les graphes des deadlocks rétrospectivement : les requêtes adéquates aux versions</title>
		<link>https://blog.developpez.com/elsuket/p12987/moteur-de-base-de-donnees-sql-server/recuperer-les-graphes-des-deadlocks-retrospectivement-les-requetes-adequates-aux-versions</link>
		<comments>https://blog.developpez.com/elsuket/p12987/moteur-de-base-de-donnees-sql-server/recuperer-les-graphes-des-deadlocks-retrospectivement-les-requetes-adequates-aux-versions#comments</comments>
		<pubDate>Sun, 17 Jan 2016 17:00:24 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1214</guid>
		<description><![CDATA[Faisant suite au petit billet que j&#8217;ai publié il y quelques temps et qui a donc un peu pris la poussière, voici les requêtes qui permettent de récupérer les deadlocks qui se sont produits. Quelle que soit la version de &#8230; <a href="https://blog.developpez.com/elsuket/p12987/moteur-de-base-de-donnees-sql-server/recuperer-les-graphes-des-deadlocks-retrospectivement-les-requetes-adequates-aux-versions">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Faisant suite au <a href="http://blog.developpez.com/elsuket/p9234/moteur-de-base-de-donnees-sql-server/obtenir_la_liste_des_deadlocks_retrospec" title="Obtenir la liste des deadlocks rétrospectivement">petit billet</a> que j&rsquo;ai publié il y quelques temps et qui a donc un peu pris la poussière, voici les requêtes qui permettent de récupérer les deadlocks qui se sont produits.<br />
<span id="more-1214"></span></p>
<p>Quelle que soit la version de SQL Server, les caractéristiques des 256 dernières situations de blocage qui ont conduit à l&rsquo;annulation de la transaction détenant le moins de ressources (puisque la moins &laquo;&nbsp;chère&nbsp;&raquo; à annuler) sont retenus par une cible de type anneau de mémoire (qui fonctionne sur le principe d&rsquo;un FIFO) par une session d’<a href="http://blog.developpez.com/elsuket/p11065/moteur-de-base-de-donnees-sql-server/evenements_etendus_sql_server_2008" title="Les Événements Étendus avec SQL Server 2008">évènements étendus</a> que l&rsquo;on pourrait qualifier de &laquo;&nbsp;système&nbsp;&raquo;, et nommée <em>system_health</em>.</p>
<p>On peut s&rsquo;en tenir au document XML exposé par ces requêtes pour comprendre quelles ressources étaient en jeu, et procéder à l&rsquo;optimisation adéquate qui permettra d&rsquo;éviter que de telles situations se reproduisent. Néanmoins, comme un schéma vaut souvent mieux que mille mots, on peut aussi récupérer le document XML de chaque ligne généré par ces requêtes, et le sauvegarder dans un fichier de type texte, dont on changera l&rsquo;extension par &laquo;&nbsp;.xdl&nbsp;&raquo; : ceci permet de voir la situation de blocage sous la forme d&rsquo;un graphe; ce type de fichier s&rsquo;ouvre avec SQL Server Management Studio (cf. <a href="http://www.eyrolles.com/Informatique/Livre/sql-server-2014-9782212135923">Livre SQL Server 2014</a>)</p>
<p>Ces graphes ont évolué avec les sorties des opus de SQL Server, si bien que, par exemple, la requête qui permet de les récupérer sous SQL Server 2008R2 ne fonctionne pas pour les versions suivantes de SQL Server. En revanche, la structure de ce document est stable depuis SQL Server 2012.</p>
<p>Voici donc les requêtes :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">-- SQL Server 2008</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; E.<span style="color: #202020;">e</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@timestamp'</span>, <span style="color: #FF0000;">'datetime'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> occurence_date_time<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>E.<span style="color: #202020;">e</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(data/value)[1]'</span>, <span style="color: #FF0000;">'varchar(max)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> xml<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> deadlock_graph<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> local_date_time<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>target_data <span style="color: #0000FF;">AS</span> xml<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> target_data<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_xe_session_targets</span> <span style="color: #0000FF;">AS</span> ST<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_xe_sessions</span> <span style="color: #0000FF;">AS</span> S<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> S.<span style="color: #202020;">address</span> <span style="color: #808080;">=</span> ST.<span style="color: #202020;">event_session_address</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S.<span style="color: #202020;">name</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'system_health'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> TD<br />
<span style="color: #808080;">CROSS</span> APPLY &nbsp; &nbsp; TD.<span style="color: #202020;">target_data</span>.<span style="color: #202020;">nodes</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'//RingBufferTarget/event'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> E<span style="color: #808080;">&#40;</span>e<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; E.<span style="color: #202020;">e</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@name'</span>, <span style="color: #FF0000;">'varchar(4000)'</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'xml_deadlock_report'</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">--SQL Server 2008 R2</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; occurence_date_time<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>T.<span style="color: #202020;">event_data</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data/value)[1]'</span>, <span style="color: #FF0000;">'varchar(max)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> xml<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> deadlock_graph<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> local_date_time<br />
<span style="color: #0000FF;">FROM</span> &nbsp; &nbsp;<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XDR.<span style="color: #202020;">xdr</span>.<span style="color: #202020;">query</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'.'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> event_data<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , XDR.<span style="color: #202020;">xdr</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@timestamp'</span>, <span style="color: #FF0000;">'datetime'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> occurence_date_time<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Cast the target_data to XML </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>target_data <span style="color: #0000FF;">AS</span> XML<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> target_data<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_xe_session_targets</span> <span style="color: #0000FF;">AS</span> ST<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_xe_sessions</span> <span style="color: #0000FF;">AS</span> S<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> s.<span style="color: #202020;">address</span> <span style="color: #808080;">=</span> st.<span style="color: #202020;">event_session_address</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S.<span style="color: #202020;">name</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'system_health'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ST.<span style="color: #202020;">target_name</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ring_buffer'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> TD <span style="color: #008080;">-- Split out the Event Nodes </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">CROSS</span> APPLY &nbsp; &nbsp; TD.<span style="color: #202020;">target_data</span>.<span style="color: #202020;">nodes</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'RingBufferTarget/event[@name=&quot;xml_deadlock_report&quot;]'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> XDR<span style="color: #808080;">&#40;</span>xdr<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> T<span style="color: #808080;">&#40;</span>event_data, occurence_date_time<span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">-- SQL Server 2012, 2014, 2016</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; SRC.<span style="color: #202020;">occurence_date_time</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , SRC.<span style="color: #202020;">deadlock_graph</span>.<span style="color: #202020;">query</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'(event/data/value/deadlock)[1]'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> deadlock_graph<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> local_date_time<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XDR.<span style="color: #202020;">xdr</span>.<span style="color: #202020;">query</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'.'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> deadlock_graph<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , XDR.<span style="color: #202020;">xdr</span>.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'@timestamp'</span>, <span style="color: #FF0000;">'datetime'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> occurence_date_time<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>ST.<span style="color: #202020;">target_data</span> <span style="color: #0000FF;">AS</span> xml<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> target_data<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_xe_session_targets</span> <span style="color: #0000FF;">AS</span> ST<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_xe_sessions</span> <span style="color: #0000FF;">AS</span> S<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> S.<span style="color: #202020;">address</span> <span style="color: #808080;">=</span> ST.<span style="color: #202020;">event_session_address</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S.<span style="color: #202020;">name</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'system_health'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ST.<span style="color: #202020;">target_name</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ring_buffer'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> TD<span style="color: #808080;">&#40;</span>target_data<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">CROSS</span> APPLY &nbsp; &nbsp; TD.<span style="color: #202020;">target_data</span>.<span style="color: #202020;">nodes</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'RingBufferTarget/event[@name=&quot;xml_deadlock_report&quot;]'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> XDR<span style="color: #808080;">&#40;</span>xdr<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> SRC;</div></td></tr></tbody></table></div>
<p>Bonne lecture et déblocage !</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ebook gratuit : introduction à SQL Server 2016</title>
		<link>https://blog.developpez.com/elsuket/p12980/lecture/ebook-gratuit-introduction-sql-server-2016</link>
		<comments>https://blog.developpez.com/elsuket/p12980/lecture/ebook-gratuit-introduction-sql-server-2016#comments</comments>
		<pubDate>Thu, 07 Jan 2016 20:41:33 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Lecture]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1176</guid>
		<description><![CDATA[Comme pour les quelques versions précédentes de SQL Server, Microsoft a mis à disposition un livre électronique décrivant les principales innovations du nouvel opus. Celui ci est téléchargeable en PDF au format standard ou mobile. Bonne lecture !]]></description>
				<content:encoded><![CDATA[<p>Comme pour les quelques versions précédentes de SQL Server, Microsoft a mis à disposition un <a href="http://blogs.msdn.com/b/microsoft_press/archive/2015/12/22/free-ebook-introducing-microsoft-sql-server-2016-mission-critical-applications-deeper-insights-hyperscale-cloud-preview-edition.aspx">livre électronique</a> décrivant les principales innovations du nouvel opus. Celui ci est téléchargeable en PDF au format standard ou mobile.</p>
<p>Bonne lecture !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>La CTP 3 de SQL Server 2016 disponible au téléchargement</title>
		<link>https://blog.developpez.com/elsuket/p12924/moteur-de-base-de-donnees-sql-server/la-ctp-3-de-sql-server-2016-disponible-au-telechargement</link>
		<comments>https://blog.developpez.com/elsuket/p12924/moteur-de-base-de-donnees-sql-server/la-ctp-3-de-sql-server-2016-disponible-au-telechargement#comments</comments>
		<pubDate>Thu, 29 Oct 2015 20:29:02 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1170</guid>
		<description><![CDATA[C&#8217;est par ici, y compris en Français. Pour la documentation relative à cette version, c&#8217;est par ici : fr / en. Bonne évaluation!]]></description>
				<content:encoded><![CDATA[<p>C&rsquo;est par <a href="https://technet.microsoft.com/fr-fr/evalcenter/mt130694">ici</a>, y compris en Français.</p>
<p>Pour la documentation relative à cette version, c&rsquo;est par ici : <a href="https://msdn.microsoft.com/fr-fr/library/ms130214.aspx">fr</a> / <a href="https://msdn.microsoft.com/en-us/library/ms130214.aspx">en</a>.</p>
<p>Bonne évaluation!</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capture manuelle de plans de requête</title>
		<link>https://blog.developpez.com/elsuket/p12879/moteur-de-base-de-donnees-sql-server/capture-manuelle-de-plans-de-requete</link>
		<comments>https://blog.developpez.com/elsuket/p12879/moteur-de-base-de-donnees-sql-server/capture-manuelle-de-plans-de-requete#comments</comments>
		<pubDate>Fri, 26 Jun 2015 17:03:50 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1126</guid>
		<description><![CDATA[SQL Server Management Studio dispose d&#8217;un outil de recherche et de remplacement de texte, qui permet notamment de travailler avec des expressions régulières. Il m&#8217;arrive souvent dans des tâches de refactoring de trouver un très grand nombre d&#8217;espaces ou de &#8230; <a href="https://blog.developpez.com/elsuket/p12857/sql-server-management-studio/comment-remplacer-les-espaces-et-tabulations-en-fin-de-lignes-dans-les-modules-de-code-sans-trop-deffort">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SQL Server Management Studio dispose d&rsquo;un outil de recherche et de remplacement de texte, qui permet notamment de travailler avec des expressions régulières. Il m&rsquo;arrive souvent dans des tâches de refactoring de trouver un très grand nombre d&rsquo;espaces ou de tabulations à la fin des lignes, et je suis bien plus passionné par optimiser et standardiser le code que par supprimer ce type de micro-boulettes.</p>
<p><span id="more-1126"></span><br />
On trouve l&rsquo;outil de recherche et de remplacement de texte en suivant le menu <em>Edit</em>, ou en pressant CTRL + F pour la recherche, et CTRL + H pour le remplacement :</p>
<p><img src="http://i.imgur.com/uNxK0ZI.png" alt="" /> </p>
<p>Dans le simple but de standardiser le code, l&rsquo;expression régulière :b+\n, qui signifie tout espace ou tabulation avant le retour à la ligne, peut simplement être remplacée par \n :</p>
<p><img src="http://i.imgur.com/phsX90I.png" alt="" /></p>
<p>Un simple clic sur <em>Replace All</em>, et les vilains espaces et tabulations sont soustraits.</p>
<p>Au-delà de ceci, vous pouvez considérer que je pinaille, voire même que je suis maniaque. C&rsquo;est probablement vrai ! Mais il faut aussi considérer le cache de requêtes. Si l&rsquo;on prend une requête et qu&rsquo;on lui ajoute un espace, une tabulation, ou tout autre caractère sans effet sur la syntaxe ou le résultat de cette requête, SQL Server considère ceci, au niveau du cache de requêtes, comme deux requêtes différentes, étant donné que leur valeur de hachage sera différente. C&rsquo;est à l&rsquo;aide de cette valeur que le moteur vérifie s&rsquo;il existe déjà un plan en cache pour cette requête ou non.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Où est passé le panneau SSIS toolbox dans SSDT-BI 2013 ?</title>
		<link>https://blog.developpez.com/elsuket/p12854/support-decisionnel/sql-server-integration-services/ou-est-passe-le-panneau-ssis-toolbox-dans-ssdt-bi-2013</link>
		<comments>https://blog.developpez.com/elsuket/p12854/support-decisionnel/sql-server-integration-services/ou-est-passe-le-panneau-ssis-toolbox-dans-ssdt-bi-2013#comments</comments>
		<pubDate>Sat, 21 Mar 2015 11:11:20 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Integration Services]]></category>
		<category><![CDATA[Support Décisionnel]]></category>
		<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Toolbox]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1113</guid>
		<description><![CDATA[Ce panneau est ouvert automatiquement à l&#8217;ouverture d&#8217;un projet SSIS. Supposons maintenant que l&#8217;on ait fermé ce panneau après avoir ajouté un projet SSRS à la solution : à l&#8217;ouverture suivante du projet ou de SSDT-BI, le volet n&#8217;est plus &#8230; <a href="https://blog.developpez.com/elsuket/p12854/support-decisionnel/sql-server-integration-services/ou-est-passe-le-panneau-ssis-toolbox-dans-ssdt-bi-2013">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Ce panneau est ouvert automatiquement à l&rsquo;ouverture d&rsquo;un projet SSIS. Supposons maintenant que l&rsquo;on ait fermé ce panneau après avoir ajouté un projet SSRS à la solution : à l&rsquo;ouverture suivante du projet ou de SSDT-BI, le volet n&rsquo;est plus là ! Pour le débutant que je suis, j&rsquo;ai donc intuitivement ouvert le menu <em>VIEW</em>, mais ne l&rsquo;y trouvais pas :</p>
<p><span id="more-1113"></span></p>
<p><img src="http://i.imgur.com/75OM4SG.png" alt="" /></p>
<p>En effet, cette &laquo;&nbsp;trousse à outils&nbsp;&raquo; est générique, et ne propose aucun contrôle, et nous offre l&rsquo;amical message suivant :</p>
<p><img src="http://i.imgur.com/pGJPOF6.png" alt="" /></p>
<p>Quelle ne fut pas ma joie de retrouver ce panneau après avoir cliqué sur le petit bouton en haut et à droite du panneau de conception !</p>
<p><img src="http://i.imgur.com/dClW9IH.png" alt="" /></p>
<p>Bonne création de paquetages SSIS !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Où trouver la définition des objets et attributs de plans de requêtes ?</title>
		<link>https://blog.developpez.com/elsuket/p12803/moteur-de-base-de-donnees-sql-server/ou-trouver-la-definition-des-objects-et-attributs-de-plans-de-requetes</link>
		<comments>https://blog.developpez.com/elsuket/p12803/moteur-de-base-de-donnees-sql-server/ou-trouver-la-definition-des-objects-et-attributs-de-plans-de-requetes#comments</comments>
		<pubDate>Tue, 09 Dec 2014 00:56:06 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1099</guid>
		<description><![CDATA[Après quelques mois d&#8217;absence et avoir assisté au Microsoft MVP Summit et au PASS Summit 2014, et m&#8217;être enfin replongé dans un peu de lecture dense sur SQL Server, voici quelques liens utiles en ce qui concerne les plans de &#8230; <a href="https://blog.developpez.com/elsuket/p12803/moteur-de-base-de-donnees-sql-server/ou-trouver-la-definition-des-objects-et-attributs-de-plans-de-requetes">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Après quelques mois d&rsquo;absence et avoir assisté au Microsoft MVP Summit et au PASS Summit 2014, et m&rsquo;être enfin replongé dans un peu de lecture dense sur SQL Server, voici quelques liens utiles en ce qui concerne les plans de requête :</p>
<ul>
<li>Définition des plans XML : <a href="http://schemas.microsoft.com/sqlserver/2004/07/showplan/">schémas XSD</a> : expose le schéma XSD des plans de requête XML, ce qui permet de trouver les améliorations au niveau de l&rsquo;optimiseur en comparant le schéma de deux versions de SQL Server</li>
<li><a href="http://msdn.microsoft.com/fr-fr/library/ms191158.aspx">Guide de référence</a> des opérateurs Showplan : une liste exhaustive de tous les opérateurs que l&rsquo;on peut trouver dans un plan de requête graphique</li>
<li>Une autre liste, publiée par <a href="https://www.simple-talk.com/books/sql-books/complete-showplan-operators/">Fabiano Amorim</a>, avec la liste des opérateurs de plan d&rsquo;exécution graphique les plus communs, expliquant leur fonctionnement, et pourquoi ils sont choisis par l&rsquo;optimiseur de requêtes
</ul>
<p>Bonne lecture !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Récompense MVP : Chapitre 2014</title>
		<link>https://blog.developpez.com/elsuket/p12606/annonces/recompense-mvp-chapitre-20132</link>
		<comments>https://blog.developpez.com/elsuket/p12606/annonces/recompense-mvp-chapitre-20132#comments</comments>
		<pubDate>Tue, 01 Jul 2014 15:00:30 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=996</guid>
		<description><![CDATA[Je viens d&#8217;être récompensé MVP SQL Server pour la quatrième fois. Je tiens donc à remercier les co-auteurs du livre sur SQL Server 2014, à paraître le 10 Juillet 2014 chez Eyrolles : Frédéric Brouard, alias SQLPro, qui a eu &#8230; <a href="https://blog.developpez.com/elsuket/p12606/annonces/recompense-mvp-chapitre-20132">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Je viens d&rsquo;être récompensé MVP SQL Server pour la quatrième fois.</p>
<p>Je tiens donc à remercier les co-auteurs du livre sur SQL Server 2014, à paraître le 10 Juillet 2014 chez Eyrolles :</p>
<ul>
<li>Frédéric Brouard, alias <a href="http://blog.developpez.com/sqlpro/">SQLPro</a>, qui a eu l&rsquo;idée géniale d&rsquo;écrire ce livre</li>
<li><a href="http://www.soutou.net/christian/topic4/index.html">Christian Soutou</a>, par ailleurs auteur de plusieurs ouvrages autour de SQL</li>
<li>David Barbarin, alias <a href="http://blog.developpez.com/mikedavem/">Mikedavem</a>, pour la fréquence et la qualité de nos discussions</li>
</ul>
<p>Ce fut un gros challenge que d&rsquo;écrire ce livre. J&rsquo;espère que c&rsquo;est le premier d&rsquo;une longue série !</p>
<p>Mais aussi :</p>
<ul>
<li>Ma compagne, qui m&rsquo;a supporté dans l&rsquo;écriture de ce livre;</li>
<li>Katherine Chen, MVP Lead à Singapour pour toute l&rsquo;Asie du Sud-Est;</li>
<li>Toutes les personnes que j&rsquo;ai rencontrées aux Journées SQL Server à Paris en Décembre 2013, notamment Arian Papillon, Pascale Doz et Christophe Laporte;</li>
<li>Toute l&rsquo;équipe de Développez.com, qui ne cesse d&rsquo;améliorer le site, et qui a la patience de corriger nos erreurs dans les billets que nous publions;</li>
<li>Panjaporn Vittayalerdpun, Senior Product Manager &#8211; Server and Application Platform chez Microsoft à Bangkok, qui organise les conférences SQL Server</li>
<li>Fukiat Julnual, Évangéliste chez Microsoft à Bangkok, PASS Chapter Thailand, qui organise la communauté SQL Server en Thaïlande;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Sauvegardes cryptées et dans Azure avec SQL Server 2014</title>
		<link>https://blog.developpez.com/elsuket/p12640/moteur-de-base-de-donnees-sql-server/sauvegardes-cryptees-et-dans-azure</link>
		<comments>https://blog.developpez.com/elsuket/p12640/moteur-de-base-de-donnees-sql-server/sauvegardes-cryptees-et-dans-azure#comments</comments>
		<pubDate>Fri, 13 Jun 2014 02:28:29 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[cryptage]]></category>
		<category><![CDATA[sauvegarde]]></category>
		<category><![CDATA[SQL Server 2014]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1071</guid>
		<description><![CDATA[Microsoft a publié un article que j&#8217;ai terminé d&#8217;écrire au début de ce mois sur ce sujet. En plus du fonctionnement du cryptage des sauvegardes, j&#8217;y détaille les étapes pour : Sauvegarder une base de données en cryptant le fichier &#8230; <a href="https://blog.developpez.com/elsuket/p12640/moteur-de-base-de-donnees-sql-server/sauvegardes-cryptees-et-dans-azure">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Microsoft a publié un <a href="http://blogs.msdn.com/b/mvpawardprogram/archive/2014/06/02/sql-server-2014-backup-encryption.aspx">article</a> que j&rsquo;ai terminé d&rsquo;écrire au début de ce mois sur ce sujet.</p>
<p>En plus du fonctionnement du cryptage des sauvegardes, j&rsquo;y détaille les étapes pour :</p>
<ol>
<li>Sauvegarder une base de données en cryptant le fichier de sauvegarde</li>
<li>Restaurer une base de données à partir d&rsquo;une fichier de sauvegarde crypté</li>
<li>Réaliser des sauvegardes cryptées dans Azure</li>
<li>Restaurer une base de données à partir d&rsquo;une sauvegarde cryptée stockée dans Azure</li>
</ol>
<p>Finalement, j&rsquo;y aborde l&rsquo;impact des divers algorithmes de cryptage sur l&rsquo;utilisation CPU et la taille des fichiers de sauvegarde.</p>
<p>L&rsquo;article est en Anglais, et je vais le traduire en Français.</p>
<p>Bonne lecture !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>24 sessions gratuites sur SQL Server 2014 : 24 hours of PASS</title>
		<link>https://blog.developpez.com/elsuket/p12637/annonces/24-sessions-gratuites-sur-sql-server-2014-24-hours-of-pass</link>
		<comments>https://blog.developpez.com/elsuket/p12637/annonces/24-sessions-gratuites-sur-sql-server-2014-24-hours-of-pass#comments</comments>
		<pubDate>Tue, 10 Jun 2014 15:57:22 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=1069</guid>
		<description><![CDATA[C&#8217;est par ici ! Bon visionnage !]]></description>
				<content:encoded><![CDATA[<p>C&rsquo;est par <a href="http://www.sqlpass.org/24hours/2014/ss2014launch/Home.aspx">ici</a> !</p>
<p>Bon visionnage !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sauvegardes de bases de données et envoi d&#8217;email avec SQL Server Express</title>
		<link>https://blog.developpez.com/elsuket/p12612/snippets/sauvegardes-de-bases-de-donnees-et-envoi-demail-avec-sql-server-express</link>
		<comments>https://blog.developpez.com/elsuket/p12612/snippets/sauvegardes-de-bases-de-donnees-et-envoi-demail-avec-sql-server-express#comments</comments>
		<pubDate>Sun, 11 May 2014 10:01:01 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Utilitaires]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[BACKUP]]></category>
		<category><![CDATA[sauvegarde]]></category>
		<category><![CDATA[SQL Server Express]]></category>

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

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

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=987</guid>
		<description><![CDATA[La réponse est très courte : avec les fonctionnalités SQLXML et XQuery intégrées à SQL Server. Il est parfois utile de pouvoir générer une liste de valeurs d&#8217;une colonne, séparées par des virgules ou un autre symbole imprimable. Bien que &#8230; <a href="https://blog.developpez.com/elsuket/p12576/t-sql/csv_scalaire_et_inversement">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La réponse est très courte : avec les fonctionnalités SQLXML et XQuery intégrées à SQL Server.<br />
<span id="more-987"></span><br />
Il est parfois utile de pouvoir générer une liste de valeurs d&rsquo;une colonne, séparées par des virgules ou un autre symbole imprimable. Bien que cela serve souvent des buts de présentation, qui n&rsquo;ont donc rien à faire avec SQL, il se trouve des cas où l&rsquo;on n&rsquo;a pas le choix. C&rsquo;est par exemple le cas avec SQL Server Reporting Services (SSRS) : en effet, cet outil efficace de création assistée de rapports permet de choisir plusieurs valeurs pour un paramètre. SSRS les transmet ensuite sous la forme d&rsquo;une chaîne de caractères, dont les valeurs sont séparées par des virgules. Lorsqu&rsquo;on requête les données avec un tel paramètre, il faut dépouiller la chaîne pour en obtenir les valeurs scalaires, intelligibles par le moteur de bases de données.</p>
<p>Voyons un premier exemple très simple de génération de liste de valeurs séparées par des virgules :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> dbo.<span style="color: #202020;">liste_GUID</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; valeur_scalaire <span style="color: #0000FF;">uniqueidentifier</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">liste_GUID</span> <span style="color: #808080;">&#40;</span>valeur_scalaire<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'30815903-5911-418B-BB56-CE0CF4981142'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'029FE2E3-E57D-4C4D-A514-2448149560F9'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'F6A73DFA-C79A-40B5-B12F-55DA66C5A158'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'D896FB47-B5B8-4E8F-BFA1-62A65F66CB8B'</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">DECLARE</span> @s <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span>;<br />
<br />
<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CUMUL <span style="color: #808080;">&#40;</span>csv<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>valeur_scalaire <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">36</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> &nbsp;<span style="color: #FF0000;">','</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span> &nbsp; dbo.<span style="color: #202020;">liste_GUID</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp;XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; @s <span style="color: #808080;">=</span> csv<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; CUMUL<br />
<br />
<span style="color: #0000FF;">SELECT</span> @s</div></td></tr></tbody></table></div>
<p>Notons qu&rsquo;avec cet exemple, nous avons une virgule en toute fin de chaîne. On peut l’éliminer simplement en écrivant :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DECLARE</span> @s <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span>;<br />
<br />
<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CUMUL <span style="color: #808080;">&#40;</span>csv<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>valeur_scalaire <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">36</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> &nbsp;<span style="color: #FF0000;">','</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span> &nbsp; dbo.<span style="color: #202020;">liste_GUID</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp;XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; @s <span style="color: #808080;">=</span> <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>csv, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>csv<span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; CUMUL<br />
<br />
<span style="color: #0000FF;">SELECT</span> @s</div></td></tr></tbody></table></div>
<p>Si l&rsquo;on a besoin de réaliser cela pour un ensemble (i.e. une colonne), on utilisera l&rsquo;opérateur APPLY, ou une sous requête corrélée.<br />
Pour l&rsquo;exemple, considérons les tables suivantes :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> Contact<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; IDContact <span style="color: #0000FF;">int</span> <span style="color: #0000FF;">IDENTITY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> PK_Contact <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , NomContact <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">20</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> UQ_Contact__NomContact <span style="color: #0000FF;">UNIQUE</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
&nbsp;<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> Club<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; IDClub <span style="color: #0000FF;">int</span> <span style="color: #0000FF;">IDENTITY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> PK_Club <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , NomClub <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">20</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> UQ_Club__NomClub <span style="color: #0000FF;">UNIQUE</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
&nbsp;<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> Membre<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; IDMembre <span style="color: #0000FF;">int</span> <span style="color: #0000FF;">IDENTITY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> PK_Membre <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , IDContact <span style="color: #0000FF;">int</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> FK_Membre_IDContact <span style="color: #0000FF;">FOREIGN</span> <span style="color: #0000FF;">KEY</span><span style="color: #808080;">&#40;</span>IDContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">REFERENCES</span> Contact<span style="color: #808080;">&#40;</span>IDContact<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , IDClub <span style="color: #0000FF;">int</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> FK_Membre_IDClub <span style="color: #0000FF;">FOREIGN</span> <span style="color: #0000FF;">KEY</span><span style="color: #808080;">&#40;</span>IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">REFERENCES</span> Club<span style="color: #808080;">&#40;</span>IDClub<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CONSTRAINT</span> UQ_Membre_IDContact_IDClub <span style="color: #0000FF;">UNIQUE</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
&nbsp;<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'BipBip'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Coyotte'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Titi'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Sylvestre'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Bugs Bunny'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Daffy Duck'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Sam Le Pirate'</span><span style="color: #808080;">&#41;</span><br />
GO<br />
&nbsp;<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SQLServer'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Oracle'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'PostGreSQL'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'MySQL'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'FireBird'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Sybase'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'DB2'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SQLite'</span><span style="color: #808080;">&#41;</span><br />
GO<br />
&nbsp;<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">2</span>, <span style="color: #000;">4</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">2</span>, <span style="color: #000;">5</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">3</span>, <span style="color: #000;">6</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">4</span>, <span style="color: #000;">7</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">4</span>, <span style="color: #000;">8</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">6</span>, <span style="color: #000;">5</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">6</span>, <span style="color: #000;">7</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">7</span>, <span style="color: #000;">8</span><span style="color: #808080;">&#41;</span><br />
GO</div></td></tr></tbody></table></div>
<p>On obtient alors la liste des clubs desquels un contact est membre avec l&rsquo;une des requêtes suivantes :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">-- Avec l'opérateur APPLY</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CT.<span style="color: #202020;">NomContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>LC.<span style="color: #202020;">liste_club</span>, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>LC.<span style="color: #202020;">liste_club</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> liste_club<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Contact</span> <span style="color: #0000FF;">AS</span> CT<br />
<span style="color: #808080;">CROSS</span> APPLY &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CL.<span style="color: #202020;">NomClub</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">', '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Club</span> <span style="color: #0000FF;">AS</span> CL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Membre</span> <span style="color: #0000FF;">AS</span> MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> MB.<span style="color: #202020;">IDClub</span> <span style="color: #808080;">=</span> CL.<span style="color: #202020;">IDClub</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CT.<span style="color: #202020;">IDContact</span> <span style="color: #808080;">=</span> MB.<span style="color: #202020;">IDContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> LC<span style="color: #808080;">&#40;</span>liste_club<span style="color: #808080;">&#41;</span>;<br />
<br />
<span style="color: #008080;">-- Avec une sous-requête corrélée</span><br />
<span style="color: #008080;">-- Pour éliminer la virgule en fin de chaîne, on utilise ici une expression de table commune (CTE)</span><br />
;<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CTE <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; CT.<span style="color: #202020;">NomContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CL.<span style="color: #202020;">NomClub</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">', '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Club</span> <span style="color: #0000FF;">AS</span> CL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Membre</span> <span style="color: #0000FF;">AS</span> MB<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; <span style="color: #0000FF;">ON</span> MB.<span style="color: #202020;">IDClub</span> <span style="color: #808080;">=</span> CL.<span style="color: #202020;">IDClub</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CT.<span style="color: #202020;">IDContact</span> <span style="color: #808080;">=</span> MB.<span style="color: #202020;">IDContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> liste_club<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; dbo.<span style="color: #202020;">Contact</span> <span style="color: #0000FF;">AS</span> CT<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; NomContact<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>liste_club, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>liste_club<span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> liste_club<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; CTE;<br />
<br />
<span style="color: #008080;">-- Mais on peut se passer de la CTE en utilisant une table dérivée :</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; LC.<span style="color: #202020;">NomContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>LC.<span style="color: #202020;">liste_club</span>, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>LC.<span style="color: #202020;">liste_club</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> liste_club<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; CT.<span style="color: #202020;">NomContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CL.<span style="color: #202020;">NomClub</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">', '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Club</span> <span style="color: #0000FF;">AS</span> CL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Membre</span> <span style="color: #0000FF;">AS</span> MB<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; <span style="color: #0000FF;">ON</span> MB.<span style="color: #202020;">IDClub</span> <span style="color: #808080;">=</span> CL.<span style="color: #202020;">IDClub</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CT.<span style="color: #202020;">IDContact</span> <span style="color: #808080;">=</span> MB.<span style="color: #202020;">IDContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> liste_club<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; dbo.<span style="color: #202020;">Contact</span> <span style="color: #0000FF;">AS</span> CT<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> LC<span style="color: #808080;">&#40;</span>NomContact, liste_club<span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>Maintenant, supposons que nous avons un rapport SSRS qui appelle une procédure stockée, et que l&rsquo;un des paramètres du rapport permet un choix multiple de valeurs. Il nous est donc nécessaire de transformer cette liste de valeurs en une table d&rsquo;une seule colonne :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DECLARE</span> @s <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'30815903-5911-418B-BB56-CE0CF4981142,029FE2E3-E57D-4C4D-A514-2448149560F9,F6A73DFA-C79A-40B5-B12F-55DA66C5A158,D896FB47-B5B8-4E8F-BFA1-62A65F66CB8B'</span><br />
<br />
<span style="color: #008080;">-- On ajoute la balise v en tête et en queue de chaîne,</span><br />
<span style="color: #008080;">-- et on remplace les virgules par le doublet</span><br />
<span style="color: #0000FF;">DECLARE</span> @x xml &nbsp;<span style="color: #808080;">=</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'&lt;v&gt;'</span><span style="color: #808080;">+</span> <span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>@s, <span style="color: #FF0000;">','</span> ,<span style="color: #FF0000;">'&lt;/v&gt;&lt;v&gt;'</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'&lt;/v&gt;'</span> <span style="color: #0000FF;">AS</span> &nbsp;xml<span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #008080;">-- On dépouille le document XML créé en utilisant la fonction nodes()</span><br />
<span style="color: #008080;">-- du langage XQuery, intégré à SQL Server depuis sa version 2005</span><br />
<span style="color: #0000FF;">SELECT</span> vs.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'.'</span>, <span style="color: #FF0000;">'uniqueidentifier'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> valeur_scalaire<br />
<span style="color: #0000FF;">FROM</span> &nbsp; @x.<span style="color: #202020;">nodes</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'/v'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> x<span style="color: #808080;">&#40;</span>vs<span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>L&rsquo;utilisation de FOR XML PATH est de très loin la méthode qui permet de générer une liste de valeurs de façon performante. Ceci n&rsquo;en fait pas une raison pour l&rsquo;utiliser à tors et à travers, mais seulement lorsque cela est nécessaire.</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Le ebook gratuit Introducing SQL Server 2014</title>
		<link>https://blog.developpez.com/elsuket/p12563/sql-server-2014/le-ebook-gratuit-introducing-sql-server-2014</link>
		<comments>https://blog.developpez.com/elsuket/p12563/sql-server-2014/le-ebook-gratuit-introducing-sql-server-2014#comments</comments>
		<pubDate>Sun, 06 Apr 2014 12:29:34 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server 2014]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=973</guid>
		<description><![CDATA[C&#8217;est par ici ! Bonne lecture !]]></description>
				<content:encoded><![CDATA[<p>C&rsquo;est par <a href="http://aka.ms/684751pdf">ici</a> !</p>
<p>Bonne lecture !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Purger le cache de SQL Server Reporting Services</title>
		<link>https://blog.developpez.com/elsuket/p12562/support-decisionnel/sql-server-reporting-services/purger_cache_ssrs</link>
		<comments>https://blog.developpez.com/elsuket/p12562/support-decisionnel/sql-server-reporting-services/purger_cache_ssrs#comments</comments>
		<pubDate>Sun, 06 Apr 2014 04:21:11 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Reporting Services]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[flush]]></category>
		<category><![CDATA[nettoyer]]></category>
		<category><![CDATA[purge]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=954</guid>
		<description><![CDATA[Lorsqu&#8217;on développe un rapport sous SQL Server Reporting Services (SSRS), il est plutôt ennuyeux de voir que les modifications que l&#8217;on apporte à un rapport ne sont pas prises en compte dans l&#8217;aperçu de Business Intelligence Development Studio (BIDS) ou &#8230; <a href="https://blog.developpez.com/elsuket/p12562/support-decisionnel/sql-server-reporting-services/purger_cache_ssrs">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Lorsqu&rsquo;on développe un rapport sous <em>SQL Server Reporting Services</em> (SSRS), il est plutôt ennuyeux de voir que les modifications que l&rsquo;on apporte à un rapport ne sont pas prises en compte dans l&rsquo;aperçu de <em>Business Intelligence Development Studio</em> (BIDS) ou de <em>SQL Server Data Tools</em> (SSDT). Même si l&rsquo;on clique sur le bouton <em>Refresh</em> du rapport, ou que l&rsquo;on redémarre BIDS / SSDT, il n&rsquo;y a rien à faire.</p>
<p>La solution, certes radicale, est de supprimer les fichiers *.rdl.data qui se trouvent dans le répertoire de la solution. On peut réaliser cela très simplement et de façon générique pour toutes les solutions de rapports SSRS.</p>
<p><span id="more-954"></span></p>
<p>J&rsquo;ai d&rsquo;abord cherché s&rsquo;il n&rsquo;existait pas une option dans les menus de BIDS et SSDT pour réaliser ceci, en vain. En revanche, j&rsquo;ai été intrigué par le menu <em>Tools</em> &gt; <em>External Tools</em> :</p>
<p><img src="http://i.imgur.com/Ch2Lz9f.png" alt="" /></p>
<p>On peut donc appeler un exécutable, et par la même une commande DOS, ce qui nous permet donc de supprimer les fichiers *.rdl.data. Comme je suis flemmard, je voulais faire en sorte que cela fonctionne quelle que soit la solution dans laquelle je travaille. En cherchant un peu, on tombe sur <a href="http://msdn.microsoft.com/fr-fr/library/42x5kfw4%28v=vs.110%29.aspx">cette page</a>, qui donne la liste des variables qui permettent d&rsquo;automatiser la build d&rsquo;un projet.</p>
<p>Après plusieurs changements de variables et essais, je suis arrivé à la commande suivante :</p>
<p><img src="http://i.imgur.com/hYz45WP.png" alt="" /></p>
<p>Nous appelons donc l&rsquo;invite de commandes DOS, en lui passant en argument :</p>
<p>&#8211; /C : une fois la commande exécutée, terminer le processus cmd.exe<br />
&#8211; /Q : exécution en mode silencieux<br />
&#8211; $ProjectDir retourne le chemin du dossier qui contient tous les fichiers du projet</p>
<p>Comme cette dernière variable contient l&rsquo;antislash en fin de chaîne, il n&rsquo;y a pas besoin de l&rsquo;ajouter.</p>
<p>Il nous suffit donc maintenant de cliquer sur <em>Tools</em> &gt; <em>Flush SSRS Data Cache</em>, et de ré-exécuter un aperçu du rapport pour s&rsquo;apercevoir que celui-ci prend maintenant en compte ses toutes dernières modifications.</p>
<p><img src="http://i.imgur.com/vtZfnTK.png" alt="" /></p>
<p>Bon reporting à tous !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction rapide et guidée à l&#8217;exploration de données (Data Mining)</title>
		<link>https://blog.developpez.com/elsuket/p12547/support-decisionnel/data-mining/introduction-data-mining</link>
		<comments>https://blog.developpez.com/elsuket/p12547/support-decisionnel/data-mining/introduction-data-mining#comments</comments>
		<pubDate>Tue, 25 Mar 2014 16:53:20 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Data Mining]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=902</guid>
		<description><![CDATA[Vous avez certainement remarqué que les sites marchands sont capables de vous proposer d&#8217;acheter d&#8217;autres articles en fonction de celui dont vous êtes en train d&#8217;explorer les caractéristiques, ou dont vous venez de valider l&#8217;achat. La plupart du temps, ces &#8230; <a href="https://blog.developpez.com/elsuket/p12547/support-decisionnel/data-mining/introduction-data-mining">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Vous avez certainement remarqué que les sites marchands sont capables de vous proposer d&rsquo;acheter d&rsquo;autres articles en fonction de celui dont vous êtes en train d&rsquo;explorer les caractéristiques, ou dont vous venez de valider l&rsquo;achat. La plupart du temps, ces articles sont plutôt bien corrélés avec l&rsquo;article acheté ou revu : c&rsquo;est un exemple de ce que l&rsquo;on peut faire calculer à un algorithme d&rsquo;exploration de données.</p>
<p>Vous vous en doutez donc : si le <em>Data Mining</em> est un ensemble de fonctionnalités qui est rarement abordé, il n&rsquo;en est pas moins très intéressant, et a un bel avenir devant lui. Je vous propose donc de découvrir très simplement avec SQL Server cette discipline, aussi stimulante techniquement que &laquo;&nbsp;décisionnellement&nbsp;&raquo;. En effet, celle-ci transforme le consommateur de rapports d&rsquo;un rôle passif / interactif à un rôle proactif.</p>
<p><span id="more-902"></span></p>
<p>Commençons d&rsquo;abord par installer la base de données exemple d&rsquo;entrepôt de données <em>AdventureWorks</em>, que l&rsquo;on trouve <a href="http://msftdbprodsamples.codeplex.com/releases/view/105902">ici</a> pour les versions 2008, 2008 R2 et 2012.<br />
Pour voir comment installer cette base de données sur votre instance SQL Server, c&rsquo;est par <a href="http://blog.developpez.com/elsuket/p11188/moteur-de-base-de-donnees-sql-server/attacher_base_donnees_sans_tran_log" title="Attacher une base de données qui n’a pas de fichier du journal des transactions">ici</a>.</p>
<p>Dans cette base de données existe une vue <em>dbo.vTargetMail</em>, que nous allons utiliser pour caractériser les clients les plus enclins à acheter un vélo.</p>
<p><img src="http://imageshack.com/a/img43/3917/5y2u.png" alt="" /></p>
<p>Nous créons donc un nouveau projet avec <em>SQL Server Data Tools</em> (le nouveau <em>Business Intelligence Development Studio</em>), et nous choisissons un projet SQL Server <em>Analysis Services and Data Mining</em> :</p>
<p><img src="http://imageshack.com/a/img842/6929/ndai.png" alt="" /></p>
<p>Une fois le tout validé par OK, la solution s&rsquo;ouvre et nous devons tout d&rsquo;abord créer une source de données :</p>
<p><img src="http://imageshack.com/a/img855/796/zeup.png" alt="" /></p>
<p>Un nouveau dialogue s&rsquo;ouvre alors, et nous devons cliquer sur le bouton <em>New &#8230;</em></p>
<p><img src="http://imageshack.com/a/img542/2544/uj0c.png" alt="" /></p>
<p>Nous mettons un point pour signifier le serveur local, et choisissons la base de données que nous venons d&rsquo;installer :</p>
<p><img src="http://imageshack.com/a/img850/253/8wl9.png" alt="" /></p>
<p>Nous devons maintenant définir sous quel utilisateur nous allons nous connecter à la source de données. Nous choisissons l&rsquo;utilisateur courant pour des raisons pratiques, mais ce n&rsquo;est pas ce que l&rsquo;on ferait pour un environnement de production.</p>
<p><img src="http://imageshack.com/a/img856/2174/15k8.png" alt="" /></p>
<p>Notons également que le compte de service qui exécute le service SQL Server Analysis Services doit être enregistré sur l&rsquo;instance SQL Server (moteur de base de données). Par défaut, ce compte est <em>NT Service\MSSQLServerOLAPService</em>. Nous devons donc exécuter le script suivant :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> LOG<span style="color: #808080;">IN</span> <span style="color: #808080;">&#91;</span>NT Service\MSSQLServerOLAPService<span style="color: #808080;">&#93;</span><br />
<span style="color: #0000FF;">FROM</span> W<span style="color: #808080;">IN</span>DOWS<br />
<br />
<span style="color: #0000FF;">USE</span> AdventureWorksDW2012<br />
GO<br />
<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">USER</span> <span style="color: #808080;">&#91;</span>NT Service\MSSQLServerOLAPService<span style="color: #808080;">&#93;</span><br />
<span style="color: #0000FF;">FOR</span> LOG<span style="color: #808080;">IN</span> <span style="color: #808080;">&#91;</span>NT Service\MSSQLServerOLAPService<span style="color: #808080;">&#93;</span><br />
GO<br />
<br />
<span style="color: #008080;">-- SQL Server 2021 et suivants</span><br />
<span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">ROLE</span> db_datareader<br />
<span style="color: #0000FF;">ADD</span> MEMBER <span style="color: #808080;">&#91;</span>NT Service\MSSQLServerOLAPService<span style="color: #808080;">&#93;</span><br />
<br />
<span style="color: #008080;">-- Jusqu'à SQL Server 2008 (R2 inclus)</span><br />
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_addrolemember</span> <span style="color: #FF0000;">'db_datareader'</span>, <span style="color: #FF0000;">'NT Service\MSSQLServerOLAPService'</span></div></td></tr></tbody></table></div>
<p>Nous pouvons cliquer sur <em>Next</em>, puis sur <em>Finish</em>, et voilà notre source de données créée. De retour dans l&rsquo;explorateur de solutions, il nous faut maintenant créer une vue source de données :</p>
<p><img src="http://imageshack.com/a/img546/7493/e0u8.png" alt="" /></p>
<p>Nous aurions pu créer la source de données à partir du dialogue qui s&rsquo;affiche :</p>
<p><img src="http://imageshack.com/a/img401/4352/sqvv.png" alt="" /></p>
<p>Comme nous l&rsquo;avons déjà créée, nous nous contentons de cliquer sur <em>Next</em>, et obtenons le dialogue suivant, qui présente la liste des tables et vues présentes dans la base de données <em>AdventureWorksDW2012</em> :</p>
<p><img src="http://imageshack.com/a/img819/2879/llws.png" alt="" /></p>
<p>Nous ajoutons donc la vue <em>dbo.vTargetMail</em>, et cliquons sur <em>Next</em>, qui nous amène à un dialogue de revue, et nous validons le tout par <em>Finish</em>.</p>
<p>Nous devons maintenant créer une structure d&rsquo;exploration de données. De retour dans l&rsquo;explorateur de solutions, il nous suffit pour ce faire de cliquer-droit sur <em>Mining Structures</em> :</p>
<p><img src="http://imageshack.com/a/img809/2473/ywep.png" alt="" /></p>
<p>Nous sautons la page d&rsquo;introduction de l&rsquo;<em>Assistant d&rsquo;Exploration de Données</em> en cliquant directement sur <em>Next</em>, ce qui nous amène le dialogue suivant :</p>
<p><img src="http://imageshack.com/a/img839/11/7mbz.png" alt="" /></p>
<p>Nous continuons avec l&rsquo;option &laquo;&nbsp;<em>A partir d&rsquo;une base de données relationnelle ou d&rsquo;un entrepôt de données</em>&laquo;&nbsp;, et cliquons sur <em>Next</em> :</p>
<p><img src="http://imageshack.com/a/img845/5362/yx9u.png" alt="" /></p>
<p>Ici nous avons le choix de plusieurs algorithmes, expliqués succinctement (plus de détails dans le livre référencé en fin d&rsquo;article):</p>
<p><img src="http://imageshack.com/a/img69/4306/qx6l.png" alt="" /></p>
<p>Nous cliquons sur <em>Next</em>, et obtenons un dialogue de revue et de validation de la vue de données : nous cliquons une nouvelles fois sur <em>Next</em>. Nous devons maintenant spécifier la liste des vues à partir desquelles l&rsquo;algorithme va calculer les réponses possibles. La case à cocher <em>Case</em> permet de spécifier l&rsquo;entité que l&rsquo;on souhaite explorer. En général, un cas est représenté par une ligne d&rsquo;une table ou d&rsquo;une vue qui stocke ou montre les caractéristiques de transactions. Nous continuons donc avec la proposition de l&rsquo;assistant :</p>
<p><img src="http://imageshack.com/a/img600/6603/yzfl.png" alt="" /></p>
<p>Nous devons maintenant choisir suivant quelles caractéristiques de l&rsquo;acheteur nous souhaitons que l&rsquo;algorithme nous aide à prédire quels sont les meilleurs clients potentiels. Comme il s&rsquo;agit d&rsquo;acheteurs de vélos, nous choisissons <em>Age</em>, <em>CommuteDistance</em>, <em>HouseOwnerFlag</em> et <em>NumberCarsOwned</em> :</p>
<p><img src="http://i1331.photobucket.com/albums/w588/elsuket/DataMining/dm_25_zps7569a66c.png" alt="" /></p>
<p>On peut aussi cliquer sur <em>Suggest</em> : le moteur échantillonne alors les données pour faire quelques propositions :</p>
<p><img src="http://imageshack.com/a/img822/394/e24u.png" alt="" /></p>
<p>Nous ne modifions pas la matrice, et validons par <em>Next</em>, ce qui amène la fenêtre suivante :</p>
<p><img src="http://i1331.photobucket.com/albums/w588/elsuket/DataMining/dm_26_zps4f8e72ed.png" alt="" /></p>
<p>En dernier lieu, il convient de spécifier le type des données : ceci se fait par un simple clic sur <em>Detect</em>.</p>
<p>Après une validation par clic sur <em>Next</em>, nous pouvons enfin choisir le taux d&rsquo;échantillonnage : comme 30% des données est un extrait relativement raisonnable, on peut se permettre de ne pas le changer. La lecture de l&rsquo;explication nous permet de comprendre ce que va faire l&rsquo;algorithme :</p>
<p><img src="http://imageshack.com/a/img30/6956/1je2.png" alt="" /></p>
<p>Nous validons le tout par un clic sur <em>Next</em>, ce qui nous permet de revoir notre paramétrage et de renommer la structure et le modèle, mais surtout de cocher la case qui nous permettra d&rsquo;obtenir les détails de l&rsquo;analyse jusqu&rsquo;au niveau des transactions exposées par la vue.</p>
<p><img src="http://imageshack.com/a/img545/7438/fu9o.png" alt="" /></p>
<p>Nous pouvons maintenant valider le tout par <em>Finish</em>, et entraîner le modèle que nous venons de créer. Pour ce faire, il nous suffit de choisir l&rsquo;option <em>Process&#8230;</em> du menu contextuel du modèle :</p>
<p><img src="http://i1331.photobucket.com/albums/w588/elsuket/DataMining/dm_20_zpsdbd4be36.png" alt="" /></p>
<p>Notons que l&rsquo;on peut faire la même chose sous <em>SQL Server Management Studio</em>, après s&rsquo;être connecté à l&rsquo;instance <em>SQL Server Analysis Services</em> :</p>
<p><img src="http://i1331.photobucket.com/albums/w588/elsuket/DataMining/dm_27_zps974e6f23.png" alt="" /></p>
<p>Il nous faut d&rsquo;abord enregistrer le modèle sur le serveur : jusqu&rsquo;ici le modèle n&rsquo;existait que dans <em>SQL Server Data Tools</em>. Nous validons donc par <em>Yes</em> l&rsquo;avertissement suivant :</p>
<p><img src="http://i1331.photobucket.com/albums/w588/elsuket/DataMining/dm_28_zps73c51280.png" alt="" /></p>
<p>Ceci nous amène le dialogue suivant. Pour simplifier, nous continuons avec les options par défaut, et cliquons sur <em>Run &#8230;</em> :</p>
<p><img src="http://i1331.photobucket.com/albums/w588/elsuket/DataMining/dm_29_zpsd58653c2.png" alt="" /></p>
<p>Le modèle est alors en cours d&rsquo;entraînement :</p>
<p><img src="http://i1331.photobucket.com/albums/w588/elsuket/DataMining/dm_30_zpsb7eefa94.png" alt="" /></p>
<p>Une fois le succès de l&rsquo;opération annoncé, nous fermons les dialogues successivement en cliquant sur <em>Close</em>. Nous basculons alors vers l&rsquo;onglet <em>Mining Model Viewer</em>, ce qui nous permet de parcourir l&rsquo;arbre :</p>
<p><img src="http://i1331.photobucket.com/albums/w588/elsuket/DataMining/dm_31_zps8ac76f3e.png" alt="" /></p>
<p>Le gradient de couleurs qui caractérise chaque nœud est d&rsquo;intensité plus faible à mesure que la population sous-jacente diminue.</p>
<p>Voici ce qu&rsquo;indique la légende lorsqu&rsquo;on clique sur le nœud <em>Age &gt; 47 and &lt; 75</em> :</p>
<p><img src="http://i1331.photobucket.com/albums/w588/elsuket/DataMining/dm_32_zps7b5ca354.png" alt="" /></p>
<p>La classe d&rsquo;âge 48-74 comporte 7675 de nos clients. Les facteurs qui influent le plus l&rsquo;achat d&rsquo;un vélo dans cette classe d&rsquo;âge sont en premier lieu le nombre de voitures possédées, suivi par l&rsquo;âge. On peut d&rsquo;ailleurs vérifier cela en basculant dans l&rsquo;onglet <em>Dependancy Network</em> :</p>
<p><img src="http://i1331.photobucket.com/albums/w588/elsuket/DataMining/dm_33_zps37bc6ffe.png" alt="" /></p>
<p>Si l&rsquo;on déplace le curseur en butée basse, on voit clairement que le facteur qui influence le plus l&rsquo;achat d&rsquo;un vélo est le nombre de voitures que l&rsquo;acheteur potentiel possède. Si l&rsquo;on rapproche le curseur de sa position originale, nous observons que viennent ensuite l&rsquo;âge, la distance séparant le domicile du lieu de travail, et enfin la propriété d&rsquo;une maison.</p>
<p>Si vous souhaitez approfondir vos connaissances sur l&rsquo;Exploration de Données avec SQL Server, voici quelques ressources :</p>
<p>&#8211; Le site <a href="http://marktab.net/Resources/Blogs.aspx">MarkTab.net</a>, qui pointe vers de nombreux blogs et publie quelques vidéos sur YouTube.<br />
&#8211; Le site <a href="http://www.sqlserverdatamining.com/ssdm/">SQLServerDataMining.com</a>.<br />
&#8211; Le livre <em>Data Mining with Microsoft SQL Server 2008</em> (ISBN: 978-0-470-27774-4, un pavé de 672 pages).</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>La transformation Pivot avec SQL Server Data Tools (ex SSIS) : attention à l&#8217;ordre !</title>
		<link>https://blog.developpez.com/elsuket/p12489/moteur-de-base-de-donnees-sql-server/indexation/pivot-ssdt-attention-ordre</link>
		<comments>https://blog.developpez.com/elsuket/p12489/moteur-de-base-de-donnees-sql-server/indexation/pivot-ssdt-attention-ordre#comments</comments>
		<pubDate>Sat, 15 Feb 2014 10:08:17 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=870</guid>
		<description><![CDATA[SQL Server Data Tools (SSDT) est le nouveau nom de SQL Server Integration Services (SSIS). Je ne suis pas un supporter des opérateurs T-SQL PIVOT et UNPIVOT, pour la simple et bonne raison qu&#8217;il ne sont pas ensemblistes, et servent &#8230; <a href="https://blog.developpez.com/elsuket/p12489/moteur-de-base-de-donnees-sql-server/indexation/pivot-ssdt-attention-ordre">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SQL Server Data Tools (SSDT) est le nouveau nom de SQL Server Integration Services (SSIS).<br />
Je ne suis pas un supporter des opérateurs T-SQL PIVOT et UNPIVOT, pour la simple et bonne raison qu&rsquo;il ne sont pas ensemblistes, et servent seulement à la présentation de données. Néanmoins, on conçoit aisément que ce sont des opérateurs utiles pour du chargement de données, surtout dans un environnement d&rsquo;entrepôt de données. J&rsquo;ai donc décidé de savoir ce qu&rsquo;il faut faire sous SSDT pour &laquo;&nbsp;pivoter&nbsp;&raquo; un jeu de données.<br />
<span id="more-870"></span><br />
Pour avoir un jeu de données à pivoter, j&rsquo;ai installé la base de données AdventureWorksDW2012, que l&rsquo;on trouve sur <a href="http://msftdbprodsamples.codeplex.com/releases/view/55330">CodePlex</a>. Pour voir comment installer cette base de données dans une instance de SQL Server, suivez le <a href="http://blog.developpez.com/elsuket/p11188/moteur-de-base-de-donnees-sql-server/attacher_base_donnees_sans_tran_log">guide</a>.</p>
<p>Nous démarrons donc en ajoutant une <em>Tâche de Flux de Données</em> dans le <em>Contrôle de Flux</em> par simple glisser-déposer (je débute avec SSDT / SSIS !) :</p>
<p><img src="http://imageshack.com/a/img835/2359/ptji.png" alt="" /></p>
<p>Dans le panneau Flux de Données, nous ajoutons maintenant une source de données ADO.NET de la même façon, puis double-cliquons dessus pour la configurer.<br />
Il nous faut tout d&rsquo;abord créer une connexion à la base de données AdventureWorksDW2012. Pour cela, nous cliquons sur <em>Nouveau &#8230;</em></p>
<p><img src="http://imageshack.com/a/img132/6080/5ou3.png" alt="" /></p>
<p>Comme nous n&rsquo;avons pas encore de connexion, nous cliquons une nouvelle fois sur le bouton <em>Nouveau</em> dans la fenêtre &laquo;&nbsp;Configurer un Gestionnaire de Connexion ADO.NET&nbsp;&raquo;, et nous obtenons la fenêtre suivante :</p>
<p><img src="http://imageshack.com/a/img69/1426/qou3.png" alt="" /></p>
<p><img src="http://imageshack.com/a/img706/1686/nckp.png" alt="" /></p>
<p>Nous validons alors le tout, et nous retrouvons dans l&rsquo;éditeur de Source ADO.NET, ou nous pouvons choisir de traiter les données extraites directement d&rsquo;une table ou d&rsquo;une vue, ou bien de spécifier une requête. Nous choisissons cette dernière option :</p>
<p><img src="http://imageshack.com/a/img594/5356/7ypz.png" alt="" /></p>
<p>Voici donc la requête, que nous collons dans l&rsquo;éditeur de Source ADO.NET, et son résultat sous SQL Server Management Studio :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PC.<span style="color: #202020;">EnglishProductCategoryName</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>F.<span style="color: #202020;">OrderDateKey</span>, <span style="color: #000;">4</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> OrderYear<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">SUM</span><span style="color: #808080;">&#40;</span>F.<span style="color: #202020;">SalesAmount</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> SalesAmount<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">FactResellerSales</span> <span style="color: #0000FF;">AS</span> F<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">DimProduct</span> <span style="color: #0000FF;">AS</span> P<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> F.<span style="color: #202020;">ProductKey</span> <span style="color: #808080;">=</span> P.<span style="color: #202020;">ProductKey</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">DimProductSubcategory</span> <span style="color: #0000FF;">AS</span> PS<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> P.<span style="color: #202020;">ProductSubcategoryKey</span> <span style="color: #808080;">=</span> PS.<span style="color: #202020;">ProductSubcategoryKey</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">DimProductCategory</span> <span style="color: #0000FF;">AS</span> PC<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> PS.<span style="color: #202020;">ProductCategoryKey</span> <span style="color: #808080;">=</span> PC.<span style="color: #202020;">ProductCategoryKey</span><br />
<span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span>&nbsp; &nbsp; &nbsp; &nbsp; PC.<span style="color: #202020;">EnglishProductCategoryName</span>, <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>F.<span style="color: #202020;">OrderDateKey</span>, <span style="color: #000;">4</span><span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p><img src="http://imageshack.com/a/img812/7338/80pd.png" alt="" /></p>
<p>Notre but des donc d&rsquo;obtenir une jeu de données avec les colonnes suivantes :</p>
<p>&#8211; 4 lignes, dont la colonne contiendra des valeurs uniques suivantes (<em>Components</em>, <em>Bikes</em>, <em>Clothing</em> et <em>Accessories</em>)<br />
&#8211; 5 colonnes, dont 4 pour les années 2005 à 2008, et une pour le volume de vente (<em>SalesAmount</em>)</p>
<p>Nous obtenons l&rsquo;interface suivante, qui nous permet de spécifier les caractéristiques de l&rsquo;opération de pivot :</p>
<p><img src="http://imageshack.com/a/img843/6627/7cxz.png" alt="" /></p>
<p>Nous validons par le bouton <em>OK</em>, puis passons sous l&rsquo;éditeur avancé :</p>
<p><img src="http://imageshack.com/a/img850/1875/5lut.png" alt="" /></p>
<p>En basculant sous l&rsquo;onglet <em>Propriétés d&rsquo;entrée / sortie</em>, on s&rsquo;aperçoit qu&rsquo;il va manquer des colonnes. En effet, les colonnes des années ne sont pas dans la sortie du pivot :</p>
<p><img src="http://imageshack.com/a/img69/8035/yp60.png" alt="" /></p>
<p>Notons ici la valeur <em>LineageID</em>, qui nous permettra d&rsquo;indiquer par la suite la colonne de la source de données pour la sortie du pivot. Dans cet exemple, c&rsquo;est 22. Nous ajoutons donc 4 colonnes, 2005, 2006, 2007 et 2008, avec le modèle suivant :</p>
<p><img src="http://imageshack.com/a/img703/1378/8phu.png" alt="" /></p>
<p>Nous obtenons donc :</p>
<p><img src="http://imageshack.com/a/img713/5834/nrse.png" alt="" /></p>
<p>Comme nous ne souhaitons pas stocker les données en sortie, mais seulement voir ce que le moteur fait, nous pouvons ajouter comme destination un compteur de lignes :</p>
<p><img src="http://imageshack.com/a/img706/2964/fof8.png" alt="" /></p>
<p>Comme le libellé de l&rsquo;erreur l&rsquo;indique, nous devons créer une variable pour stocker le nombre de lignes retournés en sortie de l&rsquo;opérateur pivot. Pour ce faire, il suffit d&rsquo;utiliser la fenêtre des variables (<em>Affichage</em> &gt; <em>Autres fenêtres</em> &gt; <em>Variables</em>) du paquetage, que nous appelons <em>rowCount</em>.</p>
<p><img src="http://imageshack.com/a/img541/2246/johz.png" alt="" /></p>
<p>Une fois fait, il nous suffit de double-cliquer sur la destination pour pouvoir spécifier la variable :</p>
<p><img src="http://imageshack.com/a/img835/2987/mfhf.png" alt="" /></p>
<p>Après avoir validé par <em>OK</em>, nous pouvons activer la visionneuse de données sur les deux pipelines, par un simple clic-droit sur chacun d&rsquo;entre-eux- Ceci nous permettra de visualiser la transformation :</p>
<p><img src="http://imageshack.com/a/img834/8379/zybt.png" alt="" /></p>
<p>Voici ce qui se passe à l&rsquo;exécution du paquetage :</p>
<p><img src="http://imageshack.com/a/img845/1959/lkw4.png" alt="" /></p>
<p>La visionneuse de gauche nous montre les données avant le pivot, et celle de droite après. On voit bien que la transformation est plus proche d&rsquo;une matrice que d&rsquo;un pivot. Ceci est dû au fait que l&rsquo;on n&rsquo;a pas ordonné les données suivant le libellé de la catégorie : dès lors, le groupement des lignes suivant ce critère n&rsquo;est pas fait. Nous cliquons sur le bouton Lecture, et comme le tampon ne contient que quelques lignes, l&rsquo;exécution du paquetage continue et se termine presque immédiatement, sans erreur.</p>
<p>Comme bien souvent dans l&rsquo;environnement SQL Server, on dispose de plusieurs possibilités pour remédier à ceci : soit ajouter une clause ORDER BY	PC.EnglishProductCategoryName à la requête, soit ajouter un opérateur de tri dans SSIS. C&rsquo;est cette dernière option que nous choisissons, puisqu&rsquo;en SQL, il n&rsquo;y a normalement pas d&rsquo;ordre.</p>
<p>Nous intercalons donc un opérateur de tri :</p>
<p><img src="http://imageshack.com/a/img809/460/u56o.png" alt="" /></p>
<p>Et nous le configurons pour que le tri se fasse suivant la colonne <em>EnglishProductCategoryName</em>; par défaut le tri est ascendant :</p>
<p><img src="http://imageshack.com/a/img268/9697/5iw5.png" alt="" /></p>
<p>Nous ré-exécutons le paquetage, dont il ne nous reste plus que la visionneuse de données en sortie du pivot. Nous obtenons alors le résultat escompté :</p>
<p><img src="http://imageshack.com/a/img850/2084/ulzv.png" alt="" /></p>
<p>Bons pivots de données avec SSDT !</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Journées SQL Server les 2 et 3 Décembre</title>
		<link>https://blog.developpez.com/elsuket/p12339/annonces/journees-sql-server-les-2-et-3-decembre</link>
		<comments>https://blog.developpez.com/elsuket/p12339/annonces/journees-sql-server-les-2-et-3-decembre#comments</comments>
		<pubDate>Mon, 18 Nov 2013 18:02:32 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=843</guid>
		<description><![CDATA[Les Journées SQL Server 2013 sont organisées par le Groupe des Utilisateurs de SQL Server, et auront lieu les 2 et 3 Décembre chez Microsoft, à Issy-les-Moulineaux. C&#8217;est l&#8217;occasion pour toute la communauté SQL Server Francophone de se retrouver autour &#8230; <a href="https://blog.developpez.com/elsuket/p12339/annonces/journees-sql-server-les-2-et-3-decembre">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Les Journées SQL Server 2013 sont organisées par le <a href="http://guss.pro/" title="GUSS">Groupe des Utilisateurs de SQL Server</a>, et auront lieu les 2 et 3 Décembre chez Microsoft, à Issy-les-Moulineaux. C&rsquo;est l&rsquo;occasion pour toute la communauté SQL Server Francophone de se retrouver autour de nombreuses sessions, dont l&rsquo;agenda se trouve <a href="http://guss.pro/wp-content/uploads/2013/11/planningJSS20131.png" title="Planning Journées SQL Server 2013">ici</a>.</p>
<p>J&rsquo;animerai avec <a href="http://mikedavem.developpez.com/">Mikedavem</a> une session sur les événements étendus sous SQL Server 2012 le Mardi 3 Décembre à 17h. Cette session d&rsquo;une heure sera intense en contenu puisque exclusivement basée sur de nombreuses démonstrations.</p>
<p>J&rsquo;espère pouvoir vous y rencontrer nombreux !</p>
<p>@++ <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trouver le port d&#8217;écoute d&#8217;une instance SQL Server (avec une requête)</title>
		<link>https://blog.developpez.com/elsuket/p12285/moteur-de-base-de-donnees-sql-server/trouver-le-port-decoute-dune-instance-sql-server-avec-une-requete</link>
		<comments>https://blog.developpez.com/elsuket/p12285/moteur-de-base-de-donnees-sql-server/trouver-le-port-decoute-dune-instance-sql-server-avec-une-requete#comments</comments>
		<pubDate>Fri, 18 Oct 2013 09:51:13 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=839</guid>
		<description><![CDATA[Le service SQL Browser permet d&#8217;obtenir la liste des instances SQL Server ainsi que leur port d&#8217;écoute. Pour des raisons de sécurité, on peut donc vouloir désactiver ce service, mais il nous faut auparavant connaître le port d&#8217;écoute de chacune &#8230; <a href="https://blog.developpez.com/elsuket/p12285/moteur-de-base-de-donnees-sql-server/trouver-le-port-decoute-dune-instance-sql-server-avec-une-requete">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Le service SQL Browser permet d&rsquo;obtenir la liste des instances SQL Server ainsi que leur port d&rsquo;écoute. Pour des raisons de sécurité, on peut donc vouloir désactiver ce service, mais il nous faut auparavant connaître le port d&rsquo;écoute de chacune d&rsquo;entre elles : par défaut, le port d&rsquo;écoute de l&rsquo;instance par défaut est 1433. Si l&rsquo;on dispose de plusieurs instances SQL Server installées sur une même machine, chacune dispose d&rsquo;un port qui lui est dédié. Voici donc une requête qui vous permet de retrouver le port d&rsquo;écoute d&rsquo;une instance SQL Server en particulier.<br />
<span id="more-839"></span><br />
Cette requête n&rsquo;est pas des plus orthodoxes puisqu&rsquo;elle fait appel à la procédure stockée étendue système xp_regread. Cela étant, elle permet de retrouver le port d&rsquo;écoute d&rsquo;une instance SQL Server instantanément :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DECLARE</span> @TCP_port <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">5</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @registry_path <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span><span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">SELECT</span> @registry_path <span style="color: #808080;">=</span> <span style="color: #0000FF;">CASE</span> <span style="color: #FF00FF;">@@SERVICENAME</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'MSSQLSERVER'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'SOFTWARE\Microsoft\MSSQLSERVER\MSSQLSERVER\SuperSocketNetLib\TCP'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">'SOFTWARE\Microsoft\Microsoft SQL Server\'</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">@@SERVICENAME</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'\MSSQLServer\SuperSocketNetLib\TCP'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
<br />
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">xp_regread</span><br />
&nbsp; &nbsp; @rootkey <span style="color: #808080;">=</span> <span style="color: #FF0000;">'HKEY_LOCAL_MACHINE'</span><br />
&nbsp; &nbsp; , @<span style="color: #0000FF;">key</span> <span style="color: #808080;">=</span> @registry_path<br />
&nbsp; &nbsp; , @value_name <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TcpPort'</span><br />
&nbsp; &nbsp; , @<span style="color: #0000FF;">value</span> <span style="color: #808080;">=</span> @TCP_port <span style="color: #0000FF;">OUTPUT</span><br />
<br />
<span style="color: #0000FF;">SELECT</span> @TCP_port <span style="color: #0000FF;">AS</span> PortNumber<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">@@SERVERNAME</span> <span style="color: #0000FF;">AS</span> ServerName<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">@@SERVICENAME</span> <span style="color: #0000FF;">AS</span> ServiceName</div></td></tr></tbody></table></div>
<p>Lorsque l&rsquo;on a le service SQL Browser désactivé, on peut se connecter à une instance nommée en précisant le nom du serveur + virgule + le numéro de port. Par exemple, si nous disposons d&rsquo;un serveur ELSUKETW8 doté d&rsquo;une instance nommée SQL2012 qui écoute les connexions sur le port 62549, alors dans la chaîne de connexion de nos applications, nous devons remplacer Server=ELSUKETW8\SQL2012 par Server=ELSUKETW8,62549.</p>
<p>Bon routage à tous !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Déçu par IntelliSense ? Essayez Devart dbForge SQL Complete !</title>
		<link>https://blog.developpez.com/elsuket/p12156/utilitaires/dbforge-sql-complete</link>
		<comments>https://blog.developpez.com/elsuket/p12156/utilitaires/dbforge-sql-complete#comments</comments>
		<pubDate>Sun, 28 Jul 2013 14:00:10 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=709</guid>
		<description><![CDATA[Quoi de plus naturel pour un moteur de base de données relationnelles SQL que le verrouillage ? En effet, toute exécution de requête entraîne l&#8217;acquisition de verrous. Comme je me rends compte que c&#8217;est un sujet quelque peu méconnu, je &#8230; <a href="https://blog.developpez.com/elsuket/p12108/moteur-de-base-de-donnees-sql-server/lescalade-de-verrous">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Quoi de plus naturel pour un moteur de base de données relationnelles SQL que le verrouillage ? En effet, toute exécution de requête entraîne l&rsquo;acquisition de verrous. Comme je me rends compte que c&rsquo;est un sujet quelque peu méconnu, je vous propose ici d&rsquo;explorer dans quelles conditions une escalade de verrous se produit, après avoir succinctement décrit ce qu&rsquo;est le verrouillage.</p>
<p><span id="more-709"></span></p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Qu&rsquo;est-ce que le verrouillage ?</strong></p>
<p>Le verrouillage est un mécanisme qui permet à plusieurs utilisateurs d&rsquo;accéder à des ressources, tout en évitant que cela résulte en des incohérences de données. Des verrous sont acquis lorsque le moteur de base de données a besoin d&rsquo;accéder à une ressource pour la lire ou la modifier. Sous SQL Server, cette opération est purement logique, et sert le support de l&rsquo;<a href="http://fr.wikipedia.org/wiki/Propri%C3%A9t%C3%A9s_ACID">ACIDité</a> de toute transaction.</p>
<p>Ce mécanisme est entièrement géré par le moteur de stockage de SQL Server, avec lequel l&rsquo;utilisateur n&rsquo;a que peu de moyens d&rsquo;interagir (et tant mieux !).<br />
On peut bien sûr affecter le comportement d&rsquo;une transaction en indiquant le <a href="http://msdn.microsoft.com/fr-fr/library/ms173763.aspx">niveau d&rsquo;isolation de transaction</a> sous lequel elle doit être traitée. Il est rarement nécessaire d&rsquo;indiquer à SQL Server quel doit être le type de verrouillage à choisir à l&rsquo;aide d&rsquo;indicateurs <a href="http://msdn.microsoft.com/fr-fr/library/ms187373%28v=sql.110%29.aspx">de table</a> ou <a href="http://msdn.microsoft.com/fr-fr/library/ms181714.aspx">de requête</a>. SQL Server a de toute façon la primauté sur ce choix, puisqu&rsquo;il outrepasse parfois les recommandations du développeur ou du DBA. Globalement, le moteur de base de données SQL Server effectue le meilleur choix.</p>
<p>Tout ceci fait qu&rsquo;outre le niveau d&rsquo;isolation de transaction, lorsqu&rsquo;on code pour SQL Server, on n&rsquo;a pas à se soucier de ce que telle ou telle opération DML va produire en termes de verrouillage. Cependant, l&rsquo;accès concurrent à une même ressource provoque parfois des situations de <a href="http://blog.developpez.com/elsuket/p12049/snippets/auditer-les-processus-bloques-levenement-blocked-process-report" title="Auditer les processus bloqués : l’événement blocked process report" target="_blank">blocage</a>, voire d&rsquo;<a href="http://blog.developpez.com/elsuket/p7610/moteur-de-base-de-donnees-sql-server/origine_des_verrous_mortels_deadlocks">étreinte mortelle</a> (<a href="http://blog.developpez.com/elsuket/p9234/moteur-de-base-de-donnees-sql-server/obtenir_la_liste_des_deadlocks_retrospec">deadlock</a>) : il est alors nécessaire de comprendre ce qui a provoqué cette situation pour pouvoir orienter les choix de SQL Server, de sorte à éviter qu&rsquo;un tel phénomène se reproduise. A ce titre, il est nécessaire de savoir :</p>
<p>&#8211; quelles sont les ressources sur lesquelles les transactions acquièrent des verrous (ligne ou clé ou page, partition, table, schéma, base de données)<br />
&#8211; quel est le type de verrou qui a été acquis sur la ressource (intentionnel, partagé, de mise à jour, exclusif, de copie en bloc)</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Dans quelles conditions une escalade de verrou se produit-elle ?</strong></p>
<p>SQL Server choisit toujours d&rsquo;acquérir des verrous de faible granularité, de façon à maximiser la concurrence d&rsquo;accès. Donc la plupart du temps, SQL Server acquiert des verrous de ligne/clé, ou de page. Il faut noter que l&rsquo;acquisition de verrous se fait directement soit au niveau ligne/clé, soit au niveau page : l&rsquo;escalade de verrous ne se fait jamais de ligne/clé à page. En effet, si le moteur de base de données a calculé qu&rsquo;il devra accéder à toutes les lignes d&rsquo;un jeu de pages, autant qu&rsquo;il acquière un unique verrou sur chacune desdites pages. Tout verrou, quelle que soit sa granularité, consomme 96 octets de mémoire, et est une structure purement logique.</p>
<p>Le principe général de l&rsquo;escalade de verrou est de remplacer un grand nombre de verrous par un verrou de plus forte granularité, de façon à consommer moins de mémoire. Cela se fait au détriment de la concurrence d&rsquo;accès, mais en faveur :</p>
<p>&#8211; de la vitesse d&rsquo;exécution : un verrous a forte granularité est acquis pour une durée plus courte<br />
&#8211; mais aussi et surtout de la consommation de mémoire : moins on acquiert de verrous, moins on consomme de mémoire.</p>
<p>Au niveau requête, l&rsquo;escalade est réalisée dès qu&rsquo;elle acquiert ou requiert plus de 5000 verrous.</p>
<p>Au  niveau instance, lorsque SQL Server détecte que la gestion des verrous consomme 24% de la taille du cache de données (à l&rsquo;exclusion de la mémoire AWE sur les systèmes x86), il va scruter les sessions qui en détiennent en grand nombre, et escalader les verrous de celles-ci. Par ailleurs, l&rsquo;option de configuration <em>locks</em> permet de contrôler l&rsquo;escalade de verrous : si la valeur configurée est différente zéro (valeur par défaut), alors SQL Server réalisera une escalade de verrous dès que 40% de cette valeur en nombre de verrous acquis ou requis est dépassée. Il réalisera ensuite une nouvelle escalade de verrous après chaque bloc de 1250 verrous acquis ou requis dans ces conditions. L&rsquo;utilisateur n&rsquo;a aucun contrôle sur les sessions que SQL Server va sélectionner pour l&rsquo;escalade de verrous, mais gageons que comme pour bien d&rsquo;autres fonctionnalités, il n&rsquo;ait pas besoin d&rsquo;aide.</p>
<p>Enfin, si la gestion des verrous consomme 60% de la mémoire allouée à SQL Server à travers l&rsquo;option <em>max server memory (MB)</em>, ce dernier peut prendre la décision d&rsquo;annuler une ou plusieurs requêtes responsables de cette grande consommation. Dans ce cas, les requêtes impactées lèvent une exception de numéro 1204, dont le libellé est le suivant :</p>
<p><em>L&rsquo;instance du moteur de base de données SQL Server ne peut pas obtenir une ressource LOCK en ce moment. Réexécutez votre instruction lorsque le nombre d&rsquo;utilisateurs actifs est moindre. Demandez à l&rsquo;administrateur de base de données de vérifier la configuration du verrou et de la mémoire pour cette instance, ou de vérifier les longues transactions.</em></p>
<p>ou en Anglais :</p>
<p><em>The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users. Ask the database administrator to check the lock and memory configuration for this instance, or to check for long-running transactions.</em></p>
<p>Cette erreur est aussi écrite dans les journaux de SQL Server.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Quelques requêtes</strong></p>
<p>La DMV <em>sys.dm_os_memory_clerks</em> nous permet de trouver la taille du gestionnaire de verrous. Voici la requête pour jusqu&rsquo;à SQL Server 2008 R2 inclus :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">TRANSACTION</span> <span style="color: #0000FF;">ISOLATION</span> <span style="color: #0000FF;">LEVEL</span> <span style="color: #0000FF;">READ</span> <span style="color: #0000FF;">UNCOMMITTED</span><br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; type<br />
&nbsp; &nbsp; &nbsp; &nbsp; , name<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">SUM</span><span style="color: #808080;">&#40;</span>single_pages_kb<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> cache_size_from_buffer_pool_KB<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">SUM</span><span style="color: #808080;">&#40;</span>multi_pages_kb<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> cache_size_out_buffer_pool_KB<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">dm_os_memory_clerks</span><br />
<span style="color: #008080;">--WHERE name LIKE 'Lock Manager%'</span><br />
<span style="color: #0000FF;">GROUP</span> &nbsp; <span style="color: #0000FF;">BY</span> type, name<br />
<span style="color: #0000FF;">ORDER</span> &nbsp; <span style="color: #0000FF;">BY</span> security_token_cache_size_from_buffer_pool_KB DESC<span style="color: #808080;">&lt;/</span>code<span style="color: #808080;">&gt;</span><br />
<br />
Et dès <span style="color: #0000FF;">SQL</span> Server <span style="color: #000;">2012</span> :<br />
<br />
<span style="color: #808080;">&lt;</span>code<span style="color: #808080;">&gt;</span><span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">TRANSACTION</span> <span style="color: #0000FF;">ISOLATION</span> <span style="color: #0000FF;">LEVEL</span> <span style="color: #0000FF;">READ</span> <span style="color: #0000FF;">UNCOMMITTED</span><br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; type<br />
&nbsp; &nbsp; &nbsp; &nbsp; , name<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">SUM</span><span style="color: #808080;">&#40;</span>pages_kb<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> cache_size_KB<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">dm_os_memory_clerks</span><br />
<span style="color: #008080;">--WHERE name LIKE 'Lock Manager%'</span><br />
<span style="color: #0000FF;">GROUP</span> &nbsp; <span style="color: #0000FF;">BY</span> type, name<br />
<span style="color: #0000FF;">ORDER</span> &nbsp; <span style="color: #0000FF;">BY</span> cache_size_KB <span style="color: #0000FF;">DESC</span></div></td></tr></tbody></table></div>
<p>On trouve un gestionnaire de verrous par <a href="http://blog.developpez.com/elsuket/p11951/moteur-de-base-de-donnees-sql-server/mise-au-point-a-propos-du-compteur-de-performance-page-life-expectancy" title="Mise au point à propos du compteur de performance Page Life Expectancy">noeud NUMA</a>. Si nous laissons la clause WHERE de ces deux requêtes en commentaire, on doit trouver CACHESTORE_SQLCP et CACHESTORE_OBJCP sur les deux premières lignes du résultat de la requête, puisque le premier représente le cache de plan de requêtes ad-hoc ou en SQL dynamique, et le second celui des procédures stockées et déclencheurs. Si on y trouve OBJECTSTORE_LOCK_MANAGER, c&rsquo;est que le gestionnaire de verrous consomme probablement une trop grande quantité de mémoire.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>LOCK_ESCALATION : cas des tables partitionnées</strong></p>
<p>Dès SQL Server 2008, il est possible de réaliser l&rsquo;escalade de verrous au niveau partition, avant que celle-ci se produise au niveau table. Mais pour ce faire, il est nécessaire que celle-ci soit positionnée à AUTO : or par défaut, elle est à TABLE. On trouve les tables candidates à ce changement à l&rsquo;aide de la requête suivante :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">;<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; PARTITIONNED_TABLE <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #0000FF;">DISTINCT</span> <span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">dm_db_partition_stats</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; partition_number <span style="color: #808080;">&amp;</span>gt; <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.'</span> <span style="color: #808080;">+</span> T.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> table_or_indexed_view_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , T.<span style="color: #202020;">lock_escalation_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CASE</span> T.<span style="color: #202020;">lock_escalation_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'TABLE'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'ALTER TABLE '</span> <span style="color: #808080;">+</span> S.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.'</span> <span style="color: #808080;">+</span> T.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' SET (LOCK_ESCALATION = AUTO)'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> sql_change_lock_escalation_level<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">schemas</span> <span style="color: #0000FF;">AS</span> S<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">tables</span> <span style="color: #0000FF;">AS</span> T<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> S.<span style="color: #202020;">schema_id</span> <span style="color: #808080;">=</span> T.<span style="color: #202020;">schema_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; PARTITIONNED_TABLE <span style="color: #0000FF;">AS</span> PT<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> PT.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> T.<span style="color: #FF00FF;">object_id</span><br />
<span style="color: #008080;">--WHERE &nbsp; &nbsp; &nbsp; &nbsp; T.lock_escalation_desc = 'TABLE'</span></div></td></tr></tbody></table></div>
<p>Bon verrouillage à tous !</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Récompense MVP : Chapitre 2013</title>
		<link>https://blog.developpez.com/elsuket/p12106/annonces/recompense-mvp-chapitre-2013</link>
		<comments>https://blog.developpez.com/elsuket/p12106/annonces/recompense-mvp-chapitre-2013#comments</comments>
		<pubDate>Sun, 07 Jul 2013 10:17:25 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=726</guid>
		<description><![CDATA[Je viens d&#8217;être récompensé pour la troisième fois MVP SQL Server, et pour la deuxième fois en Thaïlande. Cela étant, la plupart des mes participations communautaires sont en Français, évidemment sur ce forum. Je remercie donc toute l&#8217;équipe de Développez.com, &#8230; <a href="https://blog.developpez.com/elsuket/p12106/annonces/recompense-mvp-chapitre-2013">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Je viens d&rsquo;être récompensé pour la troisième fois MVP SQL Server, et pour la deuxième fois en Thaïlande.<br />
Cela étant, la plupart des mes participations communautaires sont en Français, évidemment sur ce forum.<br />
Je remercie donc toute l&rsquo;équipe de Développez.com, et je tiens aussi à remercier, en France :</p>
<p>&#8211; Frédéric Brouard, alias <a href="http://sqlpro.developpez.com/">SQLPro</a>, avec qui nous avons un livre sur SQL Server 2014 dans les tuyaux, co-écrit avec Christian Soutou<br />
&#8211; David Barbarin, alias <a href="http://blog.developpez.com/mikedavem/">Mikedavem</a>, avec qui je suis régulièrement en contact malgré le décalage horaire <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /><br />
&#8211; <a href="http://blog.datafly.pro/">Arian Papillon</a>, <a href="http://conseilit.wordpress.com/">Christophe Laporte</a>, <a href="http://blog.djeepy1.net/">Jean-Pierre Riehl</a>, que j&rsquo;ai rencontré et revus au MVP Summit 2013</p>
<p>En Thaïlande et à Singapour :</p>
<p>&#8211; Panjaporn Vittayalerdpun, Server Business Group Lead chez Microsoft à Bangkok<br />
&#8211; Fukiat Julnual, Évangéliste chez Microsoft à Bangkok, PASS Chapter Thailand<br />
&#8211; Lilan Quek, MVP Lead à Singapour<br />
&#8211; Clarisse Ng, MVP Program Specialist à Singapour</p>
<p>A bientôt sur le forum et au prochain MVP Summit !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft : large gallerie de ebooks gratuits</title>
		<link>https://blog.developpez.com/elsuket/p12091/annonces/microsoft-large-gallerie-de-ebooks-gratuits</link>
		<comments>https://blog.developpez.com/elsuket/p12091/annonces/microsoft-large-gallerie-de-ebooks-gratuits#comments</comments>
		<pubDate>Wed, 26 Jun 2013 14:42:04 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>
		<category><![CDATA[ebook]]></category>
		<category><![CDATA[Lync]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[System Center]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[Windows Server]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=705</guid>
		<description><![CDATA[C&#8217;est par ici et il y en a pour tout le monde : Lync, Office, Sharepoint, SQL Server, System Center, Visual Studio, Web Development, Windows (Azure, Phone &#38; Server) aux formats PDF, MOBI et EPUB. Bonne lecture !]]></description>
				<content:encoded><![CDATA[<p>C&rsquo;est <a href="http://social.technet.microsoft.com/wiki/contents/articles/11608.e-book-gallery-for-microsoft-technologies.aspx">par ici</a> et il y en a pour tout le monde : Lync, Office, Sharepoint, SQL Server, System Center, Visual Studio, Web Development, Windows (Azure, Phone &amp; Server) aux formats PDF, MOBI et EPUB.</p>
<p>Bonne lecture !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auditer les processus bloqués : l&#8217;événement blocked process report</title>
		<link>https://blog.developpez.com/elsuket/p12049/snippets/auditer-les-processus-bloques-levenement-blocked-process-report</link>
		<comments>https://blog.developpez.com/elsuket/p12049/snippets/auditer-les-processus-bloques-levenement-blocked-process-report#comments</comments>
		<pubDate>Sat, 15 Jun 2013 10:46:31 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Non documenté]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Utilitaires]]></category>
		<category><![CDATA[%%lockres%%]]></category>
		<category><![CDATA[blocage]]></category>
		<category><![CDATA[blocked process report]]></category>
		<category><![CDATA[blocked process threshold]]></category>
		<category><![CDATA[blocking]]></category>
		<category><![CDATA[deadlock]]></category>
		<category><![CDATA[événements étendus]]></category>
		<category><![CDATA[Extended Events]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[lock monitor]]></category>
		<category><![CDATA[Profiler]]></category>
		<category><![CDATA[sp_configure]]></category>
		<category><![CDATA[timeout]]></category>
		<category><![CDATA[verrou]]></category>
		<category><![CDATA[waitresource]]></category>
		<category><![CDATA[XE]]></category>

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

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=592</guid>
		<description><![CDATA[Un an après avoir sorti SQL Server 2012, le 2 Avril 2012, Microsoft a annoncé le 6 Avril la sortie de SQL Server 2014. Voici donc que la semaine dernière, à l&#8217;occasion du TechEd North America, Microsoft a annoncé la &#8230; <a href="https://blog.developpez.com/elsuket/p12044/moteur-de-base-de-donnees-sql-server/sql-server-2014-cest-pour-bientot">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Un an après avoir sorti SQL Server 2012, le 2 Avril 2012, Microsoft a annoncé le 6 Avril la sortie de SQL Server 2014.<br />
Voici donc que la semaine dernière, à l&rsquo;occasion du <em>TechEd North America</em>, Microsoft a annoncé la sortie en avant-première de SQL Server 2014 dans les semaines à venir, même si une date définitive de commercialisation n&rsquo;a pas encore été fixée.</p>
<p>On notera parmi les fonctionnalités les plus attendues :<br />
<span id="more-592"></span><br />
&#8211; <em>Hekaton</em>, le nom de code du moteur de base de données entièrement in-memory : la mécanique repose sur le contrôle de concurrence multi-version, ce qui permet de traiter les données sans lock, latch ou blocage. Il est bien sûr possible de choisir les tables qui utiliseront cette fonctionnalité, mais aussi de compiler les procédures stockées directement en code machine pour obtenir des gains de performance supplémentaires.</p>
<p>&#8211; SQL Server 2014 sera encore plus proche du cloud encore que SQL Server 2012, avec la possibilité, entre autres, de prendre une sauvegarde de base de données sur un compte de stockage Azure, et de la référencer par une URL. La fonctionnalité <em>Smart Backup</em> laisse SQL Server décider s&rsquo;il est temps de prendre une sauvegarde différentielle de la base de données, ou encore une sauvegarde du fichier du journal des transactions. Il sera aussi possible de créer une base de données localement, tout en ayant ses fichiers stockés dans le cloud. Enfin la fonctionnalité <em>AlwaysOn</em> sera étendue à <em>Azure</em>, avec la possibilité de créer un groupe de disponibilité dont le réplica peut se trouver dans les nuages.</p>
<p>&#8211; La mémoire pourra être étendue à l&rsquo;usage des disques SSD<br />
&#8211; Les tables utilisant des index <em>ColumnStore</em> seront dorénavant actualisables, ce qui n&rsquo;était pas encore le cas sous SQL Server 2012<br />
&#8211; Le <em>Gouverneur de Ressources</em> permettra l’accélération des IO<br />
&#8211; Les statistiques de colonnes et d&rsquo;index seront disponible au niveau partition, tandis que l&rsquo;estimation de cardinalités a été améliorée<br />
&#8211; La reconstruction en ligne d&rsquo;une partition d&rsquo;index sera désormais possible, après que SQL Server 2012 ait permis la reconstruction en ligne des index portant sur des colonnes de type LOB.</p>
<p>Il est à noter que toutes ces améliorations ont été apportés dans un cycle de développement relativement court pour SQL Server : 18 mois. Espérons que ce ne soit que le début d&rsquo;une tendance !</p>
<p>Quelques liens :</p>
<p>&#8211; <a href="http://blogs.technet.com/b/dataplatforminsider/archive/2013/06/03/sql-server-2014-unlocking-real-time-insights.aspx">le blog SQL Server</a><br />
&#8211; <a href="http://www.microsoft.com/en-us/sqlserver/sql-server-2014.aspx">S&rsquo;enregistrer pour être notifié de la disponibilité de l&rsquo;évaluation de SQL Server 2014</a><br />
&#8211; <a href="http://visualstudiomagazine.com/blogs/data-driver/2013/06/microsoft-announces-sql-server-2014.aspx">Visual Studio Magazine</a><br />
&#8211; <a href="http://redmondmag.com/articles/2012/04/02/sql-server-2012-released.aspx">RedmondMag</a></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quelles statistiques l&#8217;Optimiseur a-t-il utilisées pour calculer le plan de requête ?</title>
		<link>https://blog.developpez.com/elsuket/p12023/moteur-de-base-de-donnees-sql-server/quelles-statistiques-loptimiseur-a-t-il-utilisees-pour-calculer-le-plan-de-requete</link>
		<comments>https://blog.developpez.com/elsuket/p12023/moteur-de-base-de-donnees-sql-server/quelles-statistiques-loptimiseur-a-t-il-utilisees-pour-calculer-le-plan-de-requete#comments</comments>
		<pubDate>Thu, 06 Jun 2013 16:19:44 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Non documenté]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[8666]]></category>
		<category><![CDATA[drapeau de trace]]></category>
		<category><![CDATA[plan d'exécution]]></category>
		<category><![CDATA[statistiques]]></category>
		<category><![CDATA[trace flag]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=559</guid>
		<description><![CDATA[Si une bonne partie de votre temps de travail est consacrée à l&#8217;optimisation de requête et à la compréhension du fonctionnement de l&#8217;Optimiseur de Requêtes, vous vous êtes probablement demandé sur quelles statistiques celui-ci se base pour calculer le plan &#8230; <a href="https://blog.developpez.com/elsuket/p12023/moteur-de-base-de-donnees-sql-server/quelles-statistiques-loptimiseur-a-t-il-utilisees-pour-calculer-le-plan-de-requete">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Si une bonne partie de votre temps de travail est consacrée à l&rsquo;optimisation de requête et à la compréhension du fonctionnement de l&rsquo;Optimiseur de Requêtes, vous vous êtes probablement demandé sur quelles statistiques celui-ci se base pour calculer le plan d&rsquo;une requête.</p>
<p>Il existe un drapeau de trace <strong>non-documenté</strong>, n° 8666, qui permet d&rsquo;ajouter au document XML qui décrit le plan de requête les statistiques utilisées par l&rsquo;optimiseur pour générer le plan de requêtes.</p>
<p>Voyons comment l&rsquo;utiliser avec une requête sur la base de données <a href="http://blog.developpez.com/elsuket/p11188/moteur-de-base-de-donnees-sql-server/attacher_base_donnees_sans_tran_log">AdventureWorks2012</a> :</p>
<p><span id="more-559"></span></p>
<p>Avant toute chose, notez que ce drapeau de trace n&rsquo;est pas documenté. Comme toute fonctionnalité non-documentée, on ne doit <strong>JAMAIS</strong> utiliser celui-ci sur une base de données ou une instance qui sert une charge de production. <strong>Si tel devait être le cas, je ne peux en aucun cas être tenu pour responsable des conséquences. Vous devez limiter strictement l’usage de cette instruction aux environnements de test.</strong></p>
<p>Utilisons la requête suivante :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DBCC</span> TRACEON <span style="color: #808080;">&#40;</span><span style="color: #000;">8666</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">USE</span> AdventureWorks2012<br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SOH.<span style="color: #202020;">OrderDate</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , SOH.<span style="color: #202020;">DueDate</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , SOH.<span style="color: #202020;">ShipDate</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , SOH.<span style="color: #202020;">AccountNumber</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , SOD.<span style="color: #202020;">OrderQty</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , SOD.<span style="color: #202020;">UnitPrice</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sales.<span style="color: #202020;">SalesOrderHeader</span> <span style="color: #0000FF;">AS</span> SOH<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; Sales.<span style="color: #202020;">SalesOrderDetail</span> <span style="color: #0000FF;">AS</span> SOD<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> SOH.<span style="color: #202020;">SalesOrderID</span> <span style="color: #808080;">=</span> SOD.<span style="color: #202020;">SalesOrderID</span></div></td></tr></tbody></table></div>
<p>Demandons maintenant à SQL Server de générer le plan de requête estimé. Celui-ci s&rsquo;obtient soit en pressant CTRL + L, soit par un clic sur l&rsquo;icône suivante, présente dans la barre d&rsquo;outils : </p>
<p><img src="http://img199.imageshack.us/img199/605/estimatedexecutionplan.png" alt="" /></p>
<p>On obtiendra aussi les informations ajoutées par le drapeau de trace 8666 avec le plan d&rsquo;exécution réel, que l&rsquo;on obtient soit en pressant CTRL + M, soit par un clic sur l&rsquo;icône, suivante présente elle aussi dans la barre d&rsquo;outils : </p>
<p><img src="http://img41.imageshack.us/img41/2989/actualexecutionplan.png" alt="" /></p>
<p>Nous devons maintenant explorer le document XML à l&rsquo;origine du plan d&rsquo;exécution graphique, ce qui se fait par un simple clic droit dans une zone vierge de ce dernier :</p>
<p><img src="http://img546.imageshack.us/img546/1588/tf866601.png" alt="" /></p>
<p>Il nous suffit maintenant de chercher la chaîne de caractères <em>wszStatName</em>, et nous obtenons :</p>
<p><img src="http://img9.imageshack.us/img9/3892/tf866602.png" alt="" /></p>
<p>On voit clairement les détails de ce que SQL Server utilise comme métriques pour calculer le plan, notamment :</p>
<p>&#8211; le nom de la statistique (ici c&rsquo;est la statistiques sous-jacente à l&rsquo;index qui supporte la clé primaire)<br />
&#8211; le nom de la colonne la plus à gauche dans cette statistique (wszColName)<br />
&#8211; le nombre de lignes échantillonnées lors de la génération de la statique (m_ullSnapShotModCtr)<br />
&#8211; le nombre de lignes présentes dans la table (m_ullRowCount)<br />
&#8211; le seuil de recalcul automatique de la statistique (ullThreshold)</p>
<p>Pour cette dernière valeur, on peut d&rsquo;ailleurs faire le calcul suivant :</p>
<blockquote><p>100.0 * 24,763 / 121,317 = 20.41181367821492</p></blockquote>
<p>Soit environ 20%. Prenons la partie décimale de ce pourcentage : </p>
<blockquote><p>(0.41181367821492 / 100.0) * 121,317 = 499.5999999999945</p></blockquote>
<p>Soit environ 500 lignes. Ceci vérifie bien la règle du seuil de recalcul automatique des statistiques pour les tables de plus de 8MB : 500 lignes + 20% du nombre de lignes de la table.</p>
<p>Bons calculs de plans de requêtes et estimations de cardinalités !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reprendre le contrôle d&#8217;une instance SQL Server lorsqu&#8217;on a perdu le mot de passe de la connexion sa ou lorsque tous les DBAs en ont perdu l&#8217;accès</title>
		<link>https://blog.developpez.com/elsuket/p12007/moteur-de-base-de-donnees-sql-server/reprendre-le-controle-dune-instance-sql-server-lorsquon-a-perdu-le-mot-de-passe-de-la-connexion-sa-ou-lorsque-tous-les-dbas-en-ont-perdu-lacces</link>
		<comments>https://blog.developpez.com/elsuket/p12007/moteur-de-base-de-donnees-sql-server/reprendre-le-controle-dune-instance-sql-server-lorsquon-a-perdu-le-mot-de-passe-de-la-connexion-sa-ou-lorsque-tous-les-dbas-en-ont-perdu-lacces#comments</comments>
		<pubDate>Fri, 31 May 2013 00:36:28 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[Utilitaires]]></category>
		<category><![CDATA[instance]]></category>
		<category><![CDATA[mot de passe]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[sa]]></category>

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

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=511</guid>
		<description><![CDATA[Lorsqu&#8217;on tente d&#8217;ouvrir une connexion d&#8217;administrateur dédiée (DAC dans le jargon) à partir de l&#8217;explorateur d&#8217;objets de SQL Server Management Studio (SSMS), on obtient l&#8217;erreur suivante : Cependant si l&#8217;on se connecte à partir du menu Fichier &#62; Nouveau &#62; &#8230; <a href="https://blog.developpez.com/elsuket/p12003/moteur-de-base-de-donnees-sql-server/dedicated-administrator-connections-are-not-supported-via-ssms-as-it-establishes-multiple-connections-by-design-que-faire">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Lorsqu&rsquo;on tente d&rsquo;ouvrir une connexion d&rsquo;administrateur dédiée (DAC dans le jargon) à partir de l&rsquo;explorateur d&rsquo;objets de SQL Server Management Studio (SSMS), on obtient l&rsquo;erreur suivante :<br />
<span id="more-511"></span><br />
<img src="http://img843.imageshack.us/img843/6505/dac01.png" alt="" /></p>
<p>Cependant si l&rsquo;on se connecte à partir du menu <em>Fichier</em> &gt; <em>Nouveau</em> &gt; <em>Requête de moteur de base de données</em>, nous parvenons à nous connecter avec succès :</p>
<p><img src="http://img22.imageshack.us/img22/1714/dac02.png" alt="" /></p>
<p>L&rsquo;icône de la barre d&rsquo;outils permet de réaliser exactement la même chose :</p>
<p><img src="http://img585.imageshack.us/img585/7820/dac03.png" alt="" /></p>
<p>Cela tient au fait que lorsqu&rsquo;on ouvre une connexion avec l&rsquo;explorateur d&rsquo;objets, SSMS ouvre deux connexions :<br />
&#8211; une pour l&rsquo;explorateur d&rsquo;objets<br />
&#8211; une pour la fenêtre de requête</p>
<p>Or il n&rsquo;est possible d&rsquo;ouvrir qu&rsquo;une seule connexion DAC sur une instance SQL Server.</p>
<p>Petit rappel : une connexion DAC permet de se connecter en UDP sur le port 1434 (par défaut) à une instance SQL Server indisponible (surchage, &#8230;). Pour pouvoir se connecter de cette façon depuis une machine distincte de celle qui héberge l&rsquo;instance SQL Server, il est nécessaire d&rsquo;activer cette fonctionnalité par l&rsquo;option d&rsquo;instance &laquo;&nbsp;remote admin connections&nbsp;&raquo;. Ceci se fait simplement à l&rsquo;aide de la procédure stockée système <em>sp_configure</em> :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">sp_configure</span> <span style="color: #FF0000;">'remote admin connections'</span>, <span style="color: #000;">1</span><br />
GO<br />
<span style="color: #0000FF;">RECONFIGURE</span><br />
GO</div></td></tr></tbody></table></div>
<p>Pour savoir si la fonctionnalité est activée, il suffit d&rsquo;interroger la vue système <em>sys.configurations</em>, et de consulter la colonne <em>value_in_use</em> :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">configurations</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; name <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'%admin%'</span></div></td></tr></tbody></table></div>
<p><img src="http://img14.imageshack.us/img14/1389/dac04.png" alt="" /></p>
<p>Bonne administration à tous !</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vous êtes sûr d&#8217;avoir les BACKUP avec CHECKSUM parce que vous utilisez l&#8217;option COMPRESSION ? Vérifiez une seconde fois !</title>
		<link>https://blog.developpez.com/elsuket/p11990/snippets/backup_checksum_compression</link>
		<comments>https://blog.developpez.com/elsuket/p11990/snippets/backup_checksum_compression#comments</comments>
		<pubDate>Sun, 26 May 2013 13:32:34 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[BACKUP]]></category>
		<category><![CDATA[CHECKSUM]]></category>
		<category><![CDATA[COMPRESSION]]></category>
		<category><![CDATA[DBCC]]></category>
		<category><![CDATA[DBCC IND]]></category>
		<category><![CDATA[DBCC PAGE]]></category>
		<category><![CDATA[maintenance plan]]></category>
		<category><![CDATA[plan de maintenance]]></category>
		<category><![CDATA[sauvegarde]]></category>
		<category><![CDATA[sys.dm_db_database_page_allocations]]></category>
		<category><![CDATA[sys.messages]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=427</guid>
		<description><![CDATA[Après avoir vu comment compresser toutes les sauvegardes de base de données dès SQL Server 2008, il est intéressant de trouver comment activer l&#8217;option CHECKSUM de l&#8217;instruction BACKUP. A ce sujet, la documentation indique : Indique que l&#8217;opération de sauvegarde &#8230; <a href="https://blog.developpez.com/elsuket/p11990/snippets/backup_checksum_compression">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Après avoir vu comment <a href="http://blog.developpez.com/elsuket/p9040/moteur-de-base-de-donnees-sql-server/compresser_tous_les_backups_sans_modifie_2008">compresser toutes les sauvegardes de base de données</a> dès SQL Server 2008, il est intéressant de trouver comment activer l&rsquo;option CHECKSUM de l&rsquo;instruction BACKUP.</p>
<p>A ce sujet, la documentation indique :</p>
<blockquote><p> Indique que l&rsquo;opération de sauvegarde vérifie dans chaque page les informations de somme de contrôle et de page endommagée, si elles sont activées et disponibles, et génère une somme de contrôle pour l&rsquo;ensemble de la sauvegarde. <strong>Ceci est le comportement par défaut pour une sauvegarde compressée</strong>.</p></blockquote>
<p>Vérifions donc si cela est vrai : nous allons créer une base de données de test, et nous allons corrompre une de ses pages afin de vérifier le comportement de la sauvegarde. En effet, l&rsquo;option CHECKSUM permet de détecter la corruption de données au moment de la sauvegarde. Cela permet en plus de ne pas se retrouver dans l’inconfortable situation de devoir restaurer une base de données à partir d&rsquo;un fichier de sauvegarde corrompu.<br />
<span id="more-427"></span><br />
<img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>La vérification de l&rsquo;intégrité des pages au niveau de la base de données</strong></p>
<p>Par défaut, lorsqu&rsquo;on crée une nouvelle base de données sous SQL Server 2005 et suivants, la vérification de l&rsquo;intégrité des pages lues à partir du disque se fait à l&rsquo;aide d&rsquo;une somme de contrôle. Celle-ci est calculée à partir du contenu de la page, puis écrite dans l&rsquo;en-tête de celle-ci au moment de l&rsquo;écriture sur disque. Lorsque la page est ensuite lue à partir du disque, la somme de contrôle est recalculée, puis comparée à celle qui est dans l&rsquo;en-tête de la page : si les valeurs sont identiques, alors la page est intègre; à l&rsquo;inverse, on obtient l&rsquo;erreur 824, qui est écrite à la fois dans les journaux de SQL Server et dans le journal d&rsquo;événements de Windows.<br />
Enfin lorsqu&rsquo;on restaure une base de données qui a été créée sous une version antérieure à 2005, il est important de changer cette option de TORN_PAGE_DETECTION à PAGE_VERIFY, car la première est conservée par défaut. L&rsquo;option TORN_PAGE_DETECTION stocke deux bits pour chaque secteur de 512 octets de toute page, dont la taille est 8192 octets. De la même façon, ces 16 * 2 bits sont stockés dans l&rsquo;en-tête de la page, et comparés à la relecture de la page. Comme cette option est moins stricte que CHECKSUM, il est donc recommandé d&rsquo;utiliser cette dernière option.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Le test</strong></p>
<p>Nous créons donc la base de données sous SQL Server 2012, puis nous vérifions l&rsquo;option du contrôle de l&rsquo;intégrité des pages :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">DATABASE</span> TEST_CHECKSUM;<br />
GO<br />
<br />
<span style="color: #0000FF;">USE</span> TEST_CHECKSUM<br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; name<br />
&nbsp; &nbsp; &nbsp; &nbsp; , page_verify_option_desc<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">databases</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; name <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TEST_CHECKSUM'</span></div></td></tr></tbody></table></div>
<p><img src="http://img843.imageshack.us/img843/1872/backupchecksum01.png" alt="" /></p>
<p>Nous créons ensuite une table dans cette base de données, à laquelle nous ajoutons une ligne :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">USE</span> TEST_CHECKSUM<br />
GO<br />
<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> test_backup_checksum<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; id <span style="color: #0000FF;">tinyint</span> <span style="color: #0000FF;">IDENTITY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , nom <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">16</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">test_backup_checksum</span> <span style="color: #808080;">&#40;</span>nom<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'test_checksum'</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; dbo.<span style="color: #202020;">test_backup_checksum</span></div></td></tr></tbody></table></div>
<p>Nous forçons ensuite l&rsquo;écriture des pages sur disque, à l&rsquo;aide de l&rsquo;instruction <a href="http://blog.developpez.com/elsuket/p9529/moteur-de-base-de-donnees-sql-server/lazywriter_checkpoint_aamp_ghost_cleanup">CHECKPOINT</a>, puis nous vidons le cache de données, de sorte que la prochaine fois que nous exécuterons une requête sur cette table, ses pages seront lues à partir du disque, à l&rsquo;aide de l&rsquo;instruction DBCC DROPCLEANBUFFERS.</p>
<p><strong>N.B. : </strong>N&rsquo;exécutez <strong>JAMAIS</strong> une instruction non-documentée sur une base de données qui sert une charge de production. Si tel devait être le cas, je ne peux <strong>en aucun cas être tenu pour responsable des conséquences. Vous devez limiter strictement l&rsquo;usage de cette instruction aux environnements de test</strong>.</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CHECKPOINT</span><br />
GO<br />
<br />
<span style="color: #0000FF;">DBCC</span> DROPCLEANBUFFERS<br />
GO</div></td></tr></tbody></table></div>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>L&rsquo;instruction DBCC IND, ou la DMF sys.dm_db_database_page_allocations</strong></p>
<p>Encore deux options d&rsquo;exploration de la mécanique interne de SQL Server, qui permettent de lister les pages d&rsquo;une table ou d&rsquo;un index, et qui ne sont pas documentées. Voici le prototype d&rsquo;utilisation de ces deux alternatives :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DBCC</span> <span style="color: #808080;">IN</span>D <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'TEST_CHECKSUM'</span>, <span style="color: #FF0000;">'dbo.test_backup_checksum'</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #008080;">-- le dernier argument est l'index id</span><br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; allocated_page_file_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , allocated_page_page_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , allocated_page_iam_file_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , allocated_page_iam_page_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , index_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , partition_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , allocation_unit_type_desc <span style="color: #0000FF;">AS</span> iam_chain_type<br />
&nbsp; &nbsp; &nbsp; &nbsp; , page_type_desc<br />
&nbsp; &nbsp; &nbsp; &nbsp; , page_level<br />
&nbsp; &nbsp; &nbsp; &nbsp; , rowset_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , next_page_file_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , next_page_page_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , previous_page_file_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , previous_page_page_id<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">dm_db_database_page_allocations</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'TEST_CHECKSUM'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">OBJECT_ID</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'dbo.test_backup_checksum'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #000;">0</span> <span style="color: #008080;">-- index id : 0 pour un tas, 1 pour un index cluster, plus grand pour un index non-cluster</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">NULL</span> <span style="color: #008080;">-- partition id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF0000;">'DETAILED'</span> <span style="color: #008080;">-- niveau de détail</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; is_allocated <span style="color: #808080;">=</span> <span style="color: #000;">1</span>;</div></td></tr></tbody></table></div>
<p>On remarque tout de suite que la DMF produit bien plus d&rsquo;informations que l&rsquo;instruction DBCC (nous ne donnons pas ici toutes les colonnes), et que ses arguments sont similaires à la DMF <em>sys.dm_db_index_physical_stats</em>.</p>
<p><img src="http://img689.imageshack.us/img689/1618/backupchecksum02.png" alt="" /></p>
<p>Voyons donc ce que contient la page 272, puisque c&rsquo;est elle qui contient les données (page_type_desc = DATA_PAGE) :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">-- Activation de la sortie de la commande DBCC</span><br />
<span style="color: #0000FF;">DBCC</span> TRACEON <span style="color: #808080;">&#40;</span><span style="color: #000;">3604</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #008080;">-- DBCC PAGE ([database_name_or_id], [file_id], [page_id], [option])</span><br />
<span style="color: #008080;">-- option = 0 montre seulement l'en-tête de la page</span><br />
<span style="color: #0000FF;">DBCC</span> PAGE <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'TEST_CHECKSUM'</span>, <span style="color: #000;">1</span>, <span style="color: #000;">272</span>, <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>;<br />
GO</div></td></tr></tbody></table></div>
<p>Nous obtenons :</p>
<blockquote><p>PAGE: (1:272)</p>
<p>BUFFER:</p>
<p>BUF @0x000000027407BB80</p>
<p>bpage = 0x00000002649F4000          bhash = 0x0000000000000000          bpageno = (1:272)<br />
bdbid = 8                           breferences = 0                     bcputicks = 0<br />
bsampleCount = 0                    bUse1 = 33295                       bstat = 0x9<br />
blog = 0x2121215a                   bnext = 0x0000000000000000          </p>
<p>PAGE HEADER:</p>
<p>Page @0x00000002649F4000</p>
<p>m_pageId = (1:272)                  m_headerVersion = 1                 m_type = 1<br />
m_typeFlagBits = 0x0                m_level = 0                         <strong>m_flagBits = 0x8200</strong><br />
m_objId (AllocUnitId.idObj) = 84    m_indexId (AllocUnitId.idInd) = 256<br />
Metadata: AllocUnitId = 72057594043432960<br />
Metadata: PartitionId = 72057594039042048                                Metadata: IndexId = 0<br />
Metadata: ObjectId = 245575913      m_prevPage = (0:0)                  m_nextPage = (0:0)<br />
pminlen = 5                         m_slotCnt = 1                       m_freeCnt = 8069<br />
m_freeData = 121                    m_reservedCnt = 0                   m_lsn = (30:345:30)<br />
m_xactReserved = 0                  m_xdesId = (0:0)                    m_ghostRecCnt = 0<br />
<strong>m_tornBits = 1209479828</strong>             DB Frag ID = 1</p></blockquote>
<p>Si nous nous en référons à la <a href="http://www.sqlskills.com/blogs/paul/inside-the-storage-engine-anatomy-of-a-page/">documentation donnée par Paul Randal</a>, nous avons bien :</p>
<p>&#8211; <em>m_flagBits = 0x8200</em>, qui indique que l&rsquo;intégrité de la page est vérifiée par somme de contrôle<br />
&#8211; <em>m_tornBits</em> est la somme de contrôle de cette page</p>
<p>Nous allons maintenant mettre la base de données hors-ligne, puis éditer le fichier de données avec un éditeur hexadécimal, de façon à vérifier si SQL Server vérifie bien la somme à la lecture de la page :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">DATABASE</span> <span style="color: #0000FF;">SET</span> OFFL<span style="color: #808080;">IN</span>E<br />
GO</div></td></tr></tbody></table></div>
<p>En ce qui concerne la lecture en hexadécimal, j&rsquo;utilise le logiciel <a href="http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm">Hex Editor XVI32</a>. Une fois l&rsquo;outil ouvert en tant qu&rsquo;administrateur, il suffit de chercher la chaîne que nous avons ajouté comme ligne dans la table, en suivant le menu <em>Search</em> / <em>Find</em> :</p>
<p><img src="http://img850.imageshack.us/img850/1565/backupchecksum03.png" alt="" /></p>
<p>Un clic sur le bouton OK nous amène directement à l&rsquo;emplacement, où l&rsquo;on est alors libre de changer la chaîne, où j&rsquo;ai changé le &laquo;&nbsp;k&nbsp;&raquo; en &laquo;&nbsp;d&nbsp;&raquo;, puis sauvé le fichier :</p>
<p><img src="http://img833.imageshack.us/img833/341/backupchecksum04.png" alt="" /></p>
<p>Nous remettons la base de données en ligne :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">DATABASE</span> TEST_CHECKSUM<br />
<span style="color: #0000FF;">SET</span> ONL<span style="color: #808080;">IN</span>E<br />
GO</div></td></tr></tbody></table></div>
<p>Aucun problème. Exécutons un SELECT * FROM dbo.test_backup_checksum. Nous obtenons le message suivant :</p>
<blockquote><p>
Msg 824, Level 24, State 2, Line 1<br />
SQL Server detected a logical consistency-based I/O error: incorrect checksum (expected: 0xf9ec3284; actual: 0xfe6c3284). It occurred during a read of page (1:228) in database ID 7 at offset 0x000000001c8000 in file &lsquo;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TEST_CHECKSUM.mdf&rsquo;.  Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.</p></blockquote>
<p>Prenons maintenant une sauvegarde de cette base de données, avec COMPRESSION, mais sans spécifier l&rsquo;option CHECKSUM :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">BACKUP</span> <span style="color: #0000FF;">DATABASE</span> TEST_CHECKSUM<br />
<span style="color: #0000FF;">TO</span> <span style="color: #0000FF;">DISK</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'F:\SQLServer2012\TEST_CHECKSUM.bak'</span><br />
<span style="color: #0000FF;">WITH</span> COMPRESSION<br />
GO</div></td></tr></tbody></table></div>
<p>Aucun problème : nous obtenons :</p>
<blockquote><p>Processed 280 pages for database &lsquo;TEST_CHECKSUM&rsquo;, file &lsquo;TEST_CHECKSUM&rsquo; on file 1.<br />
Processed 3 pages for database &lsquo;TEST_CHECKSUM&rsquo;, file &lsquo;TEST_CHECKSUM_log&rsquo; on file 1.<br />
BACKUP DATABASE successfully processed 283 pages in 0.468 seconds (4.709 MB/sec).</p></blockquote>
<p>Voyons ce que contient la table d&rsquo;historique des sauvegardes :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF00FF;">user_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , backup_start_date<br />
&nbsp; &nbsp; &nbsp; &nbsp; , recovery_model<br />
&nbsp; &nbsp; &nbsp; &nbsp; , has_backup_checksums<br />
&nbsp; &nbsp; &nbsp; &nbsp; , is_damaged<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; msdb.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">backupset</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; database_name <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TEST_CHECKSUM'</span></div></td></tr></tbody></table></div>
<p><img src="http://img195.imageshack.us/img195/6295/backupchecksum05.png" alt="" /></p>
<p>On obtient un résultat similaire avec l&rsquo;instruction RESTORE HEADERONLY (colonnes <em>HasBackupChecksums</em> et <em>IsDamaged</em> toutes deux à zéro) :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">RESTORE</span> HEADERONLY<br />
<span style="color: #0000FF;">FROM</span> <span style="color: #0000FF;">DISK</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'F:\SQLServer2012\TEST_CHECKSUM.bak'</span></div></td></tr></tbody></table></div>
<p>Le fichier de sauvegarde ne dispose pas de la somme de contrôle, et n&rsquo;est pas marqué comme endommagé. Pourtant nous avons bien corrompu le fichier de données, et nous ne pouvons pas lire la table que nous avons peuplé auparavant !</p>
<p>Voyons ce que produit la même instruction, avec l&rsquo;option CHECKSUM :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">BACKUP</span> <span style="color: #0000FF;">DATABASE</span> TEST_CHECKSUM<br />
<span style="color: #0000FF;">TO</span> <span style="color: #0000FF;">DISK</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'F:\SQLServer2012\TEST_CHECKSUM_CC.bak'</span><br />
<span style="color: #0000FF;">WITH</span> COMPRESSION, <span style="color: #FF00FF;">CHECKSUM</span><br />
GO</div></td></tr></tbody></table></div>
<blockquote><p>Msg 3043, Level 16, State 1, Line 1<br />
BACKUP &lsquo;TEST_CHECKSUM&rsquo; detected an error on page (1:228) in file &lsquo;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TEST_CHECKSUM.mdf&rsquo;.<br />
Msg 3013, Level 16, State 1, Line 1<br />
BACKUP DATABASE is terminating abnormally.</p></blockquote>
<p>Voyons maintenant la même instruction, seulement avec l&rsquo;option CHECKSUM :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">BACKUP</span> <span style="color: #0000FF;">DATABASE</span> TEST_CHECKSUM<br />
<span style="color: #0000FF;">TO</span> <span style="color: #0000FF;">DISK</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'F:\SQLServer2012\TEST_CHECKSUM_CHK.bak'</span><br />
<span style="color: #0000FF;">WITH</span> <span style="color: #FF00FF;">CHECKSUM</span><br />
GO</div></td></tr></tbody></table></div>
<p>Nous obtenons la même erreur. Si nous interrogeons de nouveau la table d&rsquo;historique des sauvegardes pour cette base de données, nous ne trouvons que le premier backup, dont on sait qu&rsquo;il est corrompu. Pourtant nous n&rsquo;avons (presque) aucun moyen de le savoir, car ni cette table, ni l&rsquo;instruction RESTORE HEADERONLY ne permettent de vérifier que le fichier est bien intègre. On peut cependant vérifier les journaux de SQL Server à l&rsquo;aide de la procédure stockée étendue <a href="http://blog.developpez.com/elsuket/p10279/moteur-de-base-de-donnees-sql-server/gestion_lecture_journaux_sql_server"><em>xp_readerrorlog</em></a>, où l&rsquo;on trouve :</p>
<p><img src="http://img17.imageshack.us/img17/9685/backupchecksum06.png" alt="" /></p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Détecter la corruption le plus tôt possible</strong></p>
<p>Une des premières choses à faire après avoir réalisé une installation fraîche de SQL Server est d&rsquo;ajouter une liste d&rsquo;alertes de l&rsquo;Agent SQL Server, qui enverront un mail dès la détection d&rsquo;un problème de corruption. Ceci nécessite le paramétrage de Database Mail, et la mise en place d&rsquo;un opérateur SQL Agent. Voici le code qui permet d&rsquo;ajouter l&rsquo;alerte :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">-------------------------------</span><br />
<span style="color: #008080;">-- Nicolas Souquet - 26/05/2013</span><br />
<span style="color: #008080;">-------------------------------</span><br />
<span style="color: #0000FF;">DECLARE</span> @i <span style="color: #0000FF;">smallint</span> <span style="color: #808080;">=</span> <span style="color: #000;">823</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @alert_name sysname<br />
<br />
<span style="color: #0000FF;">DECLARE</span> @operator_name sysname <span style="color: #808080;">=</span> <span style="color: #FF0000;">'monOperateur'</span><br />
<br />
<span style="color: #0000FF;">WHILE</span> @i <span style="color: #808080;">&amp;</span>lt;<span style="color: #808080;">=</span> <span style="color: #000;">825</span><br />
<span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; @alert_name <span style="color: #808080;">=</span> <span style="color: #808080;">&amp;</span>#039;Message <span style="color: #808080;">&amp;</span>#039; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>@i <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span> msdb.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_add_alert</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @name <span style="color: #808080;">=</span> @alert_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @message_id <span style="color: #808080;">=</span> @i<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @severity <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @enabled <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @delay_between_responses <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @include_event_description_in <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @job_id <span style="color: #808080;">=</span> N<span style="color: #808080;">&amp;</span>#039;00000000<span style="color: #808080;">-</span>0000<span style="color: #808080;">-</span>0000<span style="color: #808080;">-</span>0000<span style="color: #808080;">-</span>000000000000<span style="color: #808080;">&amp;</span>#039;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span> msdb.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_add_notification</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @alert_name <span style="color: #808080;">=</span> @alert_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @operator_name <span style="color: #808080;">=</span> @operator_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @notification_method <span style="color: #808080;">=</span> <span style="color: #000;">1</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @i <span style="color: #808080;">=</span> @i <span style="color: #808080;">+</span> <span style="color: #000;">1</span><br />
<span style="color: #0000FF;">END</span></div></td></tr></tbody></table></div>
<p>L&rsquo;erreur qui nous intéresse est la 824, mais les erreurs 823 et 825 sont importantes aussi. Pour trouver leur signification, il suffit d&rsquo;interroger la vue système <em>sys.messages</em> :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">messages</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; message_id <span style="color: #808080;">BETWEEN</span> <span style="color: #000;">823</span> <span style="color: #808080;">AND</span> <span style="color: #000;">825</span><br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; language_id <span style="color: #808080;">=</span> <span style="color: #000;">1036</span> <span style="color: #008080;">-- Français</span></div></td></tr></tbody></table></div>
<p>On peut faire de même avec l&rsquo;erreur n° 3043, qui est celle que l&rsquo;on obtient lors de la sauvegarde.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Activer CHECKSUM pour toutes les sauvegardes</strong></p>
<p>Cela devrait aussi faire partie de la checklist d&rsquo;installation de SQL Server, d&rsquo;autant que c&rsquo;est d&rsquo;une simplicité enfantine : il suffit d&rsquo;activer le drapeau de trace n° 3023 :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DBCC</span> TRACEON <span style="color: #808080;">&#40;</span><span style="color: #000;">3023</span>, <span style="color: #808080;">-</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>Après avoir exécuté cette instruction, si nous ré-exécutons maintenant la commande suivante :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">BACKUP</span> <span style="color: #0000FF;">DATABASE</span> TEST_CHECKSUM<br />
<span style="color: #0000FF;">TO</span> <span style="color: #0000FF;">DISK</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'F:\SQLServer2012\TEST_CHECKSUM.bak'</span><br />
<span style="color: #0000FF;">WITH</span> COMPRESSION<br />
GO</div></td></tr></tbody></table></div>
<p>Nous obtenons l&rsquo;erreur que nous avions obtenue lorsque nous avions ajouté l&rsquo;option CHECKSUM :</p>
<blockquote><p>Msg 3043, Level 16, State 1, Line 1<br />
BACKUP &lsquo;TEST_CHECKSUM&rsquo; detected an error on page (1:228) in file &lsquo;C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TEST_CHECKSUM.mdf&rsquo;.<br />
Msg 3013, Level 16, State 1, Line 1<br />
BACKUP DATABASE is terminating abnormally.</p></blockquote>
<p>Ceci est très pratique :</p>
<p>&#8211; Si l&rsquo;on prend les sauvegardes de base de données à l&rsquo;aide de <a href="http://blog.developpez.com/elsuket/p11161/agent-sql-server/supporter_plan_de_maintenance">plans de maintenance</a>, il est impossible de spécifier que l&rsquo;on souhaite avoir la somme de contrôle;<br />
&#8211; Si l&rsquo;on code une procédure stockée qui s&rsquo;en charge, cela évite d&rsquo;avoir à l&rsquo;ajouter dans le code.</p>
<p>D&rsquo;autre part si la <a href="http://blog.developpez.com/elsuket/p9040/moteur-de-base-de-donnees-sql-server/compresser_tous_les_backups_sans_modifie_2008">compression des sauvegardes est activée au niveau de l&rsquo;instance</a>, on n&rsquo;a plus qu&rsquo;a se soucier de la sauvegarde elle-même !</p>
<p>Bonnes sauvegardes et intégrité de pages à tous !</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>La clause VALUES n&#8217;est-elle réservée qu&#8217;à l&#8217;ordre INSERT ?</title>
		<link>https://blog.developpez.com/elsuket/p11988/t-sql/la-clause-values-nest-elle-reservee-qua-lordre-insert</link>
		<comments>https://blog.developpez.com/elsuket/p11988/t-sql/la-clause-values-nest-elle-reservee-qua-lordre-insert#comments</comments>
		<pubDate>Sat, 25 May 2013 12:21:25 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[DELETE]]></category>
		<category><![CDATA[INSERT]]></category>
		<category><![CDATA[MAX]]></category>
		<category><![CDATA[MERGE]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[UPDATE]]></category>
		<category><![CDATA[VALUES]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=376</guid>
		<description><![CDATA[Si je pose la question, c&#8217;est que la réponse est &#8230; non, et ce depuis SQL Server 2008 ! En effet l&#8217;utilisation la plus commune de la clause VALUES se fait lors de la définition d&#8217;un ordre INSERT, et permettait &#8230; <a href="https://blog.developpez.com/elsuket/p11988/t-sql/la-clause-values-nest-elle-reservee-qua-lordre-insert">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Si je pose la question, c&rsquo;est que la réponse est &#8230; non, et ce depuis SQL Server 2008 !</p>
<p>En effet l&rsquo;utilisation la plus commune de la clause VALUES se fait lors de la définition d&rsquo;un ordre INSERT, et permettait jusqu&rsquo;à SQL Server 2005 inclus d&rsquo;insérer seulement une ligne dans une table.</p>
<p>Cela a changé lors de la sortie de SQL Server 2008, qui permet de réaliser un INSERT d&rsquo;au plus 1000 lignes dont les valeurs sont codées &laquo;&nbsp;en dur&nbsp;&raquo; dans un script. Voyons les autres utilisations possible de cette clause &#8230;<br />
<span id="more-376"></span></p>
<p>En fait, cette clause est utilisable pour toute instruction DML, pour peu qu&rsquo;on la précise dans la clause FROM d&rsquo;une instruction SELECT, INSERT, UPDATE ou DELETE, et dans la clause USING de l&rsquo;instruction MERGE.</p>
<p>Voici quelques exemples simples d&rsquo;utilisation, qui éveilleront votre imagination dès que vous retournerez à vos claviers.<br />
Commençons par appréhender la clause avec une requête triviale :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">-</span><span style="color: #000;">15</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">2</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> V<span style="color: #808080;">&#40;</span>i<span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>Ce qui nous retourne le résultat suivant :</p>
<p><img src="http://img835.imageshack.us/img835/6108/values01.png" alt="" /></p>
<p>Si nous regardons le plan d&rsquo;exécution à l&rsquo;aide de <a href="http://blog.developpez.com/elsuket/p10724/utilitaires/sql_sentry_plan_explorer">SQL Sentry Plan Explorer</a>, on voit que l&rsquo;estimation de cardinalité se fait proprement :</p>
<p><img src="http://img51.imageshack.us/img51/5177/values02.png" alt="" /></p>
<p>Ceci évite d&rsquo;écrire une requête avec de nombreux UNION ALL, comme suit :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">-</span><span style="color: #000;">15</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span> <span style="color: #0000FF;">SELECT</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span> <span style="color: #0000FF;">SELECT</span> <span style="color: #000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span> <span style="color: #0000FF;">SELECT</span> <span style="color: #000;">2</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span> <span style="color: #0000FF;">SELECT</span> <span style="color: #000;">3</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> V<span style="color: #808080;">&#40;</span>i<span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>Même si l&rsquo;estimation de cardinalité se fait de la même manière.</p>
<p>On peut donc spécifier un INSERT de plusieurs lignes à l&rsquo;aide de la clause VALUES :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DECLARE</span> @pays_capitale <span style="color: #0000FF;">TABLE</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pays <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">15</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , capitale <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">32</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
<span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">INSERT</span>&nbsp; <span style="color: #0000FF;">INTO</span> @pays_capitale<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pays<br />
&nbsp; &nbsp; &nbsp; &nbsp; , capitale<br />
<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">VALUES</span>&nbsp; <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'France'</span>, <span style="color: #FF0000;">'Paris'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Thaïlande'</span>, <span style="color: #FF0000;">'Bangkok'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Bouthan'</span>, <span style="color: #FF0000;">'Thimphou'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Vanuatu'</span>, <span style="color: #FF0000;">'Port-Vila'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Singapour'</span>, <span style="color: #FF0000;">'Singapour'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Viêt Nam'</span>, <span style="color: #FF0000;">'Hanoï'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Cambodge'</span>, <span style="color: #FF0000;">'Phnom Penh'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Laos'</span>, <span style="color: #FF0000;">'Vientiane'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Malaisie'</span>, <span style="color: #FF0000;">'Kuala Lumpur'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Brunei'</span>, <span style="color: #FF0000;">'Bandar Seri Begawan'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Philippines'</span>, <span style="color: #FF0000;">'Manille'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Indonésie'</span>, <span style="color: #FF0000;">'Jakarta'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Birmanie'</span>, <span style="color: #FF0000;">'Naypyidaw'</span><span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; @pays_capitale</div></td></tr></tbody></table></div>
<p>Nous obtenons le résultat suivant :</p>
<p><img src="http://img713.imageshack.us/img713/5703/values03.png" alt="" /></p>
<p>La démonstration des exemples suivants, nous utilisons le jeu de données défini par le lot de requêtes ci-dessous :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> capteur<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; capteur_id <span style="color: #0000FF;">tinyint</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">IDENTITY</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">0</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> PK_capteur <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , capteur_nom <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">15</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> UQ_capteur <span style="color: #0000FF;">UNIQUE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , capteur_date_ajout <span style="color: #0000FF;">datetime</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">CONSTRAINT</span> DF_capteur__capteur_date_ajout <span style="color: #0000FF;">DEFAULT</span> <span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> mesure<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mesure_id <span style="color: #0000FF;">int</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">-</span><span style="color: #000;">2147483648</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> PK_mesure <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , capteur_id <span style="color: #0000FF;">tinyint</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> FK_mesure__capteur_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOREIGN</span> <span style="color: #0000FF;">KEY</span> <span style="color: #808080;">&#40;</span>capteur_id<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">REFERENCES</span> dbo.<span style="color: #202020;">capteur</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , mesure_date_time <span style="color: #0000FF;">datetime</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> DF_mesure_mesure_date_time <span style="color: #0000FF;">DEFAULT</span> <span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , valeur <span style="color: #0000FF;">tinyint</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">capteur</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; capteur_nom<br />
<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Capteur 1'</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Capteur 2'</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Capteur 3'</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">mesure</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; capteur_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , valeur<br />
<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF00FF;">ABS</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">CHECKSUM</span><span style="color: #808080;">&#40;</span>NEWID<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">%</span> <span style="color: #000;">3</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">ABS</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">CHECKSUM</span><span style="color: #808080;">&#40;</span>NEWID<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">%</span> <span style="color: #000;">256</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; master.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">spt_values</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; type <span style="color: #808080;">=</span> <span style="color: #FF0000;">'P'</span><br />
GO <span style="color: #000;">50</span></div></td></tr></tbody></table></div>
<p>La vue master.dbo.spt_values retourne 2048 lignes qui ont pour type &laquo;&nbsp;P&nbsp;&raquo; : la table <em>dbo.mesure</em> contient donc 2048 * 50 = 102.400 lignes.</p>
<p>Étant donné que la clause se comporte de la même façon qu&rsquo;une table dérivée, on peut tout à fait l&rsquo;utiliser pour réaliser une jointure.<br />
Essayons de classer les mesures par fourchettes :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BUCKET.<span style="color: #202020;">low_bound</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , BUCKET.<span style="color: #202020;">high_bound</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> occurences<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">mesure</span> <span style="color: #0000FF;">AS</span> M<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">0</span>, <span style="color: #000;">5</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>, <span style="color: #000;">10</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">10</span>, <span style="color: #000;">15</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">15</span>, <span style="color: #000;">20</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">20</span>, <span style="color: #000;">30</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #000;">30</span>, <span style="color: #000;">40</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">40</span>, <span style="color: #000;">50</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">50</span>, <span style="color: #000;">100</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">100</span>, <span style="color: #000;">200</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #000;">200</span>, <span style="color: #000;">1000</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> BUCKET<span style="color: #808080;">&#40;</span>low_bound, high_bound<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> M.<span style="color: #202020;">valeur</span> <span style="color: #808080;">&amp;</span>gt;<span style="color: #808080;">=</span> BUCKET.<span style="color: #202020;">low_bound</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> M.<span style="color: #202020;">valeur</span> <span style="color: #808080;">&amp;</span>lt; BUCKET.<span style="color: #202020;">high_bound</span><br />
<span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span>&nbsp; &nbsp; &nbsp; &nbsp; BUCKET.<span style="color: #202020;">low_bound</span>, BUCKET.<span style="color: #202020;">high_bound</span><br />
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span>&nbsp; &nbsp; &nbsp; &nbsp; BUCKET.<span style="color: #202020;">low_bound</span>, BUCKET.<span style="color: #202020;">high_bound</span></div></td></tr></tbody></table></div>
<p>Ce qui nous retourne :</p>
<p><img src="http://img845.imageshack.us/img845/7702/values04.png" alt="" /></p>
<p>Voyons le cas d&rsquo;un UPDATE :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; BUCKET <span style="color: #808080;">&#40;</span>low_bound, high_bound<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">0</span>, <span style="color: #000;">5</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>, <span style="color: #000;">10</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #000;">10</span>, <span style="color: #000;">15</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">15</span>, <span style="color: #000;">20</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">20</span>, <span style="color: #000;">30</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> V<span style="color: #808080;">&#40;</span>low_bound, high_bound<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">UPDATE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">mesure</span><br />
<span style="color: #0000FF;">SET</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valeur <span style="color: #808080;">*=</span> <span style="color: #000;">2</span> <span style="color: #008080;">-- multiplie par deux la valeur mesurée</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">mesure</span> <span style="color: #0000FF;">AS</span> M<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; BUCKET <span style="color: #0000FF;">AS</span> B<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> B.<span style="color: #202020;">low_bound</span> &nbsp;M.<span style="color: #202020;">valeur</span></div></td></tr></tbody></table></div>
<p>Notez que rien ici n&rsquo;oblige à la construction d&rsquo;une expression de table commune : on peut tout à fait spécifier le constructeur de valeurs de table dans la clause INNER JOIN, comme nous l&rsquo;avons fait avec la requête précédente.</p>
<p>Si nous ré-exécutons la requête de classement par fourchettes, nous obtenons maintenant :</p>
<p><img src="http://img69.imageshack.us/img69/5861/values05.png" alt="" /></p>
<p>l&rsquo;instruction DELETE se décrit de manière similaire :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DELETE</span> <span style="color: #0000FF;">FROM</span> &nbsp; &nbsp; dbo.<span style="color: #202020;">mesure</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">mesure</span> <span style="color: #0000FF;">AS</span> M<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">VALUES</span> &nbsp;<span style="color: #808080;">&#40;</span><span style="color: #000;">30</span>, <span style="color: #000;">40</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">40</span>, <span style="color: #000;">50</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">50</span>, <span style="color: #000;">100</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #000;">100</span>, <span style="color: #000;">200</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #000;">200</span>, <span style="color: #000;">1000</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> BUCKET <span style="color: #808080;">&#40;</span>low_bound, high_bound<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> M.<span style="color: #202020;">valeur</span> <span style="color: #808080;">&amp;</span>gt;<span style="color: #808080;">=</span> BUCKET.<span style="color: #202020;">low_bound</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> M.<span style="color: #202020;">valeur</span> <span style="color: #808080;">&amp;</span>lt; BUCKET.<span style="color: #202020;">high_bound</span></div></td></tr></tbody></table></div>
<p>Après ré-exécution de la requête de distribution des valeurs par plages, on voit que la table des mesures contient maintenant :</p>
<p><img src="http://img90.imageshack.us/img90/1578/values06.png" alt="" /></p>
<p>Terminons par l&rsquo;ordre MERGE, avec lequel nous allons ajouter des capteurs, ou marquer ceux qui existent déjà à la date courante :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MERGE &nbsp; dbo.<span style="color: #202020;">capteur</span> <span style="color: #0000FF;">AS</span> TGT<br />
<span style="color: #0000FF;">USING</span> &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Capteur 1'</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Capteur 2'</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Capteur 3'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Capteur 4'</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Capteur 5'</span><span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Capteur 6'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> SRC <span style="color: #808080;">&#40;</span>capteur_nom<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> TGT.<span style="color: #202020;">capteur_nom</span> <span style="color: #808080;">=</span> SRC.<span style="color: #202020;">capteur_nom</span><br />
<span style="color: #0000FF;">WHEN</span>&nbsp; &nbsp; MATCHED <span style="color: #0000FF;">THEN</span> <span style="color: #0000FF;">UPDATE</span> <span style="color: #0000FF;">SET</span> capteur_date_ajout <span style="color: #808080;">=</span> <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">WHEN</span>&nbsp; &nbsp; <span style="color: #808080;">NOT</span> MATCHED <span style="color: #0000FF;">THEN</span> <span style="color: #0000FF;">INSERT</span> <span style="color: #808080;">&#40;</span>capteur_nom<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span>SRC.<span style="color: #202020;">capteur_nom</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">OUTPUT</span>&nbsp; $ACTION, DELETED.<span style="color: #202020;">capteur_nom</span>, <span style="color: #808080;">IN</span>SERTED.<span style="color: #202020;">capteur_nom</span>;<br />
<br />
<span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; dbo.<span style="color: #202020;">capteur</span></div></td></tr></tbody></table></div>
<p><img src="http://img855.imageshack.us/img855/6277/values07.png" alt="" /></p>
<p>On voit bien les capteurs 4, 5 et 6 ajoutés, et les capteurs 1, 2 et 3, dont les lignes existaient déjà, modifiés. Tous les capteurs portent la même date d&rsquo;ajout, transaction oblige.</p>
<p>Enfin on peut calculer le maximum d&rsquo;un tuple de valeurs sans avoir à écrire une fonction pour ce faire. Soit la variable de type TABLE suivante :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DECLARE</span> @series <span style="color: #0000FF;">TABLE</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; id <span style="color: #0000FF;">tinyint</span> <span style="color: #0000FF;">identity</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , a <span style="color: #0000FF;">tinyint</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , b <span style="color: #0000FF;">tinyint</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , c <span style="color: #0000FF;">tinyint</span><br />
<span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">INSERT</span>&nbsp; <span style="color: #0000FF;">INTO</span> @series<br />
<span style="color: #0000FF;">VALUES</span>&nbsp; <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #000;">2</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #000;">4</span>, <span style="color: #000;">5</span>, <span style="color: #000;">6</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #000;">7</span>, <span style="color: #000;">8</span>, <span style="color: #000;">9</span><span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>Nous souhaitons obtenir la plus grande valeur des trois colonnes a, b et c, pour chaque ligne. On peut exprimer ce besoin comme suit :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; id<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#40;</span>n<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span>a<span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span>b<span style="color: #808080;">&#41;</span>, <span style="color: #808080;">&#40;</span>c<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> V<span style="color: #808080;">&#40;</span>n<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; @series</div></td></tr></tbody></table></div>
<p>Ce qui amène le résultat suivant :</p>
<p><img src="http://img15.imageshack.us/img15/2505/values08.png" alt="" /></p>
<p>Amusez-vous avec VALUES !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Devart : SQL Complete et sql-format.com</title>
		<link>https://blog.developpez.com/elsuket/p11981/utilitaires/devart</link>
		<comments>https://blog.developpez.com/elsuket/p11981/utilitaires/devart#comments</comments>
		<pubDate>Sat, 18 May 2013 04:50:55 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=362</guid>
		<description><![CDATA[Si l&#8217;on est un peu perdu dans les privilèges que l&#8217;on peut octroyer à des utilisateurs ou des connexions (logins), ou que l&#8217;on souhaite tout simplement explorer les possibilités offertes par les entités de sécurité, on peut télécharger des posters &#8230; <a href="https://blog.developpez.com/elsuket/p11954/securite/les-posters-des-permissions-pour-sql-server-2008-r2-2012-et-azure">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Si l&rsquo;on est un peu perdu dans les privilèges que l&rsquo;on peut octroyer à des utilisateurs ou des connexions (logins), ou que l&rsquo;on souhaite tout simplement explorer les possibilités offertes par les entités de sécurité, on peut <a href="http://social.technet.microsoft.com/wiki/contents/articles/11842.sql-server-database-engine-permission-posters.aspx">télécharger</a> des posters qui les présentent sous forme de groupes : serveur, base de données, ou pour chaque fonctionnalité du moteur de base de données.</p>
<p>Bon octroi de privilèges !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mise au point à propos du compteur de performance Page Life Expectancy</title>
		<link>https://blog.developpez.com/elsuket/p11951/moteur-de-base-de-donnees-sql-server/mise-au-point-a-propos-du-compteur-de-performance-page-life-expectancy</link>
		<comments>https://blog.developpez.com/elsuket/p11951/moteur-de-base-de-donnees-sql-server/mise-au-point-a-propos-du-compteur-de-performance-page-life-expectancy#comments</comments>
		<pubDate>Mon, 06 May 2013 12:17:05 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=279</guid>
		<description><![CDATA[Parmi les compteurs de performance qu&#8217;expose SQL Server, il en existe quelques-uns qui ne laissent aucun doute sur les performances courantes d&#8217;une instance SQL Server. Page Life Expectancy est l&#8217;un d&#8217;entre eux, puisqu&#8217;il nous renseigne sur la durée de vie &#8230; <a href="https://blog.developpez.com/elsuket/p11951/moteur-de-base-de-donnees-sql-server/mise-au-point-a-propos-du-compteur-de-performance-page-life-expectancy">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Parmi les compteurs de performance qu&rsquo;expose SQL Server, il en existe quelques-uns qui ne laissent aucun doute sur les performances courantes d&rsquo;une instance SQL Server. <em>Page Life Expectancy</em> est l&rsquo;un d&rsquo;entre eux, puisqu&rsquo;il nous renseigne sur la durée de vie moyenne d&rsquo;une page de données en RAM, en secondes.</p>
<p>L&rsquo;ensemble des opérations de manipulation de données se faisant exclusivement en mémoire par tout SGBDR digne de ce nom, on comprend aisément que plus la valeur exposée par ce compteur est élevée, plus les performances de l&rsquo;instance sont correctes. En effet, comme un accès en RAM est en pratique au moins 1000 fois plus rapide qu&rsquo;un accès à des disques mécaniques, plus on peut traiter de données en RAM, moins on est exposé à des problèmes de performances.</p>
<p>Cela étant, les serveurs physiques actuels disposant de plusieurs sockets pour accueillir leurs CPUs, ils sont tous une implémentation de NUMA (<em>Non-Uniform Memory Access</em>), dans lequel chaque processeur dispose d&rsquo;un bus mémoire dédié. On appelle nœud NUMA l&rsquo;ensemble composé par l&rsquo;espace mémoire et le processeur situés sur le même bus. On désigne par nœud NUMA distant un nœud NUMA distinct de celui sur lequel la requête s&rsquo;exécute. </p>
<p>Si par le passé on pouvait donc se référer directement à la valeur de ce compteur, puisque les serveur ne disposaient que d&rsquo;un seul socket, qu&rsquo;en est-il avec les architectures multi-socket ? Comment suivre cette valeur sous SQL Server ? Quelle valeur de ce compteur peut servir de seuil d&rsquo;alerte ?</p>
<p>Je vous propose la réponse à ces questions dans cet article !<br />
<span id="more-279"></span></p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Page Life Expectancy (PLE), qu&rsquo;est-ce que c&rsquo;est ?</strong></p>
<p>Comme nous l&rsquo;avons vu en introduction, ce compteur de performance nous indique, en secondes, la durée moyenne pendant laquelle une page reste stockée dans en RAM : c&rsquo;est ce que l&rsquo;on appelle plus communément le <em>buffer pool</em>.</p>
<p>Comme les opérations de lecture et d&rsquo;écriture se font exclusivement en RAM, plus une page de données reste longtemps dans le buffer pool, plus l&rsquo;instance SQL Server étudiée fonctionne proprement.</p>
<p>Au contraire, si la valeur de ce compteur est faible <strong>de façon constante</strong>, cela signifie que SQL Server est constamment obligé d&rsquo;importer les pages stockées sur disque en RAM, avant de réaliser l&rsquo;opération qu&rsquo;on lui a soumis. Cela signifie généralement que la majeure partie de la charge de travail que l&rsquo;on soumet à SQL Server lit une quantité de données qui excède celle de la RAM disponible sur le serveur, ce qui peut par exemple être du tout simplement à une configuration incorrecte de l&rsquo;option d&rsquo;instance <em>max server memory (MB)</em>, à une indexation pauvre, à un plan d&rsquo;exécution sous-optimal, &#8230;<br />
Il est à noter que si l&rsquo;on observe des valeurs faibles de façon sporadique, pour une durée de quelques secondes, cela est plus proche de signifier qu&rsquo;une requête produit un grand nombre d&rsquo;entrées/sorties. Une trace <a href="http://elsuket.developpez.com/tutoriels/sqlserveur/fichier-trace-cote-serveur/"><em>SQL Profiler</em></a> combinée à un fichier du <em>Moniteur de Performances</em> permettra de déterminer la requête coupable (dans SQL Profiler, choisir File &gt; Import Performance Data pour corréler un fichier .blg avec un fichier de trace).</p>
<p>Une valeur élevée pour PLE n&rsquo;équivaut pas à une pastille verte quand à l&rsquo;état des performances de l&rsquo;instance SQL Server auditée. Il est nécessaire de corréler la valeur de ce compteur avec celle du compteur <em>Buffer Cache Hit Ratio</em> (BCHR): ce dernier exprime par un pourcentage la proportion de pages trouvées directement en RAM par rapport au nombre de pages importées à partir des disques. Ici encore, on saisit facilement que plus on est proche de 100%, plus les performances sont optimales. PLE peut avoir une valeur décente et BCHR être faible : cela signifie que les disques sont largement sollicités par la charge de travail, et qu&rsquo;ils parviennent à fournir les pages de données suffisamment rapidement à SQL Server pour qu&rsquo;il puisse opérer sans que l&rsquo;on note une véritable dégradation des performances. Dans ce cas, un audit des requêtes grandes consommatrices d&rsquo;I/O et une optimisation sont nécessaires. Je vous invite à un <a href="http://blog.developpez.com/mikedavem/?s=+Lock+Pages+In+Memory">approfondissement</a> sur le blog de Mikedavem.</p>
<p>Finalement, lorsque l&rsquo;un ou l&rsquo;autre de ces compteurs montre une valeur faible, nous sommes en présence d&rsquo;une charge de travail qui fait subir au serveur une pression mémoire qu&rsquo;il est urgent d&rsquo;investiguer. C&rsquo;est à partir de ces deux compteurs que l&rsquo;on va décider de s&rsquo;intéresser ou non à d&rsquo;autres compteurs de performance (comme les queues disque, le nombre d&rsquo;opération <a href="http://blog.developpez.com/elsuket/p9529/moteur-de-base-de-donnees-sql-server/lazywriter_checkpoint_aamp_ghost_cleanup">checkpoints et lazywites</a> par seconde), &#8230;</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> <strong>Où trouver ce compteur de performance ?</strong></p>
<p>On trouve ce compteur de performance dans le <em>Moniteur de Performances</em>, sous la catégorie <em>SQL Server:Buffer Manager</em>, de même que BCHR :</p>
<p><img src="http://img40.imageshack.us/img40/5834/miseaupointplebuffermgr.png" alt="" /></p>
<p>Néanmoins, en fouillant un peu plus, on trouve le groupe <em>SQL Server:Buffer Node</em> :</p>
<p><img src="http://imageshack.us/a/img853/4583/miseaupointplebuffernod.png" alt="" /></p>
<p>On est alors libre de suivre toutes les <em>nodes</em>, c&rsquo;est à dire les nœuds NUMA de façon individuelle, mais il nous est d&rsquo;abord nécessaire de savoir sur quel nœud NUMA ladite requête s&rsquo;exécute. Ceci prouve que la moyenne des PLE de chaque nœud NUMA, exposée par le compteur <em>SQL Server:Buffer Manager</em> / <em>Page Life Expectancy</em> masque cet état de fait. </p>
<p>Implicitement, SQL Server va donc affecter l&rsquo;exécution d&rsquo;une requête au planificateur qui est le plus susceptible de disposer, dans l&rsquo;espace mémoire qu&rsquo;il adresse, toutes les données dont la requête a besoin. Ceci est dû au fait que l&rsquo;accès à un nœud NUMA distant est coûteux en ressources CPU.<br />
L&rsquo;affectation de la quantité de mémoire se fait de manière triviale : SQL Server lit la valeur de l&rsquo;option de configuration <em>max server memory (KB)</em>, et affecte à chaque nœud NUMA cette quantité de mémoire divisée par le nombre de nœuds NUMA du serveur. Si ladite option n&rsquo;est pas configurée, SQL Server produit le même calcul avec la quantité de RAM disponible sur le serveur.</p>
<p><img src="http://img12.imageshack.us/img12/5913/iconarrowp.gif" alt="" /> Comment détecter un pression mémoire sur un nœud NUMA ?</p>
<p>Peu après la sortie commerciale de SQL Server 2005, Microsoft a publié un <a href="http://technet.microsoft.com/en-us/library/cc966413.aspx">livre blanc</a> dans lequel il était préconisé qu&rsquo;une valeur de 300 pour PLE était une situation à éviter pour une instance SQL Server supportant une chage de travail OLTP. Malheureusement, cette recommandation s&rsquo;est répandue et est restée comme un standard officieux, alors qu&rsquo;il est totalement obsolète : en effet à cette époque là, peu de serveur disposaient de plusieurs dizaines de Go de RAM, et on était au point de basculement entre les architectures CPU 32 bits et 64 bits. 300 secondes signifie qu&rsquo;en 5 minutes, SQL Server lit autant de pages depuis les disque que de mémoire qui lui est alloué. Si l&rsquo;on applique cela à un serveur qui dispose de 128 Go de RAM, il devient évident que cette valeur seuil n&rsquo;est plus appropriée. On peut considérer qu&rsquo;à cette époque, les serveurs de base de données disposaient en moyenne de 8Go de RAM. On peut appliquer une règle de trois sur les configurations actuelles pour détecter une pression mémoire.</p>
<p>On peut exposer la différence entre les nœuds NUMA à l&rsquo;aide de la vue de gestion dynamique (DMV) <em>sys.dm_os_schedulers</em> : celle-ci expose au travers de la colonne <em>parent_node_id</em> le nœud NUMA auquel un planificateur d&rsquo;exécution de requête accepte ces dernières. Le lot de requêtes suivant aide à mieux comprendre ce qui se passe sur un serveur servant une instance SQL Server :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">TRANSACTION</span> <span style="color: #0000FF;">ISOLATION</span> <span style="color: #0000FF;">LEVEL</span> <span style="color: #0000FF;">READ</span> <span style="color: #0000FF;">UNCOMMITTED</span><br />
GO<br />
<br />
<span style="color: #0000FF;">DECLARE</span> @max_server_memory_MB <span style="color: #0000FF;">int</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @memory_node_count <span style="color: #0000FF;">int</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , @node_ple_threshold <span style="color: #0000FF;">int</span><br />
<br />
<span style="color: #008080;">-- Lecture de la valeur configurée pour l'option max server memory (MB)</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; @max_server_memory_MB <span style="color: #808080;">=</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">value</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">int</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">configurations</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; name <span style="color: #808080;">=</span> <span style="color: #FF0000;">'max server memory (MB)'</span><br />
<br />
<span style="color: #008080;">-- Lecture du nombre de noeuds NUMA</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; @memory_node_count <span style="color: #808080;">=</span> <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">dm_os_memory_nodes</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; memory_node_id &nbsp;<span style="color: #000;">64</span> <span style="color: #008080;">-- le noeud 64 est pour la fonctionnalité Dedicated Administrator Connection</span><br />
<br />
<span style="color: #008080;">-- Application de la règle de trois au seuil édité par Microsoft en 2006</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; @node_ple_threshold <span style="color: #808080;">=</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span>@max_server_memory_MB <span style="color: #808080;">/</span> @memory_node_count<span style="color: #808080;">&#41;</span> <span style="color: #808080;">*</span> <span style="color: #000;">300</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> <span style="color: #000;">8192</span><br />
<br />
<span style="color: #008080;">-- Affichage des valeurs obtenues</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; @max_server_memory_MB <span style="color: #0000FF;">AS</span> max_server_memory_MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; , @memory_node_count <span style="color: #0000FF;">AS</span> memory_node_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; , @node_ple_threshold <span style="color: #0000FF;">AS</span> NUMA_node_PLE_threshold<br />
<br />
<span style="color: #008080;">-- Exposition de la PLE pour chaque noeud NUMA</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S.<span style="color: #202020;">parent_node_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , PC.<span style="color: #202020;">cntr_value</span> <span style="color: #0000FF;">AS</span> node_PLE<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , PC.<span style="color: #202020;">cntr_value</span> <span style="color: #808080;">/</span> @node_ple_threshold <span style="color: #0000FF;">AS</span> min_PLE_factor<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> PC.<span style="color: #202020;">cntr_value</span> <span style="color: #808080;">&amp;</span>lt;<span style="color: #808080;">=</span> @node_ple_threshold <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'KO'</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">'OK'</span> <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> node_PLE_state<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_exec_requests</span> <span style="color: #0000FF;">AS</span> R<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_os_schedulers</span> <span style="color: #0000FF;">AS</span> S<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> R.<span style="color: #202020;">scheduler_id</span> <span style="color: #808080;">=</span> S.<span style="color: #202020;">scheduler_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">dm_os_performance_counters</span> <span style="color: #0000FF;">AS</span> PC<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> PC.<span style="color: #202020;">instance_name</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">REPLICATE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'0'</span>, <span style="color: #000;">3</span> <span style="color: #808080;">-</span> <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>S.<span style="color: #202020;">parent_node_id</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>S.<span style="color: #202020;">parent_node_id</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">10</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #202020;">command</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'LAZY WRITER'</span> <span style="color: #008080;">-- Il existe un processus Lazywriter par noeud NUMA</span><br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PC.<span style="color: #202020;">counter_name</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Page life expectancy'</span></div></td></tr></tbody></table></div>
<p>Ceci donne par exemple :</p>
<p><img src="http://imageshack.us/a/img818/4863/plepernodeserver.png" alt="" /></p>
<p>On voit bien ici que la PLE est bien plus faible sur le nœud NUMA 0, et qu&rsquo;elle est pas totalement identique sur les autres nœuds.<br />
On peut donc penser à mettre en place une alerte lorsque la PLE d&rsquo;une des noeuds NUMA passe en-dessous de la valeur calculée par le script ci-dessus.<br />
Malheureusement les alertes proposées par SQL Server Agent ne permettent de prendre en compte que la moyenne des PLE de tous les nœuds NUMA, c&rsquo;est à dire le compteur de performance <em>SQL Server:Buffer Manager</em> / <em>Page Life Expectancy</em>.<br />
On peut cependant exécuter à intervalles réguliers et fréquents une procédure stockée qui vérifie la PLE de chaque noeud NUMA, à l&rsquo;aide d&rsquo;un job de l&rsquo;Agent SQL Server.</p>
<p>Bon monitoring à tous !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripter les connexions, rôles et utilisateurs avec leurs privilèges sous SQL Server 2005 et suivants</title>
		<link>https://blog.developpez.com/elsuket/p11945/securite/scripter-les-connexions-roles-et-utilisateurs-avec-leurs-privileges-sous-sql-server-2005-et-suivants</link>
		<comments>https://blog.developpez.com/elsuket/p11945/securite/scripter-les-connexions-roles-et-utilisateurs-avec-leurs-privileges-sous-sql-server-2005-et-suivants#comments</comments>
		<pubDate>Mon, 29 Apr 2013 23:19:52 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[connexion]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[scripter]]></category>
		<category><![CDATA[transfert]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[utilisateur]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=231</guid>
		<description><![CDATA[La procédure que Microsoft fournit pour transférer les connexions d&#8217;une instance de SQL Server à l&#8217;autre s&#8217;applique très bien à SQL Server 2000, qui a près de 13 ans ! Pourtant, avec les possibilités de transtypage ajoutées aux versions suivantes &#8230; <a href="https://blog.developpez.com/elsuket/p11945/securite/scripter-les-connexions-roles-et-utilisateurs-avec-leurs-privileges-sous-sql-server-2005-et-suivants">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La procédure que <a href="http://support.microsoft.com/kb/918992?wa=wsignin1.0">Microsoft</a> fournit pour transférer les connexions d&rsquo;une instance de SQL Server à l&rsquo;autre s&rsquo;applique très bien à SQL Server 2000, qui a près de 13 ans ! Pourtant, avec les possibilités de transtypage ajoutées aux versions suivantes de SQL Server, une requête suffit pour générer le script de création des logins.<br />
En sus, je vous donne les requêtes nécessaires à la génération des rôles, des utilisateurs, et de leurs privilèges respectifs.<br />
<span id="more-231"></span></p>
<p>Voici donc la requête qui permet de scripter les connexions :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'CREATE LOGIN ['</span> <span style="color: #808080;">+</span> name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] FROM WINDOWS'</span> <span style="color: #0000FF;">AS</span> sql_statement<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">server_principals</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; type_desc <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'WINDOWS_LOGIN'</span>, <span style="color: #FF0000;">'WINDOWS_GROUP'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; is_disabled <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'NT AUTHORITY\SYSTEM'</span>, <span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'%sqlserveragent%'</span><br />
<span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'CREATE LOGIN '</span> <span style="color: #808080;">+</span> name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">' WITH PASSWORD = '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span>, password_hash, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' HASHED'</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">', SID = '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span>, sid, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">AS</span> sql_statement<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">sql_logins</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; type_desc <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'WINDOWS_LOGIN'</span>, <span style="color: #FF0000;">'SQL_LOGIN'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; is_disabled <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'sa'</span>, <span style="color: #FF0000;">'NT AUTHORITY\SYSTEM'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">ORDER</span> &nbsp; <span style="color: #0000FF;">BY</span> sql_statement</div></td></tr></tbody></table></div>
<p>Ci-dessous, la requête qui scripte les rôles de base de données :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'CREATE ROLE ['</span> <span style="color: #808080;">+</span> name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] AUTHORIZATION dbo'</span> <span style="color: #0000FF;">AS</span> create_role_statement<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; type_desc <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DATABASE_ROLE'</span><br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'MS%'</span> <span style="color: #0000FF;">COLLATE</span> SQL_Latin1_General_CP1_CS_AS<br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'public'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; is_fixed_role <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
<span style="color: #0000FF;">ORDER</span> &nbsp; <span style="color: #0000FF;">BY</span> name</div></td></tr></tbody></table></div>
<p>Puis les utilisateurs de base de données :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'CREATE USER ['</span> <span style="color: #808080;">+</span> name <span style="color: #808080;">+</span> <span style="color: #FF0000;">'] FOR LOGIN ['</span> <span style="color: #808080;">+</span> name &nbsp;<span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span> <span style="color: #0000FF;">AS</span> create_user_statement<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; type_desc <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SQL_USER'</span>, <span style="color: #FF0000;">'WINDOWS_USER'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; name <span style="color: #808080;">NOT</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'dbo'</span>, <span style="color: #FF0000;">'guest'</span>, <span style="color: #FF0000;">'sys'</span>, <span style="color: #FF0000;">'INFORMATION_SCHEMA'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">ORDER</span> &nbsp; <span style="color: #0000FF;">BY</span> name</div></td></tr></tbody></table></div>
<p>Et enfin l&rsquo;appartenance des utilisateurs aux rôles, pour SQL Server 2005 et 2008 :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">'EXEC sp_addrolemember '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> R.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">', '</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> M.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">''</span> <span style="color: #0000FF;">AS</span> role_members_statement<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_role_members</span> <span style="color: #0000FF;">AS</span> RM<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> R<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> R.<span style="color: #202020;">principal_id</span> <span style="color: #808080;">=</span> RM.<span style="color: #202020;">role_principal_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> M<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> M.<span style="color: #202020;">principal_id</span> <span style="color: #808080;">=</span> RM.<span style="color: #202020;">member_principal_id</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #202020;">name</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'MS%'</span> <span style="color: #0000FF;">COLLATE</span> SQL_Latin1_General_CP1_CS_AS<br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; M.<span style="color: #202020;">name</span> &nbsp;<span style="color: #FF0000;">'dbo'</span><br />
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span>&nbsp; &nbsp; &nbsp; &nbsp; role_members_statement</div></td></tr></tbody></table></div>
<p>Et pour SQL Server 2012 :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #FF0000;">'ALTER ROLE '</span> <span style="color: #808080;">+</span> R.<span style="color: #202020;">name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' ADD MEMBER '</span> <span style="color: #808080;">+</span> M.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> role_members_statement<br />
<span style="color: #0000FF;">FROM</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sys.<span style="color: #202020;">database_role_members</span> <span style="color: #0000FF;">AS</span> RM<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp;sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> R<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> R.<span style="color: #202020;">principal_id</span> <span style="color: #808080;">=</span> RM.<span style="color: #202020;">role_principal_id</span><br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp;sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> M<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> M.<span style="color: #202020;">principal_id</span> <span style="color: #808080;">=</span> RM.<span style="color: #202020;">member_principal_id</span><br />
<span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #202020;">name</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">LIKE</span> <span style="color: #FF0000;">'MS%'</span> <span style="color: #0000FF;">COLLATE</span> SQL_Latin1_General_CP1_CS_AS<br />
<span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; M.<span style="color: #202020;">name</span> &nbsp;<span style="color: #FF0000;">'dbo'</span><br />
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span> &nbsp; &nbsp; &nbsp; &nbsp;role_members_statement</div></td></tr></tbody></table></div>
<p>Il nous faut enfin les privilèges des rôles :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">;<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CTE <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> role_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , G.<span style="color: #202020;">permission_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CASE</span> G.<span style="color: #0000FF;">class</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> O.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">3</span> <span style="color: #0000FF;">THEN</span> S.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF00FF;">object_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CASE</span> G.<span style="color: #0000FF;">class</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> O.<span style="color: #202020;">type_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">3</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'SCHEMA'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">0</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'DATABASE'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> object_type_desc<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> R<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_permissions</span> <span style="color: #0000FF;">AS</span> G<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> G.<span style="color: #202020;">grantee_principal_id</span> <span style="color: #808080;">=</span> R.<span style="color: #202020;">principal_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">schemas</span> <span style="color: #0000FF;">AS</span> S<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> G.<span style="color: #202020;">major_id</span> <span style="color: #808080;">=</span> S.<span style="color: #202020;">schema_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">objects</span> <span style="color: #0000FF;">AS</span> O<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> G.<span style="color: #202020;">major_id</span> <span style="color: #808080;">=</span> O.<span style="color: #FF00FF;">object_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; R.<span style="color: #202020;">name</span> &nbsp;<span style="color: #FF0000;">'public'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; G.<span style="color: #202020;">permission_name</span> &nbsp;<span style="color: #FF0000;">'CONNECT'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">--ORDER BY&nbsp; &nbsp; &nbsp; R.name, object_name, G.permission_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #FF0000;">'GRANT '</span> <span style="color: #0000FF;">COLLATE</span> database_default <span style="color: #808080;">+</span> permission_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #FF0000;">' ON '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> <span style="color: #FF00FF;">object_name</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'SCHEMA::dbo TO ['</span> <span style="color: #0000FF;">ELSE</span> <span style="color: #FF00FF;">object_name</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' TO ['</span> <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> role_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span> <span style="color: #0000FF;">AS</span> role_grant_statement<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; CTE</div></td></tr></tbody></table></div>
<p>Et nous terminons avec les privilèges des utilisateurs :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">;<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CTE <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DB_USER.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF00FF;">user_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , DB_GRANT.<span style="color: #202020;">class_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , DB_GRANT.<span style="color: #202020;">state_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , DB_GRANT.<span style="color: #202020;">permission_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CASE</span> DB_GRANT.<span style="color: #202020;">class_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'OBJECT_OR_COLUMN'</span> <span style="color: #0000FF;">THEN</span> O.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'SCHEMA'</span> <span style="color: #0000FF;">THEN</span> S.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF0000;">'TYPE'</span> <span style="color: #0000FF;">THEN</span> TY.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span> O.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> <span style="color: #FF00FF;">object_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , O.<span style="color: #202020;">type_desc</span> <span style="color: #0000FF;">AS</span> DB_object_type<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_permissions</span> <span style="color: #0000FF;">AS</span> DB_GRANT<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">database_principals</span> <span style="color: #0000FF;">AS</span> DB_USER<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> DB_GRANT.<span style="color: #202020;">grantee_principal_id</span> <span style="color: #808080;">=</span> DB_USER.<span style="color: #202020;">principal_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">objects</span> <span style="color: #0000FF;">AS</span> O<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> O.<span style="color: #FF00FF;">object_id</span> <span style="color: #808080;">=</span> DB_GRANT.<span style="color: #202020;">major_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">types</span> <span style="color: #0000FF;">AS</span> TY<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> TY.<span style="color: #202020;">user_type_id</span> <span style="color: #808080;">=</span> DB_GRANT.<span style="color: #202020;">major_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">LEFT</span> <span style="color: #808080;">JOIN</span> &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">schemas</span> <span style="color: #0000FF;">AS</span> S<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> S.<span style="color: #202020;">schema_id</span> <span style="color: #808080;">=</span> DB_GRANT.<span style="color: #202020;">major_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DB_USER.<span style="color: #202020;">name</span> &nbsp;<span style="color: #FF0000;">'public'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DB_GRANT.<span style="color: #202020;">permission_name</span> &nbsp;<span style="color: #FF0000;">'CONNECT'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; state_desc <span style="color: #0000FF;">COLLATE</span> database_default <span style="color: #808080;">+</span> <span style="color: #FF0000;">' '</span> <span style="color: #808080;">+</span> permission_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">+</span> <span style="color: #0000FF;">CASE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #FF00FF;">object_name</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">''</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span> <span style="color: #FF0000;">' ON '</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">object_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' TO ['</span> <span style="color: #808080;">+</span> <span style="color: #FF00FF;">user_name</span> &nbsp;<span style="color: #808080;">+</span> <span style="color: #FF0000;">']'</span> <span style="color: #0000FF;">AS</span> create_user_statement<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; CTE<br />
<span style="color: #0000FF;">ORDER</span> &nbsp; <span style="color: #0000FF;">BY</span> create_user_statement</div></td></tr></tbody></table></div>
<p>Bon transfert d&rsquo;entités de sécurité !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Les tribulations d&#8217;un analyste programmeur en entreprise</title>
		<link>https://blog.developpez.com/elsuket/p11863/lecture/les-tribulations-dun-analyste-programmeur-en-entreprise</link>
		<comments>https://blog.developpez.com/elsuket/p11863/lecture/les-tribulations-dun-analyste-programmeur-en-entreprise#comments</comments>
		<pubDate>Wed, 27 Mar 2013 10:18:31 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Lecture]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=225</guid>
		<description><![CDATA[C&#8217;est par ici Bonne détente !]]></description>
				<content:encoded><![CDATA[<p>C&rsquo;est par <a href="http://jesuisinformaticien.tumblr.com/">ici</a></p>
<p>Bonne détente !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Une procédure stockée pour connaître l&#8217;état des fichiers du journal des transactions</title>
		<link>https://blog.developpez.com/elsuket/p11777/moteur-de-base-de-donnees-sql-server/une-procedure-stockee-pour-connaitre-letat-des-fichiers-du-journal-des-transactions</link>
		<comments>https://blog.developpez.com/elsuket/p11777/moteur-de-base-de-donnees-sql-server/une-procedure-stockee-pour-connaitre-letat-des-fichiers-du-journal-des-transactions#comments</comments>
		<pubDate>Mon, 11 Feb 2013 05:12:22 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Non documenté]]></category>
		<category><![CDATA[DBCC]]></category>
		<category><![CDATA[journal]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[transaction]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=199</guid>
		<description><![CDATA[Ha ! le fichier du journal des transactions, l&#8217;option de récupération, son grossissement, &#8230; et bien sûr la fameuse transaction restée ouverte qui a provoqué une explosion de la taille de celui-ci, allant jusqu&#8217;à remplir le volume disque qui l&#8217;héberge &#8230; <a href="https://blog.developpez.com/elsuket/p11777/moteur-de-base-de-donnees-sql-server/une-procedure-stockee-pour-connaitre-letat-des-fichiers-du-journal-des-transactions">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Ha ! le fichier du journal des transactions, l&rsquo;option de récupération, son grossissement, &#8230; et bien sûr la fameuse transaction restée ouverte qui a provoqué une explosion de la taille de celui-ci, allant jusqu&rsquo;à remplir le volume disque qui l&rsquo;héberge : tout autant de paramétrages et d&rsquo;investigations fastidieuses.</p>
<p>Alors comme je n&rsquo;aime pas beaucoup répéter plusieurs fois les mêmes opérations sans avoir un script, ou mieux, une procédure stockée sous la main, j&rsquo;ai créé la suivante, dont voici le script de création :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">USE</span> master<br />
GO<br />
<br />
<span style="color: #008080;">-----------------------------------------------------------------</span><br />
<span style="color: #008080;">-- Nicolas Souquet - 09/02/2013</span><br />
<span style="color: #008080;">-- LA PROCEDURE STOCKEE SUIVANTE EST DONNEE EN TANT QUE TELLE</span><br />
<span style="color: #008080;">-- SON UTILISATION ET SA MODIFICATION EST A VOS RISQUES ET PÉRILS</span><br />
<span style="color: #008080;">-----------------------------------------------------------------</span><br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">PROCEDURE</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>sp__log_space_get<span style="color: #808080;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; @_database_name sysname <span style="color: #808080;">=</span> <span style="color: #808080;">NULL</span><br />
<span style="color: #0000FF;">AS</span><br />
<span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DECLARE</span> @<span style="color: #0000FF;">sql</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">256</span><span style="color: #808080;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Récupération de l'espace disque disponible</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- sur tous les volumes visibles par l'instance SQL Server</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DECLARE</span> @free_disk_space <span style="color: #0000FF;">TABLE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drive_letter <span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , free_space_MB <span style="color: #0000FF;">int</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span>&nbsp; <span style="color: #0000FF;">INTO</span> @free_disk_space<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span>&nbsp; &nbsp; master.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">xp_fixeddrives</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Récupération de l'occupation des fichiers des journaux de transaction</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- de toutes les bases de données hébergées par l'instance SQL Server</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DECLARE</span> @dbcc_sqlperf_logspace <span style="color: #0000FF;">TABLE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; database_name sysname<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , log_size <span style="color: #0000FF;">float</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , log_space_used_pct <span style="color: #0000FF;">decimal</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>,<span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , status <span style="color: #0000FF;">tinyint</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span>&nbsp; <span style="color: #0000FF;">INTO</span> @dbcc_sqlperf_logspace<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span>&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'DBCC SQLPERF(logspace)'</span><span style="color: #808080;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Récupération de la liste de tous les fichiers virtuels</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- du fichier du journal des transactions de toutes les bases de données</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- disponibles, hébergées par l'instance SQL Server</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DECLARE</span> @dbcc_loginfo <span style="color: #0000FF;">TABLE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; recovery_unit_id <span style="color: #0000FF;">tinyint</span> <span style="color: #008080;">-- new column in SQL Server 2012</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , fileid <span style="color: #0000FF;">tinyint</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , file_size <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , start_offset <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , f_seq_no <span style="color: #0000FF;">bigint</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , status <span style="color: #0000FF;">tinyint</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , parity <span style="color: #0000FF;">tinyint</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , create_LSN <span style="color: #0000FF;">varbinary</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Cas où l'on souhaite réaliser l'audit du fichier du journal des transactions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- de toutes les bases de données hébergées par l'instance SQL Server</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Dans ce cas le paramètre d'entrée @_database_name est à NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> @_database_name <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DECLARE</span> @dbcc_loginfo_all_db <span style="color: #0000FF;">TABLE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; database_name <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">128</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , log_file_id <span style="color: #0000FF;">tinyint</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , vlf_count <span style="color: #0000FF;">smallint</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Récupération de liste de toutes les bases de données disponibles</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- (pas une capture iOFFLINE, SINGLE_USER, ou ... SUSPECT ;))</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span>&nbsp; <span style="color: #0000FF;">INTO</span> @dbcc_loginfo_all_db<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; database_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , log_file_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , vlf_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D.<span style="color: #202020;">name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , MF.<span style="color: #FF00FF;">file_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">databases</span> <span style="color: #0000FF;">AS</span> D<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">master_files</span> <span style="color: #0000FF;">AS</span> MF<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> D.<span style="color: #202020;">database_id</span> <span style="color: #808080;">=</span> MF.<span style="color: #202020;">database_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D.<span style="color: #202020;">source_database_id</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span> <span style="color: #008080;">-- ce n'est pas une capture instantanée de base de données</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D.<span style="color: #202020;">state_desc</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ONLINE'</span> <span style="color: #008080;">-- la base de données est disponible</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D.<span style="color: #202020;">user_access_desc</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'MULTI_USER'</span> <span style="color: #008080;">-- la base de données est à l'écoute de connexions utilisateur</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MF.<span style="color: #202020;">type_desc</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'LOG'</span> <span style="color: #008080;">-- le type de fichier est &quot;journal des transactions&quot;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Pour chaque base de données, récupération de la liste des fichiers virtuels</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- du fichier du journal des transactions pour toutes les bases de données disponibles</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">EXISTS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #808080;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; @dbcc_loginfo_all_db<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; vlf_count <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; <span style="color: #0000FF;">TOP</span> <span style="color: #000;">1</span> @_database_name <span style="color: #808080;">=</span> database_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; @dbcc_loginfo_all_db<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; vlf_count <span style="color: #808080;">=</span> <span style="color: #000;">0</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @<span style="color: #0000FF;">sql</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DBCC LOGINFO ('</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> @_database_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">')'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span>&nbsp; <span style="color: #0000FF;">INTO</span> @dbcc_loginfo<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span>&nbsp; &nbsp; <span style="color: #808080;">&#40;</span>@<span style="color: #0000FF;">sql</span><span style="color: #808080;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CTE <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; fileid<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> vlf_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; @dbcc_loginfo<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">GROUP</span> &nbsp; <span style="color: #0000FF;">BY</span> fileid<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">UPDATE</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @dbcc_loginfo_all_db<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vlf_count <span style="color: #808080;">=</span> C.<span style="color: #202020;">vlf_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @dbcc_loginfo_all_db <span style="color: #0000FF;">AS</span> DLAD<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; CTE <span style="color: #0000FF;">AS</span> C<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> DLAD.<span style="color: #202020;">log_file_id</span> <span style="color: #808080;">=</span> C.<span style="color: #202020;">fileid</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DLAD.<span style="color: #202020;">database_name</span> <span style="color: #808080;">=</span> @_database_name<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DELETE</span>&nbsp; <span style="color: #0000FF;">FROM</span> @dbcc_loginfo<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Résultat final, avec addition de quelques détails</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LS.<span style="color: #202020;">database_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , D.<span style="color: #202020;">recovery_model_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , MF.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> logical_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , FDS.<span style="color: #202020;">drive_letter</span> <span style="color: #0000FF;">AS</span> transaction_log_file_stored_on<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , FDS.<span style="color: #202020;">free_space_MB</span> <span style="color: #0000FF;">AS</span> volume_free_space_MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>LS.<span style="color: #202020;">log_size</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">decimal</span><span style="color: #808080;">&#40;</span><span style="color: #000;">38</span>,<span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> transaction_log_file_size_MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , LS.<span style="color: #202020;">log_space_used_pct</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span>LS.<span style="color: #202020;">log_space_used_pct</span> <span style="color: #808080;">/</span> <span style="color: #000;">100.0</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">*</span> LS.<span style="color: #202020;">log_size</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">decimal</span><span style="color: #808080;">&#40;</span><span style="color: #000;">38</span>,<span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> log_used_size_MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CASE</span> MF.<span style="color: #202020;">is_percent_growth</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>MF.<span style="color: #202020;">growth</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' %'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>MF.<span style="color: #202020;">growth</span> <span style="color: #808080;">/</span> <span style="color: #000;">128</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">20</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' MB'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> growth &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; , D.<span style="color: #202020;">log_reuse_wait_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , DLAD.<span style="color: #202020;">vlf_count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , MF.<span style="color: #202020;">physical_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">master_files</span> <span style="color: #0000FF;">AS</span> MF<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; @dbcc_sqlperf_logspace <span style="color: #0000FF;">AS</span> LS<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> LS.<span style="color: #202020;">database_name</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span>MF.<span style="color: #202020;">database_id</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; @free_disk_space <span style="color: #0000FF;">AS</span> FDS<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> FDS.<span style="color: #202020;">drive_letter</span> <span style="color: #808080;">=</span> <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>MF.<span style="color: #202020;">physical_name</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">COLLATE</span> database_default<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">databases</span> <span style="color: #0000FF;">AS</span> D<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> D.<span style="color: #202020;">name</span> <span style="color: #808080;">=</span> LS.<span style="color: #202020;">database_name</span> <span style="color: #0000FF;">COLLATE</span> database_default<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; @dbcc_loginfo_all_db <span style="color: #0000FF;">AS</span> DLAD<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> DLAD.<span style="color: #202020;">database_name</span> <span style="color: #808080;">=</span> D.<span style="color: #202020;">name</span> <span style="color: #0000FF;">COLLATE</span> database_default<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> DLAD.<span style="color: #202020;">log_file_id</span> <span style="color: #808080;">=</span> MF.<span style="color: #FF00FF;">file_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> DLAD.<span style="color: #202020;">database_name</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span>MF.<span style="color: #202020;">database_id</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MF.<span style="color: #202020;">type_desc</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'LOG'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D.<span style="color: #202020;">source_database_id</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D.<span style="color: #202020;">state_desc</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ONLINE'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D.<span style="color: #202020;">user_access_desc</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'MULTI_USER'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Si la base de données que l'on souhaite auditer n'existe pas ==&amp;gt; exception</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">IF</span> <span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span>@_database_name<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">RAISERROR</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'The database named '</span><span style="color: #FF0000;">'%s'</span><span style="color: #FF0000;">' does not exist'</span>, <span style="color: #000;">16</span>, <span style="color: #000;">1</span>, @_database_name<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">RETURN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- récupération de la liste des fichiers virtuels</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- du fichier du journal des transactions de la base de données choisie</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">DECLARE</span> @vlf_count <span style="color: #0000FF;">int</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @<span style="color: #0000FF;">sql</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DBCC LOGINFO ('</span><span style="color: #FF0000;">''</span> <span style="color: #808080;">+</span> @_database_name <span style="color: #808080;">+</span> <span style="color: #FF0000;">''</span><span style="color: #FF0000;">')'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span>&nbsp; <span style="color: #0000FF;">INTO</span> @dbcc_loginfo<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXEC</span>&nbsp; &nbsp; <span style="color: #808080;">&#40;</span>@<span style="color: #0000FF;">sql</span><span style="color: #808080;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">-- Résultat final, avec addition de quelques détails</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ;<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CTE <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; fileid<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> vlf_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; @dbcc_loginfo<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">GROUP</span> &nbsp; <span style="color: #0000FF;">BY</span> fileid<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LS.<span style="color: #202020;">database_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , D.<span style="color: #202020;">recovery_model_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , MF.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> logical_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , FDS.<span style="color: #202020;">drive_letter</span> <span style="color: #0000FF;">AS</span> transaction_log_file_stored_on<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , FDS.<span style="color: #202020;">free_space_MB</span> <span style="color: #0000FF;">AS</span> volume_free_space_MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>LS.<span style="color: #202020;">log_size</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">decimal</span><span style="color: #808080;">&#40;</span><span style="color: #000;">38</span>,<span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> transaction_log_file_size_MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , LS.<span style="color: #202020;">log_space_used_pct</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span>LS.<span style="color: #202020;">log_space_used_pct</span> <span style="color: #808080;">/</span> <span style="color: #000;">100.0</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">*</span> LS.<span style="color: #202020;">log_size</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">decimal</span><span style="color: #808080;">&#40;</span><span style="color: #000;">38</span>,<span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> log_used_size_MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CASE</span> MF.<span style="color: #202020;">is_percent_growth</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">THEN</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>MF.<span style="color: #202020;">growth</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' %'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ELSE</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>MF.<span style="color: #202020;">growth</span> <span style="color: #808080;">/</span> <span style="color: #000;">128</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">20</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' MB'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> growth<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , D.<span style="color: #202020;">log_reuse_wait_desc</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , C.<span style="color: #202020;">vlf_count</span> <span style="color: #0000FF;">AS</span> VLF_count<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , MF.<span style="color: #202020;">physical_name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">master_files</span> <span style="color: #0000FF;">AS</span> MF<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; @dbcc_sqlperf_logspace <span style="color: #0000FF;">AS</span> LS<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> LS.<span style="color: #202020;">database_name</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span>MF.<span style="color: #202020;">database_id</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; @free_disk_space <span style="color: #0000FF;">AS</span> FDS<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> FDS.<span style="color: #202020;">drive_letter</span> <span style="color: #808080;">=</span> <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>MF.<span style="color: #202020;">physical_name</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">COLLATE</span> database_default<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">databases</span> <span style="color: #0000FF;">AS</span> D<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> D.<span style="color: #202020;">name</span> <span style="color: #808080;">=</span> LS.<span style="color: #202020;">database_name</span> <span style="color: #0000FF;">COLLATE</span> database_default<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; CTE <span style="color: #0000FF;">AS</span> C<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> C.<span style="color: #202020;">fileid</span> <span style="color: #808080;">=</span> MF.<span style="color: #FF00FF;">file_id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MF.<span style="color: #202020;">type_desc</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'LOG'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LS.<span style="color: #202020;">database_name</span> <span style="color: #808080;">=</span> @_database_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D.<span style="color: #202020;">source_database_id</span> <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D.<span style="color: #202020;">state_desc</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ONLINE'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">AND</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; D.<span style="color: #202020;">user_access_desc</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'MULTI_USER'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
<span style="color: #0000FF;">END</span><br />
GO<br />
<br />
<span style="color: #008080;">-- On marque la procédure stockée comme objet système</span><br />
<span style="color: #008080;">-- Dès lors, on pourra l'exécuter dans n'importe quel contexte de base de données</span><br />
<span style="color: #0000FF;">EXEC</span> sp_ms_marksystemobject <span style="color: #FF0000;">'sp__log_space_get'</span></div></td></tr></tbody></table></div>
<p>Elle donne un résultat comme le suivant :</p>
<p><a href="http://blog.developpez.com/elsuket/p11777/moteur-de-base-de-donnees-sql-server/une-procedure-stockee-pour-connaitre-letat-des-fichiers-du-journal-des-transactions/attachment/sp__log_space_get" rel="attachment wp-att-203"><img src="http://blog.developpez.com/elsuket/files/2013/02/sp__log_space_get-300x29.png" alt="sp__log_space_get" width="300" height="29" class="alignnone size-medium wp-image-203" /></a></p>
<p>à savoir :</p>
<p>&#8211; le nom de la base de données<br />
&#8211; l&rsquo;option de récupération de la base de données<br />
&#8211; le nom logique du fichier du journal des transactions (utile pour un DBCC SHRINKFILE après que le journal ait explosé en taille)<br />
&#8211; le volume sur lequel est hébergé le fichier du journal des transactions<br />
&#8211; la quantité d&rsquo;espace disque libre restant sur ce volume<br />
&#8211; la taille actuelle du fichier du journal des transactions<br />
&#8211; le pourcentage d&rsquo;utilisation de ce fichier (taille occupée dans le fichier par rapport à la taille totale du fichier)<br />
&#8211; la taille équivalente à ce pourcentage<br />
&#8211; le paramètre de grossissement de ce fichier<br />
&#8211; ce qui empêche actuellement la troncature de l&rsquo;espace occupé dans ce fichier<br />
&#8211; le chemin complet du fichier</p>
<p>On peut utiliser cette procédure stockée sous SQL Server 2005, 2008 et 2012.<br />
Elle fonctionne également pour les bases de données ayant plusieurs fichiers du journal des transactions</p>
<p>Bonne gestion des fichiers du journal des transactions !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reprise d&#8217;activité étape par étapes : le poster de Paul Randal</title>
		<link>https://blog.developpez.com/elsuket/p11773/moteur-de-base-de-donnees-sql-server/reprise-dactivite-etape-par-etapes-le-poster-de-paul-randal</link>
		<comments>https://blog.developpez.com/elsuket/p11773/moteur-de-base-de-donnees-sql-server/reprise-dactivite-etape-par-etapes-le-poster-de-paul-randal#comments</comments>
		<pubDate>Sat, 09 Feb 2013 04:21:00 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>
		<category><![CDATA[disaster recovery]]></category>
		<category><![CDATA[DR]]></category>
		<category><![CDATA[HA]]></category>
		<category><![CDATA[HADR]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=191</guid>
		<description><![CDATA[Paul Randal est très connu dans la communauté SQL Server puisqu&#8217;il publie très régulièrement des détails sur le fonctionnement interne de SQL Server, dont certains ne sont pas documentés, à travers son site SQLSkills.com (son blog et ceux d&#8217;autres experts &#8230; <a href="https://blog.developpez.com/elsuket/p11773/moteur-de-base-de-donnees-sql-server/reprise-dactivite-etape-par-etapes-le-poster-de-paul-randal">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Paul Randal est très connu dans la communauté SQL Server puisqu&rsquo;il publie très régulièrement des détails sur le fonctionnement interne de SQL Server, dont certains ne sont pas documentés, à travers son site <a href="http://www.sqlskills.com/" title="SQLSkills.com" target="_blank">SQLSkills.com</a> (son blog et ceux d&rsquo;autres experts sont référencés en bas à droite de la page).</p>
<p>Paul Randal vient donc de mettre à la disposition de la communauté un <a href="http://www.sqlskills.com/blogs/paul/sql-server-disaster-recovery-poster-now-available/" title="SQL Server Disaster Recovery Poster Now Available" target="_blank">poster</a> qui détaille les étapes de la reprise d&rsquo;activité par un diagramme décisionnel.</p>
<p>Ce diagramme contient certaines étapes qui référencent un numéro, et chaque numéro correspond à un article publié par Paul Randal. Ils sont tous référencés sur <a href="http://www.sqlskills.com/drposter.asp" title="SQL Server Disaster Recovery Poster Steps Details" target="_blank">cette page</a>.</p>
<p>Toujours bon à avoir sous la main !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cadeau de Noël de Kalen Delaney : un livre sur le verrouillage, le blocage et le versionnement de ligne</title>
		<link>https://blog.developpez.com/elsuket/p11606/moteur-de-base-de-donnees-sql-server/livre_verrouillage_blocage_versionning</link>
		<comments>https://blog.developpez.com/elsuket/p11606/moteur-de-base-de-donnees-sql-server/livre_verrouillage_blocage_versionning#comments</comments>
		<pubDate>Sat, 22 Dec 2012 07:24:37 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Lecture]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[blocage]]></category>
		<category><![CDATA[blocking]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[verrou]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=177</guid>
		<description><![CDATA[Le site de RedGate, créé par Bard Mc Gehee, publie depuis quelques années déjà de nombreux ouvrages, dont certains abordent des thèmes que l&#8217;on voit rarement explorés en détails, parfois même par les mêmes auteurs chez d&#8217;autres éditeurs. Vous n&#8217;avez &#8230; <a href="https://blog.developpez.com/elsuket/p11606/moteur-de-base-de-donnees-sql-server/livre_verrouillage_blocage_versionning">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Le site de RedGate, créé par Bard Mc Gehee, publie depuis quelques années déjà de nombreux ouvrages, dont certains abordent des thèmes que l&rsquo;on voit rarement explorés en détails, parfois même par les mêmes auteurs chez d&rsquo;autres éditeurs.</p>
<p>Vous n&rsquo;avez plus grand chose à vous mettre sous la dent après avoir lu comment fonctionne <a href="http://blog.developpez.com/elsuket/p11069/moteur-de-base-de-donnees-sql-server/comprendre_plan_requete_optimiseur" title="Comprendre les plans d’exécution et l’Optimiseur de requêtes : deux très bons ouvrages" target="_blank">l&rsquo;optimiseur de requêtes</a> ? On ne peut pas déclarer cela sérieusement avec la sortie récente de SQL Server 2012, et de ses nombreuses innovations ou améliorations <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p>Malgré toutes ces nouveautés à décortiquer, les fondamentaux du fonctionnement de SQL Server demeurent. Donc pour Noël, Kalen Delaney nous fait le cadeau de son dernier ouvrage, <a href="http://www.red-gate.com/community/books/sql-server-concurrency" title="SQL Server Concurrency by Kalen Delaney"><em>SQL Server Concurrency: Locking, Blocking and Row Versioning</em></a>, et que l&rsquo;on peut déjà télécharger gratuitement en PDF (d&rsquo;habitude RedGate ne le permet qu&rsquo;après quelques mois).</p>
<p>Bonne lecture de Noël à tous !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Que faire avec l&#8217;erreur 18486 : Login failed for user &#8216;unLogin&#8217; because the account is currently locked out</title>
		<link>https://blog.developpez.com/elsuket/p11379/securite/que-faire-avec-lerreur-18486-login-failed-for-user-unlogin-because-the-account-is-currently-locked-out</link>
		<comments>https://blog.developpez.com/elsuket/p11379/securite/que-faire-avec-lerreur-18486-login-failed-for-user-unlogin-because-the-account-is-currently-locked-out#comments</comments>
		<pubDate>Tue, 02 Oct 2012 09:11:10 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[18486]]></category>
		<category><![CDATA[connexion]]></category>
		<category><![CDATA[failed]]></category>
		<category><![CDATA[locked out]]></category>
		<category><![CDATA[login]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=173</guid>
		<description><![CDATA[Voici comment se dépatouiller de cette erreur, qui peut se produire lorsque : &#8211; le nombre de tentatives de connexion avec un mot de passe incorrect a dépassé &#8211; et que le nom de connexion est paramétré pour vérifier que &#8230; <a href="https://blog.developpez.com/elsuket/p11379/securite/que-faire-avec-lerreur-18486-login-failed-for-user-unlogin-because-the-account-is-currently-locked-out">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici comment se dépatouiller de cette erreur, qui peut se produire lorsque :</p>
<p>&#8211; le nombre de tentatives de connexion avec un mot de passe incorrect a dépassé<br />
&#8211; et que le nom de connexion est paramétré pour vérifier que les stratégies de mot de passe Windows de l&rsquo;ordinateur sur lequel l&rsquo;instance SQL Server s&rsquo;exécute</p>
<p><span id="more-173"></span></p>
<p>On peut se rendre compte de cette erreur en lisant les journaux de SQL Server, doit depuis l&rsquo;Explorateur d&rsquo;Objets de SQL Server Management Studio, soit en exécutant :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">EXEC xp_readerrorlog 0, 1, 'locked out', NULL, '20121002', '20121003'</div></td></tr></tbody></table></div>
<p>Pour s&rsquo;extraire de cette situation, on peut tout simplement changer le mot de passe; il est de toute façon nécessaire d&rsquo;adjoindre l&rsquo;option UNLOCK à l&rsquo;instruction ALTER LOGIN.<br />
En effet, ceci peut par exemple se produire après une attaque à force brute dans le but de révéler le mot de passe d&rsquo;une connexion.</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ALTER &nbsp; LOGIN [uneConnexion]<br />
WITH&nbsp; &nbsp; PASSWORD = 'unMotDePasse' UNLOCK</div></td></tr></tbody></table></div>
<p>@++ <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trouver et corriger les index uniques (non filtrés) sans contrainte</title>
		<link>https://blog.developpez.com/elsuket/p11206/moteur-de-base-de-donnees-sql-server/indexation/index_unique_sans_contrainte</link>
		<comments>https://blog.developpez.com/elsuket/p11206/moteur-de-base-de-donnees-sql-server/indexation/index_unique_sans_contrainte#comments</comments>
		<pubDate>Wed, 08 Aug 2012 08:16:01 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Exception faite des index unique filtrées, il n&#8217;y aucune différence en termes de performances entre l&#8217;ajout d&#8217;un index unique, et l&#8217;ajout d&#8217;une contrainte d&#8217;unicité (qui est elle-même supportée par un index unique). La contrainte d&#8217;unicité permet de signifier que l’intégrité &#8230; <a href="https://blog.developpez.com/elsuket/p11206/moteur-de-base-de-donnees-sql-server/indexation/index_unique_sans_contrainte">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Exception faite des index unique filtrées, il n&rsquo;y aucune différence en termes de performances entre l&rsquo;ajout d&rsquo;un index unique, et l&rsquo;ajout d&rsquo;une contrainte d&rsquo;unicité (qui est elle-même supportée par un index unique).<br />
La contrainte d&rsquo;unicité permet de signifier que l’intégrité des données est le but, alors que le but premier d&rsquo;un index est l&rsquo;accélération des requêtes.<br />
La majorité des index unique étant ajoutés pour renforcer l’intégrité des données, voici donc un script pour trouver tous les index unique non filtrés qui n&rsquo;ont pas de contrainte d&rsquo;unicité.</p>
<p><span id="more-31"></span></p>
<p>Ce script donne :</p>
<p>&#8211; le nom de la table<br />
&#8211; le nom de l&rsquo;index actuel<br />
&#8211; la liste des colonnes clé de l&rsquo;index<br />
&#8211; le script T-SQL de normalisation du nom de la contrainte d&rsquo;unicité et de suppression de l&rsquo;index actuel.</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 2012-08-08 <br />
------------------------------- <br />
DECLARE @cr char(2) = CHAR(13) + CHAR(10) <br />
&nbsp;<br />
;WITH <br />
&nbsp; CTE AS <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp; &nbsp;S.name AS schema_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; , T.name AS table_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; , I.name AS index_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; , LEFT(KC.key_column_list, LEN(KC.key_column_list) - 1) AS key_column_list <br />
&nbsp; &nbsp; FROM &nbsp; &nbsp;sys.indexes AS I <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.tables AS T <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON I.object_id = T.object_id <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.schemas AS S <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON T.schema_id = S.schema_id <br />
&nbsp; &nbsp; CROSS APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp; &nbsp;CS.name + ', ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; &nbsp;sys.columns AS CS <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INNER JOIN &nbsp;sys.index_columns AS ICS <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON CS.object_id = ICS.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND CS.column_id = ICS.column_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp; &nbsp;I.index_id = ICS.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; &nbsp;I.object_id = ICS.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; &nbsp;ICS.is_included_column = 0 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ORDER BY &nbsp;ICS.index_column_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FOR &nbsp; &nbsp;XML PATH ('') <br />
&nbsp; &nbsp; &nbsp; &nbsp; ) AS KC (key_column_list) <br />
&nbsp; &nbsp; WHERE &nbsp; &nbsp;I.is_unique = 1 -- l'index est unique <br />
&nbsp; &nbsp; AND &nbsp; &nbsp;I.is_primary_key = 0 -- il ne s'agit pas d'un index de clé primaire <br />
&nbsp; &nbsp; AND &nbsp; &nbsp;T.is_ms_shipped = 0 -- il ne s'agit pas d'une table système <br />
&nbsp; &nbsp; AND &nbsp; &nbsp;I.is_unique_constraint = 0 -- l'index n'a pas de contrainte <br />
&nbsp; &nbsp; AND &nbsp; &nbsp;I.has_filter = 0 -- l'index n'est pas filtré <br />
&nbsp; ) <br />
SELECT &nbsp;schema_name + '.' + table_name AS qualified_table_name <br />
&nbsp; , index_name AS current_index_name <br />
&nbsp; , key_column_list <br />
&nbsp; , 'ALTER TABLE ' + schema_name + '.' + table_name + @cr <br />
&nbsp; &nbsp; + 'ADD CONSTRAINT UQ_' + table_name + '__' + REPLACE(key_column_list, ', ', '__') + @cr <br />
&nbsp; &nbsp; + ' &nbsp;UNIQUE (' + key_column_list + ')' + @cr + 'GO' + @cr + @cr <br />
&nbsp; &nbsp; + 'DROP INDEX ' + QUOTENAME(index_name) + ' ON ' + schema_name + '.' + table_name + @cr + 'GO' + @cr + @cr <br />
FROM &nbsp;CTE <br />
ORDER &nbsp;BY table_name</div></td></tr></tbody></table></div>
<p>Bonne gestion des index !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Pourquoi je ne peux pas être supporter de l&#8217;utilisation des plans de maintenance en production</title>
		<link>https://blog.developpez.com/elsuket/p11161/agent-sql-server/supporter_plan_de_maintenance</link>
		<comments>https://blog.developpez.com/elsuket/p11161/agent-sql-server/supporter_plan_de_maintenance#comments</comments>
		<pubDate>Wed, 18 Jul 2012 17:27:08 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Agent SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Après un certain temps de vie, ou après que la structure d&#8217;une base de données de développement ait été copiée depuis celle de production puis modifiée, il arrive que lorsqu&#8217;on recherche les dépendances d&#8217;un objet, dans les tables systèmes ou &#8230; <a href="https://blog.developpez.com/elsuket/p7084/snippets/rafraichir_les_metadonnees_des_modules_s">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Après un certain temps de vie, ou après que la structure d&rsquo;une base de données de développement ait été copiée depuis celle de production puis modifiée, il arrive que lorsqu&rsquo;on recherche les dépendances d&rsquo;un objet, dans les tables systèmes ou en choisissant l&rsquo;option <em>Dépendances</em> du menu contextuel proposé par le clic-droit sur un module SQL (une procédure stockée, une fonction, un trigger, ou une vue définis par l&rsquo;utilisateur), les données ou l&rsquo;affichage soient incorrects, bien que l&rsquo;on soit pourtant certain que l&rsquo;objet que l&rsquo;on vient de modifier dépend bien d&rsquo;un autre.<br />
Voici comment remédier à ce désagrément &#8230;<br />
<span id="more-37"></span></p>
<p>Il suffit pour cela de rafraîchir les métadonnées, avec la procédure stockée système sp_refreshsqlmodule, disponible sous SQL Server 2005 (<strong>SP2</strong>) et ultérieurs.<br />
On peut faire cela pour un module SQL bien particulier, mais a y être, autant le faire pour tous les modules de la base de données en cours :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--------------------------------- <br />
-- Nicolas SOUQUET - 16/01/2009 - <br />
--------------------------------- <br />
DECLARE @nomModule SYSNAME <br />
&nbsp;<br />
-- Recherche du nom de toutes les procédures stockées, fonction scalaires, fonctions table en ligne, &nbsp;<br />
-- fonction table et vues définies dans le contexte de base de données en cours <br />
DECLARE curToRefresh CURSOR FOR <br />
&nbsp; SELECT name <br />
&nbsp; FROM sys.objects <br />
&nbsp; WHERE type IN ('P', 'FN', 'IF', 'TF', 'V') &nbsp;<br />
&nbsp; AND name NOT LIKE 'dt%' <br />
&nbsp; AND name NOT LIKE 'sp%' <br />
&nbsp; ORDER BY name <br />
FOR READ ONLY <br />
&nbsp;<br />
-- Recherche des dépendances pour chacun de ces objets <br />
OPEN curToRefresh <br />
FETCH NEXT FROM curToRefresh INTO @nomModule <br />
WHILE @@FETCH_STATUS = 0 <br />
BEGIN <br />
&nbsp; BEGIN TRY <br />
&nbsp; &nbsp; PRINT 'Procédure : ' + @nomModule <br />
&nbsp; &nbsp; BEGIN TRAN <br />
&nbsp; &nbsp; &nbsp; EXEC sys.sp_refreshsqlmodule @nomModule <br />
&nbsp; &nbsp; COMMIT TRAN <br />
&nbsp; END TRY <br />
&nbsp; BEGIN CATCH <br />
&nbsp; &nbsp; PRINT ' &nbsp;|---------------&gt; ERREUR : ' + ERROR_MESSAGE() <br />
&nbsp; &nbsp; ROLLBACK TRAN <br />
&nbsp; END CATCH <br />
&nbsp; FETCH NEXT FROM curToRefresh INTO @nomModule <br />
END <br />
&nbsp;<br />
DEALLOCATE curToRefresh</div></td></tr></tbody></table></div>
<p>Dès lors vous constaterez que les données contenues dans la vue système sys.sql_dependencies sous SQL Server 2005, ou dans sys.sysdepends dans SQL Server 2000, sont toutes fraîches !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copier un DTS d&#8217;un serveur à un autre</title>
		<link>https://blog.developpez.com/elsuket/p7298/utilitaires/copier_un_dts_d_un_serveur_a_un_autre</link>
		<comments>https://blog.developpez.com/elsuket/p7298/utilitaires/copier_un_dts_d_un_serveur_a_un_autre#comments</comments>
		<pubDate>Sat, 28 Feb 2009 12:22:49 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Integration Services]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

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

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une petite procédure stockée qui affiche dans la console de SSMS le nom du compte de service sous lequel s&#8217;exécute une instance SQL Server : 12345678910111213141516171819202122232425CREATE PROCEDURE spGetSQLServerServiceAccountName AS BEGIN &#160; DECLARE @nomInstance SYSNAME, &#160; &#160; @nomMachine SYSNAME &#160; &#8230; <a href="https://blog.developpez.com/elsuket/p8531/moteur-de-base-de-donnees-sql-server/une_procedure_stockee_pour_trouver_sous">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une petite procédure stockée qui affiche dans la console de SSMS le nom du compte de service sous lequel s&rsquo;exécute une instance SQL Server :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE PROCEDURE spGetSQLServerServiceAccountName <br />
AS <br />
BEGIN <br />
&nbsp; DECLARE @nomInstance SYSNAME, <br />
&nbsp; &nbsp; @nomMachine SYSNAME <br />
&nbsp; &nbsp; <br />
&nbsp; SELECT @nomInstance = CAST(SERVERPROPERTY('InstanceName') AS SYSNAME), <br />
&nbsp; &nbsp; @nomMachine = @@SERVERNAME <br />
&nbsp;<br />
&nbsp; DECLARE @cle NVARCHAR(256), <br />
&nbsp; &nbsp; @compteDeService NVARCHAR(128) <br />
&nbsp; &nbsp; <br />
&nbsp; SELECT @cle = CASE &nbsp;<br />
&nbsp; &nbsp; &nbsp; WHEN @nomInstance IS NULL THEN N'SYSTEM\CurrentControlSet\Services\MSSQLServer' <br />
&nbsp; &nbsp; &nbsp; ELSE N'SYSTEM\CurrentControlSet\Services\MSSQL$' + @nomInstance <br />
&nbsp; &nbsp; END <br />
&nbsp; <br />
&nbsp; EXEC master.dbo.xp_regread N'HKEY_LOCAL_MACHINE', <br />
&nbsp; &nbsp; &nbsp; &nbsp;@cle, <br />
&nbsp; &nbsp; &nbsp; &nbsp;N'ObjectName', <br />
&nbsp; &nbsp; &nbsp; &nbsp;@compteDeService OUTPUT, <br />
&nbsp; &nbsp; &nbsp; &nbsp;N'no_output' <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; PRINT 'Le compte de service est ' + @compteDeService <br />
END</div></td></tr></tbody></table></div>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connaître les caractéristiques d&#8217;une trace SQL Profiler</title>
		<link>https://blog.developpez.com/elsuket/p9016/moteur-de-base-de-donnees-sql-server/connaitre_les_caracteristiques_d_une_tra</link>
		<comments>https://blog.developpez.com/elsuket/p9016/moteur-de-base-de-donnees-sql-server/connaitre_les_caracteristiques_d_une_tra#comments</comments>
		<pubDate>Wed, 16 Jun 2010 06:27:27 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false"></guid>
		<description><![CDATA[La clause IN permet de filtrer une requête sur un ensemble de valeurs, soit en les listant &#171;&#160;en dur&#160;&#187;, soit pas une sous-requête. Si ce n&#8217;est pas un opérateur que j&#8217;affectionne particulièrement puisqu&#8217;il n&#8217;est pas SARGable, en voici une utilisation &#8230; <a href="https://blog.developpez.com/elsuket/p9093/t-sql/puissance_de_la_clause_in">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La clause IN permet de filtrer une requête sur un ensemble de valeurs, soit en les listant &laquo;&nbsp;en dur&nbsp;&raquo;, soit pas une sous-requête.</p>
<p>Si ce n&rsquo;est pas un opérateur que j&rsquo;affectionne particulièrement puisqu&rsquo;il n&rsquo;est pas <a href="http://blog.developpez.com/elsuket/p6886/moteur-de-base-de-donnees-sql-server/sql-searchable-arguments-ou-s-args/">SARGable</a>, en voici une utilisation assez puissante :</p>
<p><span id="more-10"></span></p>
<p>Créons donc la petite table suivante :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE TABLE uneTable &nbsp;<br />
( <br />
&nbsp; id TINYINT IDENTITY <br />
&nbsp; , uneColonne TINYINT <br />
&nbsp; , uneAutreColonne TINYINT <br />
&nbsp; , uneNouvelleColonne TINYINT <br />
) <br />
&nbsp;<br />
INSERT INTO uneTable VALUES (1, 2, 100) <br />
INSERT INTO uneTable VALUES (2, 100, 1) <br />
INSERT INTO uneTable VALUES (100, 1, 2)</div></td></tr></tbody></table></div>
<p>Vous devinez simplement le résultat de la requête suivante :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT &nbsp;id <br />
FROM &nbsp;dbo.uneTable <br />
WHERE &nbsp;uneColonne IN (1, 2)</div></td></tr></tbody></table></div>
<p>qui retourne :</p>
<p>id<br />
&#8212;<br />
1<br />
2</p>
<p>Mais quid ce celle-ci ? <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT &nbsp;id <br />
FROM &nbsp;dbo.uneTable <br />
WHERE &nbsp;1 IN (uneAutreColonne, uneNouvelleColonne)</div></td></tr></tbody></table></div>
<p>id<br />
&#8212;<br />
2<br />
3</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Suivre le nombre de fichiers journaux virtuels du fichier du journal des transactions</title>
		<link>https://blog.developpez.com/elsuket/p9312/moteur-de-base-de-donnees-sql-server/suivre_le_nombre_de_fichiers_journaux_vi</link>
		<comments>https://blog.developpez.com/elsuket/p9312/moteur-de-base-de-donnees-sql-server/suivre_le_nombre_de_fichiers_journaux_vi#comments</comments>
		<pubDate>Thu, 23 Sep 2010 06:00:02 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Avant d&#8217;envisager une réduction du fichier du journal des transactions, il convient de connaître le nombre de fichiers virtuels que contient le fichier du journal des transactions. On peut également envisager de le faire grossir de nouveau pour avoir moins &#8230; <a href="https://blog.developpez.com/elsuket/p9312/moteur-de-base-de-donnees-sql-server/suivre_le_nombre_de_fichiers_journaux_vi">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Avant d&rsquo;envisager une réduction du fichier du journal des transactions,  il convient de connaître  le nombre de fichiers virtuels que contient le fichier du journal des transactions.<br />
On peut également envisager de le faire grossir de nouveau pour avoir moins de fichiers virtuels, et obtenir de meilleures performances pour les transactions manipulant un grand volume de données.<br />
Voyons comment faire cela :</p>
<p><span id="more-104"></span></p>
<p>Il s&rsquo;agit ici d&rsquo;utiliser une bonne vieille commande DBCC <strong>non documentée</strong> : DBCC LOGINFO.<br />
Chaque ligne retournée par l&rsquo;instruction DBCC LOGINFO représente en fait un fichier virtuel.</p>
<p>Sur une base de données de production pour laquelle le fichier du journal des transactions est sauvegardé régulièrement mais où la croissance automatique a été mal gérée, on peut obtenir un grand nombre de fichiers virtuels.</p>
<p>En effet, le fichier du journal des transactions grossit suivant le paramètre d&rsquo;agrandissement de celui-ci pour la base de données considérée.<br />
Si celui-ci est petit, nous aurons un nombre de fichiers virtuels élevé.<br />
D&rsquo;où, encore une fois, l&rsquo;importance de tailler les fichiers de la base de données lors de la création de celle-ci.</p>
<p>En fait, les fichiers virtuel en cours d&rsquo;utilisation ont leur valeur de colonne <em>Status</em> égale à 2.<br />
Si l&rsquo;on veut donc savoir combien sont en cours d&rsquo;utilisation, il suffit d&rsquo;exécuter le petit script suivant :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DECLARE @vlf TABLE <br />
( <br />
&nbsp; &nbsp; FileId tinyint <br />
&nbsp; &nbsp; , FileSize bigint <br />
&nbsp; &nbsp; , StartOffset bigint <br />
&nbsp; &nbsp; , FSeqNo int <br />
&nbsp; &nbsp; , Status tinyint <br />
&nbsp; &nbsp; , Parity tinyint <br />
&nbsp; &nbsp; , CreateLSN varchar(21) <br />
) <br />
&nbsp;<br />
INSERT &nbsp; &nbsp;@vlf <br />
EXEC ('DBCC LOGINFO') <br />
&nbsp;<br />
SELECT &nbsp; &nbsp;SUM(FileSize) / 1048576 AS total_file_size_MB <br />
&nbsp; &nbsp; , SUM <br />
&nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; CASE Status <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 2 THEN FileSize <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE 0 <br />
&nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; ) / 1048576 AS file_size_in_use_MB &nbsp; &nbsp; <br />
&nbsp; &nbsp; , COUNT(*) AS VLF_amount <br />
&nbsp; &nbsp; , SUM <br />
&nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; CASE Status <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 2 THEN 1 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE 0 <br />
&nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; ) AS VLF_in_use <br />
FROM &nbsp; &nbsp;@vlf</div></td></tr></tbody></table></div>
<p>Bonne gestion du fichier du journal des transactions <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>ElSuket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Comment convertir un fichier blg en csv pour l&#8217;intégrer en base rapidement ?</title>
		<link>https://blog.developpez.com/elsuket/p9870/utilitaires/perfmon_blg_en_csv_integration</link>
		<comments>https://blog.developpez.com/elsuket/p9870/utilitaires/perfmon_blg_en_csv_integration#comments</comments>
		<pubDate>Thu, 07 Apr 2011 10:10:52 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[SQL Server Integration Services]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

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

		<guid isPermaLink="false"></guid>
		<description><![CDATA[&#8230; est maintenant disponible ici Bonne Lecture ! ElSüket]]></description>
				<content:encoded><![CDATA[<p>&#8230; est maintenant disponible <a href="http://blogs.technet.com/b/sqlman/archive/2012/05/21/detailed-sql-server-2012-upgrade-technical-guide-now-available.aspx">ici</a></p>
<p>Bonne Lecture !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Une requête pour lister tous les travaux de l&#8217;Agent SQL Server avec leur caractéristiques d&#8217;exécution</title>
		<link>https://blog.developpez.com/elsuket/p11193/agent-sql-server/une_requete_pour_lister_tous_les_travaux</link>
		<comments>https://blog.developpez.com/elsuket/p11193/agent-sql-server/une_requete_pour_lister_tous_les_travaux#comments</comments>
		<pubDate>Mon, 30 Jul 2012 14:20:45 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Agent SQL Server]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une requête qui permet de lister tous les jobs existant sur une instance SQL Server : &#8211; toutes leurs étapes &#8211; la définition de ces étapes (appel à une procédure stockée, exécution d&#8217;un package SSIS, &#8230;) &#8211; la date &#8230; <a href="https://blog.developpez.com/elsuket/p11193/agent-sql-server/une_requete_pour_lister_tous_les_travaux">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une requête qui permet de lister tous les jobs existant sur une instance SQL Server : </p>
<p>&#8211; toutes leurs étapes<br />
&#8211; la définition de ces étapes (appel à une procédure stockée, exécution d&rsquo;un package SSIS, &#8230;)<br />
&#8211; la date et l&rsquo;heure de la prochaine fois que le job sera exécuté<br />
&#8211; la fréquence à laquelle l&rsquo;exécution du job est planifiée, si le job a une planification<br />
&#8211; la date à laquelle le job job a été créé, et à laquelle il a été modifié pour la dernière fois</p>
<p><span id="more-20"></span></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 30/07/2012 <br />
------------------------------- <br />
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED <br />
GO <br />
&nbsp;<br />
SELECT &nbsp; &nbsp;J.name AS job_name <br />
&nbsp; &nbsp; , JS.step_name <br />
&nbsp; &nbsp; , JS.command <br />
&nbsp; &nbsp; , JS.database_name AS database_context <br />
&nbsp; &nbsp; , NR.next_run_date_time <br />
&nbsp; &nbsp; , CASE J.enabled WHEN 1 THEN 'YES' ELSE 'NO' END AS job_is_enabled <br />
&nbsp; &nbsp; , CASE S.enabled WHEN 1 THEN 'YES' ELSE 'NO' END AS job_is_scheduled <br />
&nbsp; &nbsp; , SP.name AS owner_login_name <br />
&nbsp; &nbsp; , CASE S.freq_type <br />
&nbsp; &nbsp; &nbsp; WHEN 1 THEN 'Once' <br />
&nbsp; &nbsp; &nbsp; WHEN 4 THEN 'Daily' <br />
&nbsp; &nbsp; &nbsp; WHEN 8 THEN 'Weekly' <br />
&nbsp; &nbsp; &nbsp; WHEN 16 THEN 'Monthly' <br />
&nbsp; &nbsp; &nbsp; WHEN 32 THEN 'Monthly relative' <br />
&nbsp; &nbsp; &nbsp; WHEN 64 THEN 'When SQL Server Agent starts' <br />
&nbsp; &nbsp; &nbsp; WHEN 128 THEN 'Start whenever the CPU(s) become idle' <br />
&nbsp; &nbsp; END AS frenquency <br />
&nbsp; &nbsp; , CASE S.freq_type <br />
&nbsp; &nbsp; &nbsp; WHEN 1 THEN 'One time only' <br />
&nbsp; &nbsp; &nbsp; WHEN 4 THEN 'Every ' + CASE CONVERT(varchar, S.freq_interval) WHEN '1' THEN 'day' ELSE 'days' END <br />
&nbsp; &nbsp; &nbsp; WHEN 8 THEN 'Every ' + CASE CONVERT(varchar, S.freq_recurrence_factor) WHEN '1' THEN 'week' ELSE 'weeks' END + ' on ' + D.freq_day_concat <br />
&nbsp; &nbsp; &nbsp; WHEN 16 THEN 'Day ' + CONVERT(varchar, S.freq_interval) + ' of every ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; + CASE CONVERT(varchar, S.freq_recurrence_factor) WHEN '1' THEN ' month' ELSE ' months' END <br />
&nbsp; &nbsp; &nbsp; WHEN 32 THEN 'The ' + CASE S.freq_relative_interval <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 1 THEN 'first' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 2 THEN 'second' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 4 THEN 'third' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 8 THEN 'fourth' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 16 THEN 'last' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + ' ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CASE S.freq_interval <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 1 THEN 'Sunday' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 2 THEN 'Monday' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 3 THEN 'Tuesday' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 4 THEN 'Wednesday' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 5 THEN 'Thursday' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 6 THEN 'Friday' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 7 THEN 'Saturday' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 8 THEN 'Day' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 9 THEN 'Weekday' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 10 THEN 'Weekend Day' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + ' of every ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CASE CONVERT(varchar, S.freq_recurrence_factor) WHEN '1' THEN ' month' ELSE ' months' END <br />
&nbsp; &nbsp; END + CASE S.freq_subday_type <br />
&nbsp; &nbsp; &nbsp; WHEN 1 THEN ', once, at ' + AT.start_time <br />
&nbsp; &nbsp; &nbsp; WHEN 2 THEN ', every ' + CONVERT(varchar(10), S.freq_subday_interval) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + ' seconds, starting at ' + AT.start_time <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + ' ending at ' &nbsp;+ AT.end_time <br />
&nbsp; &nbsp; &nbsp; WHEN 4 THEN ', every ' + CONVERT(varchar(10), S.freq_subday_interval) + ' minutes, from ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + AT.start_time + ', to ' + AT.end_time <br />
&nbsp; &nbsp; &nbsp; WHEN 8 THEN ', every ' + CONVERT(varchar(10), S.freq_subday_interval) + ' hours, starting at ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + AT.start_time + ', ending at ' + AT.end_time <br />
&nbsp; &nbsp; END AS frequency_detail <br />
&nbsp; &nbsp; , CASE <br />
&nbsp; &nbsp; &nbsp; WHEN S.freq_type = 1 THEN 'On date: ' + AD.active_start_date + ' At time: ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + AT.start_time <br />
&nbsp; &nbsp; &nbsp; WHEN S.freq_type &lt; 64 THEN 'Start date: ' + AD.active_start_date + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CASE AD.active_end_date <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN '31/12/9999' THEN ' - No end date' &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE ' - End date: ' + AD.active_end_date &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; END AS date_range <br />
&nbsp; &nbsp; , CASE C.name WHEN '[Uncategorized (Local)]' THEN 'Uncategorized' ELSE C.name END AS job_category_name <br />
&nbsp; &nbsp; , J.description AS job_description <br />
&nbsp; &nbsp; , J.date_created &nbsp;<br />
&nbsp; &nbsp; , J.date_modified <br />
FROM &nbsp; &nbsp;msdb.dbo.sysjobs AS J <br />
INNER JOIN &nbsp;msdb.dbo.sysjobsteps AS JS <br />
&nbsp; &nbsp; &nbsp; ON J.job_id = JS.job_id <br />
INNER JOIN &nbsp;msdb.dbo.sysjobschedules AS JSCH <br />
&nbsp; &nbsp; &nbsp; ON J.job_id = JSCH.job_id <br />
INNER JOIN &nbsp;msdb.dbo.sysschedules AS S <br />
&nbsp; &nbsp; &nbsp; ON JSCH.schedule_id = S.schedule_id <br />
INNER JOIN &nbsp;msdb.dbo.syscategories AS C <br />
&nbsp; &nbsp; &nbsp; ON J.category_id = C.category_id <br />
LEFT JOIN &nbsp;sys.server_principals AS SP <br />
&nbsp; &nbsp; &nbsp; ON SP.sid = J.owner_sid <br />
OUTER APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; SELECT &nbsp;freq_day + ', ' <br />
&nbsp; &nbsp; &nbsp; FROM &nbsp;( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT CASE WHEN S.freq_interval &amp; 1 = 1 THEN 'Sunday' ELSE '' END AS freq_day <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UNION ALL SELECT CASE WHEN S.freq_interval &amp; 2 = 2 THEN 'Monday' ELSE '' END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UNION ALL SELECT CASE WHEN S.freq_interval &amp; 4 = 4 THEN 'Tuesday' ELSE '' END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UNION ALL SELECT CASE WHEN S.freq_interval &amp; 8 = 8 THEN 'Wednesday' ELSE '' END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UNION ALL SELECT CASE WHEN S.freq_interval &amp; 16 = 16 THEN 'Thursday' ELSE '' END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UNION ALL SELECT CASE WHEN S.freq_interval &amp; 32 = 32 THEN 'Friday' ELSE '' END <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UNION ALL SELECT CASE WHEN S.freq_interval &amp; 64 = 64 THEN 'Saturday' ELSE '' END <br />
&nbsp; &nbsp; &nbsp; &nbsp; ) AS S <br />
&nbsp; &nbsp; &nbsp; WHERE &nbsp;LEN(freq_day) &gt; 0 <br />
&nbsp; &nbsp; &nbsp; FOR &nbsp;XML PATH ('') <br />
&nbsp; &nbsp; ) AS D (freq_day_concat) <br />
OUTER APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; SELECT &nbsp;STUFF(STUFF(REPLICATE('0', 6 - LEN(S.active_start_time)) &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(S.active_start_time AS varchar(6)), 3, 0, ':'), 6, 0, ':') AS start_time <br />
&nbsp; &nbsp; &nbsp; &nbsp; , STUFF(STUFF(REPLICATE('0', 6 - LEN(S.active_end_time)) &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST(S.active_end_time AS varchar(6)), 3, 0, ':'), 6, 0, ':') AS end_time <br />
&nbsp; &nbsp; ) AS AT <br />
OUTER APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; SELECT &nbsp;CONVERT(char(10), CAST(CAST(S.active_start_date AS char(8)) AS date), 103) AS active_start_date <br />
&nbsp; &nbsp; &nbsp; &nbsp; , CONVERT(char(10), CAST(CAST(S.active_end_date AS char(8)) AS date), 103) AS active_end_date <br />
&nbsp; &nbsp; ) AS AD <br />
OUTER APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; SELECT &nbsp;CAST(NULLIF(JSCH.next_run_date, 0) AS char(8)) + ' ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; + STUFF(STUFF(REPLICATE('0', 6 - LEN(JSCH.next_run_time)) + CAST(JSCH.next_run_time AS char(6)), 3, 0, ':'), 6, 0, ':') AS next_run_date_time <br />
&nbsp; &nbsp; ) AS NR <br />
WHERE &nbsp; &nbsp;1 = 1 <br />
--AND &nbsp; &nbsp;J.name LIKE '%unMot%' <br />
--AND &nbsp; &nbsp;JS.database_name = 'uneBD' <br />
--AND &nbsp; &nbsp;J.enabled &nbsp;= 1 <br />
ORDER BY &nbsp;J.name, JS.step_id</div></td></tr></tbody></table></div>
<p>Bonne planification de job à tous !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Attacher une base de données qui n&#8217;a pas de fichier du journal des transactions</title>
		<link>https://blog.developpez.com/elsuket/p11188/moteur-de-base-de-donnees-sql-server/attacher_base_donnees_sans_tran_log</link>
		<comments>https://blog.developpez.com/elsuket/p11188/moteur-de-base-de-donnees-sql-server/attacher_base_donnees_sans_tran_log#comments</comments>
		<pubDate>Sat, 28 Jul 2012 15:18:35 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false"></guid>
		<description><![CDATA[SQL Server 2008 a introduit la compression native des sauvegardes de base de données. S&#8217;il est simple d&#8217;ajouter l&#8217;option COMPRESSION dans une instruction BACKUP, il est encore mieux de ne même pas avoir à y penser. Pour cela, il suffit &#8230; <a href="https://blog.developpez.com/elsuket/p11176/moteur-de-base-de-donnees-sql-server/compression_par_defaut_sauvegardes">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SQL Server 2008 a introduit la compression native des sauvegardes de base de données.<br />
S&rsquo;il est simple d&rsquo;ajouter l&rsquo;option COMPRESSION dans une instruction BACKUP, il est encore mieux de ne même pas avoir à y penser.<br />
Pour cela, il suffit d&rsquo;activer la compression par défaut de toutes les sauvegardes de base de données.<br />
Notons que cela vaut pour :</p>
<p>&#8211; tous les types de sauvegarde (complète, différentielle, du journal des transactions, partielle, &#8230;)<br />
&#8211; les sauvegardes réalisées à l&rsquo;aide de plans de maintenance.</p>
<p><span id="more-122"></span></p>
<p>Il s&rsquo;agit en fait d&rsquo;une option d&rsquo;instance, nommée <em>backup compression default</em>.<br />
Par défaut elle est désactivée, mais il est très simple de l&rsquo;activer.</p>
<p>=> <strong>Avec la procédure stockée système <em>sp_configure</em></strong> :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">EXEC dbo.sp_configure 'backup compression default', 1 <br />
GO <br />
RECONFIGURE <br />
GO</div></td></tr></tbody></table></div>
<p>=> <strong>Avec <em>SQL Server Management Studio</em></strong> :</p>
<p>Après avoir cliqué-droit sur l&rsquo;instance dans l&rsquo;explorateur d&rsquo;objets (F8), il suffit de se rendre dans la page <em>Options de base de données</em> :</p>
<p><img src="http://blog.developpez.com/media/backup_compression.png" width="704" height="632" alt="" /></p>
<p>Cliquez sur OK et le tour est joué !</p>
<p>Bonnes sauvegardes; n&rsquo;oubliez pas de les tester de temps en temps <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Attention aux types de données money et smallmoney !</title>
		<link>https://blog.developpez.com/elsuket/p11175/moteur-de-base-de-donnees-sql-server/attention_money_smallmoney</link>
		<comments>https://blog.developpez.com/elsuket/p11175/moteur-de-base-de-donnees-sql-server/attention_money_smallmoney#comments</comments>
		<pubDate>Wed, 25 Jul 2012 18:23:18 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[En effet, ces deux types de données produisent des erreurs de calculs. Voici un petit test pour révéler cela : 12345678910111213141516171819202122DECLARE @mon1 smallmoney, &#160; &#160; &#160; &#160;@mon2 smallmoney, &#160; &#160; &#160; &#160;@mon3 smallmoney, &#160; &#160; &#160; &#160;@mon4 smallmoney, &#160; &#160; &#8230; <a href="https://blog.developpez.com/elsuket/p11175/moteur-de-base-de-donnees-sql-server/attention_money_smallmoney">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>En effet, ces deux types de données produisent des erreurs de calculs.<br />
Voici un petit test pour révéler cela :</p>
<p><span id="more-12"></span></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DECLARE @mon1 smallmoney, <br />
&nbsp; &nbsp; &nbsp; &nbsp;@mon2 smallmoney, <br />
&nbsp; &nbsp; &nbsp; &nbsp;@mon3 smallmoney, <br />
&nbsp; &nbsp; &nbsp; &nbsp;@mon4 smallmoney, <br />
&nbsp; &nbsp; &nbsp; &nbsp;@num1 decimal(19,4), <br />
&nbsp; &nbsp; &nbsp; &nbsp;@num2 decimal(19,4), <br />
&nbsp; &nbsp; &nbsp; &nbsp;@num3 decimal(19,4), <br />
&nbsp; &nbsp; &nbsp; &nbsp;@num4 decimal(19,4) <br />
&nbsp;<br />
SELECT @mon1 = 100 <br />
&nbsp; &nbsp; &nbsp; &nbsp;, @mon2 = 339 <br />
&nbsp; &nbsp; &nbsp; &nbsp;, @mon3 = 10000 <br />
&nbsp; &nbsp; &nbsp; &nbsp;--- <br />
&nbsp; &nbsp; &nbsp; &nbsp;, @num1 = 100 <br />
&nbsp; &nbsp; &nbsp; &nbsp;, @num2 = 339 <br />
&nbsp; &nbsp; &nbsp; &nbsp;, @num3 = 10000 <br />
&nbsp;<br />
SELECT @mon4 = @mon1 / @mon2 * @mon3 <br />
&nbsp; &nbsp; &nbsp; &nbsp;, @num4 = @num1 / @num2 * @num3 <br />
&nbsp;<br />
SELECT @mon4 AS money_result <br />
&nbsp; &nbsp; &nbsp; &nbsp;, @num4 AS numeric_result</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/money_error.PNG" width="325" height="507" alt="" /></p>
<p>Attention donc au <a href="http://blog.developpez.com/elsuket/p8233/sql-general/du-choix-des-types-de-donnees/">choix des types de données</a> !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Les posters des privilèges et permissions sous SQL Server 2008 R2, SQL Server 2012 et SQL Azure</title>
		<link>https://blog.developpez.com/elsuket/p11155/securite/poster_privilege_sql_server</link>
		<comments>https://blog.developpez.com/elsuket/p11155/securite/poster_privilege_sql_server#comments</comments>
		<pubDate>Tue, 17 Jul 2012 21:29:45 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Sécurité]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici un lien intéressant qui offre pour chaque version de SQL Server, une vue d&#8217;ensemble des privilèges et permissions que l&#8217;on peut octroyer à un utilisateur ou une connexion, quelle que soit l&#8217;entité. Bonne lecture ! ElSüket]]></description>
				<content:encoded><![CDATA[<p>Voici un lien intéressant qui offre pour chaque version de SQL Server, une vue d&rsquo;ensemble des privilèges et permissions que l&rsquo;on peut octroyer à un utilisateur ou une connexion, quelle que soit l&rsquo;entité.</p>
<p>Bonne <a href="http://social.technet.microsoft.com/wiki/contents/articles/11842.sql-server-database-engine-permission-posters.aspx">lecture</a> !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Une procédure stockée système pour monitorer les verrous</title>
		<link>https://blog.developpez.com/elsuket/p11135/moteur-de-base-de-donnees-sql-server/procedure_monitor_locks</link>
		<comments>https://blog.developpez.com/elsuket/p11135/moteur-de-base-de-donnees-sql-server/procedure_monitor_locks#comments</comments>
		<pubDate>Thu, 05 Jul 2012 02:01:08 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Je viens d&#8217;être nominé MVP SQL Server 2012 en Thaïlande, après avoir été nominé en 2009 en France. Je tiens donc à remercier tous les participants aux forums SQL et SQL Server, ainsi que tout l&#8217;équipe de Développez.com, et plus &#8230; <a href="https://blog.developpez.com/elsuket/p11133/annonces/nomination_mvp_chapitre_2012">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Je viens d&rsquo;être nominé MVP SQL Server 2012 en Thaïlande, après avoir été nominé en 2009 en France.<br />
Je tiens donc à remercier tous les participants aux forums SQL et SQL Server, ainsi que tout l&rsquo;équipe de Développez.com, et plus particulièrement :</p>
<ul>
<li><em>Frédéric Brouard</em>, alias <a href="http://sqlpro.developpez.com/">SQLPro</a></li>
<li><em>David Barbarin</em>, alias <a href="http://blog.developpez.com/mikedavem/">Mikedavem</a></li>
</ul>
<p>qui m&rsquo;ont à la fois soutenu et inspiré, et avec qui nous travaillons sur des publications, mais aussi :</p>
<ul>
<li><em>Panjaporn Vittayalerdpun</em>, Server Business Group Lead</li>
<li><em>Fukiat Julnual</em>, Évangéliste</li>
</ul>
<p>Tous deux travaillent chez Microsoft en Thaïlande, et nous avons travaillé ensemble à la création d&rsquo;une communauté .NET, pour laquelle j&rsquo;anime régulièrement des conférences à Bangkok.</p>
<p>Merci à tous et à bientôt sur le forum !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Les Événements Étendus avec SQL Server 2008</title>
		<link>https://blog.developpez.com/elsuket/p11065/moteur-de-base-de-donnees-sql-server/evenements_etendus_sql_server_2008</link>
		<comments>https://blog.developpez.com/elsuket/p11065/moteur-de-base-de-donnees-sql-server/evenements_etendus_sql_server_2008#comments</comments>
		<pubDate>Sun, 03 Jun 2012 09:13:20 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Annonces]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici un script généreusement publié par Parikshit Savjani, et qui permet d&#8217;obtenir la liste du nom de toutes les instance SQL Server installées sur un serveur. Merci Parikshit, et bon listage à tous]]></description>
				<content:encoded><![CDATA[<p>Voici un <a href="http://blogs.msdn.com/b/sqlserverfaq/archive/2009/03/20/how-to-list-all-the-installed-sql-server-on-the-server-using-tsql.aspx">script</a> généreusement publié par Parikshit Savjani, et qui permet d&rsquo;obtenir la liste du nom de toutes les instance SQL Server installées sur un serveur.</p>
<p>Merci Parikshit, et bon listage à tous <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Comprendre les plans d&#8217;exécution et l&#8217;Optimiseur de requêtes : deux très bons ouvrages</title>
		<link>https://blog.developpez.com/elsuket/p11069/moteur-de-base-de-donnees-sql-server/comprendre_plan_requete_optimiseur</link>
		<comments>https://blog.developpez.com/elsuket/p11069/moteur-de-base-de-donnees-sql-server/comprendre_plan_requete_optimiseur#comments</comments>
		<pubDate>Mon, 04 Jun 2012 08:55:29 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Lecture]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[L&#8217;Optimiseur de Requêtes est l&#8217;organe logiciel au cœur du moteur de base de données de SQL Server. Pour avoir optimisé un grand nombre de requêtes, je dois dire que c&#8217;est une bête incroyable qui continue de m&#8217;étonner : elle continue &#8230; <a href="https://blog.developpez.com/elsuket/p11069/moteur-de-base-de-donnees-sql-server/comprendre_plan_requete_optimiseur">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>L&rsquo;<em>Optimiseur de Requêtes</em> est l&rsquo;organe logiciel au cœur du moteur de base de données de SQL Server.<br />
Pour avoir optimisé un grand nombre de requêtes, je dois dire que c&rsquo;est une bête incroyable qui continue de m&rsquo;étonner : elle continue de faire fonctionner SQL Server avec des performances acceptables alors que le modèle de données laisse souvent à désirer quand ce n&rsquo;est pas pire <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p>Voici donc deux ouvrages qui exposent comment lire les plans d&rsquo;exécution graphiques, et comment l&rsquo;Optimiseur de requêtes fonctionne. Le reste, c&rsquo;est l&rsquo;expérience qui le donne !</p>
<p><span id="more-119"></span></p>
<p>=&gt; <a href="http://www.red-gate.com/community/books/assets/sql-server-execution-plans.pdf">Dissecting SQL Server Execution Plans</a>, par Grant Fritchey</p>
<p>=&gt; <a href="http://www.red-gate.com/products/sql-development/sql-prompt/entrypage/sql-query-optimizer-ebook2">Inside the SQL Server Query Optimizer</a>, par Benjamin Nevarez</p>
<p>Un bon outil pour la lecture facilitée des plans de requêtes graphique, qui plus est gratuit, est <a href="http://blog.developpez.com/elsuket/p10724/utilitaires/sql-sentry-plan-explorer/">SQL Sentry Plan Explorer</a></p>
<p>Bonne lecture !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Une requête pour connaître l&#8217;utilisation des index (et leur définition) : la DMV sys.dm_db_index_usage_stats</title>
		<link>https://blog.developpez.com/elsuket/p11068/moteur-de-base-de-donnees-sql-server/definition_stat_utilisation_index</link>
		<comments>https://blog.developpez.com/elsuket/p11068/moteur-de-base-de-donnees-sql-server/definition_stat_utilisation_index#comments</comments>
		<pubDate>Mon, 04 Jun 2012 08:32:53 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

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

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Implémentation de SQL dans SQL Server longtemps attendue, voici enfin SEQUENCE, qui permet d&#8217;obtenir un nombre augmenté d&#8217;un certain incrément à chaque appel, que l&#8217;on peut partager entre les tables et les utilisateurs d&#8217;une base de données, et bien d&#8217;autre &#8230; <a href="https://blog.developpez.com/elsuket/p11008/t-sql/sql_server_2012_sequence">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Implémentation de SQL dans SQL Server longtemps attendue, voici enfin SEQUENCE, qui permet d&rsquo;obtenir un nombre augmenté d&rsquo;un certain incrément à chaque appel, que l&rsquo;on peut partager entre les tables et les utilisateurs d&rsquo;une base de données, et bien d&rsquo;autre possibilités encore &#8230;<br />
<span id="more-168"></span><br />
<strong>Attention : cet article comporte 6 pages <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></strong></p>
<p>On notera tout d&rsquo;abord qu&rsquo;un objet de type SEQUENCE n&rsquo;est utilisable qu&rsquo;avec des types numériques précis : tinyint, smallint, int, bigint, decimal et numéric, les deux derniers avec une échelle à zéro.</p>
<p>Commençons donc par créer une SEQUENCE de la façon la plus simple qui soit :</p>
<p><code class="codecolorer text default"><span class="text">CREATE SEQUENCE dbo.maSequence</span></code></p>
<p><img src="http://blog.developpez.com/media/sequence_01.PNG" width="289" height="157" alt="" /></p>
<p>C&rsquo;est aussi simple que cela, mais nous allons voir par la suite qu&rsquo;on peut aller un peu plus loin.</p>
<p>Maintenant, comment obtenir la &laquo;&nbsp;première&nbsp;&raquo; valeur de la SEQUENCE dbo.maSequence ?<br />
Là encore, c&rsquo;est relativement simple :</p>
<p><code class="codecolorer text default"><span class="text">SELECT NEXT VALUE FOR dbo.maSequence</span></code></p>
<p><img src="http://blog.developpez.com/media/sequence_02.PNG" width="340" height="204" alt="" /></p>
<p>Donc si l&rsquo;on crée un objet SEQUENCE sans aucune option, le type par défaut est <em>bigint</em>, et la valeur initiale attribuée à cette SEQUENCE est la plus petite valeur que peut stocker le type de données <em>bigint</em>.</p>
<p>Est-ce le cas avec les autres types de données ?</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">SEQUENCE</span> dbo.<span style="color: #202020;">ma_sequence_smallint</span><br />
<span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">smallint</span><br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">VALUE</span> <span style="color: #0000FF;">FOR</span> dbo.<span style="color: #202020;">ma_sequence_smallint</span> <span style="color: #0000FF;">AS</span> next_value_ma_sequence_smallint<br />
GO<br />
<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">SEQUENCE</span> dbo.<span style="color: #202020;">ma_sequence_tinyint</span><br />
<span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">tinyint</span><br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">VALUE</span> <span style="color: #0000FF;">FOR</span> dbo.<span style="color: #202020;">ma_sequence_tinyint</span> <span style="color: #0000FF;">AS</span> next_value_ma_sequence_tinyint<br />
GO</div></td></tr></tbody></table></div>
<p>
<img src="http://blog.developpez.com/media/sequence_03.PNG" width="657" height="422" alt="" /></p>
<p>Rien de surprenant par rapport au comportement par défaut.<br />
En revanche le fait que la SEQUENCE ne commence pas à 1 comme avec les colonnes de type entier auxquelles on confère la propriété d&rsquo;auto-incrémentation à l&rsquo;aide de la clause IDENTITY est appréciable.</p>
<p>Avant de continuer à nous éclairer sur SEQUENCE, voyons comment connaître les propriétés d&rsquo;un tel objet : la vue système <em>sys.sequences</em> est là pour cela :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> sequence_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , T.<span style="color: #202020;">name</span> <span style="color: #0000FF;">AS</span> sequence_data_type_name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , S.<span style="color: #202020;">start_value</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , S.<span style="color: #202020;">increment</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , S.<span style="color: #202020;">minimum_value</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , S.<span style="color: #202020;">maximum_value</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , S.<span style="color: #202020;">is_cycling</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , S.<span style="color: #202020;">cache_size</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , S.<span style="color: #202020;">current_value</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , S.<span style="color: #202020;">is_exhausted</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">sequences</span> <span style="color: #0000FF;">AS</span> S<br />
<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; sys.<span style="color: #202020;">types</span> <span style="color: #0000FF;">AS</span> T<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> S.<span style="color: #202020;">system_type_id</span> <span style="color: #808080;">=</span> T.<span style="color: #202020;">system_type_id</span></div></td></tr></tbody></table></div>
<p>Ce qui retourne :</p>
<p><img src="http://blog.developpez.com/media/sequence_04.PNG" width="1126" height="376" alt="" /></p>
<p>Je passerai sur la description des colonnes jusqu&rsquo;à <em>maximum_value</em>, et sur <em>current_value</em> puisque leur nom est suffisamment explicite.</p>
<p>La colonne <em>is_cycling</em> nous montre qu&rsquo;il est possible de faire boucler la SEQUENCE, c&rsquo;est à dire de la faire revenir à sa valeur de départ.<br />
La colonne <em>cache_size</em> indique le nombre de valeurs qui est mise en cache. Nous verrons la notion de cache de SEQUENCE par la suite.<br />
Enfin la colonne <em>is_exhausted</em> indique s&rsquo;il est encore possible de générer de nouveaux nombres à partir de celle-ci.</p>
<p>On retrouve les objets SEQUENCE dans l&rsquo;Explorateur d&rsquo;Objets, avec les fonctionnalités accessibles par clic-droit que l&rsquo;on connaît :</p>
<p><img src="http://blog.developpez.com/media/sequence_05.PNG" width="336" height="520" alt="" /></p>
<p>Après un clic sur <em>Propriétés</em> :</p>
<p><img src="http://blog.developpez.com/media/sequence_06.png" width="457" height="759" alt="" /></p>
<p>On obtient la fenêtre suivante :</p>
<p><img src="http://blog.developpez.com/media/sequence_07.png" width="756" height="681" alt="" /></p>
<p>On peut aussi créer une SEQUENCE décrémentielle, simplement en spécifiant un incrément négatif :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">SEQUENCE</span> uneSequenceDecrementielle<br />
<span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">int</span><br />
<span style="color: #0000FF;">START</span> <span style="color: #0000FF;">WITH</span> <span style="color: #000;">0</span><br />
<span style="color: #808080;">IN</span>CREMENT <span style="color: #0000FF;">BY</span> <span style="color: #808080;">-</span><span style="color: #000;">5</span><br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">VALUE</span> <span style="color: #0000FF;">FOR</span> uneSequenceDecrementielle<br />
<span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">VALUE</span> <span style="color: #0000FF;">FOR</span> uneSequenceDecrementielle<br />
<span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">VALUE</span> <span style="color: #0000FF;">FOR</span> uneSequenceDecrementielle<br />
<span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">VALUE</span> <span style="color: #0000FF;">FOR</span> uneSequenceDecrementielle<br />
<span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">VALUE</span> <span style="color: #0000FF;">FOR</span> uneSequenceDecrementielle</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/sequence_08.png" /></p>
<p>On peut également changer l&rsquo;incrément en cours de route à l&rsquo;aide d&rsquo;une instruction ALTER SEQUENCE :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">SEQUENCE</span> dbo.<span style="color: #202020;">uneSequenceDecrementielle</span><br />
<span style="color: #808080;">IN</span>CREMENT <span style="color: #0000FF;">BY</span> <span style="color: #808080;">-</span><span style="color: #000;">2</span><br />
GO<br />
<br />
<span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">VALUE</span> <span style="color: #0000FF;">FOR</span> uneSequenceDecrementielle</div></td></tr></tbody></table></div>
<p>
<img src="http://blog.developpez.com/media/sequence_09.png" /></p>
<p>Il est également possible, comme le suggère la colonne <em>maximum_value</em> de la vue <em>sys.sequences</em>, mettre une valeur maximale à cette séquence.<br />
Il faut bien sûr dans ce cas que la valeur maximale de la séquence prenne en compte la valeur de départ, sinon celle-ci ne serait pas générable :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">SEQUENCE</span> dbo.<span style="color: #202020;">uneSequenceDecrementielle</span><br />
MAXVALUE <span style="color: #808080;">-</span><span style="color: #000;">30</span><br />
GO</div></td></tr></tbody></table></div>
<p>
<img src="http://blog.developpez.com/media/sequence_10.png" /></p>
<p>Ici comme la séquence est décrémentielle, SQL Server rejette l&rsquo;instruction ALTER SEQUENCE puisque nous avions spécifié que la SEQUENCE démarre à zéro.</p>
<p>Si nous changeons par MINVALUE :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">SEQUENCE</span> dbo.<span style="color: #202020;">uneSequenceDecrementielle</span><br />
MAXVALUE <span style="color: #808080;">-</span><span style="color: #000;">30</span><br />
GO</div></td></tr></tbody></table></div>
<p>
<img src="http://blog.developpez.com/media/sequence_11.png" /></p>
<p>Voici un message d&rsquo;avertissement intéressant : nous n&rsquo;avons pas spécifié de valeur pour la taille du cache de la SEQUENCE, mais SQL Server en a mis une par défaut &#8230;<br />
J&rsquo;ai tenté de savoir quelle est la taille du cache par défaut, et comment SQL Server stocke celle-ci en utilisant une connexion d&rsquo;administrateur dédiée (DAC), mais il semble que SQL Server réalise cela dans des tables internes.<br />
Si quelqu&rsquo;un découvre cela, merci de le poster en commentaire <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Etude de table : retourner les caractéristiques des statistiques et index d&#8217;une table (ou vue indexée)</title>
		<link>https://blog.developpez.com/elsuket/p11051/moteur-de-base-de-donnees-sql-server/indexation/etude_index_stat_table</link>
		<comments>https://blog.developpez.com/elsuket/p11051/moteur-de-base-de-donnees-sql-server/indexation/etude_index_stat_table#comments</comments>
		<pubDate>Mon, 28 May 2012 14:15:24 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici un script qui retourne : &#8211; l&#8217;en-tête des statistiques d&#8217;une table &#8211; la liste des colonnes qui participent à la statistique, ou des colonnes clé de l&#8217;index (incluses et filtrées) &#8211; le vecteur de la statistique, qui permet de &#8230; <a href="https://blog.developpez.com/elsuket/p11051/moteur-de-base-de-donnees-sql-server/indexation/etude_index_stat_table">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici un script qui retourne :</p>
<p>&#8211; l&rsquo;en-tête des statistiques d&rsquo;une table<br />
&#8211; la liste des colonnes qui participent à la statistique, ou des colonnes clé de l&rsquo;index (incluses et filtrées)<br />
&#8211; le vecteur de la statistique, qui permet de connaître sa sélectivité<br />
&#8211; optionnellement, le niveau de fragmentation des index<br />
&#8211; le nombre d&rsquo;utilisation des index<br />
&#8211; la date de dernière mise à jour de chaque statistique scrutée par le script</p>
<p><span id="more-115"></span></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br />313<br />314<br />315<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">----------------------------------------- <br />
-- 28/05/2012 - Copyright Nicolas Souquet <br />
----------------------------------------- <br />
&nbsp;<br />
SET NOCOUNT ON <br />
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED <br />
GO <br />
&nbsp;<br />
------------------------------------------------------------------------------------------------------------------------------ <br />
DECLARE &nbsp;@schema_name sysname = 'dbo' <br />
&nbsp; , @table_or_indexed_view_name sysname = 'maTable' <br />
&nbsp; , @statistic_name sysname = NULL -- NULL effectue l'étude pour toutes les statistiques ou index de la table <br />
&nbsp; --- <br />
&nbsp; , @index_study bit = 1 -- mettre à 1 pour indiquer si l'on souhaite regarder la fragmentation des index, 0 sinon <br />
&nbsp; , @index_scan_level_mode varchar(8) = 'LIMITED' -- scan level mode (DETAILED, SAMPLED, LIMITED) &nbsp;<br />
&nbsp; --- <br />
&nbsp; , @separator varchar(2) = ', ' <br />
------------------------------------------------------------------------------------------------------------------------------ <br />
-- NE RIEN CHANGER APRÈS CETTE LIGNE <br />
------------------------------------------------------------------------------------------------------------------------------ <br />
IF (SELECT OBJECT_ID('TEMPDB.dbo.#STUDY')) IS NOT NULL <br />
BEGIN <br />
&nbsp; DROP TABLE #STUDY <br />
END <br />
&nbsp;<br />
------------------------------------------------------------------------------ <br />
-- Vérifie que la table ou vue indexée existe dans la base de données en cours <br />
------------------------------------------------------------------------------ <br />
DECLARE @object_type char(1) <br />
&nbsp;<br />
SELECT &nbsp; &nbsp;@object_type = O.type <br />
FROM &nbsp; &nbsp;sys.schemas AS S <br />
INNER JOIN &nbsp;sys.objects AS O ON S.schema_id = O.schema_id <br />
WHERE &nbsp; &nbsp;S.name = @schema_name <br />
AND &nbsp; &nbsp;O.name = @table_or_indexed_view_name <br />
AND &nbsp; &nbsp;O.type IN ('U', 'V') -- table ou vue (indexée) <br />
&nbsp;<br />
IF @object_type IS NULL <br />
BEGIN <br />
&nbsp; RAISERROR('La table ou vue indexée ''%s.%s'' n''existe pas !', 16, 1, @schema_name, @table_or_indexed_view_name) <br />
&nbsp; RETURN <br />
END <br />
&nbsp;<br />
-- Seules les vues indexées on des statistiques <br />
IF @object_type = 'V' <br />
AND NOT EXISTS <br />
( <br />
&nbsp; SELECT &nbsp; &nbsp;* <br />
&nbsp; FROM &nbsp; &nbsp;sys.schemas AS S <br />
&nbsp; INNER JOIN &nbsp;sys.views AS V ON S.schema_id = V.schema_id <br />
&nbsp; INNER JOIN &nbsp;sys.indexes AS I ON V.object_id = I.object_id <br />
&nbsp; WHERE &nbsp; &nbsp;S.name = @schema_name <br />
&nbsp; AND &nbsp; &nbsp;V.name = @table_or_indexed_view_name <br />
) <br />
BEGIN <br />
&nbsp; RAISERROR('The %s.%s view is not indexed !', 16, 1, @schema_name, @table_or_indexed_view_name) <br />
&nbsp; RETURN <br />
END <br />
&nbsp;<br />
DECLARE @qualified_table_or_indexed_view_name nvarchar(256) = @schema_name + '.' + @table_or_indexed_view_name <br />
&nbsp;<br />
-------------------------------------------------- <br />
-- Collecte des statistiques de colonne et d'index <br />
-------------------------------------------------- <br />
DECLARE &nbsp;@stat_header TABLE <br />
( <br />
&nbsp; stat_name varchar(256) <br />
&nbsp; , updated varchar(32) <br />
&nbsp; , row_count bigint <br />
&nbsp; , rows_sampled bigint <br />
&nbsp; , steps int <br />
&nbsp; , density float <br />
&nbsp; , avg_key_length float <br />
&nbsp; , string_index char(3) <br />
&nbsp; , filter_expression varchar(1024) &nbsp;<br />
&nbsp; , unfiltered_rows bigint <br />
) <br />
&nbsp;<br />
DECLARE @density_vector TABLE <br />
( <br />
&nbsp; all_density float <br />
&nbsp; , average_length float <br />
&nbsp; , column_list varchar(1024) <br />
) <br />
&nbsp;<br />
DECLARE @stat_name_density_vector TABLE <br />
( <br />
&nbsp; stat_name varchar(256) <br />
&nbsp; , all_density float <br />
) <br />
&nbsp;<br />
DECLARE @stat_name varchar(256) = ' ' <br />
&nbsp; , @object_id int <br />
&nbsp; , @sql_stat_header nvarchar(256) = 'DBCC SHOW_STATISTICS(@TABLE@, @STATS@) WITH STAT_HEADER, NO_INFOMSGS' <br />
&nbsp; , @sql_density_vector nvarchar(256) = 'DBCC SHOW_STATISTICS(@TABLE@, @STATS@) WITH DENSITY_VECTOR, NO_INFOMSGS' <br />
&nbsp; , @exec_string nvarchar(512) <br />
&nbsp;<br />
WHILE DATALENGTH(@stat_name) &gt; 0 <br />
BEGIN <br />
&nbsp; SET @stat_name = NULL <br />
&nbsp;<br />
&nbsp; SELECT &nbsp; &nbsp;TOP(1) @stat_name = QUOTENAME(D.name) <br />
&nbsp; FROM &nbsp; &nbsp;sys.stats AS D <br />
&nbsp; INNER JOIN &nbsp;sys.objects AS O ON D.object_id = O.object_id <br />
&nbsp; INNER JOIN &nbsp;sys.schemas AS S ON O.schema_id = S.schema_id <br />
&nbsp; LEFT JOIN &nbsp;@stat_header AS SH ON D.name = SH.stat_name <br />
&nbsp; WHERE &nbsp; &nbsp;S.name = @schema_name <br />
&nbsp; AND &nbsp; &nbsp;O.name = @table_or_indexed_view_name <br />
&nbsp; AND &nbsp; &nbsp;SH.stat_name IS NULL <br />
&nbsp; AND &nbsp; &nbsp;(@statistic_name IS NULL OR D.name = @statistic_name) <br />
&nbsp; <br />
&nbsp; -- Statistics header <br />
&nbsp; SELECT @exec_string = REPLACE(REPLACE(@sql_stat_header, '@STATS@', @stat_name), '@TABLE@', '''' + @schema_name + '.' + @table_or_indexed_view_name &nbsp;+ '''') <br />
&nbsp;<br />
&nbsp; INSERT &nbsp;@stat_header <br />
&nbsp; EXEC &nbsp;(@exec_string) <br />
&nbsp; <br />
&nbsp; -- Density vector <br />
&nbsp; SELECT @exec_string = REPLACE(REPLACE(@sql_density_vector, '@STATS@', @stat_name), '@TABLE@', '''' + @schema_name + '.' + @table_or_indexed_view_name &nbsp;+ '''') <br />
&nbsp; <br />
&nbsp; INSERT &nbsp;@density_vector (all_density, average_length, column_list) <br />
&nbsp; EXEC &nbsp;(@exec_string) <br />
&nbsp; <br />
&nbsp; INSERT &nbsp;INTO @stat_name_density_vector <br />
&nbsp; SELECT &nbsp;TOP 1 @stat_name <br />
&nbsp; &nbsp; , all_density <br />
&nbsp; FROM &nbsp;@density_vector <br />
&nbsp; ORDER &nbsp;BY average_length <br />
&nbsp; <br />
&nbsp; DELETE &nbsp;FROM @density_vector <br />
END <br />
----------------------------------------------------------------------------------------------------------------------- <br />
;WITH <br />
&nbsp; INDEX_CTE AS <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp; &nbsp;DISTINCT I.name AS index_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; , I.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , PS.partition_number <br />
&nbsp; &nbsp; &nbsp; &nbsp; , PS.row_count <br />
&nbsp; &nbsp; &nbsp; &nbsp; , I.type_desc <br />
&nbsp; &nbsp; &nbsp; &nbsp; , I.is_unique <br />
&nbsp; &nbsp; &nbsp; &nbsp; , I.is_unique_constraint <br />
&nbsp; &nbsp; &nbsp; &nbsp; , I.is_primary_key <br />
&nbsp; &nbsp; &nbsp; &nbsp; , LEFT(KC.key_column_list, LEN(KC.key_column_list) - LEN(@separator)) AS key_column_list <br />
&nbsp; &nbsp; &nbsp; &nbsp; , LEFT(KCI.included_column_list, LEN(KCI.included_column_list) - 1) AS included_column_list <br />
&nbsp; &nbsp; &nbsp; &nbsp; , REPLACE(REPLACE(REPLACE(REPLACE(I.filter_definition, '[', ''), ']', ''), '(', ''), ')', '') AS filter_definition <br />
&nbsp; &nbsp; &nbsp; &nbsp; , STATS_DATE(O.object_id, I.index_id) AS last_stat_update <br />
&nbsp; &nbsp; &nbsp; &nbsp; , IUS.user_seeks <br />
&nbsp; &nbsp; &nbsp; &nbsp; , IUS.user_scans <br />
&nbsp; &nbsp; &nbsp; &nbsp; , IUS.user_lookups <br />
&nbsp; &nbsp; &nbsp; &nbsp; , (IUS.user_seeks + IUS.user_scans + IUS.user_lookups) AS total_user_searches <br />
&nbsp; &nbsp; &nbsp; &nbsp; , IUS.user_updates <br />
&nbsp; &nbsp; &nbsp; &nbsp; , LS.max_last_search_date <br />
&nbsp; &nbsp; &nbsp; &nbsp; , I.is_disabled &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; , (PS.reserved_page_count * 8192) / 1024 AS index_size_kb <br />
&nbsp; &nbsp; &nbsp; &nbsp; , IPS.index_level <br />
&nbsp; &nbsp; &nbsp; &nbsp; , IPS.index_depth <br />
&nbsp; &nbsp; &nbsp; &nbsp; , CAST(IPS.avg_fragmentation_in_percent AS decimal(5, 2)) AS avg_frag_pct <br />
&nbsp; &nbsp; &nbsp; &nbsp; , I.fill_factor <br />
&nbsp; &nbsp; &nbsp; &nbsp; , IPS.forwarded_record_count <br />
&nbsp; &nbsp; FROM &nbsp; &nbsp;sys.schemas AS S <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.objects AS O <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON S.schema_id = O.schema_id <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.indexes AS I &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON O.object_id = I.object_id <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.index_columns AS IC <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON IC.object_id = I.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND IC.index_id = I.index_id <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.columns AS C <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON IC.object_id = C.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND IC.column_id = C.column_id <br />
&nbsp; &nbsp; LEFT JOIN &nbsp;sys.dm_db_index_usage_stats AS IUS <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON IUS.object_id = I.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND IUS.index_id = I.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND IUS.database_id = DB_ID() <br />
&nbsp; &nbsp; LEFT JOIN &nbsp;( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , database_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , index_level <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , index_depth <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , avg_fragmentation_in_percent <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , forwarded_record_count <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp;sys.dm_db_index_physical_stats <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DB_ID() -- database <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , OBJECT_ID(@table_or_indexed_view_name) -- all tables <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , NULL -- all indexes <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , NULL -- all partitions <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , @index_scan_level_mode -- scan level mode (DETAILED, SAMPLED, LIMITED) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;@index_study = 1 <br />
&nbsp; &nbsp; &nbsp; &nbsp; ) AS IPS <br />
&nbsp; &nbsp; &nbsp; &nbsp; ON IPS.object_id = I.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; AND IPS.index_id = I.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; AND IPS.database_id = DB_ID() <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.dm_db_partition_stats AS PS <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON PS.object_id = I.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND PS.index_id = I.index_id <br />
&nbsp; &nbsp; CROSS APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp; &nbsp;CS.name + CASE ICS.is_descending_key WHEN 1 THEN ' DESC' ELSE '' END + @separator <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; &nbsp;sys.columns AS CS <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INNER JOIN &nbsp;sys.index_columns AS ICS <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON CS.object_id = ICS.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND CS.column_id = ICS.column_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp; &nbsp;IC.object_id = ICS.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; &nbsp;IC.index_id = ICS.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; &nbsp;ICS.is_included_column = 0 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ORDER BY &nbsp;ICS.index_column_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FOR XML PATH ('') <br />
&nbsp; &nbsp; &nbsp; &nbsp; ) AS KC (key_column_list) <br />
&nbsp; &nbsp; OUTER APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp; &nbsp;CSI.name + @separator <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; &nbsp;sys.columns AS CSI <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INNER JOIN &nbsp;sys.index_columns AS ICSI <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON CSI.object_id = ICSI.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND CSI.column_id = ICSI.column_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp; &nbsp;IC.object_id = ICSI.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; &nbsp;IC.index_id = ICSI.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp; &nbsp;ICSI.is_included_column = 1 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ORDER BY &nbsp;ICSI.index_column_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FOR XML PATH ('') <br />
&nbsp; &nbsp; &nbsp; &nbsp; ) AS KCI (included_column_list) <br />
&nbsp; &nbsp; OUTER APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;MAX(M.last_search_date) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp;( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;LU_USK.last_user_seek <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp;sys.dm_db_index_usage_stats AS LU_USK <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;IUS.database_id = LU_USK.database_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.object_id = LU_USK.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.index_id = LU_USK.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UNION ALL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;LU_USC.last_user_scan <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp;sys.dm_db_index_usage_stats AS LU_USC <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;IUS.database_id = LU_USC.database_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.object_id = LU_USC.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.index_id = LU_USC.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UNION ALL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;LU_LK.last_user_lookup <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp;sys.dm_db_index_usage_stats AS LU_LK <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;IUS.database_id = LU_LK.database_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.object_id = LU_LK.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND &nbsp;IUS.index_id = LU_LK.index_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) AS M (last_search_date) <br />
&nbsp; &nbsp; &nbsp; &nbsp; ) AS LS (max_last_search_date) <br />
&nbsp; &nbsp; WHERE &nbsp; &nbsp;(@schema_name IS NULL OR S.name = @schema_name) <br />
&nbsp; &nbsp; AND &nbsp; &nbsp;(@table_or_indexed_view_name IS NULL OR O.name = @table_or_indexed_view_name) <br />
&nbsp; &nbsp; AND &nbsp; &nbsp;(@stat_name IS NULL OR I.name = @stat_name) <br />
&nbsp; ) <br />
SELECT &nbsp; &nbsp;COALESCE(C.type_desc, 'STAT') AS type_desc <br />
&nbsp; &nbsp; , CAST(SH.density AS decimal(7,6)) AS header <br />
&nbsp; &nbsp; , SNDV.all_density AS vector <br />
&nbsp; &nbsp; , C.row_count <br />
&nbsp; &nbsp; , SH.stat_name <br />
&nbsp; &nbsp; , COALESCE(C.key_column_list, LEFT(SC.stat_column_list, LEN(SC.stat_column_list) - 1)) AS stat_column_list <br />
&nbsp; &nbsp; , C.included_column_list <br />
&nbsp; &nbsp; , C.index_id <br />
&nbsp; &nbsp; , C.partition_number <br />
&nbsp; &nbsp; , C.is_disabled <br />
&nbsp; &nbsp; , C.is_unique AS is_uq <br />
&nbsp; &nbsp; , C.is_unique_constraint AS is_uqc <br />
&nbsp; &nbsp; , C.is_primary_key AS is_PK <br />
&nbsp; &nbsp; , REPLACE(REPLACE(REPLACE(REPLACE(SH.filter_expression, '[', ''), ']', ''), '(', ''), ')', '') AS filter_definition <br />
&nbsp; &nbsp; , SH.row_count AS stat_row_count <br />
&nbsp; &nbsp; , COALESCE(C.row_count, SH.row_count) AS real_row_count <br />
&nbsp; &nbsp; , SI.rowmodctr <br />
&nbsp; &nbsp; , SH.rows_sampled <br />
&nbsp; &nbsp; , C.index_size_kb <br />
&nbsp; &nbsp; , STATS_DATE(D.object_id, D.stats_id) AS last_stat_update <br />
&nbsp; &nbsp; , C.user_seeks <br />
&nbsp; &nbsp; , C.user_scans <br />
&nbsp; &nbsp; , C.user_lookups &nbsp; &nbsp;<br />
&nbsp; &nbsp; , C.total_user_searches <br />
&nbsp; &nbsp; , C.user_updates <br />
&nbsp; &nbsp; , C.max_last_search_date <br />
&nbsp; &nbsp; , C.index_depth <br />
&nbsp; &nbsp; , C.avg_frag_pct <br />
&nbsp; &nbsp; , C.index_level <br />
&nbsp; &nbsp; , CASE <br />
&nbsp; &nbsp; &nbsp; WHEN COALESCE(C.type_desc, 'STAT') = 'STAT' THEN NULL <br />
&nbsp; &nbsp; &nbsp; WHEN C.index_level = 0 THEN 'LEAF' <br />
&nbsp; &nbsp; &nbsp; WHEN C.index_depth - C.index_level &gt; 1 THEN 'INTERMEDIATE' <br />
&nbsp; &nbsp; &nbsp; ELSE 'ROOT' <br />
&nbsp; &nbsp; END AS index_level_type <br />
&nbsp; &nbsp; , C.forwarded_record_count <br />
INTO &nbsp; &nbsp;#STUDY <br />
FROM &nbsp; &nbsp;@stat_header AS SH <br />
INNER JOIN &nbsp;@stat_name_density_vector AS SNDV <br />
&nbsp; &nbsp; &nbsp; ON QUOTENAME(SH.stat_name) = SNDV.stat_name <br />
LEFT JOIN &nbsp;INDEX_CTE AS C <br />
&nbsp; &nbsp; &nbsp; ON SH.stat_name = C.index_name <br />
INNER JOIN &nbsp;sys.stats AS D <br />
&nbsp; &nbsp; &nbsp; ON D.object_id = OBJECT_ID(@schema_name + '.' + @table_or_indexed_view_name) <br />
&nbsp; &nbsp; &nbsp; AND D.name = SH.stat_name <br />
INNER JOIN &nbsp;sys.sysindexes AS SI <br />
&nbsp; &nbsp; &nbsp; ON SI.id = D.object_id <br />
&nbsp; &nbsp; &nbsp; AND SI.indid = D.stats_id <br />
CROSS APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; SELECT &nbsp; &nbsp;C.name + ',' <br />
&nbsp; &nbsp; &nbsp; FROM &nbsp; &nbsp;sys.stats AS S <br />
&nbsp; &nbsp; &nbsp; INNER JOIN &nbsp;sys.stats_columns AS SC <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON S.object_id = SC.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND S.stats_id = SC.stats_id <br />
&nbsp; &nbsp; &nbsp; INNER JOIN &nbsp;sys.columns AS C <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON C.object_id = SC.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND C.column_id = SC.column_id <br />
&nbsp; &nbsp; &nbsp; WHERE &nbsp; &nbsp;SH.stat_name = S.name <br />
&nbsp; &nbsp; &nbsp; ORDER BY &nbsp;SC.stats_column_id <br />
&nbsp; &nbsp; &nbsp; FOR XML PATH ('') <br />
&nbsp; &nbsp; ) AS SC (stat_column_list) <br />
ORDER BY &nbsp;stat_name <br />
&nbsp;<br />
SELECT &nbsp;* <br />
FROM &nbsp;#STUDY <br />
ORDER &nbsp;BY type_desc</div></td></tr></tbody></table></div>
<p>Bonne étude de table !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Les nouvelles fonctions T-SQL de SQL Server 2012 &#8211; Episode 2/8 &#8211; FORMAT()</title>
		<link>https://blog.developpez.com/elsuket/p10976/sql-server-2012/sql_server_2012nouvelles_fonctions_forma</link>
		<comments>https://blog.developpez.com/elsuket/p10976/sql-server-2012/sql_server_2012nouvelles_fonctions_forma#comments</comments>
		<pubDate>Tue, 01 May 2012 04:42:11 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Nouvelles fonctions T-SQL]]></category>
		<category><![CDATA[SQL Server 2012]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[A l&#8217;épisode précédent, nous avions abordé les possibilités offertes par la nouvelle fonction PARSE(). Poursuivons avec FORMAT(), qui est une extension de CONVERT(), puisqu&#8217;elle est plus ouverte aux différentes cultures &#8230; et beaucoup plus ! Tout d&#8217;abord, la syntaxe : &#8230; <a href="https://blog.developpez.com/elsuket/p10976/sql-server-2012/sql_server_2012nouvelles_fonctions_forma">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>A l&rsquo;<a href="http://blog.developpez.com/elsuket/c3210/sql-server-2012/nouvelles-fonctions-t-sql/">épisode</a> précédent, nous avions abordé les possibilités offertes par la nouvelle fonction <a href="http://blog.developpez.com/elsuket/p10950/sql-server-2012/sql-server-2012-nouvelles-fonctions-pars/">PARSE()</a>.</p>
<p>Poursuivons avec FORMAT(), qui est une extension de CONVERT(), puisqu&rsquo;elle est plus ouverte aux différentes cultures &#8230; et beaucoup plus !<br />
<span id="more-167"></span><br />
Tout d&rsquo;abord, la syntaxe :</p>
<p><code class="codecolorer text default"><span class="text">FORMAT (valeur, format [, culture ])</span></code></p>
<p>Comme avec PARSE() :</p>
<p>&#8211; la nouveauté c&rsquo;est qu&rsquo;on peut formater une valeur suivant une culture (33 cultures disponibles !)<br />
&#8211; les types supportés par cette fonction : bigint, int, smallint, tinyint, decimal, numeric, float, real, smallmoney, money, date, time, datetime, smalldatetime, datetime2 et datetimeoffset.<br />
&#8211; on ne peut pas utiliser PARSE() pour exécuter une requête sur un serveur distant, car celle-ci dépend du .NET Framework 3.5 SP1 , et que rien ne garantit qu&rsquo;il est présent sur la machine distante.</p>
<p>On remarquera que les types de données de chaînes de caractère, comme pour PARSE(), ne sont pas supportés.<br />
Dès lors, on ne peut pas s&rsquo;attendre à pouvoir passer une date au format ISO dans une chaîne de caractères, et que cela fonctionne :</p>
<p><img src="http://blog.developpez.com/media/format_01.PNG" width="551" height="166" alt="" /></p>
<p>=> <strong>Formatage des dates</strong></p>
<p>Commençons avec quelques exemples sur les dates, qui sont généralement assez recherchés.<br />
Voyons sans la culture d&rsquo;abord :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DECLARE @dt date = '20120102' <br />
&nbsp;<br />
SELECT &nbsp;FORMAT(@dt, N'dddd, MMM dd, yyyy') AS anglo_saxon_date_format_0 <br />
&nbsp; , FORMAT(@dt, N'dddd dd MMMM yyyy') AS anglo_saxon_date_format_1 <br />
&nbsp; , FORMAT(@dt, N'dd-MM-yyyy') AS French_numeric_format <br />
&nbsp; , FORMAT(@dt, N'yyyyMMdd') AS ISO_format <br />
&nbsp; , FORMAT(@dt, N'yyyyMMdd HH:mm:ss.000') AS ISO_format_with_time</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/format_02.PNG" width="699" height="241" alt="" /></p>
<p>Et avec la culture :</p>
<p><img src="http://blog.developpez.com/media/format_03.PNG" width="617" height="243" alt="" /></p>
<p>On peut maintenant apprendre les bases d&rsquo;une langue tout en codant <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p>En revanche le formatage composite n&rsquo;est pas directement supporté :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DECLARE @dt date = '20120102' <br />
&nbsp;<br />
SELECT &nbsp;FORMAT(@dt, N'Nous sommes le dddd dd MMMM yyyy', 'fr-FR')</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/format_04.PNG" width="552" height="187" alt="" /></p>
<p>Attention donc, car les lettres qui correspondent à des parties de date sont automatiquement remplacées, sans qu&rsquo;une erreur ne soit levée.</p>
<p>Essayons d&rsquo;éviter ces lettres :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DECLARE @dt date = '20120102' <br />
&nbsp;<br />
SELECT &nbsp;FORMAT(@dt, N'Now : dddd dd MMMM yyyy', 'en-US')</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/format_05.PNG" width="504" height="179" alt="" /></p>
<p>Mais il s&rsquo;agit là d&rsquo;un jeu dangereux.<br />
Voyons si on peut les échapper. Est-ce que le classique anti-slash va fonctionner ?</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DECLARE @dt date = '20120102' <br />
&nbsp;<br />
SELECT &nbsp;FORMAT(@dt, N'Nou\s \so\m\me\s le dddd dd MMMM yyyy', 'fr-FR')</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/format_07.PNG" width="580" height="195" alt="" /></p>
<p>Il faut reconnaître que c&rsquo;est assez tortueux pour ne pas dire <em><a href="http://fr.wikipedia.org/wiki/Programmation_spaghetti">spaghetti</a></em>.<br />
Par extension, on pourra créer une fonction en T-SQL qui effectue automatiquement l’échappement de ces caractères &#8230;</p>
<p>=> <strong>Examinons maintenant les formats raccourcis</strong> :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DECLARE @dt date = '20120102' <br />
&nbsp;<br />
SELECT &nbsp;FORMAT(@dt, 'D', 'fr-FR') AS weekday_litteral_FR <br />
&nbsp; , FORMAT(@dt, 'D', 'en-US') AS weekday_litteral_US <br />
&nbsp; , FORMAT(@dt, 'd', 'fr-FR') AS decimal_date_FR <br />
&nbsp; , FORMAT(@dt, 'd', 'en-US') AS decimal_date_US <br />
&nbsp; , FORMAT(@dt, 'm', 'fr-FR') AS month_date_litteral_FR <br />
&nbsp; , FORMAT(@dt, 'm', 'en-US') AS month_date_litteral_US <br />
&nbsp; , FORMAT(@dt, 'M', 'fr-FR') AS month_date_litteral_FR_case <br />
&nbsp; , FORMAT(@dt, 'M', 'en-US') AS month_date_litteral_US_case</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/format_08.PNG" width="1100" height="293" alt="" /></p>
<p>Attention donc à la casse dans les formats !<br />
On notera que le zéro non-significatif disparaît au format Français, mais demeure au format Anglo-saxon.</p>
<p>J&rsquo;ai trouvé ceux-ci à tâtons. Voyons les dans leur ensemble :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DECLARE @now datetime = GETDATE() <br />
&nbsp; , @amount decimal(6,2) = 1234.56 <br />
&nbsp; , @integer int = 123456 <br />
&nbsp; , @percent decimal(3,2) = 0.76 <br />
&nbsp; , @fr char(5) = 'fr-FR' <br />
&nbsp; , @us char(5) = 'en-US' <br />
&nbsp;<br />
SELECT &nbsp; &nbsp;'Currency 1' AS label, @fr AS culture, 'FORMAT(@amount, ''c'', @fr)' AS sql, FORMAT(@amount, 'c', @fr) AS exemple <br />
UNION ALL &nbsp;SELECT 'Currency 2' AS label, @us AS culture, 'FORMAT(@amount, ''c'', @us)', FORMAT(@amount, 'c', @us) AS exemple <br />
-- <br />
UNION ALL &nbsp;SELECT 'Currency 3', @fr, 'FORMAT(@amount, ''C'', @fr)', FORMAT(@amount, 'C', @fr) <br />
UNION ALL &nbsp;SELECT 'Currency 4', @us, 'FORMAT(@amount, ''C'', @us)', FORMAT(@amount, 'C', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Decimal 1', @fr, 'FORMAT(@integer, ''d'', @fr)', FORMAT(@integer, 'd', @fr) <br />
UNION ALL &nbsp;SELECT 'Decimal 2', @us, 'FORMAT(@integer, ''d'', @us)', FORMAT(@integer, 'd', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Decimal 3', @fr, 'FORMAT(@integer, ''D'', @fr)', FORMAT(@integer, 'D', @fr) <br />
UNION ALL &nbsp;SELECT 'Decimal 4', @us, 'FORMAT(@integer, ''D'', @us)', FORMAT(@integer, 'D', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Decimal 5', @fr, 'FORMAT(@integer, ''D8'', @fr)', FORMAT(@integer, 'D8', @fr) <br />
UNION ALL &nbsp;SELECT 'Decimal 6', @us, 'FORMAT(@integer, ''D8'', @us)', FORMAT(@integer, 'D8', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Full date time, short time 1', @fr, 'FORMAT(@now, ''f'', @fr)', FORMAT(@now, 'f', @fr) <br />
UNION ALL &nbsp;SELECT 'Full date time, short time 2', @us, 'FORMAT(@now, ''f'', @us)', FORMAT(@now, 'f', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Full date time, long time 1', @fr, 'FORMAT(@now, ''F'', @fr)', FORMAT(@now, 'F', @fr) <br />
UNION ALL &nbsp;SELECT 'Full date time, long time 2', @us, 'FORMAT(@now, ''F'', @us)', FORMAT(@now, 'F', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'General date time, short time 1', @fr, 'FORMAT(@now, ''g'', @fr)', FORMAT(@now, 'g', @fr) <br />
UNION ALL &nbsp;SELECT 'General date time, short time 2', @us, 'FORMAT(@now, ''g'', @us)', FORMAT(@now, 'g', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'General date time, long time 1', @fr, 'FORMAT(@now, ''G'', @fr)', FORMAT(@now, 'G', @fr) <br />
UNION ALL &nbsp;SELECT 'General date time, long time 2', @us, 'FORMAT(@now, ''G'', @us)', FORMAT(@now, 'G', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Short time 1', @fr, 'FORMAT(@now, ''t'', @fr)', FORMAT(@now, 't', @fr) <br />
UNION ALL &nbsp;SELECT 'Short time 2', @us, 'FORMAT(@now, ''t'', @us)', FORMAT(@now, 't', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Long time 1', @fr, 'FORMAT(@now, ''T'', @fr)', FORMAT(@now, 'T', @fr) <br />
UNION ALL &nbsp;SELECT 'Long time 2', @us, 'FORMAT(@now, ''T'', @us)', FORMAT(@now, 'T', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Numeric 1', @fr, 'FORMAT(@amount, ''n'', @fr)', FORMAT(@amount, 'n', @fr) <br />
UNION ALL &nbsp;SELECT 'Numeric 2', @us, 'FORMAT(@amount, ''n'', @us)', FORMAT(@amount, 'n', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Numeric 3', @fr, 'FORMAT(@amount, ''N'', @fr)', FORMAT(@amount, 'N', @fr) <br />
UNION ALL &nbsp;SELECT 'Numeric 4', @us, 'FORMAT(@amount, ''N'', @us)', FORMAT(@amount, 'N', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Numeric 5', @fr, 'FORMAT(@amount, ''N0'', @fr)', FORMAT(@amount, 'N0', @fr) <br />
UNION ALL &nbsp;SELECT 'Numeric 6', @us, 'FORMAT(@amount, ''N0'', @us)', FORMAT(@amount, 'N0', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Numeric 7', @fr, 'FORMAT(@amount, ''N1'', @fr)', FORMAT(@amount, 'N1', @fr) <br />
UNION ALL &nbsp;SELECT 'Numeric 8', @us, 'FORMAT(@amount, ''N1'', @us)', FORMAT(@amount, 'N1', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Percentage 1', @fr, 'FORMAT(@percent, ''p'', @fr)', FORMAT(@percent, 'p', @fr) <br />
UNION ALL &nbsp;SELECT 'Percentage 2', @us, 'FORMAT(@percent, ''p'', @us)', FORMAT(@percent, 'p', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Percentage 3', @fr, 'FORMAT(@percent, ''P0'', @fr)', FORMAT(@percent, 'P0', @fr) <br />
UNION ALL &nbsp;SELECT 'Percentage 4', @us, 'FORMAT(@percent, ''P0'', @us)', FORMAT(@percent, 'P0', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Percentage 5', @fr, 'FORMAT(@percent, ''P1'', @fr)', FORMAT(@percent, 'P1', @fr) <br />
UNION ALL &nbsp;SELECT 'Percentage 6', @us, 'FORMAT(@percent, ''P1'', @us)', FORMAT(@percent, 'P1', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Hexadecimal 1', @fr, 'FORMAT(@integer, ''x'', @fr)', FORMAT(@integer, 'x', @fr) <br />
UNION ALL &nbsp;SELECT 'Hexadecimal 2', @us, 'FORMAT(@integer, ''x'', @us)', FORMAT(@integer, 'x', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Hexadecimal 3', @fr, 'FORMAT(@integer, ''X'', @fr)', FORMAT(@integer, 'X', @fr) <br />
UNION ALL &nbsp;SELECT 'Hexadecimal 4', @us, 'FORMAT(@integer, ''X'', @us)', FORMAT(@integer, 'X', @us) <br />
-- <br />
UNION ALL &nbsp;SELECT 'Hexadecimal 5', @fr, 'FORMAT(@integer, ''X10'', @fr)', FORMAT(@integer, 'X10', @fr) <br />
UNION ALL &nbsp;SELECT 'Hexadecimal 6', @us, 'FORMAT(@integer, ''X10'', @us)', FORMAT(@integer, 'X10', @us)</div></td></tr></tbody></table></div>
<p><img src="http://img17.imageshack.us/img17/5430/format12.png" alt="" title="" /></p>
<p>On voit donc que pour le formatage de données :</p>
<p>&#8211; numériques, la casse du format court n&rsquo;a pas d&rsquo;importance<br />
&#8211; numériques, on peut ajouter un chiffre au format court qui indique soit le nombre de décimales, soit la largeur de la mantisse<br />
&#8211; numériques de devise, la culture change bien évidemment le résultat<br />
&#8211; de date, la casse est importante, de même que la culture</p>
<p>=> <strong>Étudions les devises plus en détails</strong> :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT &nbsp;FORMAT(1234.56, 'C', 'en-US') AS US_format <br />
&nbsp; , FORMAT(1234.56, 'C', 'fr-FR') AS French_format <br />
&nbsp; , FORMAT(1234.56, 'C', 'de-DE') AS German_format <br />
&nbsp; , FORMAT(1234.56, 'C', 'en-GB') AS UK_format <br />
&nbsp; , FORMAT(1234.56, 'C', 'sv-SE') AS Swedish_format <br />
&nbsp; , FORMAT(1234.56, 'C', 'th-TH') AS Thai_format <br />
&nbsp; , FORMAT(1234.56, 'C', 'ar-SA') AS Arabic_format</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/format_13.PNG" width="615" height="246" alt="" /></p>
<p>On voit que les formats de devises sont rigoureusement respectés, notamment en ce qui concerne les points et les virgules : les anglo-saxons utilisent la virgule comme séparateur des puissances de 10 multiples de 3, alors que les Latins utilisent le point; et inversement pour les parties décimales.<br />
De même la prise en compte des pays membres de la Zone Euro ont tous leur devise préfixée ou suffixée par le symbole €, alors que le Royaume-Uni et la Suède, qui n&rsquo;en sont pas membres, ont bien évidemment conservé respectivement les symboles de la Livre Sterling et de la Couronne Suédoise.</p>
<p>Une petite remarque : en Arabe, la notation retournée par SQL Server n&rsquo;est strictement identique à ce que l&rsquo;on observe rien qu&rsquo;en collant cette valeur de fenêtre de résultats dans la fenêtre de requêtes de <em>SQL Server Management Studio</em> :</p>
<p><img src="http://blog.developpez.com/media/format_09.PNG" width="452" height="54" alt="" /></p>
<p>J&rsquo;ai essayé de faire traduire automatiquement par <em>Google Translate</em>, mais le résultat retourné est <em>R.. Q. 1,234.56</em>.<br />
Si vous pouvez expliquer ce qui s&rsquo;est passé, n&rsquo;hésitez pas à poster un commentaire !</p>
<p>=> <strong>Les masques pour les valeurs numériques</strong></p>
<p>Les masques permettent de spécifier le nombre de décimales pour une valeur numérique, et si l&rsquo;on en a besoin, d&rsquo;ajouter des symboles dans la valeur formatée à l&rsquo;aide de la position :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DECLARE @uneValeur decimal(6,2) = 1234.56 <br />
&nbsp;<br />
SELECT &nbsp;FORMAT(@uneValeur, '##,##0.00') AS exemple_1 <br />
&nbsp; , FORMAT(@uneValeur, '#,##0.00') AS exemple_2 <br />
&nbsp; , FORMAT(@uneValeur, '#,#0.00') AS exemple_3 <br />
&nbsp; , FORMAT(@uneValeur, '#,#0.0') AS exemple_4 <br />
&nbsp; , FORMAT(@uneValeur, '#,#0') AS exemple_5 <br />
&nbsp; , FORMAT(@uneValeur, '#0') AS exemple_6 <br />
&nbsp; , FORMAT(@uneValeur, '#0.0') AS exemple_7 <br />
&nbsp; , FORMAT(@uneValeur, '#0.00') AS exemple_8 <br />
&nbsp; , FORMAT(@uneValeur, '#0.000') AS exemple_9 <br />
&nbsp; , FORMAT(@uneValeur, '#|#0.000') AS exemple_10 <br />
&nbsp; , FORMAT(@uneValeur, '#\#0.000') AS exemple_11</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/format_14.PNG" width="817" height="341" alt="" /></p>
<p>Dans les colonnes exemple_2 et exemple_10, on a respectivement placé :</p>
<p>&#8211; une virgule avant les trois derniers chiffres de la partie entière de la valeur décimale<br />
&#8211; un pipe avant les deux derniers chiffres de la partie entière de la valeur décimale</p>
<p>Dans la colonne exemple_11, l&rsquo;antislash étant un caractère d&rsquo;échappement, il y a donc un symbole <em>dièse</em> qui sera intercalé entre le dernier et l&rsquo;avant-dernier chiffre de la partie entière de la valeur décimale.</p>
<p>De la même façon que ce que nous avons vu avec les formats courts, on peut aussi préciser le nombre de chiffres significatifs de la partie décimale d&rsquo;une telle valeur.<br />
Si le nombre de chiffres significatifs de la partie décimale :</p>
<p>&#8211; est plus petit que celui de la valeur passée en paramètre, alors la valeur formatée est arrondie<br />
&#8211; est plus grand que celui de la valeur passée en paramètre, alors la valeur formatée est suivie d&rsquo;autant de zéros que la différence entre le nombre de chiffres significatifs de la partie décimale et le nombre de chiffres de la partie décimale du masque de formatage.</p>
<p>Bon FORMATage de données à tous !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Consulter ou télécharger les documentations de SQL Server</title>
		<link>https://blog.developpez.com/elsuket/p10996/utilitaires/telecharger_documentation_sql_server</link>
		<comments>https://blog.developpez.com/elsuket/p10996/utilitaires/telecharger_documentation_sql_server#comments</comments>
		<pubDate>Sun, 29 Apr 2012 08:56:12 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Jusqu&#8217;à SQL Server 2008, l&#8217;aide de SQL Server, aussi connue sous le nom de SQL Server Books OnLine ou BOL, était installable localement en même temps qu&#8217;une instance SQL Server. Cela a changé avec SQL Server 2012, qui démarre automatiquement &#8230; <a href="https://blog.developpez.com/elsuket/p10966/sql-server-2012/installer_aid_sql_server_2012_local">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Jusqu&rsquo;à SQL Server 2008, l&rsquo;aide de SQL Server, aussi connue sous le nom de <em>SQL Server Books OnLine</em> ou <em>BOL</em>, était installable localement en même temps qu&rsquo;une instance SQL Server.<br />
Cela a changé avec SQL Server 2012, qui démarre automatiquement <em>Internet Explorer</em> et ouvre la page qui correspond à ce que l&rsquo;on a surligné avant de presser F1.</p>
<p>Si c&rsquo;est efficace et que l&rsquo;on peut comprendre pourquoi Microsoft a décidé de ne plus inclure les fichiers d&rsquo;aide dans le package d&rsquo;installation de SQL Server (poids plus léger, simplicité de maintenance de l&rsquo;aide, et tous les développeurs et DBAs en en général accès à Internet), que se passe-t-il si l&rsquo;on a besoin de consulter la documentation de SQL Server sur un serveur de production, qui n&rsquo;a généralement pas d&rsquo;accès à Internet pour des raisons de sécurité ? C&rsquo;est aussi pratique pour les favoris, qui permettent de consulter la syntaxe d&rsquo;une commande fréquemment utilisée mais dont on ne retient pas forcément toutes les options et subtilités.</p>
<p>On peut toujours installer celle-ci localement. Voyons comment procéder &#8230;<br />
<span id="more-166"></span><br />
Il faut d&rsquo;abord paramétrer SQL Server Management Studio 2012 pour indiquer que l&rsquo;on préfère consulter l&rsquo;aide localement.<br />
Pour ce faire, il suffit de cliquer sur <em>Help</em> puis <em>Manage Help Settings</em> :</p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale01.png" width="801" height="247" alt="" /></p>
<p>Puis de choisir entre l&rsquo;aide locale et l&rsquo;aide en ligne :</p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale03.png" width="574" height="390" alt="" /></p>
<p>Ce qui sera fait très simplement après avoir changé le bouton radio sur :</p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale05_01.png" width="571" height="388" alt="" /></p>
<p>Il faut ensuite procéder au téléchargement des fichiers :</p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale06.png" width="572" height="389" alt="" /></p>
<p>La recherche de fichiers d&rsquo;aide s&rsquo;effectue en quelques secondes :</p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale07.png" width="571" height="388" alt="" /></p>
<p>et l&rsquo;on obtient la liste de nombreuses aides de produits <em>Microsoft</em> :</p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale08.png" width="571" height="389" alt="" /></p>
<p>Il suffit de faire défiler jusqu&rsquo;à trouver celle de SQL Server, et de cliquer sur <em>Add</em> :</p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale09.png" width="570" height="388" alt="" /></p>
<p>S&rsquo;ensuit le téléchargement qui dure quelques secondes :</p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale10.png" width="572" height="391" alt="" /></p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale11.png" width="571" height="390" alt="" /></p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale12.jpg" width="565" height="383" alt="" /></p>
<p>Après un clic sur le bouton Finish, on peut quitter :</p>
<p><img src="http://img834.imageshack.us/img834/7645/sqlserver2012installaid.png" alt="" title="" /></p>
<p>Voyons maintenant comment tout cela se présente : essayons de consulter l&rsquo;aide de <code class="codecolorer text default"><span class="text">CREATE TABLE</span></code> :</p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale14.png" width="773" height="300" alt="" /></p>
<p>Après avoir surligné l&rsquo;instruction et pressé F1, l&rsquo;application <em>Help Viewer</em> démarre (c&rsquo;est très rapide).<br />
L&rsquo;application demeure accessible à partir de zone de notification (regardez bien en bas à droite de la capture ci-dessous) :</p>
<p><img src="http://img835.imageshack.us/img835/7645/sqlserver2012installaid.png" alt="" title="" /></p>
<p>L&rsquo;application s&rsquo;ouvre directement sur la documentation de l&rsquo;instruction <code class="codecolorer text default"><span class="text">CREATE TABLE</span></code> :</p>
<p><img src="http://img705.imageshack.us/img705/7645/sqlserver2012installaid.png" alt="" title="" /></p>
<p>Et on retrouve le bouton d&rsquo;ajout aux favoris :</p>
<p><img src="http://blog.developpez.com/media/sql_server_2012_install_aide_locale17.png" width="659" height="426" alt="" /></p>
<p>La recherche de la documentation d&rsquo;autres instructions se fait tout aussi aisément et rapidement : voyons <code class="codecolorer text default"><span class="text">CREATE INDEX</span></code> :</p>
<p><img src="http://img845.imageshack.us/img845/7645/sqlserver2012installaid.png" alt="" title="" /></p>
<p>Toutes les instructions contenant les deux mots apparaissent dans le panneau de navigation, à gauche, avec un extrait du début de la documentation de chacune des instructions trouvées :</p>
<p><img src="http://img812.imageshack.us/img812/7645/sqlserver2012installaid.png" alt="" title="" /></p>
<p>Cliquons sur la première, puisque c&rsquo;est celle qui nous intéresse :</p>
<p><img src="http://img853.imageshack.us/img853/7645/sqlserver2012installaid.png" alt="" title="" /></p>
<p>Documentez-vous bien, car les ajouts de fonctionnalités et <a href="http://blog.developpez.com/elsuket/c3210/sql-server-2012/nouvelles-fonctions-t-sql/">nouvelles fonctions T-SQL</a> dans <a href="http://blog.developpez.com/elsuket/c3209/sql-server-2012/">SQL Server 2012</a> sont nombreux !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Les nouvelles fonctions T-SQL de SQL Server 2012 &#8211; Episode 1/8 &#8211; PARSE() &#8211;</title>
		<link>https://blog.developpez.com/elsuket/p10950/t-sql/sql_server_2012_nouvelles_fonctions_pars</link>
		<comments>https://blog.developpez.com/elsuket/p10950/t-sql/sql_server_2012_nouvelles_fonctions_pars#comments</comments>
		<pubDate>Mon, 16 Apr 2012 12:18:57 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Nouvelles fonctions T-SQL]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Je vous propose de découvrir les 14 nouvelles fonctions que SQL Server 2012 introduit, en dédiant un billet soit à chacune d&#8217;entre-elles, ou bien à un groupe d&#8217;entre-elles. Commençons avec la fonction PARSE() &#8230; La syntaxe d&#8217;utilisation de cette fonction &#8230; <a href="https://blog.developpez.com/elsuket/p10950/t-sql/sql_server_2012_nouvelles_fonctions_pars">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Je vous propose de découvrir les 14 nouvelles fonctions que SQL Server 2012 introduit, en dédiant un billet soit à chacune d&rsquo;entre-elles, ou bien à un groupe d&rsquo;entre-elles.</p>
<p>Commençons avec la fonction PARSE() &#8230;<br />
<span id="more-165"></span><br />
La syntaxe d&rsquo;utilisation de cette fonction est la suivante :</p>
<p><code class="codecolorer text default"><span class="text">PARSE('&lt;uneValeur&gt;' AS &lt;data_type&gt; [USING '&lt;culture&gt;'])</span></code></p>
<p>La nouveauté c&rsquo;est la possibilité de formater une valeur suivant une culture, et ce n&rsquo;est pas moins de 33 cultures qui sont disponibles !<br />
De façon générale, cette fonction est une extension de ce que l&rsquo;on peut faire avec CONVERT().<br />
Rappelons dans les deux cas qu&rsquo;il s&rsquo;agit de fonctions de formatage de données.</p>
<p>On notera que :</p>
<p>&#8211; <em>data_type</em> est limité aux types suivants : bigint, int, smallint, tinyint, decimal, numeric, float, real, smallmoney, money, date, time, datetime, smalldatetime, datetime2 et datetimeoffset.</p>
<p>&#8211; On ne peut pas utiliser PARSE() pour exécuter une requête sur un serveur distant, car celle-ci dépend du .NET Framework 3.5 SP1 , et que rien ne garantit qu&rsquo;il est présent sur la machine distante.</p>
<p>Faisons quelques essais !</p>
<p><code class="codecolorer text default"><span class="text">SELECT PARSE ('100.000' AS int)</span></code></p>
<p><img src="http://blog.developpez.com/media/parse_01.PNG" width="469" height="153" alt="" /></p>
<p>Alors qu&rsquo;un <code class="codecolorer text default"><span class="text">SELECT CONVERT(int, '100.000')</span></code> :</p>
<p><img src="http://blog.developpez.com/media/parse_02.png" width="625" height="167" alt="" /></p>
<p>Essayons un <code class="codecolorer text default"><span class="text">SELECT PARSE('Lundi 16 Avril 2012' AS datetime USING 'fr-FR')</span></code></p>
<p><img src="http://blog.developpez.com/media/parse_03.PNG" width="528" height="154" alt="" /></p>
<p>Voyons au format Anglo-Saxon : <code class="codecolorer text default"><span class="text">SELECT PARSE('Monday 16 April 2012' AS datetime USING 'en-US')</span></code></p>
<p><img src="http://blog.developpez.com/media/parse_04.PNG" width="527" height="168" alt="" /></p>
<p>Quid du format que l&rsquo;on nous a donné à l&rsquo;école ? <code class="codecolorer text default"><span class="text">SELECT PARSE('Monday, April 16 2012' AS datetime USING 'en-US')</span></code></p>
<p><img src="http://blog.developpez.com/media/parse_05.png" width="529" height="162" alt="" /></p>
<p>En revanche <code class="codecolorer text default"><span class="text">SELECT PARSE('Monday, April 16th 2012' AS datetime USING 'en-US')</span></code></p>
<p><img src="http://blog.developpez.com/media/parse_06.PNG" width="751" height="155" alt="" /></p>
<p>Essayons <code class="codecolorer text default"><span class="text">SELECT PARSE('April, 16 2012' AS datetime USING 'en-US')</span></code></p>
<p><img src="http://blog.developpez.com/media/parse_07.png" width="517" height="164" alt="" /></p>
<p>Voyons avec une date du calendrier Grégo-Thaï : en effet, le calendrier Grégo-Thaï à 543 ans d&rsquo;avance sur le calendrier Grégorien :<br />
<code class="codecolorer text default"><span class="text">SELECT PARSE(N'16 &amp;#3648;&amp;#3617;&amp;#3625;&amp;#3634;&amp;#3618;&amp;#3609; 2555' AS datetime USING 'Th-TH')</span></code></p>
<p><img src="http://blog.developpez.com/media/parse_08.PNG" width="516" height="158" alt="" /></p>
<p>Et avec des variables ?</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DECLARE @date_string char(20) = 'Lundi 16 Avril 2012' <br />
&nbsp; , @culture char(5) = 'fr-FR' <br />
&nbsp;<br />
SELECT PARSE(@date_string AS datetime USING @culture)</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/parse_09.PNG" width="524" height="216" alt="" /></p>
<p>Et dans une table :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE TABLE test_PARSE <br />
( <br />
&nbsp; date_string nvarchar(20) <br />
&nbsp; , culture char(5) <br />
&nbsp; , formatted_date AS (PARSE(date_string AS datetime USING culture)) <br />
) <br />
GO <br />
&nbsp;<br />
INSERT &nbsp;INTO dbo.test_PARSE <br />
VALUES &nbsp;(N'Lundi 16 Avril 2012', 'fr-FR'), (N'16 &amp;#3648;&amp;#3617;&amp;#3625;&amp;#3634;&amp;#3618;&amp;#3609; 2555', 'th-TH') <br />
GO <br />
&nbsp;<br />
SELECT &nbsp;* <br />
FROM &nbsp;dbo.test_PARSE</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/parse_10.PNG" width="597" height="376" alt="" /></p>
<p>Vous vous demandez s&rsquo;il sera possible de retourner une valeur décimale avec le symbole de la devise suivant une culture ? la réponse est oui : avec la fonction FORMAT(), que nous verrons au prochain épisode <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
<p>Bon formatage de données !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Le petit lien qui fait du bien dans l&#8217;historique des jobs de l&#8217;Agent SQL Server 2012</title>
		<link>https://blog.developpez.com/elsuket/p10965/agent-sql-server/ssms_2012_job_historique_lien_definition</link>
		<comments>https://blog.developpez.com/elsuket/p10965/agent-sql-server/ssms_2012_job_historique_lien_definition#comments</comments>
		<pubDate>Thu, 19 Apr 2012 17:52:22 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Agent SQL Server]]></category>
		<category><![CDATA[SQL Server 2012]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Un petit lien bien agréable a été ajouté dans la visionneuse de l&#8217;historique des jobs de SQL Server dans la version 2012 de SQL Server Management Studio On peut consulter l&#8217;historique d&#8217;un job simplement en effectuant un clic-droit sur le &#8230; <a href="https://blog.developpez.com/elsuket/p10965/agent-sql-server/ssms_2012_job_historique_lien_definition">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Un petit lien bien agréable a été ajouté dans la visionneuse de l&rsquo;historique des jobs de SQL Server dans la version 2012 de <em>SQL Server Management Studio</em><br />
<span id="more-18"></span><br />
On peut consulter l&rsquo;historique d&rsquo;un job simplement en effectuant un clic-droit sur le job en question :</p>
<p><img src="http://blog.developpez.com/media/job_lien_0.png" width="434" height="663" alt="" /></p>
<p>La fenêtre du journal s&rsquo;ouvre alors :</p>
<p><img src="http://blog.developpez.com/media/job_lien_1.jpg" width="838" height="533" alt="" /></p>
<p>Et ce nouveau lien nous permet d&rsquo;accéder directement à la définition du job, ce qui n&rsquo;était pas la cas jusqu&rsquo;à <em>SQL Server Management Studio 2008</em> :</p>
<p><img src="http://blog.developpez.com/media/job_lien_2.png" width="704" height="632" alt="" /></p>
<p>Bonne gestion des jobs !</p>
<p>@++ <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Différence entre ALTER INDEX &#8230; REBUILD et ALTER INDEX &#8230; REORGANIZE</title>
		<link>https://blog.developpez.com/elsuket/p10897/moteur-de-base-de-donnees-sql-server/indexation/difference_alter_index_rebuild_reorganiz</link>
		<comments>https://blog.developpez.com/elsuket/p10897/moteur-de-base-de-donnees-sql-server/indexation/difference_alter_index_rebuild_reorganiz#comments</comments>
		<pubDate>Sat, 31 Mar 2012 11:02:52 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Après avoir vu ce que sont la fragmentation interne et externe d&#8217;un index, voyons les différences entre les options REBUILD et REORGANIZE de l&#8217;instruction ALTER INDEX (ou respectivement DBCC DBREINDEX ou DBCC INDEXDEFRAG sous SQL Server 2000) => REBUILD est &#8230; <a href="https://blog.developpez.com/elsuket/p10897/moteur-de-base-de-donnees-sql-server/indexation/difference_alter_index_rebuild_reorganiz">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Après avoir vu ce que sont la <a href="http://blog.developpez.com/elsuket/p7894/indexation/difference-entre-fragmentation-interne-e/">fragmentation interne et externe d&rsquo;un index</a>, voyons les différences entre les options REBUILD et REORGANIZE de l&rsquo;instruction ALTER INDEX (ou respectivement DBCC DBREINDEX ou DBCC INDEXDEFRAG sous SQL Server 2000)<br />
<span id="more-30"></span><br />
=> REBUILD est une opération atomique, alors que REORGANIZE ne l&rsquo;est pas.<br />
Cela signifie que si l&rsquo;on arrête une instruction ALTER INDEX &#8230; REBUILD en cours d&rsquo;exécution, tout le travail du moteur de base de données effectué jusqu’au moment de l&rsquo;arrêt de l&rsquo;exécution de l&rsquo;instruction est perdu. Ce n&rsquo;est pas le cas de REORGANIZE.</p>
<p>=> REORGANIZE ne fait que ré-arranger le niveau feuille de l&rsquo;index, et n&rsquo;alloue ou ne désalloue aucune page.<br />
En revanche, REBUILD reconstruit tous les niveaux de l&rsquo;index, et se sert au besoin de nouvelles pages, de façon à réduire la fragmentation interne et externe de l&rsquo;index. REORGANIZE ne fait que réduire la fragmentation logique de l&rsquo;index, de sorte à minimiser, si ce n&rsquo;est éviter, les aller-retours dans les pages de l&rsquo;index lors de la lecture de celui-ci.</p>
<p>=> REBUILD est exécutée hors-ligne par défaut.<br />
Dans ce cas, on ne peut pas mettre à jour la table sous-jacente s&rsquo;il s&rsquo;agit de son index cluster, et on ne peut pas changer les colonnes qui participent à la définition d&rsquo;un index non-cluster tant que l&rsquo;instruction ALTER INDEX &#8230; REBUILD est en cours d&rsquo;exécution.</p>
<p>REORGANIZE ne maintient pas ces verrous, et permet donc de continuer à effectuer des mises à jour sur la table cible de l&rsquo;instruction, qui est toujours effectuée en ligne.</p>
<p>C&rsquo;est donc pour cela que l&rsquo;on doit utiliser :</p>
<p>=> REORGANIZE lorsque la fragmentation de l&rsquo;index est faible (entre 5-10% et 25-30%)<br />
=> REBUILD lorsque la fragmentation de l&rsquo;index est plus élevée (plus de 25-30%).</p>
<p>Si l&rsquo;on exécute une instruction ALTER INDEX &#8230; REBUILD en ligne avec l&rsquo;option ONLINE, qui n&rsquo;est disponible que dans les instances de SQL Server dont l&rsquo;édition est <em>Enterprise</em>, deux index sont maintenus : l&rsquo;ancien est supprimé et remplacé par le nouveau à la fin de l&rsquo;opération. Cela permet l&rsquo;accès en écriture sur la table, même si l&rsquo;opération est plus longue et plus coûteuse. Mais cela est nécessaire lorsqu&rsquo;on a une base de données dont la disponibilité doit être 24 x 7 x 366.</p>
<p>On notera qu&rsquo;on ne peut pas reconstruire un index en ligne si :</p>
<p>&#8211; l&rsquo;index est cluster et la table a au moins une colonne de type LOB (image, text, ntext varchar(max), nvarchar(max), varbinary(max)), spatial (geography et geometry) ou hierarchy, ou encore une colonne calculée,</p>
<p>&#8211; l&rsquo;index est non-cluster, et porte sur des colonnes de type LOB, spatial ou hierarchy, ou que l&rsquo;une des colonnes clé de l&rsquo;index porte sur une colonne calculée.</p>
<p>Bonne maintenance des index !</p>
<p>ElSüket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>5 nouvelles DMV dans SQL Server 2008 R2 SP1 (et donc SQL Server 2012)</title>
		<link>https://blog.developpez.com/elsuket/p10828/moteur-de-base-de-donnees-sql-server/5_dmv_dans_sql_2008_r2_sp1_sql_2012</link>
		<comments>https://blog.developpez.com/elsuket/p10828/moteur-de-base-de-donnees-sql-server/5_dmv_dans_sql_2008_r2_sp1_sql_2012#comments</comments>
		<pubDate>Tue, 13 Mar 2012 12:53:59 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>
		<category><![CDATA[Utilitaires]]></category>

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

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici un petit lot de requêtes qui permet de connaître le nombre de Virtual Log Files en cours d&#8217;utilisation &#8230; En effet le fichier du journal des transactions est découpé en portions logiques, dont le nombre et la taille sont &#8230; <a href="https://blog.developpez.com/elsuket/p10037/moteur-de-base-de-donnees-sql-server/melee_considerations_fichier_journal_tra">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici un petit lot de requêtes qui permet de connaître le nombre de <em>Virtual Log Files</em> en cours d&rsquo;utilisation &#8230;<br />
<span id="more-110"></span></p>
<p>En effet le fichier du journal des transactions est découpé en portions logiques, dont le nombre et la taille sont variables &#8230;<br />
C&rsquo;est en fait le cas si on n&rsquo;a pas bien taillé le fichier dès la création de la base de données.<br />
Ces portions logiques sont nommées <em>fichiers virtuels du journal</em>, ou encore <em>Virtual Log Files</em>, abrégé en VLF dans la littérature.</p>
<p>En effet ce fichier, comme les fichiers de données de la base de données, peut grossir autant que cela est nécessaire.<br />
En suivant donc sa taille, on peut décider d&rsquo;augmenter la fréquence des sauvegardes de ce fichier, qui permettent dans la majorité des cas de maintenir le fichier à une taille stable.</p>
<p>Un manœuvre d&rsquo;urgence consiste à effectuer une sauvegarde du fichier du journal des transactions avec l&rsquo;option WITH TRUNCATE_ONLY (qui n&rsquo;est plus disponible sous SQL Server 2008), puis à faire rétrécir le fichier.</p>
<p>Rappelons qu&rsquo;en aucun cas autre que celui d&rsquo;urgence ou exceptionnel, on ne rétrécira ce fichier, comme les autres fichiers de la base de données.<br />
Il peut être nécessaire d&rsquo;y avoir recours :</p>
<p>&#8211; par manque d&rsquo;espace disque,<br />
&#8211; parce qu&rsquo;on a purgé un grand nombre de tables, et qu&rsquo;on considère qu&rsquo;elles n’atteindront plus jamais cette taille<br />
&#8211; parce qu&rsquo;on a changé le <a href="http://msdn.microsoft.com/fr-fr/library/ms189275.aspx">mode de récupération</a> de la base de données vers le mode SIMPLE</p>
<p>En effet c&rsquo;est ce dernier qui pilote l&rsquo;utilisation du fichier du journal des transactions.<br />
En résumé, dans le mode de récupération </p>
<p>=> SIMPLE, les fichiers virtuels du journal des transactions est vidé dès la fin d&rsquo;une transaction<br />
=> FULL toutes les transactions sont conservées dans leur intégralité jusqu&rsquo;à la prochaine sauvegarde du fichier<br />
=> BULK_LOGGED, toutes les transactions sont conservées dans leur intégralité jusqu&rsquo;à la prochaine sauvegarde du fichier, sauf pour certaines opérations, comme la reconstruction des index ou encore le chargement de fichiers par BCP ou BULK INSERT, &#8230;</p>
<p>C&rsquo;est là une vue très simple des modes de récupération, et certains facteurs peuvent affecter sa troncature :</p>
<p>&#8211; Une transaction qui a été laissée ouverte. On peut facilement le savoir à l&rsquo;aide de l&rsquo;instruction DBCC OPENTRAN.<br />
&#8211; Une réplication en cours<br />
&#8211; Une mise en miroir mise en pause<br />
&#8211; Une lecture du fichier du journal des transactions (c&rsquo;est très court mais cela peut se produire lorsqu&rsquo;on utilise <em>Change Data Capture</em><br />
&#8211; Une création d&rsquo;une <a href="http://blog.developpez.com/elsuket/p7454/moteur-de-base-de-donnees-sql-server/creer-des-captures-instantanees-de-bases/">capture instantanée</a> de la base de données<br />
&#8211; &#8230;</p>
<p>L&rsquo;instruction (non documentée) DBCC LOGINFO permet de connaître le nombre de fichiers journaux virtuels, ainsi que de savoir combien d&rsquo;entre eux sont actifs.</p>
<p>Il suffit de la décortiquer avec le lot de requête suivant pour avoir un rapide état des lieux :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 07/06/2011 <br />
------------------------------- <br />
DECLARE @vlf TABLE <br />
( <br />
&nbsp; FileId tinyint <br />
&nbsp; , FileSize bigint <br />
&nbsp; , StartOffset bigint <br />
&nbsp; , FSeqNo int <br />
&nbsp; , Status tinyint <br />
&nbsp; , Parity tinyint <br />
&nbsp; , CreateLSN varchar(21) <br />
) <br />
&nbsp;<br />
INSERT &nbsp;@vlf <br />
EXEC ('DBCC LOGINFO') <br />
&nbsp;<br />
SELECT &nbsp;SUM(FileSize) / 1048576 AS total_file_size_MB <br />
&nbsp; , SUM <br />
&nbsp; ( <br />
&nbsp; &nbsp; CASE Status <br />
&nbsp; &nbsp; &nbsp; WHEN 2 THEN FileSize <br />
&nbsp; &nbsp; &nbsp; ELSE 0 <br />
&nbsp; &nbsp; END <br />
&nbsp; ) / 1048576 AS file_size_in_use_MB <br />
&nbsp; , COUNT(*) AS VLF_amount <br />
&nbsp; , SUM <br />
&nbsp; ( <br />
&nbsp; &nbsp; CASE Status <br />
&nbsp; &nbsp; &nbsp; WHEN 2 THEN 1 <br />
&nbsp; &nbsp; &nbsp; ELSE 0 <br />
&nbsp; &nbsp; END <br />
&nbsp; ) AS VLF_in_use <br />
FROM &nbsp;@vlf <br />
&nbsp;<br />
DBCC SQLPERF(logspace)</div></td></tr></tbody></table></div>
<p>Si l&rsquo;on souhaite réduire le nombre de VLFs du fichier du journal des transactions, il faudra d&rsquo;abord le faire rétrécir.<br />
Pour ce faire, il faudra donc procéder à une sauvegarde fichier du journal des transactions (attention parfois deux sont <a href="http://blog.developpez.com/mikedavem/p8044/sql-server-2005/architecture/pourquoi-la-commande-shrinkfile-ne-redui/">nécessaires</a>)</p>
<p>Ensuite on peut faire grossir le fichier par incréments suivant la règle d&rsquo;allocation :</p>
<p>&#8211; Si la taille de l&rsquo;incrément est comprise entre 1 et 64Mo, alors 4 VLFs seront ajoutés;<br />
&#8211; Si la taille de l&rsquo;incrément est comprise entre 65Mo et 1Go, alors 8 VLFs seront ajoutés;<br />
&#8211; Si la taille de l&rsquo;incrément plus grande qu&rsquo;un 1Go, alors 16 VLFs seront ajoutés.</p>
<p>Pour faire grossir le fichier du journal des transactions, il suffit d&rsquo;exécuter le squelette suivant :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ALTER DATABASE maBaseDeDonnees <br />
MODIFY FILE (NAME = '[nomLogiqueDuFichierDuJournalDesTransactions]', SIZE = [nouvelleTaille][MB_ou_GB], FILEGROWTH = [tailleIncrement]</div></td></tr></tbody></table></div>
<p>Quelques détails :</p>
<p>=> [nomLogiqueDuFichierDuJournalDesTransactions] se trouve avec la requête suivante :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 07/06/2011 <br />
------------------------------- <br />
SELECT &nbsp;name <br />
&nbsp; , physical_name <br />
&nbsp; , type_desc <br />
FROM &nbsp;sys.database_files <br />
WHERE &nbsp;type_desc = 'LOG'</div></td></tr></tbody></table></div>
<p>Ou plus généralement :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 07/06/2011 <br />
------------------------------- <br />
SELECT &nbsp; &nbsp;D.name AS database_name <br />
&nbsp; &nbsp; , MF.name AS logical_file_name <br />
&nbsp; &nbsp; , MF.physical_name AS physical_file_name <br />
&nbsp; &nbsp; , type_desc AS file_type <br />
FROM &nbsp; &nbsp;sys.master_files AS MF <br />
INNER JOIN &nbsp;sys.databases AS D ON MF.database_id = D.database_id <br />
WHERE &nbsp; &nbsp;MF.type_desc = 'LOG' <br />
ORDER BY &nbsp;D.name</div></td></tr></tbody></table></div>
<p>=> [nouvelleTaille] est la taille que l&rsquo;on souhaite que le fichier du journal des transaction ait<br />
=> [tailleIncrement] est la taille de grossissement du fichier, si cela doit se produire<br />
=> [MB_ou_GB] est le suffixe de taille : on précise MB ou GB, (mais on peut aussi mettre KB ).</p>
<p>Bonne gestion du fichier du journal des transactions !</p>
<p>ElSüket</p>
<p>@++ <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trouver la consommation de CPU par base de données en utilisant le cache de plans, sous SQL Server 2005 et suivants</title>
		<link>https://blog.developpez.com/elsuket/p10710/moteur-de-base-de-donnees-sql-server/trouver_la_consommation_de_cpu_par_base_</link>
		<comments>https://blog.developpez.com/elsuket/p10710/moteur-de-base-de-donnees-sql-server/trouver_la_consommation_de_cpu_par_base_#comments</comments>
		<pubDate>Sun, 12 Feb 2012 10:06:15 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une petite requête qui permet de retrouver le temps CPU consommé par base de données d&#8217;une instance SQL Server 1234567891011121314151617181920212223242526------------------------------- -- Nicolas Souquet - 2012-02-12 ------------------------------- ;WITH &#160; DB_CPU_STAT AS &#160; ( &#160; &#160; SELECT &#160; &#160;D.database_id &#160; &#160; &#8230; <a href="https://blog.developpez.com/elsuket/p10710/moteur-de-base-de-donnees-sql-server/trouver_la_consommation_de_cpu_par_base_">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une petite requête qui permet de retrouver le temps CPU consommé par base de données d&rsquo;une instance SQL Server<br />
<span id="more-113"></span></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 2012-02-12 <br />
------------------------------- <br />
;WITH <br />
&nbsp; DB_CPU_STAT AS <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp; &nbsp;D.database_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; , D.name AS database_name <br />
&nbsp; &nbsp; &nbsp; &nbsp; , SUM(total_worker_time) / 1000 AS total_CPU_time_ms <br />
&nbsp; &nbsp; FROM &nbsp; &nbsp;sys.dm_exec_query_stats AS QS <br />
&nbsp; &nbsp; CROSS APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SELECT &nbsp;CONVERT(int, value) AS database_id &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp;sys.dm_exec_plan_attributes(QS.plan_handle) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;attribute = N'dbid' <br />
&nbsp; &nbsp; &nbsp; &nbsp; ) AS DB <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.databases AS D <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON DB.database_id = D.database_id <br />
&nbsp; &nbsp; GROUP BY &nbsp;D.database_id, D.name <br />
&nbsp; ) <br />
SELECT &nbsp;database_name <br />
&nbsp; , total_CPU_time_ms / 1000 AS total_CPU_time_s <br />
&nbsp; , CAST(total_CPU_time_ms * 1.0 / SUM(total_CPU_time_ms) OVER() * 100.0 AS decimal(5, 2)) AS [CPU_%] <br />
FROM &nbsp;DB_CPU_STAT <br />
WHERE &nbsp;database_id &gt; 4 -- system databases <br />
AND &nbsp;database_id &lt;&gt; 32767 -- ResourceDB <br />
ORDER &nbsp;BY total_CPU_time_ms DESC</div></td></tr></tbody></table></div>
<p>Et bonne surveillance de SQL Server <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gestion et lecture des journaux d&#8217;événements de SQL Server</title>
		<link>https://blog.developpez.com/elsuket/p10279/moteur-de-base-de-donnees-sql-server/gestion_lecture_journaux_sql_server</link>
		<comments>https://blog.developpez.com/elsuket/p10279/moteur-de-base-de-donnees-sql-server/gestion_lecture_journaux_sql_server#comments</comments>
		<pubDate>Mon, 19 Sep 2011 17:00:00 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Agent SQL Server]]></category>
		<category><![CDATA[Moteur de base de données SQL Server]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici quelques procédures stockées systèmes et quelques suites de clics dans SQL Server Management Studio pour gérer un peu plus finement les fichiers d&#8217;information et d&#8217;erreur du moteur de bases de données de SQL Server, et de l&#8217;Agent SQL Server. &#8230; <a href="https://blog.developpez.com/elsuket/p10279/moteur-de-base-de-donnees-sql-server/gestion_lecture_journaux_sql_server">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici quelques procédures stockées systèmes et quelques suites de clics dans <em>SQL Server Management Studio</em> pour gérer un peu plus finement les fichiers d&rsquo;information et d&rsquo;erreur du moteur de bases de données de SQL Server, et de l&rsquo;Agent SQL Server.<br />
<span id="more-112"></span><br />
Commençons d&rsquo;abord par l&rsquo;emplacement de ces fichiers, qui sont en fait de simples fichiers texte : par défaut il s&rsquo;agit de :<br />
<em>C:\Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\</em></p>
<p>Le <em>.n</em> indique le <a href="http://blog.developpez.com/elsuket/p7725/snippets/trouver-le-numero-d-une-instance-nommee/">numéro de l&rsquo;instance</a> s&rsquo;il s&rsquo;agit d&rsquo;une instance nommée : dans le cas contraire, le <em>.n</em> est absent.<br />
On trouve dans ce dossier : </p>
<p>=> Des fichiers ERRORLOG et ERRORLOG.[n], où [n] est un entier qui est d&rsquo;autant plus grand qu&rsquo;il est ancien.<br />
Ce sont les fichiers de journaux d&rsquo;erreurs de moteur de base de données.<br />
Si la configuration des journaux d&rsquo;événements n&rsquo;a jamais été modifiée, on a ERRORLOG.6, car comme nous allons le voir, SQL Server ne conserve que 6 journaux d&rsquo;erreur.</p>
<p>=> Des fichiers SQLAGENT et SQLAGENT.[n], où [n] est utilisé de la même façon que précédemment.<br />
On l&rsquo;aura compris, ces fichiers sont les journaux d&rsquo;événements de l&rsquo;Agent SQL Server.</p>
<p>=> Des fichiers FDLAUNCHERRORLOG et FDLAUNCHERRORLOG.[n], qui sont les journaux d&rsquo;événements du moteur de recherche en texte intégral de SQL Server.</p>
<p>=> Des fichiers log_xx.trc, qui sont les fichiers de trace SQL Profiler par défaut de SQL Server.<br />
En effet une trace SQL Profiler est démarrée par défaut à chaque démarrage d&rsquo;un instance SQL Server.<br />
En interrogeant la vue système sys.traces, vous verrez que cette trace est toujours démarrée et porte l&rsquo;id de valeur 1.</p>
<p>Tous les fichiers présents dans ce répertoire sont interprétables par n&rsquo;importe quel éditeur texte, à l&rsquo;exception des fichiers de trace par défaut.<br />
On peut ouvrir ces derniers directement par un double-clic qui exécutera SQL Profiler.</p>
<p>Dans ce billet nous nous limiterons à la gestion des fichiers d’événements :<br />
&#8211; du moteur de bases de données SQL Server<br />
&#8211; de l&rsquo;Agent SQL Server</p>
<p>On peut tout à fait changer le nombre de journaux d&rsquo;erreur à converser, et on peut aussi automatiser leur renouvellement, par exemple avec un fichier par jour.<br />
Cela permet, lorsqu&rsquo;on audite ces fichiers ou qu&rsquo;on conduit des investigations à la suite d&rsquo;un problème, d&rsquo;avoir un fichier de journal assez petit, en ne se focalisant que sur un seul jour.</p>
<p>Voyons d&rsquo;abord comment lire ces fichiers journaux à l&rsquo;aide de SQL Server Management Studio.<br />
Après avoir ouvert l&rsquo;<em>Explorateur d&rsquo;Objets</em> (F8), le nœud <em>Gestion</em> une fois développé, nous affiche un nœud <em>Journaux SQL Server</em>:<br />
<img src="http://blog.developpez.com/media/error_log_09.png" width="359" height="632" alt="" /></p>
<p>Un double-clic sur l&rsquo;un d&rsquo;entre eux affiche leur contenu, et on peut accéder aux autres journaux à partir du même dialogue :</p>
<p><img src="http://blog.developpez.com/media/error_log_10.jpg" width="693" height="433" alt="" /></p>
<p>A partir de cette fenêtre, on voit que l&rsquo;on peut visualiser plusieurs types de journaux :</p>
<p>&#8211; Ceux de l&rsquo;Agent SQL Server<br />
&#8211; Ceux du moteur de bases de donnée relationnelles<br />
&#8211; Ceux de Windows<br />
&#8211; Ceux de la messagerie de bases de données</p>
<p>On peut bien sûr mélanger le contenu de plusieurs journaux de types différents, ce qui peut aider à corréler les tenants et aboutissants d&rsquo;un événement touchant à SQL Server.</p>
<p>Enfin, à l&rsquo;aide des boutons de la barre d&rsquo;outils, il est possible de restreindre les dates entre lesquelles on souhaite afficher les messages, et aussi de rechercher dans le contenu de ceux-ci.<br />
Ces deux fonctions sont assez rapides si la machine et SQL Server fonctionnent correctement, mais il en va parfois tout autrement lorsque des problèmes surviennent.<br />
En effet, il m&rsquo;est arrivé de devoir lire des fichiers de journaux faisant plusieurs centaines de Mo, et il est impossible d&rsquo;arrêter la <em>Visionneuse de Journaux</em>, à moins de décocher tous les journaux, ce qui n&rsquo;affiche plus rien. C&rsquo;est là l&rsquo;intérêt de gérer ces fichiers.</p>
<p>Voyons donc comment augmenter (ou diminuer) le nombre de journaux d&rsquo;erreurs.<br />
Dans l&rsquo;Explorateur d&rsquo;Objets (F8), après avoir développé le nœud <em>Gestion</em>, il suffit de faire un clic-droit sur <em>Journaux SQL Server</em> puis de choisir l&rsquo;option <em>Configurer</em> :</p>
<p><img src="http://blog.developpez.com/media/error_log_01.png" width="339" height="554" alt="" /></p>
<p>On remarque que l&rsquo;étiquette portée par les fichiers journaux comporte la date de dernière écriture dans le fichier.<br />
Par défaut la case <em>Limiter le nombre de fichiers de journaux d&rsquo;erreurs avant qu&rsquo;ils ne soient recyclés</em> n&rsquo;est pas cochée.<br />
Dès lors qu&rsquo;on la coche, on est libre de spécifier le nombre de journaux que l&rsquo;on souhaite conserver :<br />
<img src="http://blog.developpez.com/media/error_log_02.png" width="704" height="499" alt="" /><br />
Je le mets toujours au maximum, 99, parce que je l&rsquo;assortis d&rsquo;un job de l&rsquo;Agent SQL Server pour recycler les journaux (ce que nous allons voir par la suite).<br />
En scriptant le changement, on obtient le script suivant :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE [master] &lt;br /&gt;<br />
GO &lt;br /&gt;<br />
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'NumErrorLogs', REG_DWORD, 99 &lt;br /&gt;<br />
GO</div></td></tr></tbody></table></div>
<p>C&rsquo;est à dire que le nombre de journaux de l&rsquo;instance SQL Server n&rsquo;est pas stocké dans une des bases de données système (on aurait pu le stocker dans la base de données master ou msdb).</p>
<p>La procédure stockée <a href="http://msdn.microsoft.com/fr-fr/library/ms182512.aspx">sp_cycle_errorlog</a> permet de forcer la création d&rsquo;un nouveau fichier de journal.<br />
Le cas échéant, elle supprime également le fichier de journal le plus ancien si son numéro incrémenté dépasse le nombre de journaux que l&rsquo;on a spécifié vouloir conserver.<br />
On peut donc créer un job de l&rsquo;Agent SQL Server qui s&rsquo;exécute tous les jours à minuit pour forcer la création d&rsquo;un nouveau journal d&rsquo;erreur.<br />
Créons donc ce job, ce que l&rsquo;on peut faire très simplement par un clic-droit sur le nœud <em>Agent SQL Server</em> de l&rsquo;Explorateur d&rsquo;Objets :<br />
<img src="http://blog.developpez.com/media/error_log_03.png" width="538" height="657" alt="" /></p>
<p>On spécifie le nom du job, et un petit commentaire sur le rôle du job ne fait jamais de mal :</p>
<p><img src="http://blog.developpez.com/media/error_log_04.png" width="705" height="631" alt="" /></p>
<p>Puis on peut passer à la page <em>Étapes</em> :</p>
<p><img src="http://blog.developpez.com/media/error_log_05.png" width="704" height="634" alt="" /></p>
<p><strong>EDIT 09/02/2012: </strong> il faut mettre le contexte de base de données à <strong>msdb</strong>, et non pas le laisser sur <em>master</em></p>
<p>On peut ensuite basculer dans la page <em>Planifications</em>.<br />
Après avoir cliqué sur le bouton <em>Nouvelle</em>, on obtient la fenêtre suivante :<br />
<img src="http://blog.developpez.com/media/error_log_06.png" width="676" height="589" alt="" /></p>
<p>En cliquant sur OK dans ce dialogue et dans le dialogue parent (<em>Propriétés du travail</em>), on valide la création du travail.<br />
On le trouve dès lors dans l&rsquo;<em>Explorateur d&rsquo;Objets</em> dans la liste des travaux :<br />
<img src="http://blog.developpez.com/media/error_log_07.png" width="323" height="510" alt="" /></p>
<p>On remarque au passage le nœud <em>Journaux d&rsquo;erreurs</em>, enfant du nœud <em>Agent SQL server</em> : c&rsquo;est à partir de celui-ci que l&rsquo;on peut lire les journaux de l&rsquo;Agent SQL Server :</p>
<p><img src="http://blog.developpez.com/media/error_log_08.png" width="323" height="690" alt="" /></p>
<p>De la même façon, il est possible de configurer la rétention d&rsquo;informations :<br />
<img src="http://blog.developpez.com/media/error_log_12.png" width="302" height="554" alt="" /></p>
<p>Comme on le voit, à la différence des options pour les journaux du moteur de bases de données relationnelles, il est ici possible de recycler les journaux de l&rsquo;<em>Agent SQL Server</em>.<br />
<img src="http://blog.developpez.com/media/error_log_13.png" width="703" height="631" alt="" /></p>
<p>Cette fois, c&rsquo;est la procédure stockée <a href="http://msdn.microsoft.com/fr-fr/library/ms186874.aspx">sp_cycle_agent_errorlog</a> qui permet de forcer le recyclage des journaux de l&rsquo;Agent SQL Server.<br />
On peut donc tout à fait l&rsquo;ajouter en seconde étape de notre travail <em>DBA &#8211; Cycle Event Logs</em> :<br />
<img src="http://blog.developpez.com/media/error_log_14.png" width="942" height="632" alt="" /></p>
<p>Après avoir cliqué sur <em>Nouveau &#8230;</em>, on peut modifier le travail pour la régénération des journaux de l&rsquo;Agent SQL Server :</p>
<p><img src="http://blog.developpez.com/media/error_log_15.png" width="703" height="632" alt="" /></p>
<p>Une fois que l&rsquo;on a cliqué sur OK, puis de la même façon dans le dialogue parent (<em>Propriétés du travail</em>), le travail est maintenant modifié pour renouveler les journaux du moteur de bases de données et de l&rsquo;Agent SQL Server, tous les jours à minuit.</p>
<p>Il est enfin possible de lire les fichiers journaux de ces deux types (SGBDR et Agent) à l&rsquo;aide de la procédure stockée étendue système xp_readerrorlog, qui n&rsquo;est pas documentée.<br />
Comprenez par là que l&rsquo;utilisation à vos risques et périls, et que rien ne garantit que Microsoft mettra toujours à disposition cette fonctionnalité dans une future version de SQL Server.<br />
Ici on peut se permettre de l&rsquo;utiliser car cela n&rsquo;a aucun impact sur le moteur de bases de données : on ne fait que de la lecture de fichiers texte qui sont stockés en dehors des structures de stockage gérées par SQL Server.</p>
<p>Voici donc la document officieuse de cette procédure stockée étendue.<br />
Elle peut prendre quatre paramètres en entrée, qui sont les suivants :</p>
<p>=> le premier indique est un int, et indique l&rsquo;indice du journal à lire : passez zéro si vous souhaitez lire le journal courant, 1 si vous souhaitez l&rsquo;archive la plus récente. On peut également de rien passer, et on obtient alors le contenu du fichier de journal du SGBDR courant.<br />
=> le deuxième est un int, et précise le type de journal à lire : passez 1 pour les journaux du SGBDR, et 2 pour l&rsquo;Agent SQL Server<br />
=> le 3e et le 4e sont des varchar(255), et sont tous deux des chaînes à rechercher dans le contenu des messages.</p>
<p>Vous l&rsquo;aurez compris, aucun des paramètres n&rsquo;est obligatoire.<br />
Comme il s&rsquo;agit d&rsquo;une procédure stockée étendue, il est impossible d&rsquo;en obtenir le nom des paramètres, ce qui fait que tout appel se fait par une suite de valeurs.</p>
<p>Si l&rsquo;on souhaite donc chercher les échecs d&rsquo;authentification dans le journal courant du SGBDR, on exécutera :</p>
<p><code class="codecolorer text default"><span class="text">EXEC xp_readerrorlog 0, 1, 'Failed', 'login'</span></code></p>
<p>Bonnes investigations des journaux SQL Server !</p>
<p>ElSüket <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gestion basée sur des stratégies : importer les stratégies de meilleures pratiques</title>
		<link>https://blog.developpez.com/elsuket/p10243/utilitaires/gestion_basee_sur_des_strategies_importe</link>
		<comments>https://blog.developpez.com/elsuket/p10243/utilitaires/gestion_basee_sur_des_strategies_importe#comments</comments>
		<pubDate>Fri, 02 Sep 2011 02:35:20 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Utilitaires]]></category>

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