<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://lucasontivero.spaces.live.com/mmm2008-07-24_12.50/rsspretty.aspx?rssquery=en-US;http%3a%2f%2flucasontivero.spaces.live.com%2fcategory%2fSQLServer%2by%2bBases%2bde%2bdatos%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Lucas Ontivero: SQLServer y Bases de datos</title><description /><link>http://lucasontivero.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catSQLServer%2by%2bBases%2bde%2bdatos</link><language>en-US</language><pubDate>Fri, 15 Aug 2008 15:15:42 GMT</pubDate><lastBuildDate>Fri, 15 Aug 2008 15:15:42 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://lucasontivero.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>3988747590285877710</live:id><live:alias>lucasontivero</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>Consultas sobre metadatos de SQLServer</title><link>http://lucasontivero.spaces.live.com/Blog/cns!375AE0CCD1AF61CE!215.entry</link><description>&lt;p&gt;
&lt;p&gt;Muchas veces, y sobre todo cunado trabajamos con una DB muy grande, necesitamos algunas cuestiones tales como:
&lt;ul&gt;
&lt;li&gt;averiguar que tablas contienen columnas 'email', 
&lt;li&gt;averiguar cuantos bytes está ocupando cada fila de cada tabla, 
&lt;li&gt;averiguar cuantas columnas tiene una tabla, 
&lt;li&gt;averiguar cuantas vistas hay en la db, 
&lt;li&gt;averiguar los parámetros de los procedimientos almacenados (ver Intelisence SQL de &lt;a href="http://horaciomontalvetti.spaces.live.com/"&gt;Horacio Montalvetti&lt;/a&gt;), 
&lt;li&gt;construir un diccionario de datos de las tablas, 
&lt;li&gt;automatizar la generación de documentación sobre la DB, 
&lt;li&gt;o incluso podríamos necesitar automatizar la generación de código a partir de la estructura de la db&lt;br&gt;teniendo en cuenta sus claves primarias, foraneas, constraints, tipo de datos, reglas, si aceptan nulos,&lt;br&gt;y hasta los comentarios. &lt;/ul&gt;
&lt;p&gt;Esto es gracias a que podemos acceder a los tablas del sistema que son las que mantienen los metadatos. Si, es reflection sobre la DB. Bueno, una de las utilidades que mas le he dado a estos metadatos es ubicar vistas, tablas, columnas y obtener sus comentarios por eso publico 2 vistas muy útiles que me han servido de mucha ayuda. 
&lt;p&gt;&lt;br&gt;&lt;pre&gt;CREATE VIEW dbo.DBCOLUMNS&lt;br&gt;AS&lt;br&gt; SELECT dbo.sysobjects.name AS TABLE_NAME, &lt;br&gt;        dbo.syscolumns.name AS COLUMN_NAME,&lt;br&gt;        dbo.systypes.name AS DATA_TYPE, &lt;br&gt;        dbo.syscolumns.length AS DATA_LENGTH, &lt;br&gt;        dbo.syscolumns.xprec AS DATA_PRECISION, &lt;br&gt;        dbo.syscolumns.xscale AS DATA_SCALE,&lt;br&gt;        dbo.syscolumns.isnullable AS NULLABLE, &lt;br&gt;        dbo.syscomments.text AS DATA_DEFAULT,&lt;br&gt;        dbo.sysproperties.[value] AS DESCRIPTION,&lt;br&gt;        dbo.syscolumns.iscomputed AS IS_COMPUTED&lt;br&gt; FROM   dbo.syscolumns &lt;br&gt;        INNER JOIN dbo.sysobjects ON dbo.syscolumns.id = dbo.sysobjects.id &lt;br&gt;        INNER JOIN dbo.systypes ON dbo.syscolumns.xusertype=dbo.systypes.xusertype &lt;br&gt;        LEFT OUTER JOIN dbo.sysproperties ON&lt;br&gt;             dbo.syscolumns.colid = dbo.sysproperties.smallid &lt;br&gt;             AND dbo.syscolumns.id = dbo.sysproperties.id &lt;br&gt;             AND dbo.sysproperties.name = N'MS_Description' &lt;br&gt;        LEFT OUTER JOIN dbo.sysobjects sysobjects_1 &lt;br&gt;        INNER JOIN dbo.syscomments ON dbo.syscomments.id = sysobjects_1.id ON &lt;br&gt;        dbo.syscolumns.cdefault = sysobjects_1.id&lt;br&gt; WHERE (dbo.sysobjects.xtype = 'U')&lt;br&gt; ORDER BY dbo.sysobjects.name, dbo.syscolumns.colid&lt;/pre&gt;&lt;pre&gt;CREATE VIEW dbo.DBCOLUMNS&lt;br&gt;AS&lt;br&gt; SELECT information_schema.tables.table_name, &lt;br&gt;        information_schema.columns.column_name, &lt;br&gt;        information_schema.columns.IS_NULLABLE AS Nulleable, &lt;br&gt;        information_schema.columns.DATA_TYPE AS Type, &lt;br&gt;        information_schema.tables.TABLE_TYPE, &lt;br&gt;        information_schema.columns.CHARACTER_MAXIMUM_LENGTH, &lt;br&gt;        information_schema.columns.NUMERIC_PRECISION, &lt;br&gt;        information_schema.columns.NUMERIC_SCALE, &lt;br&gt;        information_schema.columns.DATETIME_PRECISION&lt;br&gt; FROM   information_schema.tables INNER JOIN&lt;br&gt;        information_schema.columns ON &lt;br&gt;        information_schema.tables.table_name = information_schema.columns.table_name&lt;br&gt; WHERE (information_schema.tables.table_name NOT LIKE 'sys%') &lt;br&gt;        AND (information_schema.tables.table_name &amp;lt;&amp;gt; 'dtproperties') &lt;br&gt;        AND (information_schema.tables.table_schema &amp;lt;&amp;gt; 'INFORMATION_SCHEMA')&lt;br&gt; ORDER BY information_schema.tables.table_name, information_schema.columns.table_name&lt;/pre&gt;
&lt;p&gt; 
&lt;p&gt;Buena suerte.&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=3988747590285877710&amp;page=RSS%3a+Consultas+sobre+metadatos+de+SQLServer&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=lucasontivero.spaces.live.com&amp;amp;GT1=lucasontivero"&gt;</description><comments>http://lucasontivero.spaces.live.com/Blog/cns!375AE0CCD1AF61CE!215.entry#comment</comments><guid isPermaLink="true">http://lucasontivero.spaces.live.com/Blog/cns!375AE0CCD1AF61CE!215.entry</guid><pubDate>Wed, 22 Nov 2006 18:38:43 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://lucasontivero.spaces.live.com/blog/cns!375AE0CCD1AF61CE!215/comments/feed.rss</wfw:commentRss><wfw:comment>http://lucasontivero.spaces.live.com/Blog/cns!375AE0CCD1AF61CE!215.entry#comment</wfw:comment><dcterms:modified>2006-11-22T19:58:43Z</dcterms:modified></item></channel></rss>