Monthly Archives: October 2010

Generating SQL from Visio (non-Enterprise Architect versions)

Creating an ERD without the ability to generate SQL from it is of questionable value.  If you’re not using a CASE tool such as ERwin (and why not?), you may need to generate a DDL from your Visio layout.  If typing out SQL statements proves too laborious, here is a great workaround to generate workable SQL from your Visio diagram.

A company called Orthogonal Software has a Visio plug-in called Orthogonal Toolbox that will allow you to export the data from the Visio document to an XML File.  Additionally, Orthogonal has provided a couple XSLT’s that you can apply (look for XSLT on that page). One of which has been altered to export SQL.

Once you have the plug-in installed and the XSLT’s downloaded, it’s pretty simple.  Use the plug-in to export to XML, and apply the stylesheet when exporting.  Presto- DDL statements for your structures.

 

Row many columns and rows are in my tables…and which tables are largest?

CREATE TABLE #temp (
table_name sysname ,
row_count INT,
reserved_size VARCHAR(50),
data_size VARCHAR(50),
index_size VARCHAR(50),
unused_size VARCHAR(50))
SET NOCOUNT ON
INSERT #temp
EXEC sp_msforeachtable ‘sp_spaceused ”?”’
SELECT a.table_name,
a.row_count,
COUNT(*) AS col_count,
a.data_size
FROM #temp a
INNER JOIN information_schema.columns b
ON a.table_name collate database_default
= b.table_name collate database_default
GROUP BY a.table_name, a.row_count, a.data_size
ORDER BY CAST(REPLACE(a.data_size, ‘ KB’, ”) AS integer) DESC
DROP TABLE #temp

Tagged
Follow

Get every new post delivered to your Inbox.