<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>BenL's WebLog</title><link>http://weblogs.asp.net/benl/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Debug Build: 20510.895)</generator><item><title>Maintaining SQL Server Databases</title><link>http://weblogs.asp.net/benl/archive/2004/01/14/58808.aspx</link><pubDate>Thu, 15 Jan 2004 02:40:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:58808</guid><dc:creator>BenL</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/benl/rsscomments.aspx?PostID=58808</wfw:commentRss><comments>http://weblogs.asp.net/benl/archive/2004/01/14/58808.aspx#comments</comments><description>&lt;P&gt;&lt;FONT face=Verdana&gt;I read an interesting &lt;/FONT&gt;&lt;A href="http://weblogs.asp.net/erobillard/articles/3801.aspx"&gt;&lt;FONT face=Verdana&gt;article&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;by &lt;/FONT&gt;&lt;A href="http://weblogs.asp.net/erobillard"&gt;&lt;FONT face=Verdana&gt;Eli Robillard&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt; recently.&amp;nbsp; The very top of the article quotes Hlade's Law, "If you have a difficult task, give it to a lazy person - they will find an easier way to do it."&amp;nbsp; &lt;/FONT&gt;&lt;A href="http://authors.aspalliance.com/Ambrose/"&gt;&lt;FONT face=Verdana&gt;Ambrose&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;points out the benefits of lazy people in military positions in the comments.&amp;nbsp; I enjoyed reading these things because it made me realize that I approach my work in a similar way.&amp;nbsp; But I digress...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;In keeping with the spirit of &amp;#8220;The Lazy Programmer&amp;#8221; I am going to briefly describe a method a friend of mine showed me for maintaining SQL Server databases.&amp;nbsp; I will not outline the details of the approach.&amp;nbsp; Instead, I will provide a brief overview and reserve any details for a (possible) future blog article.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;The method my friend showed me involves setting up a main folder for your database with various sub folders to hold the different pieces.&amp;nbsp; For example, you might have a root folder called &amp;#8220;Northwind&amp;#8221; with sub folders called &amp;#8220;SP&amp;#8221; (for stored procedures), &amp;#8220;Table&amp;#8221; (for tables), &amp;#8220;PK&amp;#8221; for primary keys, &amp;#8220;FN&amp;#8221; (for user-defined functions), etc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;The contents of all of these folders contain script files to create each item.&amp;nbsp; Sticking with the North wind example, the &amp;#8220;Table&amp;#8221; folder would contain files called &amp;#8220;Customers.sql&amp;#8221;, &amp;#8220;Orders.sql&amp;#8221;, &amp;#8220;Employees.sql&amp;#8221;, etc.&amp;nbsp; The &amp;#8220;PK&amp;#8220; folder would have script files for creating primary keys on the tables in the database.&amp;nbsp; Obviously,&amp;nbsp;databases with lots of objects would have many script files in using this approach.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;After all the .sql files are created there are a couple of batch files that you run to extract all of the individual scripts into one, large script file that can be run in Query Analyzer to drop and rebuild the entire database.&amp;nbsp; These batch files can easily be run from other files or processes (say a giant application build script).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;It took some getting used to, but I have found working directly with the script files (to create tables, write sproc's, create indexes, etc.) to be much more efficient than doing things in Enterprise Manager.&amp;nbsp; For example, after creating the script to create a table, copying the column names and data types into another script file for an Insert stored procedure is very easy.&amp;nbsp; Also, using the regular expression capabilities of a tool like Visual Studio.Net really speeds up development time.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana&gt;I would be more than happy to share more about my experiences with this method.&amp;nbsp; What do you find useful in creating/maintaining SQL Server databases?&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=58808" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/benl/archive/tags/SQL+Server/default.aspx">SQL Server</category></item></channel></rss>