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

<channel>
	<title>Le Blog SQL Server d&#039;ElSüket &#187; Indexation</title>
	<atom:link href="https://blog.developpez.com/elsuket/pcategory/moteur-de-base-de-donnees-sql-server/indexation/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>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>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>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 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>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>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>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>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>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>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>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>Lister les caractéristiques des indexes sous SQL Server 2005 et 2008</title>
		<link>https://blog.developpez.com/elsuket/p9762/moteur-de-base-de-donnees-sql-server/indexation/lister_les_caracteristiques_des_indexes__2008</link>
		<comments>https://blog.developpez.com/elsuket/p9762/moteur-de-base-de-donnees-sql-server/indexation/lister_les_caracteristiques_des_indexes__2008#comments</comments>
		<pubDate>Tue, 22 Feb 2011 09:28:29 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une requête qui nous permet de retrouver pour tout index : &#8211; la liste de ses colonnes clé &#8211; la liste de ses colonnes incluses &#8211; la définition de son filtre &#8211; le script de création de cet index &#8230; <a href="https://blog.developpez.com/elsuket/p9762/moteur-de-base-de-donnees-sql-server/indexation/lister_les_caracteristiques_des_indexes__2008">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une requête qui nous permet de retrouver pour tout index :</p>
<p>&#8211; la liste de ses colonnes clé<br />
&#8211; la liste de ses colonnes incluses<br />
&#8211; la définition de son filtre<br />
&#8211; le script de création de cet index</p>
<p><span id="more-29"></span></p>
<p>Voici une première requête qui retourne la définition de tous les index d&rsquo;une base de données.<br />
On peut bien sûr ajouter des filtres afin de voir la définition des index sur une table, ou la définition d&rsquo;un index en particulier.</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------- <br />
-- Nicolas Souquet - 22/02/2011 <br />
------------------------------- <br />
SELECT &nbsp; &nbsp;DISTINCT S.name AS schema_name <br />
&nbsp; &nbsp; , T.name AS table_name <br />
&nbsp; &nbsp; , I.name AS index_name <br />
&nbsp; &nbsp; , LEFT(KC.key_column_list, LEN(KC.key_column_list) - 1) 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 />
FROM &nbsp; &nbsp;sys.schemas AS S <br />
INNER JOIN &nbsp;sys.tables AS T <br />
&nbsp; &nbsp; &nbsp; ON S.schema_id = T.schema_id <br />
INNER JOIN &nbsp;sys.indexes AS I &nbsp;<br />
&nbsp; &nbsp; &nbsp; ON T.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 />
CROSS APPLY &nbsp;( <br />
&nbsp; &nbsp; &nbsp; SELECT &nbsp; &nbsp;CS.name + ',' <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 + ',' <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 />
WHERE &nbsp; &nbsp;S.name = 'dbo' <br />
--AND &nbsp; &nbsp;T.name = 'maTable' <br />
--AND &nbsp; &nbsp;I.name = 'monIndex' <br />
ORDER BY &nbsp;T.name, I.name</div></td></tr></tbody></table></div>
<p><strong>Et une autre donnant le script de définition de l&rsquo;index :</strong></p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br /></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 - 22/02/2011 <br />
------------------------------- <br />
;WITH <br />
&nbsp; CTE AS <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT &nbsp; &nbsp;DISTINCT 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; &nbsp; &nbsp; , LEFT(KCI.included_key_column_list, LEN(KCI.included_key_column_list) - 1) AS included_key_column_list <br />
&nbsp; &nbsp; &nbsp; &nbsp; , REPLACE(REPLACE(REPLACE(REPLACE(I.filter_definition, '[', ''), ']', ''), '(', ''), ')', '') AS filter_definition <br />
&nbsp; &nbsp; &nbsp; &nbsp; , ROW_NUMBER() OVER(ORDER BY T.name, I.name) AS n <br />
&nbsp; &nbsp; FROM &nbsp; &nbsp;sys.schemas AS S <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.tables AS T <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON S.schema_id = T.schema_id <br />
&nbsp; &nbsp; INNER JOIN &nbsp;sys.indexes AS I &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON T.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; 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;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 + ',' <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_key_column_list) <br />
&nbsp; &nbsp; WHERE &nbsp; &nbsp;S.name = 'dbo' <br />
&nbsp; &nbsp; --AND &nbsp; &nbsp;T.name = 'maTable' <br />
&nbsp; &nbsp; --AND &nbsp; &nbsp;I.name = 'monIndex' <br />
&nbsp; ) <br />
SELECT &nbsp;'CREATE INDEX ' + index_name &nbsp;<br />
&nbsp; + ' ON ' + schema_name + '.' + table_name <br />
&nbsp; + '(' + key_column_list + ')' <br />
&nbsp; + CASE WHEN included_key_column_list IS NOT NULL THEN ' INCLUDE(' + included_key_column_list + ')' ELSE '' END <br />
&nbsp; + CASE WHEN filter_definition IS NOT NULL THEN ' WHERE ' + filter_definition ELSE '' END <br />
FROM &nbsp;CTE</div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rechercher les index inutiles</title>
		<link>https://blog.developpez.com/elsuket/p9496/moteur-de-base-de-donnees-sql-server/indexation/rechercher_les_index_inutiles</link>
		<comments>https://blog.developpez.com/elsuket/p9496/moteur-de-base-de-donnees-sql-server/indexation/rechercher_les_index_inutiles#comments</comments>
		<pubDate>Tue, 16 Nov 2010 10:48:15 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Si les index représentent l&#8217;optimisation la plus simple à mettre en place, on souhaite néanmoins conserver le minimum d&#8217;entre-eux, car leur maintenance lors de l&#8217;exécution de requêtes de modifications de données (INSERT, UPDATE, DELETE) peut être coûteuse, surtout sur des &#8230; <a href="https://blog.developpez.com/elsuket/p9496/moteur-de-base-de-donnees-sql-server/indexation/rechercher_les_index_inutiles">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Si les index représentent l&rsquo;optimisation la plus simple à mettre en place, on souhaite néanmoins conserver le minimum d&rsquo;entre-eux, car leur maintenance lors de l&rsquo;exécution de requêtes de modifications de données (INSERT, UPDATE, DELETE) peut être coûteuse, surtout sur des tables volumineuses.<br />
