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

<channel>
	<title>Le blog de SQLpro &#187; sql</title>
	<atom:link href="https://blog.developpez.com/sqlpro/ptag/sql/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/sqlpro</link>
	<description>Le SQL pour SQL Server, PostGreSQL et tous les autres SGBDR</description>
	<lastBuildDate>Thu, 15 Oct 2020 12:59:17 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Métadonnées de l&#8217;utilisation d&#8217;une colonne</title>
		<link>https://blog.developpez.com/sqlpro/p13155/ms-sql-server/metadonnees-de-lutilisation-dune-colonne</link>
		<comments>https://blog.developpez.com/sqlpro/p13155/ms-sql-server/metadonnees-de-lutilisation-dune-colonne#comments</comments>
		<pubDate>Mon, 23 Oct 2017 07:07:13 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[colonne]]></category>
		<category><![CDATA[contrainte]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[métadonnées]]></category>
		<category><![CDATA[sql]]></category>

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

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=751</guid>
		<description><![CDATA[Arrivée avec la norme SQL 2011, le concept de tables temporelles permet une historisation automatique des données et propose des opérateurs temporels pour &#171;&#160;voir&#160;&#187; vos données telles qu&#8217;elles étaient à un point ou une période du temps passé. Paradoxe : plus besoin de faire des sauvegardes ! Cette présentation montré au Microsoft Cloud Summit 2017 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Arrivée avec la norme SQL 2011, le concept de tables temporelles permet une historisation automatique des données et propose des opérateurs temporels pour &laquo;&nbsp;voir&nbsp;&raquo; vos données telles qu&rsquo;elles étaient à un point ou une période du temps passé. Paradoxe : plus besoin de faire des sauvegardes ! Cette présentation montré au Microsoft Cloud Summit 2017 à paris le 24 janvier 2017, vous montre l&rsquo;essentiel sur le sujet, avec SQL Server 2016 et est assortie de nombreux exemples.<br />
<span id="more-751"></span></p>
<p>La présentation PowerPoint sous forme PDF est téléchargeable ici : <a href="http://mssqlserver.fr/wp-content/uploads/2017/01/MSCloudSummit2017-SQL-et-les-tables-temporelles-Commentaires.pdf" title="SQL Server et les tables temporelles" target="_blank">SQL Server et les tables temporelles</a><br />
<strong><br />
Les exemples l&rsquo;accompagnant, sont téléchargeable ici :</strong></p>
<p><a href="http://mssqlserver.fr/wp-content/uploads/2017/01/DEMO-001-table-temporelles-sans-historique.txt" target="_blank">DEMO 001 &#8211; table temporelles sans historique (fichier SQL)</a><br />
<a href="http://mssqlserver.fr/wp-content/uploads/2017/01/DEMO-002-table-temporelles-avec-historique.txt" target="_blank">DEMO 002 &#8211; table temporelles avec historique (fichier SQL)</a><br />
<a href="DEMO 003 – stockage (fichier SQL)" target="_blank">DEMO 003 &#8211; stockage (fichier SQL)</a><br />
<a href="http://mssqlserver.fr/wp-content/uploads/2017/01/DEMO-004-R%C3%A9cup%C3%A9ration.txt" target="_blank">DEMO 004 &#8211; Récupération (fichier SQL)</a><br />
<a href="http://mssqlserver.fr/wp-content/uploads/2017/01/DEMO-005-Purge.txt" target="_blank">DEMO 005 &#8211; Purge (fichier SQL)</a><br />
<a href="http://mssqlserver.fr/wp-content/uploads/2017/01/DEMO-005b-Purge-m%C3%A9tadonn%C3%A9es-blocage.txt" target="_blank">DEMO 005b &#8211; Purge métadonnées blocage (fichier SQL)</a><br />
<a href="http://mssqlserver.fr/wp-content/uploads/2017/01/DEMO-006-interrogation.txt" target="_blank">DEMO 006 &#8211; interrogation (fichier SQL)</a><br />
<a href="http://mssqlserver.fr/wp-content/uploads/2017/01/DEMO-007-In-Memory.txthttp://" target="_blank">DEMO 007 &#8211; In Memory (fichier SQL)</a><br />
<a href="http://mssqlserver.fr/wp-content/uploads/2017/01/DEMO-ANNEXE-temporal-tables.txt" target="_blank">DEMO ANNEXE temporal tables (fichier SQL)</a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Most &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
<div id="attachment_590" style="width: 548px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg"><img src="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg" alt="Développez et administrez pour la performance avec SQL Server 2014" width="538" height="652" class="size-full wp-image-590" /></a><p class="wp-caption-text">Développez et administrez pour la performance avec SQL Server 2014</p></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LIKE &#8216;%mot%&#8217; ou les index rotatifs&#8230;.</title>
		<link>https://blog.developpez.com/sqlpro/p13123/langage-sql-norme/like-mot-ou-les-index-rotatifs</link>
		<comments>https://blog.developpez.com/sqlpro/p13123/langage-sql-norme/like-mot-ou-les-index-rotatifs#comments</comments>
		<pubDate>Thu, 05 Jan 2017 20:01:44 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[Langage SQL (norme)]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[joker]]></category>
		<category><![CDATA[LIKE]]></category>
		<category><![CDATA[recherche]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=687</guid>
		<description><![CDATA[Qui n&#8217;a jamais rêvé d&#8217;obtenir des performances pour rechercher des mots partiels contenus dans d&#8217;autres mots, comme par exemple tous les mots contenant &#171;&#160;bolo&#160;&#187; ? Dans un dictionnaire de 128 918 mots, une telle recherche met moins de 50 millisecondes à l&#8217;aide des index rotatifs, contre ??? pour le LIKE &#8216;%bolo%&#8217;&#8230; Explications&#8230; diabolos, hyperboloïde, bolonaise, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Qui n&rsquo;a jamais rêvé d&rsquo;obtenir des performances pour rechercher des mots partiels contenus dans d&rsquo;autres mots, comme par exemple tous les mots contenant &laquo;&nbsp;bolo&nbsp;&raquo; ? Dans un dictionnaire de 128 918 mots, une telle recherche met moins de 50 millisecondes à l&rsquo;aide des index rotatifs, contre ??? pour le LIKE &lsquo;%bolo%&rsquo;&#8230; Explications&#8230;<br />
<span id="more-687"></span><br />
diabolos, hyperboloïde, bolonaise, bolomètre, diabolo, bolométriques, amphibologie, bolonais, paraboloïde, amphibologique, bolométrique&#8230; Tels sont les mots du dictionnaire LEXIQUE du CNRS contenant la chaine de caractères &laquo;&nbsp;boblo&nbsp;&raquo;.</p>
<p><strong>LE PROBLÈME</strong></p>
<p>Les index des bases de données relationnelles, de type BTree (arbre équilibrés) trient les chaines de caractères par rapport à l&rsquo;ordre orthographique des chaines de caractères au regard du classement des lettres de l&rsquo;alphabet et de la collation choisie, cette dernière pouvant être sensible ou non, à la casse, aux accents&#8230;. Du fait de cet ordre, il est donc possible de rechercher par intervalle comme c&rsquo;est le cas de la recherche d&rsquo;un mot commençant par&#8230; En effet, si nous recherchons les mots commençant par &laquo;&nbsp;fass&nbsp;&raquo; ils sont regroupés les uns à la suite des autres dans l&rsquo;index, ce qui permet un accès immédiat et la solution est, par exemple la suivante :
<ol>
<ul>fasse</ul>
<ul>fassent</ul>
<ul>fasses</ul>
<ul>fassiez</ul>
<ul>fassions</ul>
</ol>
<p>Pour ce qui est des mots finissant par, l&rsquo;index ne nous est d&rsquo;aucune utilité, mais une astuce consiste à créer les mots inversés (par exemple à l&rsquo;aide d&rsquo;une colonne calculée), les indexer et rechercher par le même type de LIKE sur l&rsquo;inverse de la terminaison souhaitée. Par exemple, rechercher tous les mots se terminant par &laquo;&nbsp;aide&rsquo;, il suffit de faire la recherche suivante :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'edia%'</span></div></div>
<p>et de renvoyer le mot correspondant !<br />
Bien entendu pour rechercher un mot commençant par&#8230; et finissant par&#8230;, il suffit de combiner les deux recherches !<br />
Un exemple est apporté par l&rsquo;extrait de requête suivant :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">WHERE</span> MOT_MOT <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'enta%'</span> <span style="color: #993333; font-weight: bold;">AND</span> MOT_INVERSE <span style="color: #993333; font-weight: bold;">LIKE</span> CONCAT<span style="color: #66cc66;">&#40;</span>REVERSE<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'aient'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'%'</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Mais comment être efficace lorsque l&rsquo;on recherche une chaine à l&rsquo;intérieur d&rsquo;un mot ? C&rsquo;est là qu&rsquo;intervient la notion d&rsquo;index &laquo;&nbsp;rotatif&nbsp;&raquo;&#8230;</p>
<p><strong>LE CONCEPT</strong></p>
<p><strong>Un index &laquo;&nbsp;rotatif&nbsp;&raquo;</strong> est en fait une liste de mots pour laquelle on supprime successivement la lettre du début à chaque tour, d&rsquo;où le nom d&rsquo;index &laquo;&nbsp;rotatif&nbsp;&raquo;.<br />
Par exemple le mot &laquo;&nbsp;locomotive&nbsp;&raquo; sera ainsi décliné :
<ol>
<ul>locomotive</ul>
<ul>ocomotive</ul>
<ul>comotive</ul>
<ul>omotive</ul>
<ul>motive</ul>
<ul>otive</ul>
<ul>tive</ul>
<ul>ive</ul>
<ul>ve</ul>
<ul>e</ul>
</ol>
<p>On numérote alors chaque rotation, y compris le mot racine dont par convention on attribuera l&rsquo;indice 0 comme niveau de rotation. Par exemple le &laquo;&nbsp;sous-mot&nbsp;&raquo; &laquo;&nbsp;motive&nbsp;&raquo; aura un indice de rotation de 4 parce qu&rsquo;on lui aura retiré les 4 premières lettres.<br />
Une fois ces mots Ajoutés dans une table de mots, il suffit de les indexer et d&rsquo;ajouter une table des références croisées entre les mots racine et les rotations. La recherche peut désormais se faire via un LIKE &lsquo;mot%&rsquo; qui permet d&rsquo;exploiter l&rsquo;index ! Mais il faut ensuite remonter au mot racine par une jointure à l&rsquo;aide de la table des références croisées.</p>
<p><strong>LA MÉCANIQUE</strong></p>
<p>Afin de bien distinguer ces objets techniques de votre base, objets qui n&rsquo;ont rien à voir avec les objets fonctionnels de votre application, je vous conseille de créer un schéma SQL spécifique pour les y stocker logiquement</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> SCHEMA S_XRT;</div></div>
<p><strong>Les tables pour ce faire.</strong></p>
<p>Deux tables suffisent : la table des mots, et la table des références croisées.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> S_XRT<span style="color: #66cc66;">.</span>T_MOT<br />
<span style="color: #66cc66;">&#40;</span>MOT_ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">IDENTITY</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span><br />
<span style="color: #808080; font-style: italic;">--&gt; doit être sensible aux accents mais pas à la casse ! Exemple maïs et </span><br />
<span style="color: #808080; font-style: italic;">-- &nbsp;mais, sur et sûr, retraite et retraité, congres et congrès !</span><br />
&nbsp;MOT_MOT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">COLLATE</span> French_BIN <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">UNIQUE</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> S_XRT<span style="color: #66cc66;">.</span>T_MOT_ROTATION_MRT<br />
<span style="color: #66cc66;">&#40;</span>MRT_ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">IDENTITY</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span><br />
<span style="color: #808080; font-style: italic;">-- pointe vers la rotation du mot</span><br />
&nbsp;MOT_ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> S_XRT<span style="color: #66cc66;">.</span>T_MOT <span style="color: #66cc66;">&#40;</span>MOT_ID<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
<span style="color: #808080; font-style: italic;">-- pointe vers la racine du mot</span><br />
&nbsp;MOT_ID_RACINE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> S_XRT<span style="color: #66cc66;">.</span>T_MOT <span style="color: #66cc66;">&#40;</span>MOT_ID<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
<span style="color: #808080; font-style: italic;">-- indice de rotation</span><br />
&nbsp;MRT_ROTATION &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TINYINT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span><br />
&nbsp;<span style="color: #993333; font-weight: bold;">UNIQUE</span> <span style="color: #66cc66;">&#40;</span>MOT_ID<span style="color: #66cc66;">,</span> MOT_ID_RACINE<span style="color: #66cc66;">,</span> MRT_ROTATION<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p><strong>Les routines</strong></p>
<p>Une procédure va permettre d&rsquo;indexer un mot. En voici le code en Transact SQL :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> S_XRT<span style="color: #66cc66;">.</span>P_INDEXATION_ROTATIVE @MOT <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<br />
<span style="color: #993333; font-weight: bold;">SET</span> NOCOUNT <span style="color: #993333; font-weight: bold;">ON</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">SET</span> @MOT <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">LOWER</span><span style="color: #66cc66;">&#40;</span>LTRIM<span style="color: #66cc66;">&#40;</span>RTRIM<span style="color: #66cc66;">&#40;</span>@MOT<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @L TINYINT <span style="color: #66cc66;">=</span> LEN<span style="color: #66cc66;">&#40;</span>@MOT<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @ID_MOT <span style="color: #993333; font-weight: bold;">INT</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @ROTATIONS <span style="color: #993333; font-weight: bold;">TABLE</span> <br />
<span style="color: #66cc66;">&#40;</span>MOT &nbsp; <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">COLLATE</span> French_BIN<span style="color: #66cc66;">,</span><br />
&nbsp;ROT &nbsp; TINYINT<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">-- calcul des rotations, racine comprise (0)</span><br />
<span style="color: #993333; font-weight: bold;">WITH</span> T <span style="color: #993333; font-weight: bold;">AS</span> <br />
<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> @MOT <span style="color: #993333; font-weight: bold;">AS</span> M<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AS</span> I<br />
&nbsp;<span style="color: #993333; font-weight: bold;">UNION</span> &nbsp;<span style="color: #993333; font-weight: bold;">ALL</span><br />
&nbsp;<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">RIGHT</span><span style="color: #66cc66;">&#40;</span>M<span style="color: #66cc66;">,</span> @L<span style="color: #66cc66;">-</span>I <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> I <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><br />
&nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; T<br />
&nbsp;<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;I <span style="color: #66cc66;">&lt;</span> @L <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @ROTATIONS<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> T;<br />
<br />
<span style="color: #808080; font-style: italic;">-- insertions des mots manquants</span><br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> S_XRT<span style="color: #66cc66;">.</span>T_MOT<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> MOT<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @ROTATIONS<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;MOT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> MOT_MOT<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; S_XRT<span style="color: #66cc66;">.</span>T_MOT<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">-- récupération de l'ID du mot racine</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @ID_MOT <span style="color: #66cc66;">=</span> MOT_ID<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; S_XRT<span style="color: #66cc66;">.</span>T_MOT<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;MOT_MOT <span style="color: #66cc66;">=</span> @MOT;<br />
<br />
<span style="color: #808080; font-style: italic;">-- insertions des rotations manquantes</span><br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> S_XRT<span style="color: #66cc66;">.</span>T_MOT_ROTATION_MRT<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> M<span style="color: #66cc66;">.</span>MOT_ID<span style="color: #66cc66;">,</span> @ID_MOT<span style="color: #66cc66;">,</span> R<span style="color: #66cc66;">.</span>ROT<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @ROTATIONS <span style="color: #993333; font-weight: bold;">AS</span> R<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> S_XRT<span style="color: #66cc66;">.</span>T_MOT <span style="color: #993333; font-weight: bold;">AS</span> M<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> R<span style="color: #66cc66;">.</span>MOT <span style="color: #66cc66;">=</span> M<span style="color: #66cc66;">.</span>MOT_MOT<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;<span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; S_XRT<span style="color: #66cc66;">.</span>T_MOT_ROTATION_MRT <span style="color: #993333; font-weight: bold;">AS</span> MR<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;MR<span style="color: #66cc66;">.</span>MOT_ID <span style="color: #66cc66;">=</span> M<span style="color: #66cc66;">.</span>MOT_ID<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;MR<span style="color: #66cc66;">.</span>MOT_ID_RACINE <span style="color: #66cc66;">=</span> @ID_MOT<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;MR<span style="color: #66cc66;">.</span>MRT_ROTATION <span style="color: #66cc66;">=</span> R<span style="color: #66cc66;">.</span>ROT<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Enfin, une fonction table constituée d&rsquo;une simple requête paramétrée, va permettre de retrouver les mots racine à partir des partiels :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> S_XRT<span style="color: #66cc66;">.</span>F_SUPER_LIKE <span style="color: #66cc66;">&#40;</span>@MOT <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">RETURNS</span> <span style="color: #993333; font-weight: bold;">TABLE</span><br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> MR<span style="color: #66cc66;">.</span>MOT_ID<span style="color: #66cc66;">,</span> MR<span style="color: #66cc66;">.</span>MOT_MOT<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; S_XRT<span style="color: #66cc66;">.</span>T_MOT <span style="color: #993333; font-weight: bold;">AS</span> M<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> <span style="color: #66cc66;">&#91;</span>S_XRT<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>T_MOT_ROTATION_MRT<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> R<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> M<span style="color: #66cc66;">.</span>MOT_ID <span style="color: #66cc66;">=</span> R<span style="color: #66cc66;">.</span>MOT_ID<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> S_XRT<span style="color: #66cc66;">.</span>T_MOT <span style="color: #993333; font-weight: bold;">AS</span> MR<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> R<span style="color: #66cc66;">.</span>MOT_ID_RACINE <span style="color: #66cc66;">=</span> MR<span style="color: #66cc66;">.</span>MOT_ID<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;M<span style="color: #66cc66;">.</span>MOT_MOT <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #993333; font-weight: bold;">LOWER</span><span style="color: #66cc66;">&#40;</span>RTRIM<span style="color: #66cc66;">&#40;</span>LTRIM<span style="color: #66cc66;">&#40;</span>@MOT<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'%'</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p><strong>QUELQUES TESTS</strong></p>
<p>Nous sommes partis d&rsquo;une base contenant le dictionnaire LEXIQUE du CNRS, comportant 128 918 mots.<br />
Notre méthode pour les indexer tous a été d&rsquo;utiliser un curseur pour connaitre le temps moyen mis par la procédure d&rsquo;indexation. Ce traitement a été effectué sur une machine ayant les caractéristiques suivantes : 2 processeurs XEON, 48 cœurs , 128 Go de RAM, 8 disques SAS en RAID 10 avec SQL Server 2016.<br />
Le temps de traitement a été de 26 minutes et 21 secondes, soit, pour 128 918 mots, 12 ms par mot.<br />
Le traitement a généré  :<br />
*   376 567 entrées de mots dans la table S_XRT.T_MOT (représentant 24 Mo)<br />
* 1 168 547 lignes dans la table S_XRT.T_MOT_ROTATION_MRT (représentant 62 Mo)<br />
À noter qu&rsquo;après réindexation, on observe une diminution du volume des données : 22 et 57 Ko respectivement.</p>
<p>Voici le batch que nous avons utilisé (la table du dictionnaire LEXIQUE du CNRS est dbo.TS_MOT_MOT :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">DECLARE</span> @T DATETIME <span style="color: #66cc66;">=</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> C CURSOR <br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LOCAL</span> FORWARD_ONLY STATIC READ_ONLY<br />
<span style="color: #993333; font-weight: bold;">FOR</span> <br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SELECT</span> MOT_MOT <br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; dbo<span style="color: #66cc66;">.</span>TS_MOT_MOT<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;MOT_LONGUEUR <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">1</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @MOT <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">OPEN</span> C;<br />
<br />
FETCH C <span style="color: #993333; font-weight: bold;">INTO</span> @MOT;<br />
<br />
WHILE @@FETCH_STATUS <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">EXEC</span> S_XRT<span style="color: #66cc66;">.</span>P_INDEXATION_ROTATIVE @MOT;<br />
&nbsp; &nbsp;FETCH C <span style="color: #993333; font-weight: bold;">INTO</span> @MOT;<br />
<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<br />
CLOSE C;<br />
<br />
DEALLOCATE C;<br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>ms<span style="color: #66cc66;">,</span> @T<span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>L&rsquo;utilisation de la fonction table en ligne S_XRT.F_SUPER_LIKE, met en moyenne 50 ms quelques soit la racine cherchée si elle est constituée d&rsquo;au moins 3 caractères. Exemple :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> S_XRT<span style="color: #66cc66;">.</span>F_SUPER_LIKE<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'moti'</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Pour la pire des recherches, le système met moins d&rsquo;une seconde à trouver les 130 162 mots contenant la lettre e !</p>
<p>Pour comparaison, la recherche des mots comprenant les caractères &laquo;&nbsp;eta&nbsp;&raquo;, d&rsquo;une part directement dans le dictionnaire à l&rsquo;aide d&rsquo;un LIKE &lsquo;%eta%&rsquo; et d&rsquo;autres part dans l&rsquo;index rotatif donne les métriques suivantes :<br />
* Dictionnaire, LIKE&rsquo;%eta%&rsquo; : temps UC = 652 ms, temps écoulé = 430 ms.<br />
* Index rotatif, S_XRT.F_SUPER_LIKE (&lsquo;eta&rsquo;) : Temps UC = 265 ms, temps écoulé = 50 ms.</p>
<p>Paradoxalement les plans de requête ne reflètent pas vraiment cette différence. les couts des plans apparaissent ainsi :<br />
* Index rotatif, S_XRT.F_SUPER_LIKE (&lsquo;eta&rsquo;) : 3,79 (soit 86 % de l&rsquo;ensemble<br />
* Dictionnaire, LIKE&rsquo;%eta%&rsquo; : 0,61 (soit 14% de l&rsquo;ensemble)</p>
<div id="attachment_692" style="width: 635px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2017/01/Fonction-SUPER-LIKE.jpg"><img src="http://blog.developpez.com/sqlpro/files/2017/01/Fonction-SUPER-LIKE-1024x132.jpg" alt="Plan de requête SQL Server utilisant une fonction table en ligne et l&#039;index rotatif" width="800" height="104" class="size-large wp-image-692" /></a><p class="wp-caption-text">Plan de requête SQL Server utilisant une fonction table en ligne et l&rsquo;index rotatif</p></div>
<div id="attachment_693" style="width: 223px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2017/01/LIKE-direct.jpg"><img src="http://blog.developpez.com/sqlpro/files/2017/01/LIKE-direct.jpg" alt="Utilisation directe du LIKE &#039;%toto%&#039;" width="213" height="68" class="size-full wp-image-693" /></a><p class="wp-caption-text">Utilisation directe du LIKE &lsquo;%toto%&rsquo;</p></div>
<p><strong>UN PEU D&rsquo;ASTUCE</strong></p>
<p>Au fur et à mesure de son utilisation, les index rotatifs grandissent de moins en moins, car ils contiennent déjà des rotations utilisables pour d&rsquo;autres mots. On peut donc prévoir certaines manœuvres pour les rendre plus efficaces encore, comme le précalcul de certaines données, la compression des index ou encore l&rsquo;utilisation de vues matérialisées (ou indexées sur SQL Server).</p>
<p>À titre d&rsquo;exemple, nous avons obtenus la métrique suivante : temps UC = 63 ms, temps écoulé = 67 ms, à  l&rsquo;aide de l&rsquo;une de ces techniques !</p>
<p><strong>LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE</strong><br />
<a href="http://sqlpro.developpez.com/_fichierSQL/IndexRotatifs.txt" title="Fichier du code" target="_blank">Le code SQL</a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
<div id="attachment_590" style="width: 548px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg"><img src="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg" alt="Développez et administrez pour la performance avec SQL Server 2014" width="538" height="652" class="size-full wp-image-590" /></a><p class="wp-caption-text">Développez et administrez pour la performance avec SQL Server 2014</p></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Une requête pour lister les privilèges au niveau des utilisateurs SQL</title>
		<link>https://blog.developpez.com/sqlpro/p12897/ms-sql-server/une-requete-pour-lister-les-privileges-au-niveau-des-utilisateurs-sql</link>
		<comments>https://blog.developpez.com/sqlpro/p12897/ms-sql-server/une-requete-pour-lister-les-privileges-au-niveau-des-utilisateurs-sql#comments</comments>
		<pubDate>Wed, 29 Jul 2015 20:51:03 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[DCL]]></category>
		<category><![CDATA[DENY]]></category>
		<category><![CDATA[GRANT]]></category>
		<category><![CDATA[PRIVILEGE]]></category>
		<category><![CDATA[REVOKE]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[USER]]></category>
		<category><![CDATA[utilisateur]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=578</guid>
		<description><![CDATA[Cette requête permet de retrouver l&#8217;ensemble des privilèges attribués dans une base à tous les utilisateurs SQL WITH T AS &#40; SELECT CONNEXION.name AS LOGIN_NAME, &#160; &#160; &#160; &#160;GRANTEE.default_schema_name AS DEFAULT_SCHEMA, &#160; &#160; &#160; &#160;PRIVILEGE.state_desc AS SQL_ORDER, &#160; &#160; &#160; &#160;GRANTOR.name AS GRANTOR, &#160; &#160; &#160; &#160;GRANTEE.name AS GRANTEE, &#160; &#160; &#160; &#160;PRIVILEGE.&#34;permission_name&#34; AS PRIVILEGE, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Cette requête permet de retrouver l&rsquo;ensemble des privilèges attribués dans une base à tous les utilisateurs SQL<br />
<span id="more-578"></span></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">WITH</span> T <span style="color: #993333; font-weight: bold;">AS</span> <br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> CONNEXION<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> LOGIN_NAME<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;GRANTEE<span style="color: #66cc66;">.</span>default_schema_name <span style="color: #993333; font-weight: bold;">AS</span> DEFAULT_SCHEMA<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;PRIVILEGE<span style="color: #66cc66;">.</span>state_desc <span style="color: #993333; font-weight: bold;">AS</span> SQL_ORDER<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;GRANTOR<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> GRANTOR<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;GRANTEE<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> GRANTEE<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;PRIVILEGE<span style="color: #66cc66;">.</span><span style="color: #ff0000;">&quot;permission_name&quot;</span> <span style="color: #993333; font-weight: bold;">AS</span> PRIVILEGE<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;s<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> OBJECT_SCHEMA<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;o<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> OBJECT_NAME<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;LTRIM<span style="color: #66cc66;">&#40;</span>STUFF<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">', '</span> <span style="color: #66cc66;">+</span> name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">COLUMNS</span> <span style="color: #993333; font-weight: bold;">AS</span> c<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;PRIVILEGE<span style="color: #66cc66;">.</span>minor_id <span style="color: #66cc66;">=</span> c<span style="color: #66cc66;">.</span>column_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FOR</span> XML PATH<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> COLUMN_LIST<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;PRIVILEGE<span style="color: #66cc66;">.</span>class_desc <span style="color: #993333; font-weight: bold;">AS</span> OBJECT_CLASS<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CASE</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHEN</span> &nbsp;<span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">THEN</span> DB_NAME<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHEN</span> &nbsp;<span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">THEN</span> o<span style="color: #66cc66;">.</span>type_desc<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHEN</span> &nbsp;<span style="color: #cc66cc;">3</span> <span style="color: #993333; font-weight: bold;">THEN</span> ss<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">COLLATE</span> database_default<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHEN</span> &nbsp;<span style="color: #cc66cc;">4</span> <span style="color: #993333; font-weight: bold;">THEN</span> dbp<span style="color: #66cc66;">.</span>name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHEN</span> &nbsp;<span style="color: #cc66cc;">5</span> <span style="color: #993333; font-weight: bold;">THEN</span> asb<span style="color: #66cc66;">.</span>name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHEN</span> &nbsp;<span style="color: #cc66cc;">6</span> <span style="color: #993333; font-weight: bold;">THEN</span> typ<span style="color: #66cc66;">.</span>name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">10</span> <span style="color: #993333; font-weight: bold;">THEN</span> xsc<span style="color: #66cc66;">.</span>name<br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">AS</span> OBJECT_TYPE_OR_NAME<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>database_principals <span style="color: #993333; font-weight: bold;">AS</span> GRANTEE<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>server_principals <span style="color: #993333; font-weight: bold;">AS</span> CONNEXION<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> GRANTEE<span style="color: #66cc66;">.</span>sid <span style="color: #66cc66;">=</span> CONNEXION<span style="color: #66cc66;">.</span>sid<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>database_permissions <span style="color: #993333; font-weight: bold;">AS</span> PRIVILEGE<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> GRANTEE<span style="color: #66cc66;">.</span>principal_id <span style="color: #66cc66;">=</span> PRIVILEGE<span style="color: #66cc66;">.</span>grantee_principal_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>database_principals <span style="color: #993333; font-weight: bold;">AS</span> GRANTOR<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>grantor_principal_id <span style="color: #66cc66;">=</span> GRANTOR<span style="color: #66cc66;">.</span>principal_id<br />
<span style="color: #808080; font-style: italic;">-- lien avec les objets primaires</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>objects <span style="color: #993333; font-weight: bold;">AS</span> o<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> o<span style="color: #66cc66;">.</span>object_id <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>schemas <span style="color: #993333; font-weight: bold;">AS</span> s<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">ON</span> o<span style="color: #66cc66;">.</span>schema_id <span style="color: #66cc66;">=</span> s<span style="color: #66cc66;">.</span>schema_id<br />
<span style="color: #808080; font-style: italic;">-- lien avec les schémas</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>schemas <span style="color: #993333; font-weight: bold;">AS</span> ss<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> ss<span style="color: #66cc66;">.</span>schema_id &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">3</span><br />
<span style="color: #808080; font-style: italic;">-- lien avec les &quot;principals&quot; de la base de données </span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>database_principals <span style="color: #993333; font-weight: bold;">AS</span> dbp<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> dbp<span style="color: #66cc66;">.</span>principal_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">4</span><br />
<span style="color: #808080; font-style: italic;">-- lien avec les &quot;assembly&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>assemblies <span style="color: #993333; font-weight: bold;">AS</span> asb<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> asb<span style="color: #66cc66;">.</span>assembly_id &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">5</span><br />
<span style="color: #808080; font-style: italic;">-- lien avec les &quot;type&quot; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6 = </span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>types <span style="color: #993333; font-weight: bold;">AS</span> typ<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> typ<span style="color: #66cc66;">.</span>user_type_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">6</span><br />
<span style="color: #808080; font-style: italic;">-- lien avec les collections de schémas XML</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>xml_schema_collections <span style="color: #993333; font-weight: bold;">AS</span> xsc<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> xsc<span style="color: #66cc66;">.</span>xml_collection_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">10</span><br />
<span style="color: #808080; font-style: italic;">-- lien avec les types de message &nbsp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>service_message_types <span style="color: #993333; font-weight: bold;">AS</span> smt<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> smt<span style="color: #66cc66;">.</span>message_type_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">15</span>&nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">-- lien avec les contrats de service</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>service_contracts <span style="color: #993333; font-weight: bold;">AS</span> sc<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> sc<span style="color: #66cc66;">.</span>service_contract_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">16</span>&nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">-- lien avec les services</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>services <span style="color: #993333; font-weight: bold;">AS</span> srv<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> srv<span style="color: #66cc66;">.</span>service_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">17</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<span style="color: #808080; font-style: italic;">-- lien avec les liaisons de service distant</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>remote_service_bindings <span style="color: #993333; font-weight: bold;">AS</span> rsb<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> rsb<span style="color: #66cc66;">.</span>remote_service_binding_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">18</span>&nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">-- lien avec les 19 = Itinéraire</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>routes <span style="color: #993333; font-weight: bold;">AS</span> r<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> r<span style="color: #66cc66;">.</span>route_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">19</span>&nbsp; &nbsp; <br />
<span style="color: #808080; font-style: italic;">-- lien avec les cataloguec de texte intégral</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>fulltext_catalogs <span style="color: #993333; font-weight: bold;">AS</span> ftc<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> ftc<span style="color: #66cc66;">.</span>fulltext_catalog_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">23</span><br />
<span style="color: #808080; font-style: italic;">-- lien avec les clés symétriques</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>symmetric_keys <span style="color: #993333; font-weight: bold;">AS</span> sk<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> sk<span style="color: #66cc66;">.</span>symmetric_key_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">24</span><br />
<span style="color: #808080; font-style: italic;">-- lien avec les certificats</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>certificates <span style="color: #993333; font-weight: bold;">AS</span> ctf<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> ctf<span style="color: #66cc66;">.</span>certificate_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">25</span><br />
<span style="color: #808080; font-style: italic;">-- lien avec les clés asymétriques </span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>asymmetric_keys <span style="color: #993333; font-weight: bold;">AS</span> ask<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> PRIVILEGE<span style="color: #66cc66;">.</span>major_id <span style="color: #66cc66;">=</span> ask<span style="color: #66cc66;">.</span>asymmetric_key_id<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> minor_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">AND</span> PRIVILEGE<span style="color: #66cc66;">.</span>class <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">26</span><br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;GRANTEE<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TYPE</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'S'</span> <span style="color: #808080; font-style: italic;">--&gt; SQL_USER</span><br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">COALESCE</span> <span style="color: #66cc66;">&#40;</span>N<span style="color: #ff0000;">'EXECUTE AS USER = '</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">+</span> GRANTOR <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">''</span><span style="color: #ff0000;">'; '</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SQL_ORDER <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">+</span> PRIVILEGE <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">' ON '</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'['</span> <span style="color: #66cc66;">+</span> OBJECT_SCHEMA <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'].['</span> <span style="color: #66cc66;">+</span> OBJECT_NAME <span style="color: #66cc66;">+</span><span style="color: #ff0000;">'] '</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>N<span style="color: #ff0000;">'('</span> <span style="color: #66cc66;">+</span> COLUMN_LIST <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">')'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OBJECT_CLASS <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'::'</span> <span style="color: #66cc66;">+</span> OBJECT_TYPE_OR_NAME<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;N<span style="color: #ff0000;">' TO '</span> <span style="color: #66cc66;">+</span> GRANTEE <span style="color: #66cc66;">+</span><span style="color: #ff0000;">'; REVERT;'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> SQL_COMMAND<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">*</span> <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp;T;</div></div>
<p>La colonne SQL_COMMAND contient le script SQL destiné à reproduire l&rsquo;exécution du privilège.<br />
En sus, la sortie fournit les informations suivantes :</p>
<ul>
<li>LOGIN_NAME : le compte de connexion associé à l&rsquo;utilisateur SQL</li>
<li>DEFAULT_SCHEMA : le schéma SQL par défaut de l&rsquo;utilisateur</li>
<li>SQL_ORDER : l&rsquo;ordre SQL du DCL (GRANT, DENY&#8230;)</li>
<li>GRANTOR : le gratifiant</li>
<li>GRANTEE : le gratifié</li>
<li>PRIVILEGE : le privilège octroyé</li>
<li>OBJECT_SCHEMA : le schéma SQL de l&rsquo;objet</li>
<li>OBJECT_NAME : le nom de l&rsquo;objet relationnel</li>
<li>COLUMN_LIST : la liste des colonnes privilégiées</li>
<li>OBJECT_CLASS : le nom de classe de l&rsquo;objet</li>
<li>OBJECT_TYPE_OR_NAME : le nom de type de l&rsquo;objet ou le nom de l&rsquo;objet pour les objets non relationnels (conteneurs, types, assemblies&#8230;)</li>
</ul>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calcules de durée en jour avec des mois comptables  de 30 jours</title>
		<link>https://blog.developpez.com/sqlpro/p12855/langage-sql-norme/calcules-de-duree-en-jour-avec-des-mois-compatbels-de-30-jours</link>
		<comments>https://blog.developpez.com/sqlpro/p12855/langage-sql-norme/calcules-de-duree-en-jour-avec-des-mois-compatbels-de-30-jours#comments</comments>
		<pubDate>Mon, 23 Mar 2015 22:55:56 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[Langage SQL (norme)]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[30 jours]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[mois comptable]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=556</guid>
		<description><![CDATA[À la suite d&#8217;une demande du forum, je me suis penché sur le calcul de durée en jour avec des mois comptables de 30 jours. Comme d&#8217;habitude il faut passer par une table de date ! La demande originale est postée ici : www.developpez.net/forums/d1508019/bases-donnees/ms-sql-server/developpement/ Nous sommes partit de la table suivante : CREATE TABLE T_DAT [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>À la suite d&rsquo;une demande du forum, je me suis penché sur le calcul de durée en jour avec des mois comptables de 30 jours. Comme d&rsquo;habitude il faut passer par une table de date !<br />
<span id="more-556"></span><br />
La demande originale est postée ici :<br />
<a href="www.developpez.net/forums/d1508019/bases-donnees/ms-sql-server/developpement/">www.developpez.net/forums/d1508019/bases-donnees/ms-sql-server/developpement/</a></p>
<p>Nous sommes partit de la table suivante :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> T_DAT<br />
<span style="color: #66cc66;">&#40;</span>DAT_DATE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">DATE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span><br />
&nbsp;DAT_AN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">&#40;</span>DAT_DATE<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">SMALLINT</span><span style="color: #66cc66;">&#41;</span> PERSISTED<span style="color: #66cc66;">,</span><br />
&nbsp;DAT_MOIS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">&#40;</span>DAT_DATE<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TINYINT<span style="color: #66cc66;">&#41;</span> PERSISTED<span style="color: #66cc66;">,</span><br />
&nbsp;DAT_JOUR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">&#40;</span>DAT_DATE<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TINYINT<span style="color: #66cc66;">&#41;</span> &nbsp; PERSISTED<span style="color: #66cc66;">,</span><br />
&nbsp;DAT_NB_JOUR_FIN_MOIS &nbsp; &nbsp; TINYINT <span style="color: #66cc66;">,</span><br />
&nbsp;DAT_JOUR_FIN_MOIS &nbsp; &nbsp; &nbsp; &nbsp;TINYINT<br />
<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Que nous avons rempli avec les 3 requêtes suivantes :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SET</span> NOCOUNT <span style="color: #993333; font-weight: bold;">ON</span>;<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @D <span style="color: #993333; font-weight: bold;">DATE</span><br />
<span style="color: #993333; font-weight: bold;">SET</span> @D <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'2000-01-01'</span><br />
WHILE @D <span style="color: #66cc66;">&lt;</span> <span style="color: #ff0000;">'2100-12-31'</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_DAT <span style="color: #66cc66;">&#40;</span>DAT_DATE<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>@D<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @D <span style="color: #66cc66;">=</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> @D<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">WITH</span> T0 <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> DAT_DATE<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">ROW_NUMBER</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span>PARTITION <span style="color: #993333; font-weight: bold;">BY</span> DAT_AN<span style="color: #66cc66;">,</span> DAT_MOIS <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> DAT_JOUR <span style="color: #993333; font-weight: bold;">DESC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">AS</span> NB_JOUR_FIN_MOIS<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; T_DAT<br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">UPDATE</span> T<br />
<span style="color: #993333; font-weight: bold;">SET</span> &nbsp; &nbsp;DAT_NB_JOUR_FIN_MOIS <span style="color: #66cc66;">=</span> NB_JOUR_FIN_MOIS<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; T_DAT <span style="color: #993333; font-weight: bold;">AS</span> T<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> T0 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">ON</span> T<span style="color: #66cc66;">.</span>DAT_DATE <span style="color: #66cc66;">=</span> T0<span style="color: #66cc66;">.</span>DAT_DATE;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">UPDATE</span> T<br />
<span style="color: #993333; font-weight: bold;">SET</span> &nbsp; &nbsp;DAT_JOUR_FIN_MOIS <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>DAT_JOUR <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; T_DAT <span style="color: #993333; font-weight: bold;">AS</span> T<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> T_DAT <span style="color: #993333; font-weight: bold;">AS</span> T2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">ON</span> T<span style="color: #66cc66;">.</span>DAT_AN <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>DAT_AN<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> &nbsp;T<span style="color: #66cc66;">.</span>DAT_MOIS <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>DAT_MOIS<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> T2<span style="color: #66cc66;">.</span>DAT_NB_JOUR_FIN_MOIS <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<p>Nous avons ensuite créé la fonction de calcul :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE FUNCTION F_MOIS30 (@D1 DATE, @D2 DATE)<br />
RETURNS INT<br />
AS<br />
BEGIN<br />
&nbsp; &nbsp;DECLARE @AN INT, @MOIS INT, @JFM INT<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;SELECT @AN = DAT_AN, @MOIS = DAT_MOIS, @JFM = DAT_NB_JOUR_FIN_MOIS<br />
&nbsp; &nbsp;FROM &nbsp; T_DAT <br />
&nbsp; &nbsp;WHERE DAT_DATE = @D1;<br />
<br />
&nbsp; &nbsp;SELECT @AN = DAT_AN - @AN, @MOIS = DAT_MOIS - @MOIS, @JFM = @JFM + DAT_JOUR<br />
&nbsp; &nbsp;FROM &nbsp; T_DAT <br />
&nbsp; &nbsp;WHERE DAT_DATE = @D2;<br />
<br />
&nbsp; &nbsp;RETURN (@AN * 12 + @MOIS - 1) * 30 + @JFM<br />
END;<br />
GO</div></div>
<p>Il ne restait plus qu&#039;à la tester :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT dbo.F_MOIS30('2014-03-20', '2015-02-01')</div></div>
<p>Ce qui donne 312 résultat escompté !</p>
<p>CQFD</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
