<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Microfrost's Blog</title>
	<atom:link href="http://microfrost.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://microfrost.wordpress.com</link>
	<description>Articoli sulla programmazione</description>
	<lastBuildDate>Wed, 03 Dec 2008 11:47:25 +0000</lastBuildDate>
	<language>it</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='microfrost.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Microfrost's Blog</title>
		<link>http://microfrost.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://microfrost.wordpress.com/osd.xml" title="Microfrost&#039;s Blog" />
	<atom:link rel='hub' href='http://microfrost.wordpress.com/?pushpress=hub'/>
		<item>
		<title>SQL 2005: User-Defined Data Types (UDDTs)</title>
		<link>http://microfrost.wordpress.com/2008/12/02/sql-2005-user-defined-data-types-uddts/</link>
		<comments>http://microfrost.wordpress.com/2008/12/02/sql-2005-user-defined-data-types-uddts/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 16:51:00 +0000</pubDate>
		<dc:creator>microfrost</dc:creator>
				<category><![CDATA[Analisi e modellazione dati]]></category>
		<category><![CDATA[clr]]></category>
		<category><![CDATA[udts]]></category>
		<category><![CDATA[user data types]]></category>

		<guid isPermaLink="false">http://microfrost.wordpress.com/?p=71</guid>
		<description><![CDATA[In questo articolo vedremo dal punto di vista pratico come creare user data types con sql 2005 utilizzando codice CLR.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=microfrost.wordpress.com&amp;blog=5609789&amp;post=71&amp;subd=microfrost&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;">In SQL Server 2005, è possibile creare UDTs utilizzando il codice CLR. </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;">Diamo un&#8217;occhiata a come creare T-SQL alias e poi vediamo come utilizzare il codice CLR per definire UDTs.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="text-decoration:underline;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">Esempio: indirizzo <span> </span>E-mail</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">Creiamo un nuovo progetto <em>class library</em> in<strong> </strong>Visual Studio, quindi scriviamo la nostra classe </span><strong><span style="font-size:10pt;line-height:115%;font-family:&quot;">EmailCS</span></strong><span style="font-size:10pt;line-height:115%;font-family:&quot;"> e compiliamo per creare il nostro bell’ <span style="text-decoration:underline;">Assembly</span>.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">using</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> System;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">using</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> System.Data;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">using</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> System.Data.SqlClient;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">using</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> System.Data.SqlTypes;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">using</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> Microsoft.SqlServer.Server;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">using</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> System.Text;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">using</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> System.Text.RegularExpressions;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">using</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> System.IO;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">[<span style="color:teal;">Serializable</span>]</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">[Microsoft.SqlServer.Server.<span style="color:teal;">SqlUserDefinedType</span>(<span style="color:teal;">Format</span>.UserDefined, MaxByteSize = 8000)]</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">public</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">struct</span> <span style="color:teal;">EmailCS</span> : <span style="color:teal;">INullable</span>, <span style="color:teal;">IBinarySerialize</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:green;font-family:&quot;">// Regular expression per una mail del tipo: somebody@somecompany.domain</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">private</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">static</span> <span style="color:blue;">readonly</span> <span style="color:teal;">Regex</span> RegExParser</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">= <span style="color:blue;">new</span> <span style="color:teal;">Regex</span>(<span style="color:maroon;">@&#8221;^([\w-]+\.)*?[\w-]+@[\w-]+\.([\w-]+\.)*?[\w]+$&#8221;</span>,<span style="color:teal;">RegexOptions</span>.CultureInvariant);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;">private</span><span style="font-size:8pt;font-family:&quot;"> <span style="color:teal;">StringBuilder</span> parsedemail;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;">private</span><span style="font-size:8pt;font-family:&quot;"> <span style="color:blue;">bool</span> m_Null;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;"><span>                </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:green;font-family:&quot;">// Costruttore per un valore noto</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">public</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> EmailCS(<span style="color:blue;">string</span> value)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">this</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US">.parsedemail = <span style="color:blue;">new</span> <span style="color:teal;">StringBuilder</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">this</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US">.parsedemail.Append(value);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">his</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US">.m_Null = <span style="color:blue;">false</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">public</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">override</span> <span style="color:blue;">string</span> ToString()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">return</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">this</span>.parsedemail.ToString();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">public</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">bool</span> IsNull</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">get</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">return</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> m_Null;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">public</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">static</span> <span style="color:teal;">EmailCS</span> Null</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">get</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:teal;font-family:&quot;" lang="EN-US">EmailCS</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> h = <span style="color:blue;">new</span> <span style="color:teal;">EmailCS</span>();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">h.m_Null = <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">return</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> h;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">public</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">static</span> <span style="color:teal;">EmailCS</span> Parse(<span style="color:teal;">SqlString</span> s)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">if</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> (s.IsNull)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">return</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> Null;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">string</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> value = s.ToString();</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:teal;font-family:&quot;" lang="EN-US">Match</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> m = RegExParser.Match(value);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">if</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> (!m.Success || value.Length &gt; 4000)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;">throw</span><span style="font-size:8pt;font-family:&quot;"> <span style="color:blue;">new</span> <span style="color:teal;">ArgumentException</span>(<span style="color:maroon;">&#8220;Formato e-mail non corretto. &#8220;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;">+ <span style="color:maroon;">&#8220;Il formato è somebody@somecompany.domain, la lunghezza massima dei caratteri è 4000.&#8221;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;"><span>                                </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:green;font-family:&quot;" lang="EN-US">// ok</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:teal;font-family:&quot;" lang="EN-US">EmailCS</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> u = <span style="color:blue;">new</span> <span style="color:teal;">EmailCS</span>(value);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">return</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> u;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:green;font-family:&quot;" lang="EN-US">// User-defined serialization</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">public</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">void</span> Read(<span style="color:teal;">BinaryReader</span> r)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">parsedemail = <span style="color:blue;">new</span> <span style="color:teal;">StringBuilder</span>(r.ReadString());</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">public</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">void</span> Write(<span style="color:teal;">BinaryWriter</span> w)<span>     </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">w.Write(<span style="color:blue;">this</span>.parsedemail.ToString());</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">Ora apriamo </span><span style="font-size:10pt;line-height:115%;font-family:&quot;">SQL Server Management Studio e facciamo una nuova query.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="text-decoration:underline;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">Creiamo db di Test</span></span></strong><span style="font-size:10pt;line-height:115%;font-family:&quot;">:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">USE</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> master<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">EXEC</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:maroon;">sp_configure</span> <span style="color:red;">&#8216;clr enabled&#8217;</span><span style="color:gray;">,</span> 1<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">RECONFIGURE</span><span style="font-size:8pt;color:gray;font-family:&quot;" lang="EN-US">;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">IF</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:fuchsia;">DB_ID</span><span style="color:gray;">(</span>N<span style="color:red;">&#8216;Test01&#8242;</span><span style="color:gray;">)</span> <span style="color:gray;">IS</span> <span style="color:gray;">NULL</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"><span>   </span></span><span style="font-size:8pt;color:blue;font-family:&quot;">CREATE</span><span style="font-size:8pt;font-family:&quot;"> <span style="color:blue;">DATABASE</span> Test01<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:5pt 0;"><strong><span style="font-size:10pt;font-family:&quot;"><span> </span><span style="text-decoration:underline;"><span lang="EN-US">T-SQL Aliases</span></span></span></strong><span style="font-size:10pt;font-family:&quot;" lang="EN-US"> :</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">USE</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> Test01<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">CREATE</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">TYPE</span> StandardAddress</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US"><span>  </span><span style="color:blue;">FROM</span> <span style="color:blue;">nvarchar</span><span style="color:gray;">(</span>50<span style="color:gray;">)</span> <span style="color:gray;">NULL;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:5pt 0;"><strong><span style="text-decoration:underline;"><span style="font-size:10pt;font-family:&quot;">CLR UDTs</span></span></strong><span style="font-size:10pt;font-family:&quot;"> :</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Importiamo ora il nostro assembly creato in precedenza.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">USE</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> Test01<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">CREATE</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">ASSEMBLY</span> Test1</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">FROM</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:red;">&#8216;C:\Documents and Settings\Salvatore-VM\My Documents\Visual Studio 2005\Projects\Test1\Test1\bin\Debug\Test1.dll&#8217;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;">WITH</span><span style="font-size:8pt;font-family:&quot;"> PERMISSION_SET <span style="color:gray;">=</span> SAFE<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Creiamo ora il nostro tipo di dato</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">CREATE</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">TYPE</span> dbo<span style="color:gray;">.</span>EmailCS</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">EXTERNAL</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> <span style="color:blue;">NAME</span> Test1<span style="color:gray;">.</span>EmailCS<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:5pt 0;"><strong><span style="text-decoration:underline;"><span style="font-size:10pt;font-family:&quot;" lang="EN-US">Test CLR UDTs</span></span></strong><span style="font-size:10pt;font-family:&quot;" lang="EN-US"> :</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:green;font-family:&quot;" lang="EN-US">&#8211;Test valore sconosciuto:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">DECLARE</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> @myemail EmailCS<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">SET</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> @myemail <span style="color:gray;">=</span> <span style="color:gray;">NULL;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;">SELECT</span><span style="font-size:8pt;font-family:&quot;"> @myemail<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:green;font-family:&quot;">&#8211;Test valore errato:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">DECLARE</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> @myemail EmailCS<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">SET</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> @myemail <span style="color:gray;">=</span> N<span style="color:red;">&#8216;wrong#address&#8217;</span><span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:green;font-family:&quot;">&#8211;Test caratteri troppo lunghi:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">DECLARE</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> @myemail EmailCS<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">SET</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> @myemail <span style="color:gray;">=</span> <span style="color:fuchsia;">REPLICATE</span><span style="color:gray;">(</span>N<span style="color:red;">&#8216;a&#8217;</span><span style="color:gray;">,</span>4000<span style="color:gray;">)+</span>N<span style="color:red;">&#8216; @a.com&#8217;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;" lang="EN-US">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:green;font-family:&quot;" lang="EN-US">&#8211;Test valore corretto:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">DECLARE</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> @myemail EmailCS<span style="color:gray;">;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">SET</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> @myemail <span style="color:gray;">=</span> N<span style="color:red;">&#8216;salvatore@mydomain.it&#8217;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;color:blue;font-family:&quot;" lang="EN-US">SELECT</span><span style="font-size:8pt;font-family:&quot;" lang="EN-US"> @myemail<span style="color:gray;">,</span> @myemail<span style="color:gray;">.</span>ToString<span style="color:gray;">();</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:8pt;font-family:&quot;">GO</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/microfrost.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/microfrost.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/microfrost.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/microfrost.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/microfrost.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/microfrost.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/microfrost.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/microfrost.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/microfrost.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/microfrost.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/microfrost.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/microfrost.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/microfrost.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/microfrost.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=microfrost.wordpress.com&amp;blog=5609789&amp;post=71&amp;subd=microfrost&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://microfrost.wordpress.com/2008/12/02/sql-2005-user-defined-data-types-uddts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/26f2fe837b34abd736548abcd4453ab7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">microfrost</media:title>
		</media:content>
	</item>
		<item>
		<title>Sql: Normalizzare un database</title>
		<link>http://microfrost.wordpress.com/2008/11/27/sql-normalizzare-un-database/</link>
		<comments>http://microfrost.wordpress.com/2008/11/27/sql-normalizzare-un-database/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 15:12:39 +0000</pubDate>
		<dc:creator>microfrost</dc:creator>
				<category><![CDATA[Analisi e modellazione dati]]></category>
		<category><![CDATA[normalizzazione]]></category>
		<category><![CDATA[prima forma]]></category>
		<category><![CDATA[seconda forma]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[terza forma]]></category>

		<guid isPermaLink="false">http://microfrost.wordpress.com/?p=60</guid>
		<description><![CDATA[In questo articolo tratteremo il tema della normalizzazione di una base dati, analizzando la prima, la seconda e la terza forma normale.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=microfrost.wordpress.com&amp;blog=5609789&amp;post=60&amp;subd=microfrost&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#4f81bd;font-family:&quot;">Cos’è la normalizzazione di un database?</span></strong></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">È un procedimento di tipo graduale che realizza un’ottimizzazione progressiva del database eliminando definitivamente la ridondanza dalle relazioni e quindi dal database.</span></p>
<p style="background:white;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">Si ha <strong>ridondanza</strong> dei dati ogni volta che vengono memorizzati inutilmente dei dati ripetuti.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#4f6228;font-family:&quot;">Esempio</span></strong><span style="font-size:10pt;color:#262626;font-family:&quot;">: </span></p>
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><span style="text-decoration:underline;"><span style="font-size:10pt;color:#262626;font-family:&quot;">ordine</span></span><span style="font-size:10pt;color:#262626;font-family:&quot;"> (<em>cod_fornitore,nome_fornitore,cod_fiscale,merce,prezzo,quantità</em>)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">può essere trasformata in due tabelle:</span></p>
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><span style="text-decoration:underline;"><span style="font-size:10pt;color:#262626;font-family:&quot;">ordine</span></span><span style="font-size:10pt;color:#262626;font-family:&quot;">(<em>merce,prezzo,quantità, cod_fornitore</em>)</span></p>
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><span style="text-decoration:underline;"><span style="font-size:10pt;color:#262626;font-family:&quot;">f</span></span><span style="text-decoration:underline;"><span style="font-size:10pt;font-family:&quot;">ornitore</span></span><span style="font-size:10pt;font-family:&quot;">(</span><em><span style="font-size:10pt;color:#262626;font-family:&quot;">cod_fornitore, fornitore, cod_fiscale</span></em><span style="font-size:10pt;color:#262626;font-family:&quot;">)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">In questo modo se gli acquisti effettuati da un certo fornitore compaiono mille volte, non dovremo per mille volte ripetere inutilmente l’informazione <em>nome</em> _<em>fornitore </em>e<em> cod_fiscale,</em>.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="text-decoration:underline;"><span style="font-size:10pt;color:#262626;font-family:&quot;">Analizziamo le prime <span> </span>tre forme normali:</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#4f81bd;font-family:&quot;">Prima forma</span></strong></p>
<p style="background:white;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">Una relazione si dice in prima forma normale (1NF) se e solo se tutti i suoi attributi sono valori atomici.<br />
Ciò implica che né gli attributi, né i valori da questi assunti possono essere scomposti ulteriormente.</span></p>
<p style="background:white;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">La relazione che segue non è in prima forma normale:</span></p>
<table class="MsoNormalTable" style="background:white;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="height:13.85pt;">
<td style="height:13.85pt;background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Nome</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="height:13.85pt;background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Indirizzo</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr style="height:13.1pt;">
<td style="height:13.1pt;background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="height:13.1pt;background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr style="height:13.85pt;">
<td style="height:13.85pt;background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Pippo</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="height:13.85pt;background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Via Verdi 24, Milano</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr style="height:13.85pt;">
<td style="height:13.85pt;background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Pluto</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="height:13.85pt;background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Via Mazzini 123, Roma</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
</tbody>
</table>
<p style="background:white;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;"> </span></p>
<p style="background:white;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">in quanto l’attributo <strong>Indirizzo</strong> non è atomico: può essere suddiviso in Indirizzo e Città. La relazione si normalizza trasformandola in:</span></p>
<table class="MsoNormalTable" style="background:white;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Nome</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Indirizzo</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Città </span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;-</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;-</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Pippo</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Via Verdi 24</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Milano</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Pluto</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Via Mazzini 123</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Roma </span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#4f81bd;font-family:&quot;">Seconda forma</span></strong></p>
<p style="background:white;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">Una relazione è in seconda forma normale se e solo se soddisfa la 1NF e inoltre ciascun attributo che non fa parte della chiave è indipendente funzionalmente da una qualunque chiave candidata.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">Si ha <strong>dipendenza funzionale</strong> tra un attributo x e una chiave se i valori di x dipendono dai valori assunti dalla chiave, ovvero se si viene a determinare una relazione biunivoca tra i valori di x e i valori della chiave.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">Data la relazione:    <em><span style="font-family:&quot;"> r </span></em>(A, B, K, J)     con A chiave primaria o candidata<br />
e avendo che: <span class="note-grandi1"><em><span style="font-family:&quot;">(il simbolo -&gt; significa : ” determina il valore di:”)</span></em></span>: A -&gt; K e K -&gt; J<br />
si verifica una dipendenza transitiva tra A e J , in quanto J dipende da A tramite K.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">Esempio:</span></p>
<table class="MsoNormalTable" style="background:white;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod.Borsa</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Tipo_materiale</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Tipo_finitura </span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;&#8212;-</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod. Elite</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Pelle</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Oro</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod. Elite</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Sintetico</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Acciaio </span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod. Standard</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">SimilPelle</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Argento </span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod. Standard</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Sintetico</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Acciaio</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod. Top</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Pelle</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Oro</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
</tbody>
</table>
<p style="background:white;margin:0;"><strong><span style="font-size:10pt;color:#262626;font-family:&quot;">Tipo_<span> finitura </span></span></strong><span style="font-size:10pt;color:#262626;font-family:&quot;">è dipendente funzionalmente da un sottoinsieme della chiave primaria, ovvero da <strong>Mod.Borsa</strong>, dunque la tabella non è in 2NF.<br />
È possibile normalizzare la relazione trasformandola in:</span></p>
<table class="MsoNormalTable" style="background:white;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod.Borsa</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Tipo_materiale</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod. Elite</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Pelle</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod. Elite</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Sintetico</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod. Standard</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">SimilPelle</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod. Standard</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Sintetico</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Mod. Top</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Pelle</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"> </span></strong></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Tipo_materiale</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"> </span></strong></p>
<p class="MsoNormal" style="line-height:normal;text-align:center;margin:0;" align="center"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Tipo_finitura </span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Pelle</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Oro</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Sintetico</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Acciaio </span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">SimilPelle</span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
<td style="background-color:transparent;border:#f0f0f0;padding:3.75pt;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;">Argento </span></strong><span style="font-size:10pt;color:#c0504d;font-family:&quot;"></span></p>
</td>
</tr>
</tbody>
</table>
<p style="background:white;margin:0;"><strong><span style="font-size:10pt;color:#4f81bd;font-family:&quot;"> </span></strong></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#4f81bd;font-family:&quot;">Terza forma</span></strong></p>
<p style="background:white;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">La terza forma normale ha come scopo l’eliminazione dalla relazione delle dipendenze funzionali transitive.</span></p>
<p style="background:white;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">Una relazione è in terza forma normale (3NF) se, oltre ad essere in 2NF, ciascun attributo che non partecipa alla chiave non è transitivamente dipendente da una qualunque chiave candidata.</span></p>
<p style="background:white;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">Si verifica una <strong>dipendenza funzionale transitiva</strong> quando un attributo J appartenente alla relazione <em><span style="font-family:&quot;">r </span></em>dipende da un attributo K della relazione che non è chiave candidata e che a sua volta dipende da un attributo A, che è chiave candidata o primaria. </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Per verificare se una tabella in 2NF è anche in 3NF basta chiederci: </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">“<em>Esiste un campo non chiave che dipenda funzionalmente da un altro campo non chiave?</em>”.</span><span style="font-size:10pt;color:#262626;font-family:&quot;"></span></p>
<p style="background:white;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;"> </span></p>
<p style="background:white;margin:0;"><span style="font-size:10pt;color:#262626;font-family:&quot;">Data la relazione:    <em><span style="font-family:&quot;"> r </span></em>(A, B, K, J)     con A chiave primaria o candidata<br />
e avendo che: <span class="note-grandi1"><em><span style="font-family:&quot;">(il simbolo -&gt; significa : ” determina il valore di:”)</span></em></span>: A -&gt; K e K -&gt; J<br />
si verifica una dipendenza transitiva tra A e J , in quanto J dipende da A tramite K.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/microfrost.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/microfrost.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/microfrost.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/microfrost.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/microfrost.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/microfrost.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/microfrost.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/microfrost.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/microfrost.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/microfrost.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/microfrost.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/microfrost.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/microfrost.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/microfrost.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=microfrost.wordpress.com&amp;blog=5609789&amp;post=60&amp;subd=microfrost&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://microfrost.wordpress.com/2008/11/27/sql-normalizzare-un-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/26f2fe837b34abd736548abcd4453ab7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">microfrost</media:title>
		</media:content>
	</item>
		<item>
		<title>Sql : Modello logico-concettuale</title>
		<link>http://microfrost.wordpress.com/2008/11/26/sql-modello-logico-concettuale/</link>
		<comments>http://microfrost.wordpress.com/2008/11/26/sql-modello-logico-concettuale/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 15:03:59 +0000</pubDate>
		<dc:creator>microfrost</dc:creator>
				<category><![CDATA[Analisi e modellazione dati]]></category>
		<category><![CDATA[er]]></category>
		<category><![CDATA[modello concettuale]]></category>
		<category><![CDATA[modello loico]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[visio]]></category>

		<guid isPermaLink="false">http://microfrost.wordpress.com/?p=51</guid>
		<description><![CDATA[In questo articolo esamineremo il modello logico e concettuale di un database. Sono presenti esempi di creazione con Visio di modelli ORM e ER.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=microfrost.wordpress.com&amp;blog=5609789&amp;post=51&amp;subd=microfrost&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="line-height:normal;margin:0;"><span><strong><span style="text-decoration:underline;"><span style="font-size:10pt;color:#4f81bd;font-family:Verdana,sans-serif;">Best Practices</span></span></strong></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Verdana,sans-serif;"></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Il primo passo nello sviluppo di un modello di dati è identificare i requisiti. </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Dal modello concettuale, si crea un modello logico. In alternativa, è possibile creare un modello logico direttamente. </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Dal modello logico, si crea un modello fisico. Il processo di progettazione non è finito qui, però. Quindi è buona cosa perfezionare il modello fisico in base alla sicurezza, prestazioni ,scalabilità e bisogni.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Infine, è necessario costruire un prototipo per testare la progettazione del database.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Elenchiamo le migliori pratiche per la modellazione dei dati:</span></p>
<p class="MsoListParagraphCxSpFirst" style="text-indent:-18pt;line-height:normal;margin:0 0 0 36pt;"><span style="font-size:10pt;color:#002060;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><strong><span style="font-size:10pt;color:#002060;font-family:&quot;">Prestare particolare attenzione alla portata del progetto</span></strong><span style="font-size:10pt;color:#002060;font-family:&quot;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="line-height:normal;margin:0 0 0 36pt;"><span style="font-size:10pt;font-family:&quot;">Si deve considerare che i cambiamenti aziendali avvengono in modo rapido. Pertanto, è necessario essere preparati per diverse iterazioni nel corso del processo di progettazione.</span><span style="font-size:10pt;font-family:&quot;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;line-height:normal;margin:0 0 0 36pt;"><span style="font-size:10pt;color:#002060;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><strong><span style="font-size:10pt;color:#002060;font-family:&quot;">Scegliere il metodo appropriato</span></strong><span style="font-size:10pt;color:#002060;font-family:&quot;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="line-height:normal;margin:0 0 0 36pt;"><span style="font-size:10pt;font-family:&quot;"><span> </span>I diagrammi <strong><em>ER</em></strong> sono uno standard informale per la base di dati. Inoltre, <strong><em>ORM</em></strong>, che è più espressivo rispetto al modello ER, è utile per la presentazione di norme complesse.</span><span style="font-size:10pt;font-family:&quot;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;line-height:normal;margin:0 0 0 36pt;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><strong><span style="font-size:10pt;color:#002060;font-family:&quot;">Utilizzare uno strumento di modellazione database</span></strong><span style="font-size:10pt;font-family:&quot;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="line-height:normal;margin:0 0 0 36pt;"><span style="font-size:10pt;font-family:&quot;">Strumenti come Visio consentono la creazione di un modello logico partendo da un modello concettuale.</span><span style="font-size:10pt;font-family:&quot;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;line-height:normal;margin:0 0 0 36pt;"><span style="font-size:10pt;color:#002060;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><strong><span style="font-size:10pt;color:#002060;font-family:&quot;">Includere il modello fisico in un sistema di source control</span></strong><span style="font-size:10pt;color:#002060;font-family:&quot;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="line-height:normal;margin:0 0 0 36pt;"><span style="font-size:10pt;font-family:&quot;">È possibile utilizzare Visual Studio Team System per la sorgente di controllo.</span><span style="font-size:10pt;font-family:&quot;"></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent:-18pt;line-height:normal;margin:0 0 0 36pt;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><strong><span style="font-size:10pt;color:#002060;font-family:&quot;">Iniziare con un rigoroso modello relazionale, ma essere pronti a fare alcuni compromessi per soddisfare le esigenze aziendali</span></strong><span style="font-size:10pt;font-family:&quot;"></span></p>
<p class="MsoListParagraphCxSpLast" style="line-height:normal;margin:0 0 0 36pt;"><span style="font-size:10pt;font-family:&quot;"><span> </span>Ad esempio, di solito bisogna normalizzare <span> </span>alcuni dati per raggiungere una soddisfacente performance.</span><span style="font-size:10pt;font-family:&quot;"></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">L’ <strong><span style="color:#002060;">ORM</span></strong> (<em>Object Role Modeling</em>) va a verbalizzare i dati pertinenti come dati elementari (modello concettuale).</span><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><em><span style="text-decoration:underline;"><span style="font-size:10pt;font-family:&quot;">Vediamone un esempio pratico:</span></span></em></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Dopo una chiacchierata col cliente è venuto fuori questo:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;font-family:&quot;">Bisogna creare un sistema di vendite</span></strong><span style="font-size:10pt;font-family:&quot;">:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><em><span style="font-size:10pt;font-family:&quot;"><span> </span>I <span style="text-decoration:underline;"><span style="color:red;">clienti</span></span> inviano <span style="text-decoration:underline;"><span style="color:red;">ordini</span></span>. </span></em></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><em><span style="font-size:10pt;font-family:&quot;">Ogni ordine può contenere più <span style="text-decoration:underline;"><span style="color:red;">prodotti</span></span>, e un unico prodotto può essere visualizzato su più ordini: c’è un <span style="text-decoration:underline;"><span style="color:red;">dettaglio degli ordini</span></span>. </span></em></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><em><span style="font-size:10pt;font-family:&quot;">Un cliente ordina un prodotto in <span style="text-decoration:underline;"><span style="color:#1f497d;">quantità</span></span>, con o senza uno <span style="text-decoration:underline;"><span style="color:#1f497d;">sconto</span></span>. Un singolo cliente presumibilmente invia più ordini. </span></em></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><em><span style="font-size:10pt;font-family:&quot;">Ogni prodotto ha un <span style="text-decoration:underline;">nome</span>, una <span style="text-decoration:underline;"><span style="color:#1f497d;">unità di misura</span></span>, e un <span style="text-decoration:underline;"><span style="color:#1f497d;">prezzo</span></span>. </span></em></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><em><span style="font-size:10pt;font-family:&quot;">Per ogni cliente, è necessario raccoglierne il <span style="text-decoration:underline;"><span style="color:#1f497d;">nome</span></span>, <span style="text-decoration:underline;"><span style="color:#1f497d;">l&#8217;indirizzo</span></span> e il numero del <span style="text-decoration:underline;"><span style="color:#1f497d;">codice fiscale</span></span>. Il numero fiscale è <strong>unico</strong>. </span></em></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><em><span style="font-size:10pt;font-family:&quot;">Un ordine ha sempre una <span style="text-decoration:underline;"><span style="color:#1f497d;">data</span></span> e un noto cliente. È necessario fornire un modo per identificare i clienti, prodotti e ordini.</span></em></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#632423;font-family:&quot;">Ora possiamo creare il nostro modello ORM con Visio</span></strong><span style="font-size:10pt;font-family:&quot;">:</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Apriamo Visio e creiamo il nostro modello ORM.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Aggiungiamoci le 4 entità: <span style="color:red;">Clienti</span>,<span style="color:red;">Ordini</span>,<span style="color:red;">Prodotti</span>,<span style="color:red;">DettaglioOrdini</span> <span> </span>e quindi i valori per ciascuna entità e leghiamoli tra loro.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p><a href="http://microfrost.files.wordpress.com/2008/11/orm_visio14.jpg"><img class="alignnone size-full wp-image-57" title="orm_visio14" src="http://microfrost.files.wordpress.com/2008/11/orm_visio14.jpg?w=455&#038;h=631" alt="orm_visio14" width="455" height="631" /></a></span></p>
<p><span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Verdana,sans-serif;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">Ora siamo pronti a creare anche il diagramma <strong><span style="color:#1f497d;">ER</span></strong> (Entity Relationship):</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:Verdana,sans-serif;"></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><a href="http://microfrost.files.wordpress.com/2008/11/er_visio1vsd1.jpg"><img class="alignnone size-full wp-image-58" title="er_visio1vsd1" src="http://microfrost.files.wordpress.com/2008/11/er_visio1vsd1.jpg?w=455" alt="er_visio1vsd1"   /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/microfrost.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/microfrost.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/microfrost.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/microfrost.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/microfrost.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/microfrost.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/microfrost.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/microfrost.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/microfrost.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/microfrost.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/microfrost.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/microfrost.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/microfrost.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/microfrost.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=microfrost.wordpress.com&amp;blog=5609789&amp;post=51&amp;subd=microfrost&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://microfrost.wordpress.com/2008/11/26/sql-modello-logico-concettuale/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/26f2fe837b34abd736548abcd4453ab7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">microfrost</media:title>
		</media:content>

		<media:content url="http://microfrost.files.wordpress.com/2008/11/orm_visio14.jpg" medium="image">
			<media:title type="html">orm_visio14</media:title>
		</media:content>

		<media:content url="http://microfrost.files.wordpress.com/2008/11/er_visio1vsd1.jpg" medium="image">
			<media:title type="html">er_visio1vsd1</media:title>
		</media:content>
	</item>
		<item>
		<title>Sql 2005 : T-SQL o CLR?</title>
		<link>http://microfrost.wordpress.com/2008/11/25/sql-2005-t-sql-o-clr/</link>
		<comments>http://microfrost.wordpress.com/2008/11/25/sql-2005-t-sql-o-clr/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 12:41:52 +0000</pubDate>
		<dc:creator>microfrost</dc:creator>
				<category><![CDATA[Analisi e modellazione dati]]></category>
		<category><![CDATA[clr]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql 2005]]></category>
		<category><![CDATA[t-sq]]></category>

		<guid isPermaLink="false">http://microfrost.wordpress.com/?p=41</guid>
		<description><![CDATA[In questo articolo vedremo le differenze tra T-Sql e CLR all'interno di Sql 2005. 
Quindi compileremo e distribuiremo insieme un piccolo assemby che verrà caricato in SQL ed eseguito come stored procedure.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=microfrost.wordpress.com&amp;blog=5609789&amp;post=41&amp;subd=microfrost&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:black;font-family:&quot;">Common Language Runtime</span></strong><span style="font-size:10pt;color:black;font-family:&quot;"> (CLR) rappresenta l&#8217;elemento essenziale di Microsot .NET Framework e fornisce l&#8217;ambiente di esecuzione per tutto il codice .NET Framework. Il codice eseguito all&#8217;interno di CLR viene definito codice gestito. CLR fornisce diverse funzioni e vari servizi richiesti per l&#8217;esecuzione del programma, che includono la compilazione JIT (Just-In-Time), l&#8217;allocazione e la gestione della memoria, l&#8217;applicazione dell&#8217;indipendenza dai tipi, la gestione delle eccezioni e dei thread e la protezione.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:black;font-family:&quot;">Transact-SQL</span></strong><span style="font-size:10pt;color:black;font-family:&quot;"> è stato progettato specificamente per l&#8217;accesso e la modifica diretta dei dati nel database. Pur rappresentando la migliore soluzione nell&#8217;accesso e nella gestione dei dati, Transact-SQL non contiene costrutti di programmazione che facilitano la modifica e il calcolo dei dati.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;">Il codice gestito risulta più adatto di Transact-SQL per i calcoli e per una logica di esecuzione complessa. Inoltre dispone di un supporto esteso per numerose attività complesse, tra cui la gestione delle stringhe e le espressioni regolari. Tramite le funzionalità della libreria di .NET Framework è possibile accedere a migliaia di classi e routine già esistenti da qualsiasi stored procedure, trigger o funzione definita dall&#8217;utente. </span></p>
<p style="margin-bottom:0;vertical-align:top;"><span style="font-size:10pt;color:black;font-family:&quot;">Durante la scrittura di stored procedure, trigger e funzioni definite dall&#8217;utente, è necessario decidere se utilizzare il tradizionale Transact-SQL o un linguaggio .NET Framework come Visual Basic .NET o Visual C#. Utilizzare Transact-SQL per l&#8217;accesso ai dati con un minimo di logica procedurale. Utilizzare il codice gestito per funzioni che richiedono un utilizzo intensivo della CPU o per procedure dalla logica complessa oppure quando si desidera utilizzare la BCL di .NET Framework.</span></p>
<p style="margin-bottom:0;vertical-align:top;"><span style="font-size:10pt;color:black;font-family:&quot;">Un altro fattore da tenere presente quando si decide se utilizzare Transact-SQL o codice gestito è la posizione in cui si desidera che risieda il codice, ovvero nel server o nel client. È possibile eseguire sul server sia Transact-SQL che il codice gestito. In questo modo il codice e i dati vengono posti vicino uno all&#8217;altro, consentendo di sfruttare la capacità di elaborazione del server. Talvolta potrebbe essere consigliabile evitare di eseguire sul server di database attività che richiedono un uso intensivo del processore. Oggi la maggior parte dei computer client è molto potente e può essere utile sfruttare questa capacità di elaborazione eseguendo la maggior quantità del codice sul client. Su un client è possibile eseguire il codice gestito, ma non Transact-SQL.</span></p>
<p style="margin-bottom:0;vertical-align:top;line-height:140%;"><span style="font-size:10pt;color:black;line-height:140%;font-family:&quot;"> </span></p>
<p style="margin-bottom:0;vertical-align:top;line-height:140%;text-align:center;" align="center"><strong><span style="text-decoration:underline;"><span style="font-size:10pt;color:black;line-height:140%;font-family:&quot;">Smanettiamo:</span></span></strong></p>
<p style="margin-bottom:0;vertical-align:top;"><strong><span style="font-size:10pt;color:#1f497d;font-family:&quot;">Abilitazione</span></strong></p>
<pre style="vertical-align:top;"><span style="color:#632423;font-family:&quot;"><span style="font-size:x-small;">sp_configure 'clr enabled', 1</span></span></pre>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:#632423;font-family:&quot;">GO</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:#632423;font-family:&quot;">RECONFIGURE</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:#632423;font-family:&quot;">GO</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#1f497d;font-family:&quot;">Compilazione e distribuzione<span>  </span>assembly </span></strong></p>
<pre style="vertical-align:top;"><span style="font-size:x-small;"><span style="color:blue;font-family:&quot;" lang="EN-US">using</span><span style="color:black;font-family:&quot;" lang="EN-US"> System;</span></span></pre>
<pre style="vertical-align:top;"><span style="font-size:x-small;"><span style="color:blue;font-family:&quot;" lang="EN-US">using</span><span style="color:black;font-family:&quot;" lang="EN-US"> System.Data;</span></span></pre>
<pre style="vertical-align:top;"><span style="font-size:x-small;"><span style="color:blue;font-family:&quot;" lang="EN-US">using</span><span style="color:black;font-family:&quot;" lang="EN-US"> Microsoft.SqlServer.Server;</span></span></pre>
<pre style="vertical-align:top;"><span style="font-size:x-small;"><span style="color:blue;font-family:&quot;" lang="EN-US">using</span><span style="color:black;font-family:&quot;" lang="EN-US"> System.Data.SqlTypes;</span></span></pre>
<pre style="vertical-align:top;"><span style="color:black;font-family:&quot;" lang="EN-US"><span style="font-size:x-small;"> </span></span></pre>
<pre style="vertical-align:top;"><span style="font-size:x-small;"><span style="color:blue;font-family:&quot;" lang="EN-US">public</span><span style="color:black;font-family:&quot;" lang="EN-US"> </span><span style="color:blue;font-family:&quot;" lang="EN-US">class</span><span style="color:black;font-family:&quot;" lang="EN-US"> HelloWorldProc</span></span></pre>
<pre style="vertical-align:top;"><span style="color:black;font-family:&quot;" lang="EN-US"><span style="font-size:x-small;">{</span></span></pre>
<pre style="vertical-align:top;"><span style="color:black;font-family:&quot;" lang="EN-US"><span style="font-size:x-small;"><span>    </span>[Microsoft.SqlServer.Server.SqlProcedure]</span></span></pre>
<pre style="vertical-align:top;"><span style="font-size:x-small;"><span style="color:black;font-family:&quot;" lang="EN-US"><span>    </span></span><span style="color:blue;font-family:&quot;" lang="EN-US">public</span><span style="color:black;font-family:&quot;" lang="EN-US"> </span><span style="color:blue;font-family:&quot;" lang="EN-US">static</span><span style="color:black;font-family:&quot;" lang="EN-US"> </span><span style="color:blue;font-family:&quot;" lang="EN-US">void</span><span style="color:black;font-family:&quot;" lang="EN-US"> HelloWorld()</span></span></pre>
<pre style="vertical-align:top;"><span style="color:black;font-family:&quot;" lang="EN-US"><span style="font-size:x-small;"><span>    </span>{</span></span></pre>
<pre style="vertical-align:top;"><span style="font-size:x-small;"><span style="color:black;font-family:&quot;" lang="EN-US"><span>        </span>SqlContext.Pipe.Send(</span><span style="color:maroon;font-family:&quot;" lang="EN-US">"Hello world!\n"</span><span style="color:black;font-family:&quot;" lang="EN-US">);</span></span></pre>
<pre style="vertical-align:top;"><span style="font-size:x-small;"><span style="color:black;font-family:&quot;" lang="EN-US"><span>    </span></span><span style="color:black;font-family:&quot;">}</span></span></pre>
<pre style="vertical-align:top;"><span style="color:black;font-family:&quot;"><span style="font-size:x-small;">}</span></span></pre>
<pre style="vertical-align:top;"><span style="color:black;font-family:&quot;"><span style="font-size:x-small;"> </span></span></pre>
<p style="margin-bottom:0;vertical-align:top;"><span style="font-size:10pt;color:black;font-family:&quot;">Questo programma verrà quindi compilato come una libreria, caricato in SQL Server ed eseguito come una stored procedure.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;">In SQL Server vengono installati i file di ridistribuzione di .NET Framework per impostazione predefinita. In questi file è incluso <span> </span>csc.exe, ovvero il compilatori della riga di comando per Visual C#. Per compilare l&#8217;esempio, è necessario modificare la variabile PATH in modo tale che faccia riferimento alla directory contenente csc.exe :</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;"> </span></p>
<pre style="vertical-align:top;text-align:center;"><span style="color:#1f497d;font-family:&quot;" lang="EN-US"><span style="font-size:x-small;">C:\Windows\Microsoft.NET\Framework\(version)</span></span></pre>
<pre style="vertical-align:top;text-align:center;"><span style="color:#1f497d;font-family:&quot;" lang="EN-US"><span style="font-size:x-small;"> </span></span></pre>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;">Una volta aggiunta la directory di .NET Framework al percorso, sarà possibile compilare in un assembly la stored procedure di esempio con il seguente comando. </span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;text-align:center;margin:0;" align="center"><span style="font-size:10pt;color:#1f497d;font-family:&quot;">csc /target:library helloworld.cs</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;text-align:center;margin:0;" align="center"><span style="font-size:10pt;color:#1f497d;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;">Una volta compilata correttamente la routine di esempio, è possibile eseguirne il test in SQL Server. A questo scopo, aprire SQL Server Management Studio e creare una nuova query, eseguendo la connessione ad un database.</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;">Sarà necessario creare l&#8217;assembly per accedere alla stored procedure. Per questo esempio, si supponga di aver creato l&#8217;assembly helloworld.dll nella directory C:\. </span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;">Aggiungere alla query la seguente istruzione Transact-SQL:</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;text-align:center;margin:0;" align="center"><span style="font-size:10pt;color:#1f497d;font-family:&quot;" lang="EN-US">CREATE ASSEMBLY helloworld from &#8216;c:\helloworld.dll&#8217; WITH PERMISSION_SET = SAFE</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;text-align:center;margin:0;" align="center"><span style="font-size:10pt;color:#1f497d;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;">Dopo la creazione dell&#8217;assembly sarà possibile accedere al metodo HelloWorld utilizzando l&#8217;istruzione:</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:#1f497d;font-family:&quot;" lang="EN-US">CREATE PROCEDURE hello</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:#1f497d;font-family:&quot;" lang="EN-US">AS</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:#1f497d;font-family:&quot;" lang="EN-US">EXTERNAL NAME helloworld.HelloWorldProc.HelloWorld</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;">Una volta creata, la routine potrà essere eseguita come una normale stored procedure scritta in Transact-SQL. Eseguire il seguente comando:</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;text-align:center;margin:0;" align="center"><span style="font-size:10pt;color:#1f497d;font-family:&quot;">EXEC hello</span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;text-align:center;margin:0;" align="center"><span style="font-size:10pt;color:#1f497d;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#1f497d;font-family:&quot;">Rimozione dell&#8217;esempio di stored procedure &#8220;Hello World&#8221; ed assembly</span></strong></p>
<p class="MsoNormal" style="vertical-align:top;line-height:normal;margin:0;"><strong><span style="font-size:10pt;color:#1f497d;font-family:&quot;"> </span></strong></p>
<pre style="vertical-align:top;text-align:center;"><span style="color:#1f497d;font-family:&quot;" lang="EN-US"><span style="font-size:x-small;">drop procedure hello</span></span></pre>
<pre style="vertical-align:top;text-align:center;"><span style="color:#1f497d;font-family:&quot;" lang="EN-US"><span style="font-size:x-small;">drop assembly helloworld</span></span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/microfrost.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/microfrost.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/microfrost.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/microfrost.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/microfrost.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/microfrost.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/microfrost.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/microfrost.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/microfrost.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/microfrost.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/microfrost.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/microfrost.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/microfrost.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/microfrost.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=microfrost.wordpress.com&amp;blog=5609789&amp;post=41&amp;subd=microfrost&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://microfrost.wordpress.com/2008/11/25/sql-2005-t-sql-o-clr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/26f2fe837b34abd736548abcd4453ab7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">microfrost</media:title>
		</media:content>
	</item>
		<item>
		<title>Sql 2005 : I componenti</title>
		<link>http://microfrost.wordpress.com/2008/11/23/sql-2005-i-componenti/</link>
		<comments>http://microfrost.wordpress.com/2008/11/23/sql-2005-i-componenti/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 20:18:15 +0000</pubDate>
		<dc:creator>microfrost</dc:creator>
				<category><![CDATA[Analisi e modellazione dati]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[database engine]]></category>
		<category><![CDATA[full-text search]]></category>
		<category><![CDATA[integration services]]></category>
		<category><![CDATA[notification services]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[reporting services]]></category>
		<category><![CDATA[service brocker]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql 2005]]></category>
		<category><![CDATA[sql 2005 componenti]]></category>
		<category><![CDATA[sql server agent]]></category>

		<guid isPermaLink="false">http://microfrost.wordpress.com/?p=38</guid>
		<description><![CDATA[In questo artcicolo vedremo in modo sommario i componenti di Sql 2005 e le loro principali caratteristiche.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=microfrost.wordpress.com&amp;blog=5609789&amp;post=38&amp;subd=microfrost&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="line-height:14.25pt;margin:0 0 10pt;"><span style="font-size:10pt;color:#00b0f0;font-family:&quot;">Database Engine </span><span style="font-size:10pt;color:black;font-family:&quot;">Comprende il motore principale dei servizi di SQL Server ed è responsabile per la memorizzazione, l&#8217;elaborazione, e la sicurezza dei dati. Si utilizza il motore di database per creare database relazionali OLTP e costruire data ware-houses per applicazioni di BI. In SQL Server 2005, il motore include molte nuove funzionalità, tra cui Common Language Runtime (CLR) l&#8217;integrazione e il supporto per XML (Extensible Markup Language) e Web Services.</span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0;"><span style="font-size:10pt;color:#00b0f0;font-family:&quot;">Service Broker </span><span style="font-size:10pt;color:black;font-family:&quot;">Il servizio, nativo in SQL Server 2005, consente di gestire messaggi asincroni all’interno di un database, fra istanze diverse di database o fra SQL Server diversi su macchine separate. L’obiettivo è semplice: aumentare il livello di scalabilità delle applicazioni front-end rimandando al back-end il grosso del lavoro. </span><span style="font-size:10pt;color:black;font-family:&quot;"></span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;">Proviamo a spiegarci con un esempio classico: su un sito di commercio elettronico, a fronte di un acquisto, deve partire un processo di generazione dell’ordine che sicuramente comporta operazioni sul magazzino, la generazione delle informazioni sulla spedizione, il controllo della disponibilità finanziaria del cliente e probabilmente varie altre operazioni. Se queste operazioni sono eseguite dalla pagina di check-out viene bloccato un thread dell’applicazione ASP.NET per tutta la durata del processo e vengono eseguiti dei lock sulle varie tabelle che possono rallentare altri ordini da processare; inoltre, tutte le risorse coinvolte devono essere disponibili al momento dell’acquisto; non ultimo la comunicazione fra l’applicazione e le risorse deve essere molto efficiente per non rallentare appunto l’intero front-end.</span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0 0 10pt;"><span style="font-size:10pt;color:#00b0f0;font-family:&quot;">Replication </span><span style="font-size:10pt;color:black;font-family:&quot;">Consente di copiare i dati e oggetti tra basi di dati distribuite. </span><span style="font-size:10pt;color:black;font-family:&quot;"></span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0 0 10pt;"><span style="font-size:10pt;color:#00b0f0;font-family:&quot;">Full-Text Search </span><span style="font-size:10pt;color:black;font-family:&quot;">Si tratta di un componente in grado di effettuare interrogazioni veloci ed efficienti su indicizzazioni di testi, ovvero query che si basano su termini chiave, parti di testo o semplici parole. Possiamo ottenere i massimi benefici da questa tecnica soprattutto in presenza di grandi moli di informazioni di tipo non strutturato, come possono essere testi o interi documenti.</span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0 0 10pt;"><span style="font-size:10pt;color:#00b0f0;font-family:&quot;">SQL Server Agent </span><span style="font-size:10pt;color:black;font-family:&quot;">SQL Server Agent è uno strumento di amministrazione di database per la pianificazione e l&#8217;esecuzione di jobs come, ad esempio, i backup di database.</span><span style="font-size:10pt;color:black;font-family:&quot;"></span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0 0 10pt;"><span style="font-size:10pt;color:#00b0f0;font-family:&quot;">Integration Services </span><span style="font-size:10pt;color:black;font-family:&quot;">SSIS è una piattaforma utile a sviluppare soluzioni rivolte all’integrazione di dati fra sistemi, ma è anche sinonimo di ETL. Un ETL (Extraction, Transformation and Loading) non è altro che un’applicazione finalizzata a caricare e trasformare dati da più piattaforme per elaborarli in base alle specifiche che l’analisi finale richiede. Oltre a rappresentare un potente strumento di questo tipo, SSIS ha ulteriori funzionalità, rivolte ad esempio alla manutenzione dei server, al richiamo di web services, al trasferimento di file FTP e via discorrendo.</span><span style="font-size:10pt;color:red;font-family:&quot;"></span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0 0 10pt;"><span style="font-size:10pt;color:#00b0f0;font-family:&quot;">Reporting Services </span><span style="font-size:10pt;color:black;font-family:&quot;">Reporting Services è un ambiente di reporting basato su server e gestito tramite Web service. È possibile distribuire i report in un&#8217;ampia gamma di formati e sono disponibili numerose opzioni per l&#8217;interattività e la stampa. Tramite la distribuzione di report come origine dati per le applicazioni di Business Intelligence, anche le analisi più complesse risultano ampiamente accessibili agli utenti.</span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0;"><span style="font-size:10pt;color:#00b0f0;font-family:&quot;">Analysis Services </span><span style="font-size:10pt;color:black;font-family:&quot;">Con SQL Server 2005, per la prima volta Analysis Services consente di ottenere una visione unificata e integrata di tutti i dati aziendali, che possono essere utilizzati come base per le normali attività di reporting, analisi OLAP, scorecard KPI (Key Performance Indicator) e data mining (letteralmente <span> </span>‘estrazione dati’).</span><span style="font-size:10pt;color:black;font-family:&quot;"></span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0;"><span style="font-size:10pt;color:black;font-family:&quot;"> </span><span style="font-size:10pt;color:black;font-family:&quot;"></span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0 0 10pt;"><span style="font-size:10pt;color:#00b0f0;font-family:&quot;">Notification Services </span><span style="font-size:10pt;color:black;font-family:&quot;">Microsoft SQL Server 2005 Notification Services è una piattaforma per lo sviluppo e la distribuzione di applicazioni in grado di generare e inviare notifiche. È possibile utilizzare tale piattaforma per generare e inviare tempestivamente messaggi personalizzati a migliaia o milioni di sottoscrittori con la possibilità di recapitare i messaggi a un&#8217;ampia gamma di dispositivi.</span><span style="font-size:10pt;color:red;font-family:&quot;"></span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0 0 10pt;"><strong><span style="font-size:10pt;color:black;font-family:&quot;">OLAP</span></strong><span style="font-size:10pt;color:black;font-family:&quot;">, acronimo che sta per l&#8217;espressione <em>On-Line Analytical Processing</em>, designa un insieme di tecniche software per l&#8217;analisi interattiva e veloce di grandi quantità di dati, che è possibile esaminare in modalità piuttosto complesse. Questa è la componente tecnologica base del data warehouse e, ad esempio, serve alle aziende per analizzare i risultati delle vendite, l&#8217;andamento dei costi di acquisto merci, al marketing per misurare il successo di una campagna pubblicitaria, ad una università i dati di un sondaggio ed altri casi simili. Gli strumenti OLAP si differenziano dagli OLTP per il fatto che i primi hanno come obiettivo la performance nella ricerca e il raggiungimento di un&#8217;ampiezza di interrogazione quanto più grande possibile; i secondi, invece, hanno come obiettivo la garanzia di integrità e sicurezza delle transazioni<strong>.</strong></span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0 0 10pt;"><strong><span style="font-size:10pt;color:black;font-family:&quot;">OLTP</span></strong><span style="font-size:10pt;color:black;font-family:&quot;">: <em>On Line Transaction Processing</em> A differenza delle analisi con tecnologia OLAP (<em>Online Analytical Processing</em>), la tecnologia OLTP non prevede la creazione di banche dati separate, infatti le analisi vengono effettuate direttamente sui dati di esercizio</span></p>
<p class="MsoNormal" style="line-height:14.25pt;margin:0 0 10pt;"><strong><span style="font-size:10pt;color:black;font-family:&quot;">Database distribuito</span></strong><span style="font-size:10pt;color:black;font-family:&quot;">: Un database distribuito è un database che si trova sotto il controllo di un Database management system (<strong>DBMS</strong>) nel quale gli archivi non sono memorizzati sullo stesso computer. Il database può essere dislocato in più computer situati nello stesso luogo, oppure distribuito in una rete di computer connessi tra loro.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/microfrost.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/microfrost.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/microfrost.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/microfrost.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/microfrost.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/microfrost.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/microfrost.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/microfrost.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/microfrost.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/microfrost.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/microfrost.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/microfrost.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/microfrost.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/microfrost.wordpress.com/38/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=microfrost.wordpress.com&amp;blog=5609789&amp;post=38&amp;subd=microfrost&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://microfrost.wordpress.com/2008/11/23/sql-2005-i-componenti/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/26f2fe837b34abd736548abcd4453ab7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">microfrost</media:title>
		</media:content>
	</item>
	</channel>
</rss>