Voyons comment collecter cette information &#8230;<br />
<span id="more-28"></span><br />
La requête suivante retourne tous les index de la base de données en cours pour lesquels seule la maintenance a eu lieu (mais qui n&rsquo;ont servi aucune requête de type SELECT (IUS.user_lookups + IUS.user_scans + IUS.user_seeks = 0):</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 /></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/11/2010 <br />
------------------------------- <br />
SELECT &nbsp; &nbsp;T.name AS table_name <br />
&nbsp; &nbsp; , PS.row_count <br />
&nbsp; &nbsp; , I.name AS index_name <br />
&nbsp; &nbsp; , dbo.nico(I.object_id, I.index_id) AS index_key <br />
&nbsp; &nbsp; , IUS.user_lookups + IUS.user_scans + IUS.user_seeks AS total_user_searches <br />
&nbsp; &nbsp; , IUS.user_updates <br />
&nbsp; &nbsp; , IUS.system_lookups + IUS.system_scans + IUS.system_seeks AS total_system_searches <br />
&nbsp; &nbsp; , IUS.system_updates <br />
FROM &nbsp; &nbsp;sys.dm_db_index_usage_stats AS IUS <br />
INNER JOIN &nbsp;sys.indexes AS I <br />
&nbsp; &nbsp; &nbsp; ON IUS.database_id = DB_ID() <br />
&nbsp; &nbsp; &nbsp; AND IUS.object_id = I.object_id <br />
&nbsp; &nbsp; &nbsp; AND IUS.index_id = I.index_id <br />
INNER JOIN &nbsp;sys.tables AS T <br />
&nbsp; &nbsp; &nbsp; ON I.object_id = T.object_id <br />
INNER JOIN &nbsp;sys.dm_db_partition_stats AS PS &nbsp;<br />
&nbsp; &nbsp; &nbsp; ON PS.object_id = T.object_id <br />
&nbsp; &nbsp; &nbsp; AND PS.index_id BETWEEN 0 AND 1 <br />
LEFT JOIN &nbsp;sys.objects AS O <br />
&nbsp; &nbsp; &nbsp; ON O.parent_object_id = I.object_id <br />
&nbsp; &nbsp; &nbsp; AND O.type = 'PK' <br />
&nbsp; &nbsp; &nbsp; AND O.name = I.name <br />
WHERE &nbsp; &nbsp;IUS.user_lookups + IUS.user_scans + IUS.user_seeks = 0 <br />
AND &nbsp; &nbsp;O.object_id IS NULL <br />
ORDER BY &nbsp;IUS.user_updates DESC --PS.row_count DESC</div></td></tr></tbody></table></div>
<p>On exclut les indexes sous-jacents à une clé primaire, puisque leur suppression obligerait celle de la contrainte.</p>
<p>Si l&rsquo;on souhaite extraire la clé de l&rsquo;index, il faudra alors créer la petite fonction suivante :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></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/11/2010 <br />
------------------------------- <br />
CREATE FUNCTION dbo.ufn_GetIndexKey <br />
&nbsp; ( <br />
&nbsp; &nbsp; @_object_id int <br />
&nbsp; &nbsp; , @_index_id int <br />
&nbsp; ) <br />
&nbsp; RETURNS varchar(max) <br />
AS <br />
BEGIN &nbsp;<br />
&nbsp; DECLARE @index_key varchar(max) <br />
&nbsp; <br />
&nbsp; SELECT &nbsp; &nbsp;@index_key = CASE WHEN @index_key IS NULL THEN C.name ELSE @index_key + + ', ' + C.name END &nbsp;<br />
&nbsp; FROM &nbsp; &nbsp;sys.indexes AS I <br />
&nbsp; INNER JOIN &nbsp;sys.index_columns AS IC <br />
&nbsp; &nbsp; &nbsp; &nbsp; ON I.object_id = IC.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; AND I.index_id = IC.index_id <br />
&nbsp; INNER JOIN &nbsp;sys.columns AS C <br />
&nbsp; &nbsp; &nbsp; &nbsp; ON IC.object_id = C.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; AND IC.column_id = C.column_id <br />
&nbsp; WHERE &nbsp; &nbsp;I.object_id = @_object_id <br />
&nbsp; AND &nbsp; &nbsp;I.index_id = @_index_id <br />
&nbsp; ORDER BY &nbsp;IC.index_column_id <br />
&nbsp;<br />
&nbsp; RETURN @index_key <br />
END</div></td></tr></tbody></table></div>
<p>Que l&rsquo;on peut utiliser directement 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 /></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;T.name AS table_name <br />
&nbsp; &nbsp; , PS.row_count <br />
&nbsp; &nbsp; , I.name AS index_name <br />
&nbsp; &nbsp; , dbo.ufn_GetIndexKey (I.object_id, I.index_id) AS index_key <br />
&nbsp; &nbsp; , IUS.user_lookups + IUS.user_scans + IUS.user_seeks AS total_user_searches <br />
&nbsp; &nbsp; , IUS.user_updates <br />
&nbsp; &nbsp; , IUS.system_lookups + IUS.system_scans + IUS.system_seeks AS total_system_searches <br />
&nbsp; &nbsp; , IUS.system_updates <br />
FROM &nbsp; &nbsp;sys.dm_db_index_usage_stats AS IUS <br />
INNER JOIN &nbsp;sys.indexes AS I <br />
&nbsp; &nbsp; &nbsp; ON IUS.database_id = DB_ID() <br />
&nbsp; &nbsp; &nbsp; AND IUS.object_id = I.object_id <br />
&nbsp; &nbsp; &nbsp; AND IUS.index_id = I.index_id <br />
INNER JOIN &nbsp;sys.tables AS T <br />
&nbsp; &nbsp; &nbsp; ON I.object_id = T.object_id <br />
INNER JOIN &nbsp;sys.dm_db_partition_stats AS PS &nbsp;<br />
&nbsp; &nbsp; &nbsp; ON PS.object_id = T.object_id <br />
&nbsp; &nbsp; &nbsp; AND PS.index_id BETWEEN 0 AND 1 <br />
LEFT JOIN &nbsp;sys.objects AS O <br />
&nbsp; &nbsp; &nbsp; ON O.parent_object_id = I.object_id <br />
&nbsp; &nbsp; &nbsp; AND O.type = 'PK' <br />
&nbsp; &nbsp; &nbsp; AND O.name = I.name <br />
WHERE &nbsp; &nbsp;IUS.user_lookups + IUS.user_scans + IUS.user_seeks = 0 <br />
AND &nbsp; &nbsp;O.object_id IS NULL <br />
ORDER BY &nbsp;IUS.user_updates DESC --PS.row_count DESC</div></td></tr></tbody></table></div>
<p>Il ne reste alors plus qu&rsquo;à juger de la pertinence de la suppression de l&rsquo;index, car leur création est assez coûteuse.<br />
En effet, si on supprime un index et qu&rsquo;on se rend compte qu&rsquo;il aurait pu servir des requêtes :</p>
<p>&#8211; dans le cas où on dispose d&rsquo;une édition <em>Standard</em> de SQL Server, on doit recréer l&rsquo;index et cela bloque la table<br />
&#8211; dans le cas où on dispose d&rsquo;une édition <em>Enterprise</em> de SQL Server, on peut recréer l&rsquo;index en ligne, mais cela utilise massivement la base de données système TempDB dans laquelle est effectuée le tri, plus l&rsquo;espace disque nécessaire à la copie de l&rsquo;index, et enfin le coût de maintenance de deux index au lieu d&rsquo;un.</p>
<p>Bonne indexation !</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lister les colonnes des index d&#8217;une base de données</title>
		<link>https://blog.developpez.com/elsuket/p8701/moteur-de-base-de-donnees-sql-server/indexation/lister_les_colonnes_des_index_d_une_base</link>
		<comments>https://blog.developpez.com/elsuket/p8701/moteur-de-base-de-donnees-sql-server/indexation/lister_les_colonnes_des_index_d_une_base#comments</comments>
		<pubDate>Mon, 08 Mar 2010 12:36:14 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une petite requête qui permet de lister les colonnes de tous les index d&#8217;une base de données, avec leur type et l&#8217;ordre des colonnes dans la clé de l&#8217;index : 123456789101112131415161718192021------------------------------- -- Nicolas SOUQUET - 08/03/2010 ------------------------------- -- SQL &#8230; <a href="https://blog.developpez.com/elsuket/p8701/moteur-de-base-de-donnees-sql-server/indexation/lister_les_colonnes_des_index_d_une_base">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une petite requête qui permet de lister les colonnes de tous les index d&rsquo;une base de données, avec leur type et l&rsquo;ordre des colonnes dans la clé de l&rsquo;index :<br />
<span id="more-26"></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 /></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 - 08/03/2010 <br />
------------------------------- <br />
-- SQL Server 2005 et 2008 <br />
SELECT &nbsp; &nbsp;T.name AS nom_table <br />
&nbsp; &nbsp; , I.type_desc AS type_index <br />
&nbsp; &nbsp; , I.name AS nom_index <br />
&nbsp; &nbsp; , C.name AS nom_colonne <br />
&nbsp; &nbsp; , IC.key_ordinal AS position_colonne <br />
&nbsp; &nbsp; , IC.is_included_column AS is_included <br />
FROM &nbsp; &nbsp;sys.tables AS T <br />
INNER JOIN &nbsp;sys.indexes AS I <br />
&nbsp; &nbsp; &nbsp; ON T.object_id = I.object_id <br />
INNER JOIN &nbsp;sys.index_columns AS IC <br />
&nbsp; &nbsp; &nbsp; ON I.object_id = IC.object_id <br />
&nbsp; &nbsp; &nbsp; AND I.index_id = IC.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 />
--WHERE &nbsp; &nbsp;T.name = 'maTable' <br />
ORDER BY &nbsp;T.name, I.name, IC.key_ordinal</div></td></tr></tbody></table></div>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></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 - 20/07/2010 <br />
------------------------------- <br />
-- SQL Server 2000 <br />
&nbsp;<br />
SELECT &nbsp; &nbsp;T.name AS table_name <br />
&nbsp; &nbsp; , I.name AS index_name <br />
&nbsp; &nbsp; , CASE I.indid <br />
&nbsp; &nbsp; &nbsp; WHEN 1 THEN 'CLUSTER' <br />
&nbsp; &nbsp; &nbsp; ELSE 'NON-CLUSTER' <br />
&nbsp; &nbsp; END AS index_type <br />
&nbsp; &nbsp; , C.name AS column_name <br />
&nbsp; &nbsp; , IK.keyno AS index_key_col_pos <br />
FROM &nbsp; &nbsp;sysindexes AS I <br />
INNER JOIN &nbsp;sysobjects AS T <br />
&nbsp; &nbsp; &nbsp; ON I.id = T.id <br />
INNER JOIN &nbsp;sysindexkeys AS IK <br />
&nbsp; &nbsp; &nbsp; ON I.id = IK.id <br />
&nbsp; &nbsp; &nbsp; AND I.indid = IK.indid <br />
INNER JOIN &nbsp;syscolumns AS C <br />
&nbsp; &nbsp; &nbsp; ON IK.id = C.id <br />
&nbsp; &nbsp; &nbsp; AND IK.colid = C.colid <br />
WHERE &nbsp; &nbsp;T.type = 'U' <br />
AND &nbsp; &nbsp;I.name NOT LIKE '%_!WA!_Sys!_%' ESCAPE '!' <br />
AND &nbsp; &nbsp;I.indid &gt; 0 <br />
ORDER BY &nbsp;T.name, I.name</div></td></tr></tbody></table></div>
<p>Bonne indexation !</p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Une procédure pour connaître l&#8217;état physique et l&#8217;utilisation des index</title>
		<link>https://blog.developpez.com/elsuket/p8901/moteur-de-base-de-donnees-sql-server/indexation/une_procedure_pour_connaitre_letait_phys</link>
		<comments>https://blog.developpez.com/elsuket/p8901/moteur-de-base-de-donnees-sql-server/indexation/une_procedure_pour_connaitre_letait_phys#comments</comments>
		<pubDate>Tue, 04 May 2010 14:26:11 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une petite procédure stockée qui permet de connaître l&#8217;état physique des index (nombre de pages du niveau feuille, fragmentation et taux d&#8217;utilisation des pages) en même temps que la façon dont ils sont utilisés (nombres de seeks et de &#8230; <a href="https://blog.developpez.com/elsuket/p8901/moteur-de-base-de-donnees-sql-server/indexation/une_procedure_pour_connaitre_letait_phys">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une petite procédure stockée qui permet de connaître l&rsquo;état physique des index (nombre de pages du niveau feuille, fragmentation et taux d&rsquo;utilisation des pages) en même temps que la façon dont ils sont utilisés (nombres de seeks et de scans, &#8230;).</p>
<p>Elle est utilisable pour collecter ces statistiques sur l&rsquo;ensemble d&rsquo;une base de données, ou bien sur une table en particulier<br />
<span id="more-27"></span></p>
<p>Voici le code :</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 /></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/05/2010 <br />
------------------------------- <br />
CREATE PROCEDURE ps_get_index_stats <br />
&nbsp; @_table_name sysname = NULL <br />
AS <br />
BEGIN <br />
&nbsp; SET NOCOUNT ON <br />
&nbsp;<br />
&nbsp; -- Si le nom de la table n'exsite pas, <br />
&nbsp; -- alors cela revient à passer NULL en object_id à la fonction sys.dm_db_index_physical_stats <br />
&nbsp; -- ce qui a pour effet de collecter toutes les statististiques de tous les index de la BD <br />
&nbsp; IF <br />
&nbsp; ( <br />
&nbsp; &nbsp; @_table_name IS NOT NULL <br />
&nbsp; &nbsp; AND NOT EXISTS <br />
&nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; SELECT &nbsp;* <br />
&nbsp; &nbsp; &nbsp; FROM &nbsp;sys.tables <br />
&nbsp; &nbsp; &nbsp; WHERE &nbsp;name = @_table_name <br />
&nbsp; &nbsp; ) <br />
&nbsp; ) <br />
&nbsp; BEGIN <br />
&nbsp; &nbsp; RAISERROR('The table %s does not exist', 16, 1, @_table_name) <br />
&nbsp; &nbsp; RETURN <br />
&nbsp; END <br />
&nbsp;<br />
&nbsp; SELECT &nbsp; &nbsp;D.name AS database_name <br />
&nbsp; &nbsp; &nbsp; , O.name AS table_name <br />
&nbsp; &nbsp; &nbsp; , I.name AS index_name <br />
&nbsp; &nbsp; &nbsp; , CASE IPS.index_type_desc <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHEN 'CLUSTERED INDEX' THEN 'CL' <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHEN 'NONCLUSTERED INDEX' THEN 'N-CL' <br />
&nbsp; &nbsp; &nbsp; &nbsp; ELSE IPS.index_type_desc <br />
&nbsp; &nbsp; &nbsp; END AS index_type <br />
&nbsp; &nbsp; &nbsp; , IUS.user_updates <br />
&nbsp; &nbsp; &nbsp; , IUS.user_seeks <br />
&nbsp; &nbsp; &nbsp; , IUS.user_scans <br />
&nbsp; &nbsp; &nbsp; , IUS.last_user_seek <br />
&nbsp; &nbsp; &nbsp; , IUS.last_user_scan <br />
&nbsp; &nbsp; &nbsp; , IPS.index_depth <br />
&nbsp; &nbsp; &nbsp; , IPS.page_count <br />
&nbsp; &nbsp; &nbsp; , CAST(IPS.avg_fragmentation_in_percent AS decimal(5, 2)) AS frag <br />
&nbsp; &nbsp; &nbsp; , CAST(IPS.avg_page_space_used_in_percent AS decimal(5, 2)) AS page_usage <br />
&nbsp; &nbsp; &nbsp; , STATS_DATE(IPS.object_id, IPS.index_id) AS last_update <br />
&nbsp; FROM &nbsp; &nbsp;sys.dm_db_index_physical_stats <br />
&nbsp; &nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; DB_ID() -- Base de données <br />
&nbsp; &nbsp; &nbsp; &nbsp; , OBJECT_ID(@_table_name) -- Table <br />
&nbsp; &nbsp; &nbsp; &nbsp; , NULL -- Index <br />
&nbsp; &nbsp; &nbsp; &nbsp; , NULL -- Partition <br />
&nbsp; &nbsp; &nbsp; &nbsp; , 'DETAILED' -- Niveau de détail <br />
&nbsp; &nbsp; &nbsp; ) IPS <br />
&nbsp; LEFT JOIN &nbsp;sys.dm_db_index_usage_stats AS IUS <br />
&nbsp; &nbsp; &nbsp; &nbsp; ON IUS.database_id = IPS.database_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; AND IUS.object_id = IPS.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; AND IUS.index_id = IPS.index_id <br />
&nbsp; INNER JOIN &nbsp;sys.databases AS D <br />
&nbsp; &nbsp; &nbsp; &nbsp; ON D.database_id = IPS.database_id <br />
&nbsp; INNER JOIN &nbsp;sys.indexes AS I <br />
&nbsp; &nbsp; &nbsp; &nbsp; ON I.object_id = IPS.object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; AND I.index_id = IPS.index_id <br />
&nbsp; INNER JOIN &nbsp;sys.objects AS O <br />
&nbsp; &nbsp; &nbsp; &nbsp; ON O.object_id = IPS.object_id <br />
&nbsp; WHERE &nbsp; &nbsp;IPS.index_level = 0 <br />
&nbsp; AND &nbsp; &nbsp;IPS.alloc_unit_type_desc &lt;&gt; 'LOB_DATA' <br />
END</div></td></tr></tbody></table></div>
<p>Et deux exemples d&rsquo;utilisation :</p>
<p>=> <code class="codecolorer text default"><span class="text">EXEC ps_get_index_stats</span></code></p>
<p>Collecte les statistiques de tous les index de la base de données</p>
<p>=> <code class="codecolorer text default"><span class="text">EXEC ps_get_index_stats 'maTable'</span></code></p>
<p>Collecte les statistiques de tous les index de la table <em>maTable</em></p>
<p>Vous pouvez bien sûr modifier son code pour pouvoir filtrer par base de données, par index et par partition.</p>
<p>Attention en revanche, car si l&rsquo;on passe des paramètres incorrects (valeurs négatives ou pas de valeur (NULL)) aux fonctions DB_ID() et OBJECT_ID(), cela a pour effet de collecter toutes les statistiques avec comme granularité la plus élevée.</p>
<p>On peut utiliser ce script pour décider de la <a href="http://blog.developpez.com/elsuket/p7712/agent-sql-server/une-procedure-stockee-pour-defragmenter/">reconstruction</a> ou de la réorganisation d&rsquo;un index &#8230;</p>
<p>Bonne indexation <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>Une procédure stockée pour défragmenter les indexes sous SQL Server 2005 et ultérieur</title>
		<link>https://blog.developpez.com/elsuket/p7712/moteur-de-base-de-donnees-sql-server/indexation/une_procedure_stockee_pour_defragmenter</link>
		<comments>https://blog.developpez.com/elsuket/p7712/moteur-de-base-de-donnees-sql-server/indexation/une_procedure_stockee_pour_defragmenter#comments</comments>
		<pubDate>Fri, 05 Jun 2009 16:53:33 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Agent SQL Server]]></category>
		<category><![CDATA[Indexation]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Voici une petite procédure stockée que l&#8217;on peut exécuter régulièrement dans un job pour défragmenter les indexes de toutes les bases de données, en fixant les seuils de nombre de page et de pourcentage moyen de fragmentation 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169--------------------------------- -- Nicolas &#8230; <a href="https://blog.developpez.com/elsuket/p7712/moteur-de-base-de-donnees-sql-server/indexation/une_procedure_stockee_pour_defragmenter">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Voici une petite procédure stockée que l&rsquo;on peut exécuter régulièrement dans un job pour défragmenter les indexes de toutes les bases de données, en fixant les seuils de nombre de page et de pourcentage moyen de fragmentation</p>
<p><span id="more-24"></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 /></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 - 05/06/2009 - <br />
--------------------------------- <br />
CREATE PROCEDURE [dbo].[Ps_Indexes_Rebuild] <br />
AS <br />
BEGIN <br />
&nbsp; SET NOCOUNT ON <br />
&nbsp;<br />
&nbsp; -- Table dans laquelle on va récupérer les noms et caractéristiques des indexes <br />
&nbsp; DECLARE @Tbindexes TABLE <br />
&nbsp; ( <br />
&nbsp; &nbsp; DB SYSNAME, <br />
&nbsp; &nbsp; Tables SYSNAME, <br />
&nbsp; &nbsp; IndexName SYSNAME, <br />
&nbsp; &nbsp; Frag VARCHAR(5), <br />
&nbsp; &nbsp; PageUsage VARCHAR(5), <br />
&nbsp; &nbsp; Pages VARCHAR(10), <br />
&nbsp; &nbsp; FillFactors TINYINT, <br />
&nbsp; &nbsp; Seeks VARCHAR(20), <br />
&nbsp; &nbsp; Scans VARCHAR(20), <br />
&nbsp; &nbsp; LastUserSeek VARCHAR(19), <br />
&nbsp; &nbsp; LastUserScan VARCHAR(19), <br />
&nbsp; &nbsp; IsUniqueConstraint BIT, <br />
&nbsp; &nbsp; IsPadded BIT, <br />
&nbsp; &nbsp; IsHypothetical BIT <br />
&nbsp; ) <br />
&nbsp;<br />
&nbsp; -- Table dans laquelle on récupère les statistiques des indexes <br />
&nbsp; DECLARE @TbIndexesStats TABLE <br />
&nbsp; ( <br />
&nbsp; &nbsp; database_id SMALLINT, <br />
&nbsp; &nbsp; object_id INT, <br />
&nbsp; &nbsp; index_id INT, <br />
&nbsp; &nbsp; avg_fragmentation_in_percent NUMERIC(4,2), <br />
&nbsp; &nbsp; avg_page_space_used_in_percent NUMERIC(4,2), <br />
&nbsp; &nbsp; page_count BIGINT, <br />
&nbsp; &nbsp; user_seeks BIGINT, <br />
&nbsp; &nbsp; user_scans BIGINT, <br />
&nbsp; &nbsp; last_user_seek DATETIME, <br />
&nbsp; &nbsp; last_user_scan DATETIME <br />
&nbsp; ); <br />
&nbsp;<br />
&nbsp; -- Récupération des stats sur les indexes <br />
&nbsp; WITH CTE_DB AS <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT database_id <br />
&nbsp; &nbsp; FROM sys.databases <br />
&nbsp; &nbsp; WHERE name NOT IN ('master', 'model', 'msdb', 'tempdb', 'ReportServer', 'ReportServerTempDB', 'distribution') <br />
&nbsp; ) <br />
&nbsp; INSERT INTO @TbIndexesStats <br />
&nbsp; SELECT IPS.database_id, <br />
&nbsp; &nbsp; &nbsp; IPS.object_id, <br />
&nbsp; &nbsp; &nbsp; IPS.index_id, <br />
&nbsp; &nbsp; &nbsp; IPS.avg_fragmentation_in_percent, <br />
&nbsp; &nbsp; &nbsp; IPS.avg_page_space_used_in_percent, <br />
&nbsp; &nbsp; &nbsp; IPS.page_count, <br />
&nbsp; &nbsp; &nbsp; IUS.user_seeks, <br />
&nbsp; &nbsp; &nbsp; IUS.user_scans, <br />
&nbsp; &nbsp; &nbsp; IUS.last_user_seek, <br />
&nbsp; &nbsp; &nbsp; IUS.last_user_scan <br />
&nbsp; FROM sys.dm_db_index_physical_stats(NULL, NULL, NULL, NULL, 'SAMPLED') IPS <br />
&nbsp; JOIN CTE_DB ON CTE_DB.database_id = IPS.database_id <br />
&nbsp; JOIN sys.dm_db_index_usage_stats IUS <br />
&nbsp; &nbsp; &nbsp; ON IUS.database_id = IPS.database_id <br />
&nbsp; &nbsp; &nbsp; AND IUS.object_id = IPS.object_id <br />
&nbsp; &nbsp; &nbsp; AND IUS.index_id = IPS.index_id <br />
&nbsp; WHERE IPS.index_id &gt; 0 <br />
&nbsp; AND IPS.avg_fragmentation_in_percent &gt; 25.0 <br />
&nbsp; AND IPS.page_count &gt; 50 <br />
&nbsp;<br />
&nbsp; -- Récupération des noms et caractéristiques des indexes <br />
&nbsp; DECLARE @SQL VARCHAR(1024), <br />
&nbsp; &nbsp; &nbsp; @Database_id VARCHAR(10), <br />
&nbsp; &nbsp; &nbsp; @Object_id VARCHAR(10), <br />
&nbsp; &nbsp; &nbsp; @Index_id VARCHAR(10), <br />
&nbsp; &nbsp; &nbsp; @AvgFragInPercent VARCHAR(5), <br />
&nbsp; &nbsp; &nbsp; @AvgPageSpaceUsedInPercent VARCHAR(5), <br />
&nbsp; &nbsp; &nbsp; @PageCount VARCHAR(10), <br />
&nbsp; &nbsp; &nbsp; @User_seeks VARCHAR(20), <br />
&nbsp; &nbsp; &nbsp; @User_scans VARCHAR(20), <br />
&nbsp; &nbsp; &nbsp; @Last_user_seek VARCHAR(19), <br />
&nbsp; &nbsp; &nbsp; @Last_user_scan VARCHAR(19) <br />
&nbsp;<br />
&nbsp; DECLARE curDBIndexes CURSOR FOR <br />
&nbsp; &nbsp; SELECT CAST(database_id AS VARCHAR(10)), <br />
&nbsp; &nbsp; &nbsp; CAST(object_id AS VARCHAR(10)), <br />
&nbsp; &nbsp; &nbsp; CAST(index_id AS VARCHAR(10)), <br />
&nbsp; &nbsp; &nbsp; CAST(avg_fragmentation_in_percent AS VARCHAR(5)), <br />
&nbsp; &nbsp; &nbsp; CAST(avg_page_space_used_in_percent AS VARCHAR(5)), <br />
&nbsp; &nbsp; &nbsp; CAST(page_count AS VARCHAR(10)), <br />
&nbsp; &nbsp; &nbsp; CAST(user_seeks AS VARCHAR(20)), <br />
&nbsp; &nbsp; &nbsp; CAST(user_scans AS VARCHAR(20)), <br />
&nbsp; &nbsp; &nbsp; COALESCE(CONVERT(VARCHAR(19), last_user_seek, 120), 'NULL'), <br />
&nbsp; &nbsp; &nbsp; COALESCE(CONVERT(VARCHAR(19), last_user_scan, 120), 'NULL') <br />
&nbsp; &nbsp; FROM @TbIndexesStats <br />
&nbsp; FOR READ ONLY <br />
&nbsp;<br />
&nbsp; OPEN curDBIndexes <br />
&nbsp; FETCH NEXT FROM curDBIndexes INTO @Database_id, @Object_id, @Index_id, @AvgFragInPercent, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @AvgPageSpaceUsedInPercent, @PageCount, @User_seeks, @User_scans, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Last_user_seek, @Last_user_scan <br />
&nbsp; WHILE @@FETCH_STATUS = 0 <br />
&nbsp; BEGIN <br />
&nbsp; &nbsp; SET @SQL = 'SELECT DB_NAME(' + @Database_id + '),' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'O.name,' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'IDX.name,' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @AvgFragInPercent + ',' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @AvgPageSpaceUsedInPercent + ',' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @PageCount + ',' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'IDX.fill_factor, ' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @User_seeks + ',' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @User_scans + ',''' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Last_user_seek + ''',''' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Last_user_scan + ''',' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'IDX.is_unique_constraint, ' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'IDX.is_padded, ' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'IDX.is_hypothetical' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' FROM ' + DB_NAME(CAST(@Database_id AS INT)) + '.sys.indexes IDX' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' JOIN ' &nbsp;+ DB_NAME(CAST(@Database_id AS INT)) + '.sys.objects O ON O.object_id = IDX.object_id' + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' WHERE IDX.object_id = ' + @Object_id + <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' AND IDX.index_id = ' + @Index_id <br />
&nbsp;<br />
&nbsp; &nbsp; INSERT INTO @Tbindexes <br />
&nbsp; &nbsp; EXEC (@SQL) <br />
&nbsp;<br />
&nbsp; &nbsp; FETCH NEXT FROM curDBIndexes INTO @Database_id, @Object_id, @Index_id, @AvgFragInPercent, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @AvgPageSpaceUsedInPercent, @PageCount, @User_seeks, @User_scans, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Last_user_seek, @Last_user_scan <br />
&nbsp; END <br />
&nbsp; DEALLOCATE curDBIndexes <br />
&nbsp;<br />
&nbsp; -- Reconstruction des indexes <br />
&nbsp; DECLARE @DB SYSNAME, <br />
&nbsp; &nbsp; &nbsp; @Tables SYSNAME, <br />
&nbsp; &nbsp; &nbsp; @IndexName SYSNAME, <br />
&nbsp; &nbsp; &nbsp; @FillFactors VARCHAR(5), <br />
&nbsp; &nbsp; &nbsp; @IsPadded BIT, <br />
&nbsp; &nbsp; &nbsp; @RebuildCommand VARCHAR(1024) <br />
&nbsp;<br />
&nbsp; DECLARE CUR_INDEXES_TO_REBUILD CURSOR FOR <br />
&nbsp; &nbsp; SELECT DB, <br />
&nbsp; &nbsp; &nbsp; &nbsp; Tables, <br />
&nbsp; &nbsp; &nbsp; &nbsp; IndexName, <br />
&nbsp; &nbsp; &nbsp; &nbsp; CAST( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CASE FillFactors <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 0 THEN 99 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE FillFactors <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END AS VARCHAR(5) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ), <br />
&nbsp; &nbsp; &nbsp; &nbsp; IsPadded <br />
&nbsp; &nbsp; FROM @Tbindexes <br />
&nbsp; FOR READ ONLY <br />
&nbsp;<br />
&nbsp; OPEN CUR_INDEXES_TO_REBUILD <br />
&nbsp; FETCH NEXT FROM CUR_INDEXES_TO_REBUILD INTO @DB, @Tables, @IndexName, @FillFactors, @IsPadded <br />
&nbsp; WHILE @@FETCH_STATUS = 0 <br />
&nbsp; BEGIN <br />
&nbsp; &nbsp; SELECT @RebuildCommand = 'ALTER INDEX ' + @IndexName + ' ON ' + @DB + '.dbo.' + @Tables + &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' REBUILD WITH (FILLFACTOR = ' + @FillFactors + &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CASE @IsPadded <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 1 THEN ', PAD_INDEX = ON)' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE ')' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; EXEC (@RebuildCommand) <br />
&nbsp; &nbsp; FETCH NEXT FROM CUR_INDEXES_TO_REBUILD INTO @DB, @Tables, @IndexName, @FillFactors, @IsPadded <br />
&nbsp; END <br />
&nbsp; DEALLOCATE CUR_INDEXES_TO_REBUILD <br />
END</div></td></tr></tbody></table></div>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Vérifier l&#8217;unicité d&#8217;une position avec le type GEOGRAPHY sous SQL Server 2008</title>
		<link>https://blog.developpez.com/elsuket/p8257/moteur-de-base-de-donnees-sql-server/indexation/verifier_l_unicite_d_une_position_avec_l_2008</link>
		<comments>https://blog.developpez.com/elsuket/p8257/moteur-de-base-de-donnees-sql-server/indexation/verifier_l_unicite_d_une_position_avec_l_2008#comments</comments>
		<pubDate>Thu, 29 Oct 2009 22:33:34 +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[Systèmes d&#039;information géographiques]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[SQL Server 2008 a introduit de nombreux nouveaux types de données, dont le type de données géographiques GEOGRAPHY. Ce n&#8217;est pas un type habituel, puisque c&#8217;est un type CLR.NET intégré à SQL Server. L&#8217;avantage présenté par l&#8217;intégration de ce type &#8230; <a href="https://blog.developpez.com/elsuket/p8257/moteur-de-base-de-donnees-sql-server/indexation/verifier_l_unicite_d_une_position_avec_l_2008">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SQL Server 2008 a introduit de nombreux nouveaux types de données, dont le type de données géographiques GEOGRAPHY.<br />
Ce n&rsquo;est pas un type habituel, puisque c&rsquo;est un type CLR.NET intégré à SQL Server.</p>
<p>L&rsquo;avantage présenté par l&rsquo;intégration de ce type est l&rsquo;ensemble des méthodes standard &laquo;&nbsp;livrées&nbsp;&raquo; avec ce type, qui permettent d&rsquo;extraire très simplement une latitude (attribut Lat), une longitude (attribut Long), ou encore de connaître la distance entre deux points géographiques avec la méthode <a href="http://msdn.microsoft.com/fr-fr/library/bb933808.aspx">STDistance</a>.</p>
<p>Mais il devient alors plus complexe de garantir l&rsquo;unicité de positions dans une table où l&rsquo;on stocke la celle de plusieurs villes.<br />
En effet, si une colonne de ce type est spécifiée comme clé d&rsquo;une contrainte d&rsquo;unicité, le moteur de base de données SQL Server lève une exception.</p>
<p>Est-il possible de contourner ce problème ?</p>
<p><span id="more-160"></span></p>
<p>Si nous tentons de créer la 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE TABLE dbo.TbCoordonneeVille <br />
( <br />
&nbsp; IDCoordonneeVille INT NOT NULL IDENTITY CONSTRAINT PK_TbCoordonneeVille PRIMARY KEY, <br />
&nbsp; nomVille VARCHAR(45) NOT NULL CONSTRAINT UQ_TbCoordonneeVille_nomVille UNIQUE, <br />
&nbsp; geoPositionVille GEOGRAPHY NOT NULL CONSTRAINT UQ_TbCoordonneeVille_geoPositionVille UNIQUE &nbsp;<br />
)</div></td></tr></tbody></table></div>
<p>Nous obtenons l&rsquo;erreur :</p>
<blockquote><p>Msg 1919, Niveau 16, État 1, Ligne 1<br />
La colonne &lsquo;geoPositionVille&rsquo; dans la table &lsquo;TbCoordonneeVille&rsquo; n&rsquo;est pas d&rsquo;un type valide lui permettant d&rsquo;être utilisée en tant que colonne clé dans un index.<br />
Msg 1750, Niveau 16, État 0, Ligne 1<br />
Impossible de créer la contrainte. Voir les erreurs précédentes.</p></blockquote>
<p>Nous sommes donc contraints de créer la table sans la contrainte d&rsquo;unicité sur la colonne geoPositionVille :</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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE TABLE dbo.TbCoordonneeVille <br />
( <br />
&nbsp; IDCoordonneeVille INT NOT NULL IDENTITY CONSTRAINT PK_TbCoordonneeVille PRIMARY KEY, <br />
&nbsp; nomVille VARCHAR(45) NOT NULL CONSTRAINT UQ_TbCoordonneeVille_nomVille UNIQUE, <br />
&nbsp; geoPositionVille GEOGRAPHY NOT NULL <br />
)</div></td></tr></tbody></table></div>
<p>Comment faire pour garantir l&rsquo;unicité des positions des villes sans perdre les avantages offerts par le type GEOGRAPHY ?<br />
Il est possible de créer une contrainte d&rsquo;unicité sur des colonnes calculées persistantes.</p>
<p>Ajoutons donc deux colonnes calculées, une pour la latitude, et une autre pour la longitude.<br />
Attention, la casse sur les méthodes CLR est importante.</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 /></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 - 29/10/2009 <br />
------------------------------- <br />
ALTER TABLE dbo.TbCoordonneeVille <br />
ADD latitudeVille AS (geoPositionVille.Lat) PERSISTED NOT NULL, <br />
&nbsp; longitudeVille AS (geoPositionVille.Long) PERSISTED NOT NULL</div></td></tr></tbody></table></div>
<p>Il nous suffit ensuite de créer une contrainte d&rsquo;unicité sur ces deux colonnes :</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 /></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 - 29/10/2009 <br />
------------------------------- <br />
ALTER TABLE dbo.TbCoordonneeVille <br />
ADD CONSTRAINT UQ_TbCoordonneeVille_latitudeVille_longitudeVille <br />
&nbsp; UNIQUE (latitudeVille, longitudeVille)</div></td></tr></tbody></table></div>
<p>Essayons maintenant d&rsquo;insérer deux villes dont le nom est différent, mais dont les coordonnées sont identiques :</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">INSERT INTO dbo.TbCoordonneeVille (nomVille, geoPositionVille) <br />
VALUES ('Toulouse', GEOGRAPHY::STPointFromText('POINT(43.604503 1.444026)', 4326)) <br />
GO <br />
&nbsp;<br />
INSERT INTO dbo.TbCoordonneeVille (nomVille, geoPositionVille) <br />
VALUES ('Lyon', GEOGRAPHY::STPointFromText('POINT(43.604503 1.444026)', 4326)) <br />
GO</div></td></tr></tbody></table></div>
<p>La première instruction se passe sans problèmes.<br />
En revanche la seconde échoue, et nous obtenons l&rsquo;erreur suivante :</p>
<blockquote><p>Msg 2627, Niveau 14, État 1, Ligne 1<br />
Violation de la contrainte UNIQUE KEY &lsquo;UQ_TbCoordonneeVille_latitudeVille_longitudeVille&rsquo;. Impossible d&rsquo;insérer une clé en double dans l&rsquo;objet &lsquo;dbo.TbCoordonneeVille&rsquo;.<br />
L&rsquo;instruction a été arrêtée.</p></blockquote>
<p>Vérifions le contenu de la table :</p>
<p><img src="http://blog.developpez.com/media/geographyUnique1.PNG" width="1079" height="363" alt="" /></p>
<p>Une solution alternative est de créer une vue indexée, ce qui présentera un bon avantage si la table est souvent lue.<br />
Supprimons la table puis recréons-la :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">DROP TABLE dbo.TbCoordonneeVille <br />
GO <br />
&nbsp;<br />
CREATE TABLE dbo.TbCoordonneeVille <br />
( <br />
&nbsp; IDCoordonneeVille INT NOT NULL IDENTITY CONSTRAINT PK_TbCoordonneeVille PRIMARY KEY, <br />
&nbsp; nomVille VARCHAR(45) NOT NULL CONSTRAINT UQ_TbCoordonneeVille_nomVille UNIQUE, <br />
&nbsp; geoPositionVille GEOGRAPHY NOT NULL <br />
)</div></td></tr></tbody></table></div>
<p>Créons ensuite la vue :</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">------------------------------- <br />
-- Nicolas SOUQUET - 29/10/2009 <br />
------------------------------- <br />
CREATE VIEW dbo.VwCoordonneeVille <br />
&nbsp; WITH SCHEMABINDING <br />
AS <br />
SELECT nomVille, <br />
&nbsp; &nbsp; geoPositionVille.Lat AS latitudeVille, <br />
&nbsp; &nbsp; geoPositionVille.Long AS longitudeVille <br />
FROM dbo.TbCoordonneeVille</div></td></tr></tbody></table></div>
<p>Puis indexons-la :</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 /></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 - 29/10/2009 <br />
------------------------------- <br />
CREATE UNIQUE CLUSTERED INDEX IXUQC_VwCoordonneeVille_latitudeVille_longitudeVille <br />
ON dbo.VwCoordonneeVille(latitudeVille, longitudeVille)</div></td></tr></tbody></table></div>
<p>Et tentons les mêmes insertions que celles que nous avons faites pour tester la contrainte d&rsquo;unicité sur les colonnes calculées persistantes :</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">INSERT INTO dbo.TbCoordonneeVille (nomVille, geoPositionVille) <br />
VALUES ('Toulouse', GEOGRAPHY::STPointFromText('POINT(43.604503 1.444026)', 4326)) <br />
GO <br />
&nbsp;<br />
INSERT INTO dbo.TbCoordonneeVille (nomVille, geoPositionVille) <br />
VALUES ('Lyon', GEOGRAPHY::STPointFromText('POINT(43.604503 1.444026)', 4326)) <br />
GO</div></td></tr></tbody></table></div>
<p>Là encore, la première instruction se passe sans problème, mais la seconde échoue, provoquant l&rsquo;erreur suivante :</p>
<blockquote><p>Msg 2601, Niveau 14, État 1, Ligne 1<br />
Impossible d&rsquo;insérer une ligne de clé en double dans l&rsquo;objet &lsquo;dbo.VwCoordonneeVille&rsquo; avec un index unique &lsquo;IXUQC_VwCoordonneeVille_latitudeVille_longitudeVille&rsquo;.<br />
L&rsquo;instruction a été arrêtée.</p></blockquote>
<p>Interrogeons néanmoins la vue :</p>
<p><img src="http://blog.developpez.com/media/geographyUnique2.PNG" width="770" height="348" alt="" /></p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vérifier l&#8217;unicité de tuples NULLables avec les index filtrés sous SQL Server 2008</title>
		<link>https://blog.developpez.com/elsuket/p8256/moteur-de-base-de-donnees-sql-server/indexation/verifier_l_unicite_de_tuples_avec_les_in_2008</link>
		<comments>https://blog.developpez.com/elsuket/p8256/moteur-de-base-de-donnees-sql-server/indexation/verifier_l_unicite_de_tuples_avec_les_in_2008#comments</comments>
		<pubDate>Thu, 29 Oct 2009 21:40:56 +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[Toute contrainte d&#8217;unicité entraîne la création implicite d&#8217;une index unique sur la table, dont la clé est constituée des colonnes spécifiées dans la contrainte d&#8217;unicité. Or, lors de l&#8217;insertion d&#8217;une nouvelle ligne ou de la modification d&#8217;une des colonnes constituant &#8230; <a href="https://blog.developpez.com/elsuket/p8256/moteur-de-base-de-donnees-sql-server/indexation/verifier_l_unicite_de_tuples_avec_les_in_2008">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Toute contrainte d&rsquo;unicité entraîne la création implicite d&rsquo;une index unique sur la table, dont la clé est constituée des colonnes spécifiées dans la contrainte d&rsquo;unicité.</p>
<p>Or, lors de l&rsquo;insertion d&rsquo;une nouvelle ligne ou de la modification d&rsquo;une des colonnes constituant la clé unique, SQL Server considère NULL comme une valeur.<br />
Cela est faux puisque NULL n&rsquo;est pas une valeur : c&rsquo;est l&rsquo;absence de valeur.</p>
<p>Avec SQL Server 2008 ont été introduits les index filtrés, qui permettent de spécifier les lignes candidates à l&rsquo;indexation, par l&rsquo;ajout d&rsquo;une simple clause WHERE.<br />
Dès lors, il est possible de contourner le problème posé par les contraintes d&rsquo;unicité en se servant de ce type d&rsquo;index &#8230;</p>
<p><span id="more-91"></span></p>
<p>Supposons que nous avons plusieurs applications qui doivent se connecter à notre base de données, et que l&rsquo;authentification des utilisateurs est gérée dans cette base de données à l&rsquo;aide de la table suivante :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE TABLE dbo.TbUtilisateur <br />
( <br />
&nbsp; IDUtilisateur INT NOT NULL IDENTITY CONSTRAINT PK_TbUtilisateur PRIMARY KEY, <br />
&nbsp; nomUtilisateur VARCHAR(30) NOT NULL, <br />
&nbsp; prenomUtilisateur VARCHAR(30) NOT NULL, <br />
&nbsp; identifiantUtilisateur VARCHAR(10) CONSTRAINT UQ_TbUtilisateur_identifiantUtilisateur UNIQUE, <br />
&nbsp; motDePasseUtilisateur VARCHAR(10) <br />
) <br />
&nbsp;<br />
ALTER TABLE dbo.TbUtilisateur <br />
ADD CONSTRAINT CHK_TbUtilisateur_identifiantUtilisateur_motDePasseUtilisateur <br />
&nbsp; CHECK ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; identifiantUtilisateur IS NULL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND motDePasseUtilisateur IS NULL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OR <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; identifiantUtilisateur IS NOT NULL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND motDePasseUtilisateur IS NOT NULL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) <br />
&nbsp; &nbsp; &nbsp; )</div></td></tr></tbody></table></div>
<p>Il est nécessaire que l&rsquo;identifiant qui permet à nos utilisateurs de se connecter soit unique.<br />
Notre application donne le droit aux administrateurs d&rsquo;enregistrer les nouveaux salariés.<br />
Lors de la première connexion de ceux-ci, il doivent spécifier un identifiant et un mot de passe que les administrateurs ne peuvent pas choisir à leur place, et il a été décidé que ces deux valeurs seront laissées à NULL jusqu&rsquo;à la première connexion de l&rsquo;utilisateur.</p>
<p>Le contenu de la table pourrait dont être le suivant :</p>
<p><img src="http://blog.developpez.com/media/filteredIndexUnique1.PNG" width="522" height="57" alt="" /></p>
<p>Essayons maintenant d&rsquo;enregistrer un nouvel utilisateur :</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">INSERT INTO dbo.TbUtilisateur <br />
( <br />
&nbsp; nomUtilisateur, <br />
&nbsp; prenomUtilisateur, <br />
&nbsp; identifiantUtilisateur, <br />
&nbsp; motDePasseUtilisateur <br />
) <br />
VALUES <br />
( <br />
&nbsp; 'DELANEY', <br />
&nbsp; 'Kalen', <br />
&nbsp; NULL, <br />
&nbsp; NULL <br />
)</div></td></tr></tbody></table></div>
<p>Cela provoque l&rsquo;erreur suivante :</p>
<blockquote><p>Msg 2627, Niveau 14, État 1, Ligne 1<br />
Violation de la contrainte UNIQUE KEY &lsquo;UQ_TbUtilisateur_identifiantUtilisateur&rsquo;. Impossible d&rsquo;insérer une clé en double dans l&rsquo;objet &lsquo;dbo.TbUtilisateur&rsquo;.<br />
L&rsquo;instruction a été arrêtée.</p></blockquote>
<p>Remplaçons donc la contrainte d&rsquo;unicité par un index filtré :</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">------------------------------- <br />
-- Nicolas SOUQUET - 29/10/2009 <br />
------------------------------- <br />
ALTER TABLE dbo.TbUtilisateur <br />
DROP CONSTRAINT UQ_TbUtilisateur_identifiantUtilisateur <br />
GO <br />
&nbsp;<br />
CREATE UNIQUE NONCLUSTERED INDEX IUXQ_TbUtilisateur_F_identifiantUtilisateur <br />
ON dbo.TbUtilisateur(identifiantUtilisateur) <br />
WHERE identifiantUtilisateur IS NOT NULL</div></td></tr></tbody></table></div>
<p>Tentons de nouveau l&rsquo;insertion de ce nouvel utilisateur :</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">INSERT INTO dbo.TbUtilisateur <br />
( <br />
&nbsp; nomUtilisateur, <br />
&nbsp; prenomUtilisateur, <br />
&nbsp; identifiantUtilisateur, <br />
&nbsp; motDePasseUtilisateur <br />
) <br />
VALUES <br />
( <br />
&nbsp; 'DELANEY', <br />
&nbsp; 'Kalen', <br />
&nbsp; NULL, <br />
&nbsp; NULL <br />
)</div></td></tr></tbody></table></div>
<p><img src="http://blog.developpez.com/media/filteredIndexUnique2.PNG" width="523" height="78" alt="" /></p>
<p>Pour vérifier, tentons d&rsquo;insérer un nouvel utilisateur avec le même identifiant de connexion que M. Brouard :</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">INSERT INTO dbo.TbUtilisateur <br />
( <br />
&nbsp; nomUtilisateur, <br />
&nbsp; prenomUtilisateur, <br />
&nbsp; identifiantUtilisateur, <br />
&nbsp; motDePasseUtilisateur <br />
) <br />
VALUES <br />
( <br />
&nbsp; 'RANDAL', <br />
&nbsp; 'Paul', <br />
&nbsp; 'FB', <br />
&nbsp; '***' <br />
)</div></td></tr></tbody></table></div>
<p>Cela provoque l&rsquo;erreur suivante :</p>
<blockquote><p>Msg 2601, Niveau 14, État 1, Ligne 1<br />
Impossible d&rsquo;insérer une ligne de clé en double dans l&rsquo;objet &lsquo;dbo.TbUtilisateur&rsquo; avec un index unique &lsquo;IUXQ_TbUtilisateur_F_identifiantUtilisateur&rsquo;.<br />
L&rsquo;instruction a été arrêtée.</p></blockquote>
<p>L&rsquo;unicité des identifiants de connexion est donc bien vérifiée, et laisse la place aux nouveaux entrants <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Différence entre fragmentation interne et externe d&#8217;un index</title>
		<link>https://blog.developpez.com/elsuket/p7894/moteur-de-base-de-donnees-sql-server/indexation/difference_entre_fragmentation_interne_e</link>
		<comments>https://blog.developpez.com/elsuket/p7894/moteur-de-base-de-donnees-sql-server/indexation/difference_entre_fragmentation_interne_e#comments</comments>
		<pubDate>Thu, 23 Jul 2009 17:00:12 +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[Quand on parle de la fragmentation physique des indexes, on parle aussi de fragmentation externe. Celle-ci se &#171;&#160;produit&#160;&#187; lorsque l&#8217;ordre logique des pages de l&#8217;index est incorrect. Les nouvelles valeurs de clé de l&#8217;index sont alors insérées dans de nouvelles &#8230; <a href="https://blog.developpez.com/elsuket/p7894/moteur-de-base-de-donnees-sql-server/indexation/difference_entre_fragmentation_interne_e">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Quand on parle de la fragmentation physique des indexes, on parle aussi de fragmentation externe. Celle-ci se &laquo;&nbsp;produit&nbsp;&raquo; lorsque l&rsquo;ordre logique des pages de l&rsquo;index est incorrect. Les nouvelles valeurs de clé de l&rsquo;index sont alors insérées dans de nouvelles pages d&rsquo;index, qui désordonnent l&rsquo;ordre original de la clé de l&rsquo;index.</p>
<p>Quand on parle de fragmentation logique de l&rsquo;index, on parle aussi de fragmentation interne : c&rsquo;est le cas lorsque la quantité de données stockée dans les pages de l&rsquo;index est plus petite que la quantité maximale de données que peut stocker une page.</p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajouter des contraintes à des tables déjà existantes</title>
		<link>https://blog.developpez.com/elsuket/p7900/moteur-de-base-de-donnees-sql-server/indexation/ajouter_des_contraintes_a_des_tables_dej</link>
		<comments>https://blog.developpez.com/elsuket/p7900/moteur-de-base-de-donnees-sql-server/indexation/ajouter_des_contraintes_a_des_tables_dej#comments</comments>
		<pubDate>Sat, 25 Jul 2009 14:07:42 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Comment peut-on ajouter des contraintes de tous types à une table qui existe déjà, mais dont on a modifié la structure ou tout simplement oublié d&#8217;ajouter la contrainte en même temps que la colonne ? Considérons le DDL des tables &#8230; <a href="https://blog.developpez.com/elsuket/p7900/moteur-de-base-de-donnees-sql-server/indexation/ajouter_des_contraintes_a_des_tables_dej">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Comment peut-on ajouter des contraintes de tous types à une table qui existe déjà, mais dont on a modifié la structure ou tout simplement oublié d&rsquo;ajouter la contrainte en même temps que la colonne ?</p>
<p><span id="more-7"></span></p>
<p>Considérons le DDL des tables suivantes :</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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--------------------------------- <br />
-- Nicolas SOUQUET - 25/07/2009 - <br />
--------------------------------- <br />
CREATE TABLE TbPays <br />
( <br />
&nbsp; IDPays INT IDENTITY, <br />
&nbsp; nomPays VARCHAR(30), <br />
&nbsp; prefixeTelephonique VARCHAR(4), <br />
&nbsp; longueurNumeroTelephone TINYINT <br />
) <br />
&nbsp;<br />
CREATE TABLE TbClient <br />
( <br />
&nbsp; IDClient INT IDENTITY, <br />
&nbsp; nomClient VARCHAR(20), <br />
&nbsp; IDPays INT, <br />
&nbsp; numeroTelephoneClient VARCHAR(36) <br />
) <br />
&nbsp;<br />
CREATE TABLE TbAbonnement &nbsp;<br />
( <br />
&nbsp; IDAbonnement INT IDENTITY, <br />
&nbsp; referenceAbonnement CHAR(10), <br />
&nbsp; nomAbonnement VARCHAR(30), <br />
&nbsp; descriptionAbonnemement VARCHAR(255) <br />
) <br />
&nbsp;<br />
CREATE TABLE TbAbonnementClient <br />
( <br />
&nbsp; IDAbonnementClient INT IDENTITY, <br />
&nbsp; IDClient INT, <br />
&nbsp; IDAbonnement INT, <br />
&nbsp; dateAbonnementClient DATETIME <br />
)</div></td></tr></tbody></table></div>
<p>Manifestement il manque toutes les contraintes  :</p>
<p>&#8211; de valuation obligatoire (NOT NULL),<br />
&#8211; de clé primaire,<br />
&#8211; de clé étrangère,<br />
&#8211; d&rsquo;unicité,<br />
&#8211; de valeur par défaut<br />
&#8211; de domaine (CHECK)</p>
<p><strong>Le squelette d&rsquo;ajout de contraintes est le suivant :</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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--------------------------------- <br />
-- Nicolas SOUQUET - 25/07/2009 - <br />
---------------------------------</div></td></tr></tbody></table></div>
<p>=> contraintes de valuation obligatoire</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 />
ALTER COLUMN maColonne memeType NOT NULL</div></td></tr></tbody></table></div>
<p>=> contraintes de clé primaire</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">ALTER TABLE maTable <br />
ADD CONSTRAINT PK_maTable <br />
&nbsp; PRIMARY KEY (colonnesConstituantLaCléPrimaire)</div></td></tr></tbody></table></div>
<p>=> contraintes de clé étrangère</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">ALTER TABLE maTable <br />
ADD CONSTRAINT FK_maTable_colonneDeCleEtrangere <br />
&nbsp; FOREIGN KEY(colonneDeCleEtrangere) <br />
&nbsp; REFERENCES tableContenantLaClePrimaireAReferencer(colonneDeClePrimaire)</div></td></tr></tbody></table></div>
<p>=> contraintes d&rsquo;unicité</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">ALTER TABLE maTable <br />
ADD CONSTRAINT UQ_maTable_colonnesConstituantLeTupleQuiDoitEtreUnique <br />
&nbsp; UNIQUE (colonnesConstituantLeTupleQuiDoitEtreUnique)</div></td></tr></tbody></table></div>
<p>=> contraintes de valeur par défaut :</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">ALTER TABLE maTable <br />
ADD CONSTRAINT DF_maTable_maColonne <br />
&nbsp; DEFAULT (uneValeur) FOR (maColonne)</div></td></tr></tbody></table></div>
<p>=> contraintes de domaine (CHECK)<br />
ALTER TABLE maTable<br />
ADD CONSTRAINT CHK_maTable_maColonne<br />
	CHECK(maColonne [formuleDeVerification]</p>
<p><strong>Définissons les dans cet ordre :</strong></p>
<p>=> <strong>Contraintes de valuation obligatoire</strong> </p>
<p>Une clé primaire ne pouvant logiquement pas être NULL, nous devons définir toute les colonnes qui vont servir de clé primaire aux tables comme ne pouvant pas être NULL.<br />
Nous devons également obliger la valuation des colonnes qui sont des clés naturelles, et celles qui seront clé étrangère :</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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--------------------------------- <br />
-- Nicolas SOUQUET - 25/07/2009 - <br />
--------------------------------- <br />
-- TbPays <br />
ALTER TABLE dbo.TbPays <br />
ALTER COLUMN IDPays INT NOT NULL <br />
&nbsp;<br />
ALTER TABLE dbo.TbPays <br />
ALTER COLUMN nomPays VARCHAR(30) NOT NULL <br />
&nbsp;<br />
ALTER TABLE dbo.TbPays <br />
ALTER COLUMN prefixeTelephonique VARCHAR(4) NOT NULL <br />
&nbsp;<br />
ALTER TABLE dbo.TbPays <br />
ALTER COLUMN longueurNumeroTelephone TINYINT NOT NULL <br />
&nbsp;<br />
-- TbClient <br />
ALTER TABLE dbo.TbClient <br />
ALTER COLUMN IDClient INT NOT NULL <br />
&nbsp;<br />
ALTER TABLE dbo.TbClient <br />
ALTER COLUMN nomClient VARCHAR(20) NOT NULL <br />
&nbsp;<br />
ALTER TABLE dbo.TbClient <br />
ALTER COLUMN IDPays INT NOT NULL <br />
&nbsp;<br />
ALTER TABLE dbo.TbClient <br />
ALTER COLUMN numeroTelephoneClient VARCHAR(36) NOT NULL <br />
&nbsp;<br />
-- TbAbonnement <br />
ALTER TABLE dbo.TbAbonnement <br />
ALTER COLUMN IDAbonnement INT NOT NULL <br />
&nbsp;<br />
ALTER TABLE dbo.TbAbonnement <br />
ALTER COLUMN referenceAbonnement NOT NULL <br />
&nbsp;<br />
ALTER TABLE dbo.TbAbonnement <br />
ALTER COLUMN nomAbonnement VARCHAR(30) NOT NULL <br />
&nbsp;<br />
-- TbAbonnementClient <br />
ALTER TABLE dbo.TbAbonnementClient <br />
ALTER COLUMN IDAbonnementClient INT NOT NULL <br />
&nbsp;<br />
ALTER TABLE dbo.TbAbonnementClient <br />
ALTER COLUMN IDClient INT NOT NULL <br />
&nbsp;<br />
ALTER TABLE dbo.TbAbonnementClient <br />
ALTER COLUMN IDAbonnement INT NOT NULL <br />
&nbsp;<br />
ALTER TABLE dbo.TbAbonnementClient <br />
ALTER COLUMN dateAbonnementClient DATETIME NOT NULL</div></td></tr></tbody></table></div>
<p>=> <strong>Contraintes de clé primaire</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 - 25/07/2009 - <br />
--------------------------------- <br />
-- TbPays <br />
ALTER TABLE dbo.TbPays <br />
ADD CONSTRAINT PK_TbPays_IDPays PRIMARY KEY (IDPays) <br />
&nbsp;<br />
-- TbClient <br />
ALTER TABLE dbo.TbClient <br />
ADD CONSTRAINT PK_TbClient_IDClient PRIMARY KEY(IDClient) <br />
&nbsp;<br />
-- TbAbonnement <br />
ALTER TABLE dbo.TbAbonnement <br />
ADD CONSTRAINT PK_TbAbonnement_IDAbonnement PRIMARY KEY (IDAbonnement) <br />
&nbsp;<br />
-- TbAbonnementClient <br />
ALTER TABLE dbo.TbAbonnementClient <br />
ADD CONSTRAINT PK_TbAbonnementClient_IDAbonnementClient PRIMARY KEY (IDAbonnementClient)</div></td></tr></tbody></table></div>
<p>=> <strong>Contraintes de clé étrangère</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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--------------------------------- <br />
-- Nicolas SOUQUET - 25/07/2009 - <br />
--------------------------------- <br />
-- TbClient <br />
ALTER TABLE dbo.TbClient <br />
ADD CONSTRAINT FK_TbClient_IDPays <br />
&nbsp; FOREIGN KEY (IDPays) REFERENCES dbo.TbPays(IDPays) <br />
&nbsp;<br />
-- TbAbonnementClient <br />
ALTER TABLE dbo.TbAbonnementClient <br />
ADD CONSTRAINT FK_TbAbonnementClient_IDClient <br />
&nbsp; FOREIGN KEY (IDClient) REFERENCES dbo.TbClient(IDClient), <br />
&nbsp; ---- <br />
&nbsp; CONSTRAINT FK_TbAbonnementClient_IDAbonnement <br />
&nbsp; FOREIGN KEY (IDAbonnement) REFERENCES dbo.TbAbonnement(IDAbonnement)</div></td></tr></tbody></table></div>
<p>=> <strong>Contraintes d&rsquo;unicité</strong></p>
<p>Elles permettent de s&rsquo;assurer qu&rsquo;aucune valeur ne sera pas insérée en double dans des colonnes qui ne constituent pas la clé primaire.<br />
Bien qu&rsquo;une clé primaire permette également d&rsquo;assurer l&rsquo;unicité, on ne peut bien sûr en définir qu&rsquo;une seule par table, pour qu&rsquo;il soit possible de la référencer par des clés étrangères dans d&rsquo;autres tables.<br />
Au contraire, on peut définir plusieurs contraintes d&rsquo;unicité par table.</p>
<p>Similairement, des indexes sont créés implicitement lors de la création d&rsquo;une clé primaire ou d&rsquo;une contrainte d&rsquo;unicité.<br />
Mais seul l&rsquo;index de clé primaire est toujours cluster : l&rsquo;index sous-jacent à une contrainte d&rsquo;unicité est cluster si la table n&rsquo;a pas de clé primaire définie, et non-cluster à l&rsquo;inverse.<br />
Comme pour une clé primaire, il est nécessaire de mettre la colonne qui a la sélectivité la plus élevée en premier dans la définition de la contrainte d&rsquo;unicité, car cet ordre sert dans la définition de l&rsquo;index.<br />
Comme les recherches à travers les indexes se font suivant la valeur de la première clé, l&rsquo;index sera d&rsquo;autant plus efficace que la valeur de sa première clé sera sélective.</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 - 25/07/2009 - <br />
--------------------------------- <br />
-- TbClient <br />
ALTER TABLE dbo.TbClient <br />
ADD CONSTRAINT UQ_TbClient_nomClient UNIQUE (nomClient), <br />
&nbsp; CONSTRAINT UQ_TbClient_numeroTelephoneClient UNIQUE (numeroTelephoneClient) <br />
&nbsp;<br />
-- TbAbonnement <br />
ALTER TABLE dbo.TbAbonnement <br />
ADD CONSTRAINT UQ_TbAbonnement_nomAbonnement UNIQUE (nomAbonnement) <br />
&nbsp;<br />
ALTER TABLE dbo.TbAbonnement <br />
ADD CONSTRAINT UQ_TbAbonnement_referenceAbonnement UNIQUE (referenceAbonnement) <br />
&nbsp;<br />
-- TbAbonnementClient <br />
ALTER TABLE dbo.TbAbonnementClient <br />
ADD CONSTRAINT UQ_TbAbonnementClient_IDClient_IDAbonnement UNIQUE(IDClient, IDAbonnement)</div></td></tr></tbody></table></div>
<p>=> <strong>Contraintes de valeur par défaut :</strong></p>
<p>Il peut être intéressant de définir une valeur par défaut pour l&rsquo;insertion (mais pas à l&rsquo;UPDATE) d&rsquo;une nouvelle ligne à une table si la colonne est omise dans la spécification de l&rsquo;instruction INSERT :</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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--------------------------------- <br />
-- Nicolas SOUQUET - 25/07/2009 - <br />
--------------------------------- <br />
ALTER TABLE dbo.TbAbonnementClient <br />
ADD CONSTRAINT DF_TbAbonnementClient_dateAbonnementClient <br />
&nbsp; DEFAULT (GETDATE()) FOR dateAbonnementClient</div></td></tr></tbody></table></div>
<p>Ainsi si nous écrivons :</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">--------------------------------- <br />
-- Nicolas SOUQUET - 25/07/2009 - <br />
--------------------------------- <br />
INSERT INTO dbo.TbAbonnementClient <br />
( <br />
&nbsp; IDClient, <br />
&nbsp; IDAbonnement <br />
) <br />
VALUES <br />
( <br />
&nbsp; @IDClient, <br />
&nbsp; @IDAbonnement <br />
)</div></td></tr></tbody></table></div>
<p>la colonne <em>dateAbonnementClient</em> sera valuée à la date actuelle du système.</p>
<p>=> <strong>Contraintes de domaine</strong></p>
<p>Elles permettent de limiter ou de vérifier les valeurs que peuvent contenir une colonne.<br />
Elles nécessitent une formule de vérification, qui peut être spécifiée directement lors de la définition de la contrainte, ou bien à travers une fonction définie par l&rsquo;utilisateur.<br />
L&rsquo;utilisation d&rsquo;une fonction pour la définition d&rsquo;une contrainte de domaine permet bien souvent de ne pas avoir recours à un déclencheur pour vérifier la validité des données.</p>
<p>Ici, nous souhaitons vérifier que les numéros de téléphone que nous stockons dans la base de données contiennent le préfixe du pays du client, et que la longueur des numéros de téléphone est correcte.<br />
Pour cela nous créons la fonction suivante :</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--------------------------------- <br />
-- Nicolas SOUQUET - 25/07/2009 - <br />
--------------------------------- <br />
CREATE FUNCTION Fn_IsNumTelClient_Correct <br />
&nbsp; ( <br />
&nbsp; &nbsp; @IDPays INT, <br />
&nbsp; &nbsp; @numeroTelephoneClient VARCHAR(36) <br />
&nbsp; ) <br />
RETURNS BIT <br />
WITH SCHEMABINDING <br />
AS <br />
BEGIN <br />
&nbsp; RETURN <br />
&nbsp; ( <br />
&nbsp; &nbsp; SELECT CASE <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN @numeroTelephoneClient LIKE prefixeTelephonique + '%' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND LEN(@numeroTelephoneClient) = longueurNumeroTelephone <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;THEN CAST(1 AS BIT) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE CAST(0 AS BIT) <br />
&nbsp; &nbsp; &nbsp; &nbsp; END <br />
&nbsp; &nbsp; FROM dbo.TbPays <br />
&nbsp; &nbsp; WHERE IDPays = @IDPays <br />
&nbsp; ) <br />
END</div></td></tr></tbody></table></div>
<p>La contrainte de domaine sera alors définie comme suit :</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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--------------------------------- <br />
-- Nicolas SOUQUET - 25/07/2009 - <br />
--------------------------------- <br />
ALTER TABLE dbo.TbAbonnementClient <br />
ADD CONSTRAINT CHK_TbAbonnementClient_numeroTelephoneClient <br />
&nbsp; CHECK(dbo.Fn_IsNumTelClient_Correct(IDPays, numeroTelephoneClient) = 1)</div></td></tr></tbody></table></div>
<p>Nous souhaitons également vérifier que les valeurs de la colonne <em>referenceAbonnement</em> de la table <em>TbAbonnement</em> aient le format XXX-nnn-nn.<br />
Là nous pouvons définir celui-ci directement  dans la spécification de la contrainte :</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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--------------------------------- <br />
-- Nicolas SOUQUET - 25/07/2009 - <br />
--------------------------------- <br />
ALTER TABLE dbo.TbAbonnement <br />
ADD CONSTRAINT CHK_TbAbonnement_referenceAbonnement <br />
&nbsp; CHECK(referenceAbonnement LIKE '[A-Z][A-Z][A-Z]-[0-9][0-9][0-9]-[0-9][0-9]')</div></td></tr></tbody></table></div>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Agent SQL Server] Gestion de l&#8217;historique</title>
		<link>https://blog.developpez.com/elsuket/p6884/moteur-de-base-de-donnees-sql-server/indexation/agent_sql_server_gestion_de_l_historique</link>
		<comments>https://blog.developpez.com/elsuket/p6884/moteur-de-base-de-donnees-sql-server/indexation/agent_sql_server_gestion_de_l_historique#comments</comments>
		<pubDate>Fri, 05 Dec 2008 23:01:50 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Agent SQL Server]]></category>
		<category><![CDATA[Indexation]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Outre sa principale fonctionnalité de gestion d&#8217;exécutions, l&#8217;Agent SQL Server comporte quelques fonctionnalités intéressantes concernant la gestion de son historique. Par défaut, l&#8217;historique pour chaque job est configuré à un maximum de 100 lignes, et de 1000 lignes pour tous &#8230; <a href="https://blog.developpez.com/elsuket/p6884/moteur-de-base-de-donnees-sql-server/indexation/agent_sql_server_gestion_de_l_historique">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Outre sa principale fonctionnalité de gestion d&rsquo;exécutions, l&rsquo;Agent SQL Server comporte quelques fonctionnalités intéressantes concernant la gestion de son historique.<br />
<span id="more-23"></span><br />
Par défaut, l&rsquo;historique pour chaque job est configuré à un maximum de 100 lignes, et de 1000 lignes pour tous les jobs.<br />
Donc si votre job s&rsquo;exécute plus de 100 fois par jour, et que vous arrivez au travail en souhaitant voir si celui-ci s&rsquo;est correctement exécuté pendant que vous dormiez paisiblement, c&rsquo;est râpé <img src="https://blog.developpez.com/elsuket/wp-includes/images/smilies/icon_biggrin.gif" alt=":D" class="wp-smiley" /></p>
<p>En choisissant l&rsquo;option &laquo;&nbsp;Propriétés&nbsp;&raquo; par clic-droit sur la node &laquo;&nbsp;SQL Server Agent&nbsp;&raquo; sous SQL Server Management Studio, voici ce que l&rsquo;on trouve :</p>
<p><img src="http://blog.developpez.com/media/histoAgent1.png" width="704" height="632" alt="" /></p>
<p>Autre désagrément : l&rsquo;historique concernant un job est assez long, par exemple si vous exécutez un job une fois par semaine depuis des mois.<br />
Vous souhaitez maintenant purger l&rsquo;historique, pour voir ce qui se passera la semaine prochaine, d&rsquo;un coup d&rsquo;oeil :</p>
<p><img src="http://blog.developpez.com/media/histoAgent2.png" width="1065" height="636" alt="" /></p>
<p>Vous pouvez également supprimer de l&rsquo;historique les lignes qui sont plus vieilles qu&rsquo;une date de votre choix, avec l&rsquo;option &laquo;&nbsp;Supprimer l&rsquo;historique avant&nbsp;&raquo; :</p>
<p><img src="http://blog.developpez.com/media/histoAgent3.png" width="440" height="368" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Purge du cache de plans</title>
		<link>https://blog.developpez.com/elsuket/p6630/moteur-de-base-de-donnees-sql-server/indexation/purge_du_cache_de_plans</link>
		<comments>https://blog.developpez.com/elsuket/p6630/moteur-de-base-de-donnees-sql-server/indexation/purge_du_cache_de_plans#comments</comments>
		<pubDate>Fri, 24 Oct 2008 21:34:03 +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[Il est possible qu&#8217;un jour vous trouviez dans les journaux de SQL Server le libellé suivant : SQL Server has encountered n occurrence(s) of cachestore flush for the (partie du cache de plans) cachestore due to some database maintenance or &#8230; <a href="https://blog.developpez.com/elsuket/p6630/moteur-de-base-de-donnees-sql-server/indexation/purge_du_cache_de_plans">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Il est possible qu&rsquo;un jour vous trouviez dans les journaux de SQL Server le libellé suivant :</p>
<p><em>SQL Server has encountered n occurrence(s) of cachestore flush for the (partie du cache de plans) cachestore due to some database maintenance or reconfigure operations&nbsp;&raquo;<br />
</em></p>
<p>Ce message n&rsquo;apparaît qu&rsquo;à partir du SP2 de SQL Server 2005, et il est écrit par intervalles de 5 minutes.<br />
La purge du cache de plans peut se produire dans les cas suivants :<br />
<span id="more-22"></span><br />
Avec l&rsquo;instruction ALTER DATABASE :</p>
<pre>
- Lors du détachement d'une base de données,
- ALTER DATABASE maBD SET AUTO_CLOSE ON,
- ALTER DATABASE maBD COLLATE nouvelleCollation,
- ALTER DATABASE maBD SET READ_ONLY,
- ALTER DATABASE maBD SET READ_WRITE,
- ALTER DATABASE maBD SET ONLINE,
- ALTER DATABASE maBD SET OFFLINE,
- ALTER DATABASE maBD MODIFY NAME = maNouvelleBD,
- ALTER DATABASE maBD MODIFY FILEGROUP GroupeDeFichiers DEFAULT,
- ALTER DATABASE maBD MODIFY FILEGROUP GroupeDeFichiers READ_WRITE,
- ALTER DATABASE maBD MODIFY FILEGROUP GroupeDeFichiers READ_ONLY,
- DROP DATABASE nomDeBDCaptureeParSnapshot.</pre>
<p>Ou bien lorsqu&rsquo;une des options d&rsquo;instance suivante est modifiée à l&rsquo;aide de sp_configure avec RECONFIGURE :</p>
<pre>- cross db ownership chaining,
- index create memory (KB),
- remote query timeout (s),
- user options,
- max text repl size (B),
- cost threshold for parallelism,
- max degree of parallelism,
- min memory per query (KB),
- query wait (s),
- min server memory (MB),
- max server memory (MB),
- query governor cost limit</pre>
<p>ou encore avec l&rsquo;une de ces commandes DBCC :</p>
<pre>- DBCC CHECKDB
- DBCC FREEPROCCACHE,
- DBCC FREESYSTEMCACHE.
</pre>
<p>Et enfin lors du succès de la reconstruction d&rsquo;un fichier de journal des transactions.</p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recherche d&#8217;indexes manquants sous SQL Server 2005</title>
		<link>https://blog.developpez.com/elsuket/p6345/moteur-de-base-de-donnees-sql-server/indexation/title_107</link>
		<comments>https://blog.developpez.com/elsuket/p6345/moteur-de-base-de-donnees-sql-server/indexation/title_107#comments</comments>
		<pubDate>Mon, 08 Sep 2008 22:15:34 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[Indexation]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Une nouvelle fonctionnalité intéressante, introduite avec SQL Server 2005, est la recherche d’indexes manquants. Elle permet, de façon très simple, de trouver les indexes manquants qui pourraient simplifier le travail du moteur de base de données s’ils étaient posés sur &#8230; <a href="https://blog.developpez.com/elsuket/p6345/moteur-de-base-de-donnees-sql-server/indexation/title_107">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Une nouvelle fonctionnalité intéressante, introduite avec SQL Server 2005, est la recherche d’indexes manquants.<br />
 Elle permet, de façon très simple, de trouver les indexes manquants qui pourraient simplifier le travail<br />
du moteur de base de données s’ils étaient posés sur des tables de base ou des vues indexées.<br />
Néanmoins, cette fonctionnalité comporte quelques limitations, qui doivent être prise en compte avant qu’on<br />
ait décidé de créer l’index conseillé par SQL Server.<br />
Comme vous le verrez, plusieurs sujets sont connexes à cet article, mais nous ne les aborderons pas ici.<br />
Ils seront l’objet de prochains articles.</p>
<p><span id="more-21"></span></p>
<pre><strong>	1. Présentation</strong></pre>
<p>Le moteur de base de données comprend, en outre, un optimiseur de requêtes : c’est un des modules pilier d&rsquo;un SGBD.<br />
Celui-ci est chargé de trouver le meilleur moyen d’exécuter une requête en un minimum de temps et en consommant un minimum de ressources.<br />
Il génère pour cela, à l’enregistrement d’une nouvelle procédure stockée par exemple, un plan de requête qu’il conserve dans<br />
le cache de procédures. Ce plan de requête est généré en fonction des statistiques de colonnes.<br />
Au fur et à mesure que la base de données vit, que les requêtes évoluent, il est possible que les indexes posés il y a quelques temps ne soient plus optimaux.<br />
Dans un tel cas, le moteur de base de données génère un « mauvais » plan de requête.<br />
Cette nouvelle fonctionnalité introduite par SQL Server permet de conserver ces « mauvaises  » informations pour nous<br />
faciliter la complexe tâche du paramétrage de base de données.<br />
Il nous reste donc à décider de les implémenter ou non.</p>
<pre><strong>	2. Vues de gestion dynamiques impliquées dans la recherche d’indexes manquants</strong></pre>
<p>SQL Server 2005 met à notre disposition quatre vues de gestion dynamique.<br />
Nous utiliserons trois de ces vues pour nous aider à la recherche d’indexes manquants :
<pre>

	- <em>sys.dm_db_missing_index_group_stats</em>:

	Cette vue nous renseignera sur le gain de performances que l’on pourrait obtenir si nous implémentions l’index conseillé.
	Les colonnes qui nous intéressent sont :

		• <em>user_seeks</em> : Nombre de recherches pour lesquelles des requêtes auraient pu tirer profit de l’index 	recommandé.

		• <em>user_scans</em> : Nombre d’analyses d’index pour lesquelles des requêtes auraient pu tirer profit de l’index recommandé.

		• <em>unique_compiles</em> : Nombre de (re)compilations qui auraient pu tirer profit de l’index recommandé. Une recompilation est très coûteuse.

		• <em>avg_total_user_cost</em> : C’est ce que coûte, en moyenne, au moteur de base de données, d’exécuter une requête sans l’index recommandé.

		• <em>avg_user_impact</em> : C’est le gain, en pourcentage, que le moteur de base de données estime pouvoir gagner sur le coût de la requête
		(avg_total_user_cost).

		• <em>last_user_seek</em> : de type DATETIME, elle renseigne sur la date de la dernière occurrence de recherche qui aurait pu profiter
		de l’index conseillé.

		• <em>last_user_scan</em> : même commentaire que pour last_user_seek, excepté qu’il s’agit de la dernière recherche.

	- <em>sys.dm_db_missing_index_groups</em>: 

	Cette vue nous servira à faire le lien entre la vue précédente, qui nous renseigne sur les gains de performance possibles,
	et la vue suivante, qui va nous permettre de créer la commande CREATE INDEX …

	- <em>sys.dm_db_missing_index_details</em>: 

	Cette vue nous éclairera sur les colonnes des tables à indexer. Les colonnes qui nous intéressent sont :

		• <em>equality_columns</em> : liste des colonnes qui constituent un prédicat d’égalité
		 dans l’expression de la requête (WHERE maColonne = maValeur, JOIN maTableB ON maTableA.IDA = maTableB.IDB).

		• <em>inequality_columns</em> : liste des colonnes qui constituent un prédicat d’inégalité
		 (<code class="codecolorer text default"><span class="text">WHERE maColonne &lt; maValeur, JOIN maTableB ON maTableA.IDA &gt; maTableB.IDB</span></code>).

		• <em>included_columns</em> : liste de colonnes qui permettront de couvrir la requête.

		• <em>statement</em> : nom qualifié de la table sur laquelle l’index doit être posé.
</pre>
<p>La  quatrième vue de gestion dynamique est <em>sys.dm_db_missing_index_columns</em>.<br />
Elle permet d’associer les colonnes de l’index conseillé par <em>sys.dm_db_missing_index_groups</em> et de montrer « en colonne » dans quelle clause de la commande de création des indexes la colonne en question doit se trouver.<br />
C’est ce que propose <em>sys.dm_db_missing_index_details</em> par une liste de colonnes de table, séparées par des virgules.</p>
<pre><strong>	3. Une première approche</strong></pre>
<p>Relions donc toutes ces informations avec les jointures appropriées :</p>
<pre>

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">------------------------------ <br />
- Nicolas SOUQUET - 08/09/2008 <br />
------------------------------ <br />
&nbsp;<br />
&nbsp; SELECT MIGS.unique_compiles Comp, <br />
&nbsp; &nbsp; &nbsp; MIGS.user_seeks, <br />
&nbsp; &nbsp; &nbsp; MIGS.user_scans, <br />
&nbsp; &nbsp; &nbsp; MIGS.avg_total_user_cost, <br />
&nbsp; &nbsp; &nbsp; MIGS.avg_user_impact, <br />
&nbsp; &nbsp; &nbsp; MIGS.last_user_seek, <br />
&nbsp; &nbsp; &nbsp; MIGS.last_user_scan, <br />
&nbsp; &nbsp; &nbsp; REPLACE(REPLACE(MID.Statement, '[', ''), ']', '') 'Database.Schema.Table', <br />
&nbsp; &nbsp; &nbsp; REPLACE(REPLACE(MID.equality_columns, '[', ''), ']', '') Egalite, <br />
&nbsp; &nbsp; &nbsp; REPLACE(REPLACE(MID.inequality_columns, '[', ''), ']', '') Inegalite, <br />
&nbsp; &nbsp; &nbsp; REPLACE(REPLACE(MID.included_columns, '[', ''), ']', '') Incluse <br />
&nbsp; FROM sys.dm_db_missing_index_group_stats MIGS <br />
&nbsp; JOIN sys.dm_db_missing_index_groups MIG ON MIGS.GROUP_HANDLE = MIG.index_group_handle <br />
&nbsp; JOIN sys.dm_db_missing_index_details MID ON MIG.INDEX_HANDLE = MID.index_handle <br />
&nbsp; WHERE DB_NAME(MID.database_id) NOT IN ('master', 'msdb', 'model', 'ReportServer', 'ReportServerTempDB', 'Distribution', 'TempDB')</div></td></tr></tbody></table></div>

</pre>
<p>Nous avons maintenant toutes les informations pour créer les indexes qui manquent à notre base de données.  Mais dans cette foule d’informations, lesquels sont vraiment nécessaires ?<br />
J’ai le souvenir que cette requête m’ait parfois retourné plus de 300 lignes …<br />
Pour trouver dans un premier temps les indexes les plus nécessaires à une base de données pauvrement indexée, il faudrait associer le coût de chaque requête au nombre de recherches et d’analyses d’indexes,<br />
et de (re)compilations de plans de requête, et tenir compte de la « fraîcheur » des données retournées par ces vues de gestion dynamique.</p>
<p>Soit donc la requête suivante :</p>
<pre>

<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 /></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 - 08/09/2008 <br />
------------------------------ <br />
&nbsp;<br />
&nbsp; SELECT ROUND((MIGS.user_seeks + MIGS.user_scans + MIGS.unique_compiles) * MIGS.avg_total_user_cost * MIGS.avg_user_impact, 0) Avantage, <br />
&nbsp; &nbsp; &nbsp; MIGS.last_user_seek, <br />
&nbsp; &nbsp; &nbsp; MIGS.last_user_scan, <br />
&nbsp; &nbsp; &nbsp; REPLACE(REPLACE(MID.Statement, '[', ''), ']', '') 'Database.Schema.Table', <br />
&nbsp; &nbsp; &nbsp; REPLACE(REPLACE(MID.equality_columns, '[', ''), ']', '') Egalite, <br />
&nbsp; &nbsp; &nbsp; REPLACE(REPLACE(MID.inequality_columns, '[', ''), ']', '') Inegalite, <br />
&nbsp; &nbsp; &nbsp; REPLACE(REPLACE(MID.included_columns, '[', ''), ']', '') Incluse <br />
&nbsp; FROM sys.dm_db_missing_index_group_stats MIGS <br />
&nbsp; JOIN sys.dm_db_missing_index_groups MIG ON MIGS.GROUP_HANDLE = MIG.index_group_handle <br />
&nbsp; JOIN sys.dm_db_missing_index_details MID ON MIG.INDEX_HANDLE = MID.index_handle <br />
&nbsp; WHERE CONVERT(CHAR(10), MIGS.LAST_USER_SEEK, 103) = CONVERT(CHAR(10), GETDATE(), 103) <br />
&nbsp; AND DB_NAME(MID.database_id) NOT IN ('master', 'msdb', 'model', 'ReportServer', 'ReportServerTempDB', 'Distribution', 'TempDB') <br />
&nbsp; ORDER BY Avantage DESC</div></td></tr></tbody></table></div>

</pre>
<p>Maintenant, nous avons les indexes manquants qui ont coûté le plus cher à notre serveur, et qui auraient même été nécessaires aujourd’hui.<br />
Si l’on ré-exécute cette requête quelques secondes après l’avoir exécutée une première fois sur une base de données OLTP,<br />
ou sur un serveur OLAP très utilisé, et que l’on constate que les premières lignes (c&rsquo;est-à-dire celles qui nous renseignent<br />
sur les indexes les plus nécessaires) ont un «avantage » bien supérieur à celui de la première exécution,  c’est très<br />
certainement que si votre serveur était doué de parole, il vous remercierait de l’avoir créé.<br />
Mais alors, comment créer ces indexes ?</p>
<pre><strong>	4.Création des indexes nécessaires</strong></pre>
<p>Vous aurez certainement dénoté la simplicité avec laquelle SQL Server 2005 nous expose les indexes qu’il serait nécessaire de créer. Prenons la syntaxe de la commande CREATE INDEX, sans ses options :</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">CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name &nbsp;<br />
&nbsp; &nbsp; ON &lt;object&gt; ( column [ ASC | DESC ] [ ,...n ] ) &nbsp;<br />
&nbsp; &nbsp; [ INCLUDE ( column_name [ ,...n ] ) ]</div></td></tr></tbody></table></div>
<p>En supposant que nous avons au moins l’index de clé primaire, cluster, sur les tables montrées par les premières lignes de la requête précédente, nous créerons simplement notre commande en remplaçant :</p>
<p>&#8211;	column par les colonnes de table listées dans les colonnes  Egalite et Inegalite de la précédente requête,<br />
&#8211;	column_name dans la clause INCLUDE par les colonnes de table listées dans la colonne Incluse de la précédente requête</p>
<p>Il y a une dernière petite subtilité : nous devons placer les colonnes d’égalité avant celles d’inégalité dans la clause ON, mais également veiller à ordonner les colonnes d’égalité dans l’ordre décroissant de leur sélectivité.</p>
<p>En effet, l’optimiseur de requête de SQL Server 2005 (et d’autres SGBD) est basé sur les coûts, c&rsquo;est-à-dire la quantité de ressources qui vont être nécessaires à l’exécution d’une requête.<br />
Il se base sur la sélectivité des colonnes, c&rsquo;est-à-dire le nombre de valeurs différentes que contiennent chacune des colonnes de nos tables, pour estimer ce coût.<br />
Ces statistiques sont conservées soit au niveau colonne (node « Statistiques » des tables dans SQL Server Management Studio), soit dans les indexes.<br />
Par opposition à une colonne de type BIT qui est très peu sélective, une colonne auto-incrémentée est très sélective.</p>
<p>Pour rechercher les données qui sont la réponse à notre requête, l’optimiseur de requêtes va commencer par rechercher nos<br />
critères (clause WHERE de la commande SELECT, par exemple) dans les colonnes ayant la sélectivité la plus élevée, de sorte<br />
qu’il aura ensuite un jeu de données le plus petit possible pour vérifier les autres contraintes de la requête.<br />
Nous veillerons donc à vérifier l’ordre dans lequel nous allons ordonner nos colonnes d’ « égalité » : les vues de gestion dynamique les retournent souvent dans le bon ordre, mais une requête :</p>
<p><code class="codecolorer text default"><span class="text">SELECT COUNT(DISTINCT maColonne) FROM maTable</span></code></p>
<p>nous ôtera les doutes.</p>
<p>Comme le moteur de bases de données ne peut pas maintenir des statistiques sur des données qui ne sont pas<br />
contenues dans les colonnes, il découle que les colonnes d’inégalité révélées par notre dernière requête devront se<br />
trouver à la suite des colonnes répertoriées comme colonnes d’ « égalité ».</p>
<p>Qu’en est-il des colonnes répertoriées « Incluse » ? Ces colonnes, qui sont répertoriées dans le SELECT de nos requêtes,<br />
à l’exception des colonnes participant à un calcul agrégé (SUM, MIN, MAX, …) permettent de couvrir nos requêtes en évitant<br />
les bookmarks lookups, eux-aussi très coûteux.<br />
Les colonnes incluses sont également une nouvelle fonctionnalité introduite avec SQL Server 2005.</p>
<p>Finalement, la trame de notre requête d’index sera :</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">CREATE INDEX IX_maTable_mesColonnes <br />
ON monSchema.maTable (mesColonnesEgalite, mesColonnesInegalite) <br />
INCLUDE (mesColonnesIncluse) <br />
WITH (mesOptions)</div></td></tr></tbody></table></div>
<pre><strong>	5.Limitations de la fonctionnalité d’indexes manquants</strong>

Cette fonctionnalité a cependant quelques revers : 

	- Comme nous l’avons vu, elle retourne une liste de colonnes mais ne précise pas dans quel ordre elles doivent constituer la clé de l’index,

	- Elle ne constitue pas une aide à la configuration d’un index (options FILLFACTOR et PAD_INDEX),

	- Dans certains cas, elle ne renseigne que sur les colonnes incluses. Il faudra donc chercher quelle(s) est la
	 requête à l’origine  de ce groupe d’index manquant, puis optimiser la requête en conséquence

	- Elle ne renseigne pas sur la « fraîcheur » des données : la requête que je vous propose peut tout à fait montrer un
	 « avantage » énorme, qui a été généré par une requête que nous avons modifiée il y a quelques jours. 

	En effet, ces informations sont purgées :
		• Lors du redémarrage du serveur ou du service SQL Server,
		• Lors de la création d’un index sur une table pour laquelle la fonctionnalité nous conseille la création de plusieurs indexes.</pre>
<pre><strong>	6.Conclusion</strong></pre>
<p>Comme nous venons de le voir, cette fonctionnalité permet d’indexer très rapidement une base de données qui ne l’est que très pauvrement, mais elle permet aussi de suivre la vie de la base de données.</p>
<p>Même si cette fonctionnalité ne constitue pas un outil précis de paramétrage de base de données (en existe-t-il ?), elle nous aidera à vérifier, en plus des options d’instruction (SET STATISTICS)<br />
et du plan de requête (accessible par CTRL+L sous SQL Server Management Studio) si, lorsque l’on doit optimiser une requête, on doit se tourner vers la création d’un index approprié,<br />
ou bien vers une autre expression de la même requête (parfois ce sera les deux)</p>
<p>ElSuket</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
