<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-18803479</id><updated>2011-06-27T10:23:21.319-07:00</updated><category term='DROP TABLE'/><category term='DBCC CHECKDB'/><category term='DDL Trigger'/><category term='SQL Server 2005'/><category term='ALTER TABLE'/><category term='Production DBA'/><title type='text'>SQL Server Notes</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>27</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-18803479.post-4707441027618679305</id><published>2011-06-27T10:22:00.000-07:00</published><updated>2011-06-27T10:23:21.326-07:00</updated><title type='text'>Restarting server on remorte desktop</title><content type='html'>command prompt:&lt;br /&gt;Shutdown /r /f /m bltrdevm58123 /t 0&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-4707441027618679305?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/4707441027618679305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=4707441027618679305&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/4707441027618679305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/4707441027618679305'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2011/06/restarting-server-on-remorte-desktop.html' title='Restarting server on remorte desktop'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-1570912559025712642</id><published>2011-05-11T17:38:00.000-07:00</published><updated>2011-05-13T13:40:56.998-07:00</updated><title type='text'>Drop and Create Foreign keys</title><content type='html'>This query generates the drop and create statements for foreign keys in SQL Server.&lt;br /&gt;DECLARE&lt;br /&gt; @constraint_name sysname,&lt;br /&gt; @parent_schema sysname,&lt;br /&gt; @parent_name sysname,&lt;br /&gt; @referenced_object_schema sysname,&lt;br /&gt; @referenced_object_name sysname,&lt;br /&gt; @column_name sysname,&lt;br /&gt; @referenced_column_name sysname,&lt;br /&gt; @is_not_for_replication bit,&lt;br /&gt; @is_not_trusted bit,&lt;br /&gt; @delete_referential_action tinyint,&lt;br /&gt; @update_referential_action tinyint,&lt;br /&gt; @AddLine nvarchar(max),&lt;br /&gt; @DropLine nvarchar(max),&lt;br /&gt; @fkline nvarchar(max),&lt;br /&gt; @pkline nvarchar(max),&lt;br /&gt; @object_id int,&lt;br /&gt; @parent_object_id int&lt;br /&gt;&lt;br /&gt;DECLARE &lt;br /&gt; @AddScript TABLE (line nvarchar(max))&lt;br /&gt;DECLARE &lt;br /&gt; @DropScript TABLE (line nvarchar(max))&lt;br /&gt;&lt;br /&gt; SET NOCOUNT ON&lt;br /&gt;&lt;br /&gt; -- Create cursor for foreign keys system view&lt;br /&gt; DECLARE cFKeys CURSOR READ_ONLY&lt;br /&gt; FOR &lt;br /&gt; SELECT object_id, &lt;br /&gt; parent_object_id, &lt;br /&gt; OBJECT_SCHEMA_NAME(parent_object_id), &lt;br /&gt; object_name (parent_object_id), &lt;br /&gt; [name], &lt;br /&gt; is_not_trusted, &lt;br /&gt; OBJECT_SCHEMA_NAME(referenced_object_id), &lt;br /&gt; object_name(referenced_object_id),&lt;br /&gt; delete_referential_action,&lt;br /&gt; update_referential_action,&lt;br /&gt; is_not_for_replication&lt;br /&gt; FROM sys.foreign_keys&lt;br /&gt; &lt;br /&gt; OPEN cFKeys&lt;br /&gt; &lt;br /&gt; -- Collect basic data&lt;br /&gt; FETCH NEXT FROM cFKeys INTO @object_id, @parent_object_id, @parent_schema, @parent_name, @constraint_name, @is_not_trusted, @referenced_object_schema, @referenced_object_name, @delete_referential_action, @update_referential_action, @is_not_for_replication&lt;br /&gt; WHILE (@@fetch_status &lt;&gt; -1)&lt;br /&gt; BEGIN&lt;br /&gt; IF (@@fetch_status &lt;&gt; -2)&lt;br /&gt; BEGIN&lt;br /&gt; -- Start creating command string. One for add and one for drop constraint&lt;br /&gt; SET @AddLine = N'ALTER TABLE ' + quotename(@parent_schema) + N'.' + quotename(@parent_name)&lt;br /&gt; SET @DropLine = N'ALTER TABLE ' + quotename(@parent_schema) + N'.' + quotename(@parent_name)&lt;br /&gt; -- Check if it is enabled or not&lt;br /&gt; IF @is_not_trusted = 1&lt;br /&gt; SET @AddLine = @AddLine + N' WITH NOCHECK'&lt;br /&gt; ELSE&lt;br /&gt; SET @AddLine = @AddLine + N' WITH CHECK'&lt;br /&gt; &lt;br /&gt; SET @AddLine = @AddLine + N' ADD CONSTRAINT ' + quotename(@constraint_name) + N' FOREIGN KEY (' &lt;br /&gt; SET @DropLine = @DropLine + N' DROP CONSTRAINT ' + quotename(@constraint_name)&lt;br /&gt; &lt;br /&gt; -- Gather all columns for current key from foreign key columns system view&lt;br /&gt; DECLARE cColumns CURSOR READ_ONLY&lt;br /&gt; FOR &lt;br /&gt; SELECT fc.name, pc.name&lt;br /&gt; FROM sys.foreign_key_columns fk &lt;br /&gt; inner join sys.columns fc on fk.parent_object_id = fc.object_id and fk.parent_column_id = fc.column_id&lt;br /&gt; inner join sys.columns pc on fk.referenced_object_id = pc.object_id and fk.referenced_column_id = pc.column_id&lt;br /&gt; WHERE parent_object_id = @parent_object_id and fk.constraint_object_id = @object_id&lt;br /&gt; &lt;br /&gt; OPEN cColumns&lt;br /&gt; &lt;br /&gt; SET @fkline = N''&lt;br /&gt; SET @pkline = N''&lt;br /&gt; &lt;br /&gt; FETCH NEXT FROM cColumns INTO @column_name, @referenced_column_name&lt;br /&gt; WHILE (@@fetch_status &lt;&gt; -1)&lt;br /&gt; BEGIN&lt;br /&gt; IF (@@fetch_status &lt;&gt; -2)&lt;br /&gt; BEGIN&lt;br /&gt; -- One line for column list and one for referenced columns&lt;br /&gt; SET @fkline = @fkline + @column_name&lt;br /&gt; SET @pkline = @pkline + @referenced_column_name&lt;br /&gt; END&lt;br /&gt; FETCH NEXT FROM cColumns INTO @column_name, @referenced_column_name&lt;br /&gt; IF (@@fetch_status = 0)&lt;br /&gt; BEGIN&lt;br /&gt; SET @fkline = @fkline + ', '&lt;br /&gt; SET @pkline = @pkline + ', '&lt;br /&gt; END&lt;br /&gt; END&lt;br /&gt; &lt;br /&gt; CLOSE cColumns&lt;br /&gt; DEALLOCATE cColumns&lt;br /&gt; -- Add column list&lt;br /&gt; SET @AddLine = @AddLine + @fkline + N')' + CHAR(13) &lt;br /&gt; -- Add referenced table and column list&lt;br /&gt; SET @AddLine = @AddLine + 'REFERENCES ' + quotename(@referenced_object_schema) + N'.' + quotename(@referenced_object_name) &lt;br /&gt; SET @AddLine = @AddLine + N' (' + @pkline + N')'&lt;br /&gt; -- Check the referential action that was declared for this key as well as replication option&lt;br /&gt; SET @AddLine = @AddLine +&lt;br /&gt; ' ON DELETE' + &lt;br /&gt; CASE @delete_referential_action &lt;br /&gt; WHEN 1 THEN N' CASCADE'&lt;br /&gt; WHEN 2 THEN N' SET NULL'&lt;br /&gt; WHEN 3 THEN N' SET DEFAULT'&lt;br /&gt; ELSE N' NO ACTION'&lt;br /&gt; END +&lt;br /&gt; ' ON UPDATE' +&lt;br /&gt; CASE @UPDATE_REFERENTIAL_ACTION&lt;br /&gt; WHEN 1 THEN N' CASCADE'&lt;br /&gt; WHEN 2 THEN N' SET NULL'&lt;br /&gt; WHEN 3 THEN N' SET DEFAULT'&lt;br /&gt; ELSE N' NO ACTION'&lt;br /&gt; END +&lt;br /&gt; CASE &lt;br /&gt; WHEN @IS_NOT_FOR_REPLICATION = 1 THEN N' NOT FOR REPLICATION'&lt;br /&gt; ELSE N''&lt;br /&gt; END&lt;br /&gt; -- Insert command into table for later use&lt;br /&gt; INSERT INTO @DropScript SELECT @DropLine&lt;br /&gt; INSERT INTO @AddScript SELECT @AddLine&lt;br /&gt; &lt;br /&gt; FETCH NEXT FROM cFKeys INTO @object_id, @parent_object_id, @parent_schema, @parent_name, @constraint_name, @is_not_trusted, @referenced_object_schema, @referenced_object_name, @delete_referential_action, @update_referential_action, @is_not_for_replication&lt;br /&gt; END&lt;br /&gt; END&lt;br /&gt; &lt;br /&gt; CLOSE cFKeys&lt;br /&gt; DEALLOCATE cFKeys&lt;br /&gt; &lt;br /&gt; SET NOCOUNT OFF&lt;br /&gt; &lt;br /&gt; SELECT line FROM @DropScript&lt;br /&gt; SELECT line FROM @AddScript&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-1570912559025712642?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/1570912559025712642/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=1570912559025712642&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/1570912559025712642'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/1570912559025712642'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2011/05/drop-and-create-foreign-keys.html' title='Drop and Create Foreign keys'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-6038191825529017749</id><published>2011-05-11T16:35:00.000-07:00</published><updated>2011-05-13T13:40:56.938-07:00</updated><title type='text'>SQL Server query All HEAPS</title><content type='html'>This query pulls all the tables in SQL Server that are HEAPS. That is all tables without a cluster.&lt;br /&gt;&lt;br /&gt;SELECT&lt;br /&gt;&lt;br /&gt;SCHEMA_NAME(o.schema_id) AS [Schema]&lt;br /&gt;&lt;br /&gt;,object_name(i.object_id ) AS [Tables]&lt;br /&gt;&lt;br /&gt;,p.rows AS ROWS&lt;br /&gt;&lt;br /&gt;,user_seeks&lt;br /&gt;&lt;br /&gt;,user_scans&lt;br /&gt;&lt;br /&gt;,user_lookups&lt;br /&gt;&lt;br /&gt;,user_updates&lt;br /&gt;&lt;br /&gt;,last_user_seek&lt;br /&gt;&lt;br /&gt;,last_user_scan&lt;br /&gt;&lt;br /&gt;,last_user_lookup&lt;br /&gt;&lt;br /&gt;, i.type_desc&lt;br /&gt;&lt;br /&gt;FROM sys.indexes i&lt;br /&gt;&lt;br /&gt;INNER JOIN sys.objects o ON i.object_id = o.object_id&lt;br /&gt;&lt;br /&gt;INNER JOIN sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id&lt;br /&gt;&lt;br /&gt;LEFT OUTER JOIN sys.dm_db_index_usage_stats ius ON i.object_id = ius.object_id AND i.index_id = ius.index_id&lt;br /&gt;&lt;br /&gt;WHERE i.type_desc = 'HEAP'&lt;br /&gt;&lt;br /&gt;ORDER BY user_updates Desc&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-6038191825529017749?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/6038191825529017749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=6038191825529017749&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/6038191825529017749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/6038191825529017749'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2011/05/sql-server-query-all-heaps.html' title='SQL Server query All HEAPS'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-293501098349583875</id><published>2011-05-05T14:49:00.000-07:00</published><updated>2011-05-05T14:54:01.208-07:00</updated><title type='text'>Tables without Primary keys</title><content type='html'>&lt;strong&gt;SELECT SCHEMA_NAME(o.schema_id) AS [Schema]&lt;br /&gt;&lt;br /&gt;,object_name(i.object_id ) AS [Tables]&lt;br /&gt;,p.rows AS ROWS&lt;br /&gt;,user_seeks&lt;br /&gt;,user_scans&lt;br /&gt;,user_lookups&lt;br /&gt;,user_updates&lt;br /&gt;,last_user_seek&lt;br /&gt;,last_user_scan&lt;br /&gt;,last_user_lookup&lt;br /&gt;, i.type_desc&lt;br /&gt;FROM sys.indexes i&lt;br /&gt;&lt;br /&gt;INNER JOIN sys.objects o ON i.object_id = o.object_id&lt;br /&gt;&lt;br /&gt;INNER JOIN sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id&lt;br /&gt;&lt;br /&gt;LEFT OUTER JOIN sys.dm_db_index_usage_stats ius ON i.object_id = ius.object_id AND i.index_id = ius.index_id&lt;br /&gt;WHERE i.type_desc = 'HEAP'&lt;br /&gt;ORDER BY user_updates Desc&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-293501098349583875?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/293501098349583875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=293501098349583875&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/293501098349583875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/293501098349583875'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2011/05/tables-without-primary-keys.html' title='Tables without Primary keys'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-546166314629354737</id><published>2008-01-22T07:11:00.001-08:00</published><updated>2008-01-22T07:12:47.296-08:00</updated><title type='text'>How to Attach (or Reattach) a Database Missing the LDF</title><content type='html'>SQL Server 2005: How to Attach (or Reattach) a Database Missing the LDF&lt;br /&gt;Home -&gt; Database&lt;br /&gt;3902 views&lt;br /&gt;&lt;br /&gt;From the computer of: shamanstears (592 recipes)&lt;br /&gt;Created: Nov 20, 2006     Updated: Nov 28, 2006&lt;br /&gt;&lt;br /&gt;If you need to attach a database that has no log file (.LDF), or have deleted the log file because it was too big and need to reattach the database, SQL Server 2005 does allow you to do this. You can attach the database by following this Tech-Recipe:&lt;br /&gt;&lt;br /&gt;1. Open the SQL Server Management Studio and connect to the desired server.&lt;br /&gt;&lt;br /&gt;2. Right-click on Databases and select Attach.&lt;br /&gt;&lt;br /&gt;3. Click the Add button and select the database file to be attached.&lt;br /&gt;&lt;br /&gt;4. Under database details, select the .LDF file and click the Remove button.&lt;br /&gt;&lt;br /&gt;5. Click OK.&lt;br /&gt;&lt;br /&gt;The database will be attached with a new logfile.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-546166314629354737?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.tech-recipes.com/rx/1867/sql_server_2005_how_to_attach_or_reattach_a_database_missing_the_ldf' title='How to Attach (or Reattach) a Database Missing the LDF'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/546166314629354737/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=546166314629354737&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/546166314629354737'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/546166314629354737'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2008/01/how-to-attach-or-reattach-database.html' title='How to Attach (or Reattach) a Database Missing the LDF'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-5866287503623765957</id><published>2008-01-15T06:24:00.001-08:00</published><updated>2008-01-15T06:24:54.173-08:00</updated><title type='text'>SQL Server Version and SP Serveice Pack Level</title><content type='html'>SELECT  SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-5866287503623765957?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/5866287503623765957/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=5866287503623765957&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/5866287503623765957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/5866287503623765957'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2008/01/sql-server-version-and-sp-serveice-pack.html' title='SQL Server Version and SP Serveice Pack Level'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-2565877722803597687</id><published>2007-11-05T10:29:00.000-08:00</published><updated>2007-11-05T10:32:33.139-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Production DBA'/><category scheme='http://www.blogger.com/atom/ns#' term='DBCC CHECKDB'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server 2005'/><title type='text'>Standard Production DBA Tasks: DBCC CHECKDB</title><content type='html'>Standard Production DBA Tasks: &lt;br /&gt;&lt;br /&gt;DBCC CHECKDB (Transact-SQL)&lt;br /&gt;Updated: 1 February 2007 &lt;br /&gt;Checks the logical and physical integrity of all the objects in the specified database by performing the following operations: &lt;br /&gt;Runs DBCC CHECKALLOC on the database.&lt;br /&gt;Runs DBCC CHECKTABLE on every table and view in the database.&lt;br /&gt;Runs DBCC CHECKCATALOG on the database.&lt;br /&gt;Validates the contents of every indexed view in the database.&lt;br /&gt;Validates the Service Broker data in the database.&lt;br /&gt;This means that the DBCC CHECKALLOC, DBCC CHECKTABLE, or DBCC CHECKCATALOG commands do not have to be run separately from DBCC CHECKDB. For more detailed information about the checks that these commands perform, see the descriptions of these commands.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-2565877722803597687?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://technet.microsoft.com/en-us/library/ms176064.aspx' title='Standard Production DBA Tasks: DBCC CHECKDB'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/2565877722803597687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=2565877722803597687&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/2565877722803597687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/2565877722803597687'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2007/11/standard-production-dba-tasks-dbcc.html' title='Standard Production DBA Tasks: DBCC CHECKDB'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-8418056962287758959</id><published>2007-11-05T09:45:00.000-08:00</published><updated>2007-11-05T10:03:59.386-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DROP TABLE'/><category scheme='http://www.blogger.com/atom/ns#' term='ALTER TABLE'/><category scheme='http://www.blogger.com/atom/ns#' term='DDL Trigger'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server 2005'/><title type='text'>New SQL Server 2005 Features: DDL Trigger</title><content type='html'>New SQL Server 2005 Features: DDL Trigger &lt;br /&gt;&lt;br /&gt;SS05 has a nice feature that allows you to control who is dinking with your tables and what they can do. &lt;br /&gt;&lt;br /&gt;“A DDL Trigger can fire after execution of any Transact-SQL event that belongs to a predefined grouping of similar events. For example, if you want a DDL trigger to fire after any CREATE TABLE, ALTER TABLE, or DROP TABLE statement is run, you can specify FOR DDL_TABLE_EVENTS in the CREATE TRIGGER statement. After CREATE TRIGGER is run, the events that are covered by an event group are added to the sys.trigger_events catalog view.” http://msdn2.microsoft.com/en-us/library/ms186406.aspx&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-8418056962287758959?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://msdn2.microsoft.com/en-us/library/ms186406.aspx' title='New SQL Server 2005 Features: DDL Trigger'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/8418056962287758959/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=8418056962287758959&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/8418056962287758959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/8418056962287758959'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2007/11/new-sql-server-2005-features-ddl.html' title='New SQL Server 2005 Features: DDL Trigger'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-738937041016020098</id><published>2007-11-05T09:44:00.000-08:00</published><updated>2007-11-05T09:45:32.417-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server 2005'/><title type='text'>New SQL 2005 Features - On-line Restore.</title><content type='html'>Favorite SQL 2005 Features On-line Restore.&lt;br /&gt;On-line Restore. This works well with restoring one filegroup while not bringing down the whole system&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-738937041016020098?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/738937041016020098/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=738937041016020098&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/738937041016020098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/738937041016020098'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2007/11/new-sql-2005-features-on-line-restore.html' title='New SQL 2005 Features - On-line Restore.'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-114970007573349810</id><published>2006-06-07T10:07:00.000-07:00</published><updated>2006-06-07T10:07:56.326-07:00</updated><title type='text'>Ben Link Recruiter</title><content type='html'>Ben Link&lt;br /&gt;Recruiter&lt;br /&gt;Insight Global, Inc.&lt;br /&gt;1420 Spring Hill Road&lt;br /&gt;Suite 130&lt;br /&gt;McLean, VA 22102&lt;br /&gt;703.442.7717 phone&lt;br /&gt;703.442.7716 fax&lt;br /&gt;www.insightglobal.net"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-114970007573349810?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://us.f366.mail.yahoo.com/ym/ShowLetter?MsgId=903_29385582_1522572_1957_1179_0_424470_3410_1335862671&amp;Idx=5&amp;YY=23738&amp;inc=100&amp;order=down&amp;sort=date&amp;pos=0&amp;view=a&amp;head=b&amp;box=Inbox' title='Ben Link Recruiter'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/114970007573349810/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=114970007573349810&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114970007573349810'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114970007573349810'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/06/ben-link-recruiter.html' title='Ben Link Recruiter'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-114908951435768164</id><published>2006-05-31T08:31:00.000-07:00</published><updated>2006-05-31T08:31:54.443-07:00</updated><title type='text'>Copy file and add time to name</title><content type='html'>' Copy File&lt;br /&gt;' Option Explicit&lt;br /&gt;&lt;br /&gt;Function Main()&lt;br /&gt;&lt;br /&gt; Dim oFSO&lt;br /&gt; Dim sSourceFile&lt;br /&gt; Dim sDestinationFile&lt;br /&gt; Dim sdate&lt;br /&gt; sdate =  CStr(Year(Date)) &amp; CStr(Month(Date)) &amp; CStr(Day(Date))  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; Set oFSO = CreateObject("Scripting.FileSystemObject")&lt;br /&gt;&lt;br /&gt; sSourceFile = "\\Server\C$\importexport\File_Name.asc"&lt;br /&gt; sDestinationFile = "\\ Server\d$\DBA\ Archive\File_Name" &amp; sdate &amp;".asc"&lt;br /&gt; 'MsgBox( sDestinationFile)&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; oFSO.CopyFile sSourceFile, sDestinationFile&lt;br /&gt;&lt;br /&gt; ' Clean Up&lt;br /&gt; Set oFSO = Nothing&lt;br /&gt;&lt;br /&gt; Main = DTSTaskExecResult_Success&lt;br /&gt;End Function&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-114908951435768164?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/114908951435768164/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=114908951435768164&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114908951435768164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114908951435768164'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/05/copy-file-and-add-time-to-name.html' title='Copy file and add time to name'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-114899698311240237</id><published>2006-05-30T06:49:00.000-07:00</published><updated>2006-05-30T06:49:43.166-07:00</updated><title type='text'>YYYYMM</title><content type='html'>SUBSTRING(CONVERT(varchar(8), [Date], 112), 1, 6) AS YYYYMM,&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-114899698311240237?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://extremetracking.com/open;unique?login=jboc' title='YYYYMM'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/114899698311240237/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=114899698311240237&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114899698311240237'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114899698311240237'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/05/yyyymm.html' title='YYYYMM'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-114797959145305632</id><published>2006-05-18T12:13:00.000-07:00</published><updated>2006-05-18T12:13:11.453-07:00</updated><title type='text'>VBScript Functions</title><content type='html'>&lt;a href="http://www.w3schools.com/vbscript/vbscript_ref_functions.asp"&gt;VBScript Functions&lt;/a&gt;: "VBScript Functions&lt;br /&gt;  &lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;This page contains all the built-in VBScript functions. The page is divided into following sections:&lt;br /&gt;&lt;br /&gt;Date/Time functions &lt;br /&gt;Conversion functions &lt;br /&gt;Format functions &lt;br /&gt; Math functions &lt;br /&gt;Array functions &lt;br /&gt; String functions &lt;br /&gt;Other functions &lt;br /&gt;"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-114797959145305632?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.w3schools.com/vbscript/vbscript_ref_functions.asp' title='VBScript Functions'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/114797959145305632/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=114797959145305632&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114797959145305632'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114797959145305632'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/05/vbscript-functions.html' title='VBScript Functions'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-114797916252872899</id><published>2006-05-18T12:06:00.000-07:00</published><updated>2006-05-18T12:06:08.560-07:00</updated><title type='text'>VBScript - VB Script in DTS - Else Elseif</title><content type='html'>&lt;a href="http://www.tek-tips.com/viewthread.cfm?qid=1164995&amp;amp;page=1"&gt;VBScript - VB Script in DTS&lt;/a&gt;: "Im trying to use ActiveX within a DTS package. What I'm trying to do is us bit of simply VBScript to transmit data from one data source to another.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Function Main()&lt;br /&gt;        IF&lt;br /&gt;&lt;br /&gt;        DTSSource('Type') = 1&lt;br /&gt;&lt;br /&gt;    Then     &lt;br /&gt;        &lt;br /&gt;        DTSDestination('Type') = 'P1'&lt;br /&gt;&lt;br /&gt;    Else     &lt;br /&gt;&lt;br /&gt;        DTSDestination('Type') = 'Other'&lt;br /&gt;&lt;br /&gt;End If&lt;br /&gt;    &lt;br /&gt;    Main = DTSTransformStat_OK&lt;br /&gt;End Function&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;However this doesnt seem to work. Can anyone explain why this might be.&lt;br /&gt;&lt;br /&gt;Cheers&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Tek-Tips Forums is Member Supported. Click Here to donate.&lt;br /&gt;mrmovie (TechnicalUser)14 Dec 05 6:22 &lt;br /&gt;can you confirm that &lt;br /&gt;DTSSource('Type') actually returns something you can convert to a string?&lt;br /&gt;this DTSSource('Type') statement doesnt make any sense to me.&lt;br /&gt;&lt;br /&gt;if doesnt look like you pass anything to your function and your function appears to return something which isnt defined within the function, again i am not sure i understand this&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;NotSQL (TechnicalUser)14 Dec 05 6:28 &lt;br /&gt;Its ok i've got it to work... Thanks Though.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;IF DTSSource('Type') = 1  Then     &lt;br /&gt;        &lt;br /&gt;        DTSDestination('Type') = 'P1'&lt;br /&gt;&lt;br /&gt;    Elseif DTSSource('Type') = 2 Then &lt;br /&gt;&lt;br /&gt;        DTSDestination('Type') = 'P2'&lt;br /&gt;&lt;br /&gt;    Elseif DTSSource('Type') = 3 Then&lt;br /&gt;&lt;br /&gt;        DTSDestination('Type') = 'P3'&lt;br /&gt;&lt;br /&gt;    Elseif    DTSSource('Type') = 4 Then     &lt;br /&gt;&lt;br /&gt;        DTSDestination('Type') = 'P4'&lt;br /&gt;&lt;br /&gt;    Elseif DTSSource('Type') = 5 Then &lt;br /&gt;&lt;br /&gt;        DTSDestination('Type')"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-114797916252872899?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.tek-tips.com/viewthread.cfm?qid=1164995&amp;page=1' title='VBScript - VB Script in DTS - Else Elseif'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/114797916252872899/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=114797916252872899&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114797916252872899'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114797916252872899'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/05/vbscript-vb-script-in-dts-else-elseif.html' title='VBScript - VB Script in DTS - Else Elseif'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-114485530757740990</id><published>2006-04-12T08:21:00.000-07:00</published><updated>2006-04-12T08:21:49.046-07:00</updated><title type='text'>DTS: ActiveX rename File with Time and Date and Move</title><content type='html'>'**********************************************************************&lt;br /&gt;'  Visual Basic ActiveX Script&lt;br /&gt;'************************************************************************&lt;br /&gt;&lt;br /&gt;' Copy File&lt;br /&gt;' Option Explicit&lt;br /&gt;&lt;br /&gt;Function Main()&lt;br /&gt;&lt;br /&gt; Dim oFSO&lt;br /&gt; Dim sSourceFile&lt;br /&gt; Dim sDestinationFile&lt;br /&gt; Dim sdate&lt;br /&gt; sdate =  CStr(Year(Date)) &amp; CStr(Month(Date)) &amp; CStr(Day(Date) &amp; CStr(Hour(Time)) &amp; CStr(Minute(Time))&amp;  CStr(Second(Time)))  &lt;br /&gt; Set oFSO = CreateObject("Scripting.FileSystemObject")&lt;br /&gt; &lt;br /&gt; sSourceFile = "\\svrdev\D$\MSSQL\Log_Ship_Test\VSTLog.trn"&lt;br /&gt; sDestinationFile = "\\svrTest\D$\DBA\LogShipping_Test\VSTLog" &amp; sdate &amp;".trn"&lt;br /&gt; 'MsgBox( sdate)&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; oFSO.CopyFile sSourceFile, sDestinationFile&lt;br /&gt;&lt;br /&gt; ' Clean Up&lt;br /&gt; Set oFSO = Nothing&lt;br /&gt;&lt;br /&gt; Main = DTSTaskExecResult_Success&lt;br /&gt;End Function&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-114485530757740990?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/114485530757740990/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=114485530757740990&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114485530757740990'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114485530757740990'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/04/dts-activex-rename-file-with-time-and.html' title='DTS: ActiveX rename File with Time and Date and Move'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-114254991488998637</id><published>2006-03-16T14:58:00.000-08:00</published><updated>2006-03-16T14:58:34.930-08:00</updated><title type='text'>VBScript delete files in a folder that are certain days old</title><content type='html'>&lt;a href="http://www.sqlservercentral.com/columnists/hji/usingvbscripttoautomatetasks.asp"&gt;Using VBScript to Automate Tasks&lt;/a&gt;: "VBScript to delete files in a folder that are certain days old&lt;br /&gt;As part of a disaster recovery plan, you may need to transfer backup files from one server to another. However, you probably don't want to keep accumulating backup files that you run out of space on your backup server. In this case, you want to delete files that are certain days (or weeks) old. The following VBScript can handle this task nicely. You can customize this code, such as changing the value of iDaysOld, to fit your needs. Most of the code should be self-explanatory. For more on disk space management, see one of my articles published a couple of weeks ago. &lt;br /&gt;Option Explicit&lt;br /&gt;on error resume next&lt;br /&gt; Dim oFSO&lt;br /&gt; Dim sDirectoryPath&lt;br /&gt; Dim oFolder&lt;br /&gt; Dim oFileCollection&lt;br /&gt; Dim oFile&lt;br /&gt; Dim iDaysOld&lt;br /&gt;&lt;br /&gt;'Customize values here to fit your needs&lt;br /&gt; iDaysOld = 21&lt;br /&gt; Set oFSO = CreateObject("Scripting.FileSystemObject")&lt;br /&gt; sDirectoryPath = "FolderName here. Can be UNC path like \\MyServer\MyFolder"&lt;br /&gt; set oFolder = oFSO.GetFolder(sDirectoryPath)&lt;br /&gt; set oFileCollection = oFolder.Files&lt;br /&gt;&lt;br /&gt;'Walk through each file in this folder collection. &lt;br /&gt;'If it is older than 3 weeks (21) days, then delete it.&lt;br /&gt; For each oFile in oFileCollection&lt;br /&gt;  If oFile.DateLastModified &lt; (Date() - iDaysOld) Then&lt;br /&gt;   oFile.Delete(True)&lt;br /&gt;  End If&lt;br /&gt; Next&lt;br /&gt;&lt;br /&gt;'Clean up&lt;br /&gt; Set oFSO = Nothing&lt;br /&gt; Set oFolder = Nothing&lt;br /&gt; Set oFileCollection = Nothing&lt;br /&gt; Set oFile = Nothing"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-114254991488998637?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.sqlservercentral.com/columnists/hji/usingvbscripttoautomatetasks.asp' title='VBScript delete files in a folder that are certain days old'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/114254991488998637/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=114254991488998637&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114254991488998637'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114254991488998637'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/03/vbscript-delete-files-in-folder-that.html' title='VBScript delete files in a folder that are certain days old'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-114252283227737248</id><published>2006-03-16T07:27:00.000-08:00</published><updated>2006-03-16T07:27:13.783-08:00</updated><title type='text'>SQL Server 2000 Security - Part 11 - DTS Security</title><content type='html'>&lt;a href="http://72.14.203.104/search?q=cache:RFchRmfEf-YJ:www.databasejournal.com/features/mssql/article.php/3404791+SQL+Server+Security+Manage+Jobs+SQL+Agent&amp;amp;hl=en&amp;amp;gl=us&amp;amp;ct=clnk&amp;amp;cd=3"&gt;SQL Server 2000 Security - Part 11 - DTS Security&lt;/a&gt;: "You can also schedule execution of DTS packages using SQL Server Agent jobs. This ability is granted by default to the public group, based on permissions to execute sp_add_job and sp_add_jobschedule stored procedures in the MSDB database (this applies to all SQL Server Agent jobs, not just the ones that invoke DTS packages). Typically, it is recommended to restrict access to them to a limited number of privileged logins. While jobs typically execute in the security contexts of their owner, in the case of DTS packages this might be different. The reason is the fact that a task that contains invocation of a DTS package accomplishes this by the running DTSRun command line utility, which involves, in turn, the use of CmdExec. If you limit permissions to launch CmdExec jobs to members of the SysAdmin fixed server role (which is the default behavior), jobs will still execute in the same security context as their owners. However, you can change this default in the SQL Server Agent Properties dialog box, accessible by selecting the Properties option from the SQL Server Agent node under the Management folder in the SQL Server Enterprise Manager console. In the Job System tab, you need to clear the checkbox next to the "Only users with SysAdmin privileges can execute CmdExec and ActiveScripting job steps" and provide a Proxy Account name and password. The proxy account provides the security context for execution of DTS packages, so ensure that it has access to all relevant data stores, file system paths or COM components, which might be used by ActiveX scripting tasks. Remember, however, that at the same time you allow users without SysAdmin privileges to run potentially dangerous ActiveScripting jobs."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-114252283227737248?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://72.14.203.104/search?q=cache:RFchRmfEf-YJ:www.databasejournal.com/features/mssql/article.php/3404791+SQL+Server+Security+Manage+Jobs+SQL+Agent&amp;hl=en&amp;gl=us&amp;ct=clnk&amp;cd=3' title='SQL Server 2000 Security - Part 11 - DTS Security'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/114252283227737248/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=114252283227737248&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114252283227737248'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114252283227737248'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/03/sql-server-2000-security-part-11-dts.html' title='SQL Server 2000 Security - Part 11 - DTS Security'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-114079556150723110</id><published>2006-02-24T07:39:00.000-08:00</published><updated>2006-02-24T07:39:21.530-08:00</updated><title type='text'>Performing date comparisons in VB6</title><content type='html'>&lt;a href="http://techrepublic.com.com/5100-3513-5799938.html?tag=nl.e065"&gt;Performing date comparisons in VB6&lt;/a&gt;: "Performing date comparisons in VB6&lt;br /&gt;&lt;br /&gt;by  Peter Aitken  |  More from Peter Aitken  |  Published: 8/1/05 &lt;br /&gt;The representation of dates in VB6 makes it really easy to compare dates, yet some programmers still go to unnecessary lengths to perform a comparison. Peter Aitken demonstrates that it's a breeze to perform date comparisons in VB6.  &lt;br /&gt; &lt;br /&gt;One of the ways that VB6 really shines is in how it handles dates using the Date data type. You can display a date in any one of several standard date formats, but internally, it's represented as a serial number specifying the number of days since December 31, 1899, with negative values used for dates prior to then. You can also use the decimal portion of the value to represent a time of day, but that's beyond the scope of this tip. &lt;br /&gt;&lt;br /&gt;The representation of dates makes it really easy to compare dates, yet some VB programmers still go to unnecessary complexity to perform a comparison. There's no need to extract the year, month, and day individually for comparison-you can compare dates directly using the standard comparison operators. &lt;br /&gt;&lt;br /&gt;For example, the date June 30, 2004, is represented by the serial number 38168. If you want to compare it with another date, you can just compare the serial numbers to see if one date is smaller, the same, or larger than the other. &lt;br /&gt;&lt;br /&gt;Here's an example that executes one block of statements if the date stored in the type Date variable MyDate is earlier than January 1, 2000, and another block if it's the same or later than that date. &lt;br /&gt;&lt;br /&gt;If MyDate &lt; #1/1/2000# Then&lt;br /&gt;    ' Statements here are executed if MyDate is earlier.&lt;br /&gt;Else&lt;br /&gt;    ' Statements here are executed if MyDate is the same or later.&lt;br /&gt;End If &lt;br /&gt;&lt;br /&gt;This is just one example of the flexibility of VB's Date data type."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-114079556150723110?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://techrepublic.com.com/5100-3513-5799938.html?tag=nl.e065' title='Performing date comparisons in VB6'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/114079556150723110/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=114079556150723110&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114079556150723110'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/114079556150723110'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/02/performing-date-comparisons-in-vb6.html' title='Performing date comparisons in VB6'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-113958702965745325</id><published>2006-02-10T07:57:00.000-08:00</published><updated>2006-02-10T07:57:09.696-08:00</updated><title type='text'>Use Stars in SQL Server</title><content type='html'>&lt;a href="http://techrepublic.com.com/5100-9592_11-5818852.html"&gt;Create a histograph in SQL Server&lt;/a&gt;: "Create a histograph in SQL Server&lt;br /&gt;&lt;br /&gt;by  Arthur Fuller  |  More from Arthur Fuller  |  Published: 8/15/05 &lt;br /&gt;&lt;br /&gt;Takeaway: &lt;br /&gt;Arthur Fuller worked on a project recently that assigned star ratings to each problem. This system led him to create code that demonstrates how you would present this data via SQL Server. Check out his non database-dependent example code.  &lt;br /&gt;&lt;br /&gt;Star ratings are often used in film, hotel, and restaurant ratings. However, I worked on a project recently that used the star ratings scale to identify how critical a problem is; for instance, the more stars, the more urgent it was that the problem be addressed. This led me to wonder how you would present this data via SQL Server.&lt;br /&gt;&lt;br /&gt;For starters, you can store the number of stars as a smallint, or even derive it using a calculation, as the statement below illustrates. Then comes the issue of presentation—how to turn a rating of 5 into five asterisks, as they might appear in a newspaper's film or restaurant review.&lt;br /&gt;&lt;br /&gt;Now you must decide how you want to deliver the data (which in this case are star ratings). You have two choices:&lt;br /&gt;&lt;br /&gt;You can leave it up to the client. This is easy for you, but hard for the developers of each client because the more clients, the more redundant code. &lt;br /&gt;You can do it in the database. There's no downside to this option, and every client can simply extract the column without having to calculate. &lt;br /&gt;In a case like this, I choose to deliver the result from the back-end and not the front-end. My reasoning is simple: For every additional front-end, new application-specific code is required. When you deliver the result from the back-end, new applications can reuse code.&lt;br /&gt;&lt;br /&gt;A non database-dependent example&lt;br /&gt;Let's suppose a table contains a column called NumberOfStars (varchar(5)), as well as all of the other required details. We can create a virtual column of type varchar that presents as many stars as the NumberOfStars column wants.&lt;br /&gt;&lt;br /&gt;To begin, use this code (you may substitute any valid column reference for the second parameter):&lt;br /&gt;&lt;br /&gt;SELECT REPLICATE( '*', 4)Assuming a column called Stars is in a table called Reviews, you could write the following:&lt;br /&gt;&lt;br /&gt;SELECT REPLICATE( '*', Reviews.Stars) &lt;br /&gt;FROM ReviewsTry this command against the Northwind database:&lt;br /&gt;&lt;br /&gt;SELECT Quantity, REPLICATE( '*', Quantity/5)&lt;br /&gt;FROM [Order Details]&lt;br /&gt;WHERE Discount IS NOT NULLThis will result in a list like this (the list is truncated to save space):&lt;br /&gt;&lt;br /&gt;12    **&lt;br /&gt;10    **&lt;br /&gt;5     *&lt;br /&gt;9     *&lt;br /&gt;40    ********&lt;br /&gt;10    **&lt;br /&gt;35    *******&lt;br /&gt;15    ***&lt;br /&gt;6     *&lt;br /&gt;15    ***In the code above, I use the most generic alphabet. Depending on the fonts available, you could make it more interesting by substituting a graphic character for the asterisk. For example, take a look through the three Wingdings fonts. If you see something you like, substitute that character for the asterisk. You won't see the results in Query Analyzer, which is typographically agnostic, but you should see them in another client.&lt;br /&gt;&lt;br /&gt;TechRepublic's free SQL Server newsletter, delivered each Tuesday, contains hands-on tips that will help you become more adept with this powerful relational database management system. Automatically subscribe today!"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-113958702965745325?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://techrepublic.com.com/5100-9592_11-5818852.html' title='Use Stars in SQL Server'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/113958702965745325/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=113958702965745325&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113958702965745325'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113958702965745325'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/02/use-stars-in-sql-server.html' title='Use Stars in SQL Server'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-113906137971839887</id><published>2006-02-04T05:56:00.000-08:00</published><updated>2006-02-04T05:56:19.763-08:00</updated><title type='text'>www.washingtonpost.com - Two-Candidate Marriage</title><content type='html'>&lt;a href="http://www.washingtonpost.com/wp-dyn/content/article/2006/01/25/AR2006012501128_pf.html"&gt;Baker Appears Undaunted By Fundraising Disparity&lt;/a&gt;: "Two-Candidate Marriage&lt;br /&gt;&lt;br /&gt;Speaking of the Iveys, Glenn's wife, Jolene , is planning to run for the House of Delegates.&lt;br /&gt;&lt;br /&gt;Jolene Ivey had been pondering for weeks whether to become a candidate for delegate or take on Britt, who has been mentioned as a possible running mate for Duncan. The legislators for the 47th District -- Britt and Democratic delegates Victor R. Ramirez , Rosetta C. Parker and Doyle L. Niemann -- are all serving their first terms.&lt;br /&gt;&lt;br /&gt;"I figured I don't have enough to do," Ivey said with a chuckle, later rattling off a list of activities that keep the former stay-at-home mom's days jampacked. "But the bottom line is, when you want to get something done, you ask a busy person."&lt;br /&gt;&lt;br /&gt;Ivey, the mother of five young boys who works part time doing public relations for Community Teachers Institute, a think tank in the District, said that the county needs to "get back on track" and that these are not the times for "wussy politicians" to be in office.&lt;br /&gt;&lt;br /&gt;She has never run for elected office before -- unless you count student office in high school. "You would have thought I was running for president, though," she said."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-113906137971839887?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.washingtonpost.com/wp-dyn/content/article/2006/01/25/AR2006012501128_pf.html' title='www.washingtonpost.com - Two-Candidate Marriage'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/113906137971839887/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=113906137971839887&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113906137971839887'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113906137971839887'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/02/wwwwashingtonpostcom-two-candidate.html' title='www.washingtonpost.com - Two-Candidate Marriage'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-113898425294015677</id><published>2006-02-03T08:30:00.000-08:00</published><updated>2006-02-03T08:30:52.980-08:00</updated><title type='text'>Definition of UNC</title><content type='html'>&lt;a href="http://www.sharpened.net/glossary/definition.php?unc"&gt;Definition of UNC&lt;/a&gt;: "UNC&lt;br /&gt; &lt;br /&gt;Stands for 'Universal Naming Convention,' not just the home of the North Carolina Tar Heels. UNC is a filename format that is used to specify the location of files, folders, and resources on a local-area network (LAN). The UNC address of a file may look something like this:&lt;br /&gt;&lt;br /&gt;\\server-name\directory\filename&lt;br /&gt;&lt;br /&gt;UNC can also be used to identify peripheral devices shared on the network, including scanners and printers. It provides each shared resource with a unique address. This allows operating systems that support UNC (such as Windows) to access specific resources quickly and efficiently."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-113898425294015677?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.sharpened.net/glossary/definition.php?unc' title='Definition of UNC'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/113898425294015677/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=113898425294015677&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113898425294015677'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113898425294015677'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/02/definition-of-unc.html' title='Definition of UNC'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-113897290738344736</id><published>2006-02-03T05:21:00.000-08:00</published><updated>2006-02-03T05:21:47.446-08:00</updated><title type='text'>Using Parameters with Stored Procedures</title><content type='html'>&lt;a href="http://www.sqlservercentral.com/columnists/kKellenberger/usingparameterswithstoredprocedures.asp"&gt;Using Parameters with Stored Procedures&lt;/a&gt;: "&lt;br /&gt;&lt;br /&gt;Using Parameters with Stored Procedures&lt;br /&gt;Regular Columnist : Kathi Kellenberger &lt;br /&gt;Posted: 02/03/2006&lt;br /&gt;(Original Publication Date: 8/8/2005) &lt;br /&gt;More Articles From This Columnist &lt;br /&gt;19,495 Reads &lt;br /&gt; &lt;br /&gt;Join the discussion and read comments on this article. &lt;br /&gt;  &lt;br /&gt;Add to Your Virtual Briefcase  &lt;br /&gt;(What is this?)  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Article Rating       Total number of votes [49]     &lt;br /&gt;&lt;br /&gt;Summary:&lt;br /&gt;It seems that SQL Server developers avoid stored procedures whenever possible, especially if they are new to the product. Kathi Kellenberger brings us a basic article that you can give to developers that explains the basics of how you use parameters with ADO.NET, especially output parameters. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--------------------------------------------------------------------------------&lt;br /&gt;This Content Sponsored by:   &lt;br /&gt;Introduction &lt;br /&gt;The prefered way for applications to access SQL Server data is by the use of stored procedures. The benefits include increased performance, security, and code reuse. Often, beginning SQL Server developers find the use of parameters, especially output parameters, with stored procedures confusing. This article will demonstrate how to use parameters with stored procedures, including some sample code using VB.Net. The examples shown are based on SQL 2000, but the concepts apply to SQL 2005 as well.&lt;br /&gt;&lt;br /&gt;Creating a stored procedure&lt;br /&gt;From Books Online, here is the syntax used to create a stored procedure:&lt;br /&gt;&lt;br /&gt;CREATE PROC [ EDURE ] [ owner. ] procedure_name [ ; number ]&lt;br /&gt;    [ { @parameter data_type }&lt;br /&gt;        [ VARYING ] [ = default ] [ OUTPUT ]&lt;br /&gt;    ] [ ,...n ]&lt;br /&gt;&lt;br /&gt;[ WITH&lt;br /&gt;    { RECOMPILE | ENCRYPTION | RECOMPILE , ENCRYPTION } ]&lt;br /&gt;&lt;br /&gt;[ FOR REPLICATION ]&lt;br /&gt;&lt;br /&gt;AS sql_statement [ ...n ]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can also use the alter procedure statement to modify an existing stored procedure. A stored procedure can have up to 2,100 parameters. It is probably safe to assume that the typical stored procedure has no more than ten. &lt;br /&gt;&lt;br /&gt;Here is a very simple create procedure statement that takes two input parameters and one output parameter. Normally, a stored procedure will perform some kind of data manipulation or retrieval, so this is not the average example. It will, however, serve as a simple way to illustrate the use of parameters.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;CREATE PROC usp_AddTwoIntegers @FirstNumber int = 5,&lt;br /&gt;   @SecondNumber int, @Answer varchar(30) OUTPUT as&lt;br /&gt;&lt;br /&gt;   Declare @sum int&lt;br /&gt;   Set @sum = @FirstNumber + @SecondNumber&lt;br /&gt;   Set @Answer = 'The answer is ' + convert(varchar,@sum)&lt;br /&gt;   Return @sum&lt;br /&gt;&lt;br /&gt;How to define a paramter &lt;br /&gt;The first thing to remember is that the parameter name must start with an @ symbol. The name can’t have spaces, and there are some characters that are not allowed. If you just stick with alpha-numeric characters and underscores in your parameter names you won’t have any problems naming parameters.&lt;br /&gt;&lt;br /&gt;Second, the data type of the parameter and possibly the size must be stated. For example, the size of a parameter of type VARCHAR must be specified. Third, if you wish to access a return value from the parameter, the OUTPUT keyword must be used. In the example create proc statement, three parameters are defined, two are integers. One of the parameters, @Answer, is an OUTPUT parameter and will be used to pass a value back to the caller. &lt;br /&gt;&lt;br /&gt;Parameters can be given a default value. The @FirstNumber parameter has a default value of 5. &lt;br /&gt;&lt;br /&gt;How to Call a Stored Procedure from Query Analyzer&lt;br /&gt;A stored procedure can be called from query analyzer, another stored procedure or any other client that can talk to SQL Server. Here is a sample script that can be pasted into Query Analyzer to demonstrate the use of our proc:&lt;br /&gt;&lt;br /&gt;Declare @a int, @b int, @c varchar(30)&lt;br /&gt;Select @a = 1, @b = 2&lt;br /&gt;Exec usp_AddTwoIntegers @a, @b, @c OUTPUT&lt;br /&gt;Select @c&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;---------------&lt;br /&gt;The answer is 3&lt;br /&gt;&lt;br /&gt;Notice that the keyword OUTPUT is used in the calling statement as well as the proc's definition. All of the arguments were defined as variables but given names that don’t match the original parameter names. This works because SQL resolves the parameters based on the position.&lt;br /&gt;&lt;br /&gt;Only the output parameter must be defined up front. The next example passes literal values for the first two arguments.&lt;br /&gt;&lt;br /&gt;Declare @Answer varchar(30)&lt;br /&gt;Exec usp_AddTwoIntegers 1,2,@Answer OUTPUT&lt;br /&gt;Select @Answer&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;---------------&lt;br /&gt;The answer is 3&lt;br /&gt;&lt;br /&gt;It is also possible to mix up the order of the arguments if the parameters are named in the calling statement.&lt;br /&gt;&lt;br /&gt;The @FirstNumber parameter has a default that the proc will use since the argument is not specified.&lt;br /&gt;&lt;br /&gt;Declare @Answer varchar(30)&lt;br /&gt;Exec usp_AddTwoIntegers @Answer = @Answer OUTPUT, @SecondNumber = 5&lt;br /&gt;Select @Answer&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;----------------&lt;br /&gt;The answer is 10&lt;br /&gt;&lt;br /&gt;Hopefully many of you have noticed that the actual numeric sum is also returned from the procedure. This example shows how to access the return value.&lt;br /&gt;&lt;br /&gt;Declare @sum int, @Answer varchar(30)&lt;br /&gt;Exec @sum = usp_AddTwoIntegers 5,5,@Answer&lt;br /&gt;Select @sum&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-----------&lt;br /&gt;10&lt;br /&gt;&lt;br /&gt;Normally return values are used to report the success or failure of the procedure. So, even though you can return any integer value from the proc, usually a 0 for success or 1 for failure is returned. &lt;br /&gt;&lt;br /&gt;Stored procedures are usually used to retrieve or manipulate data. Here is a typical stored procedure using the Northwind sample database that ships with SQL 2000. The parameter is used in the where clause to filter the results.&lt;br /&gt;&lt;br /&gt;Create proc usp_GetCustomerName @CustomerID varchar(5) as&lt;br /&gt;      Select CompanyName from Customers where CustomerID = @CustomerID&lt;br /&gt;&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;exec usp_GetCustomerName 'ANTON'&lt;br /&gt;&lt;br /&gt;CompanyName&lt;br /&gt;-----------------------&lt;br /&gt;Antonio Moreno Taquería&lt;br /&gt;&lt;br /&gt;Calling a stored procedure from VB.Net &lt;br /&gt;As promised, here is a code snippet showing how to call a stored procedure using VB.Net. Again, no one would ever call a stored procedure to add two numbers together. This example is given to illustrate the use of parameters.&lt;br /&gt;&lt;br /&gt;Create a new VB.Net Windows Application project. Add a button to the form. Add this statement to top of the form’s code window:&lt;br /&gt;&lt;br /&gt; Imports System.Data.SqlClient&lt;br /&gt;&lt;br /&gt;Paste this code into the form’s code window right above the End Class statement. I added the sample stored procedure to the Northwind database. Modify the connection string so it will work in your environment. &lt;br /&gt;&lt;br /&gt;Private Sub Button1_Click(ByVal sender As System.Object, _&lt;br /&gt;   ByVal e As System.EventArgs) Handles Button1.Click&lt;br /&gt;&lt;br /&gt;        'You may need to modify the connection string&lt;br /&gt;        Dim conn As New SqlConnection("Integrated Security=SSPI;" _&lt;br /&gt;   &amp; "Persist Security Info=False;Initial Catalog=Northwind;" _&lt;br /&gt;   &amp; "Data Source=(local);Packet Size=4096;")&lt;br /&gt;        conn.Open()&lt;br /&gt;&lt;br /&gt;        'set up the command object&lt;br /&gt;        Dim myCommand As New SqlCommand("usp_AddTwoIntegers", conn)&lt;br /&gt;        myCommand.CommandType = CommandType.StoredProcedure&lt;br /&gt;&lt;br /&gt;        'add the first two parameters&lt;br /&gt;        myCommand.Parameters.Add("@FirstNumber", 5) 'this one is optional&lt;br /&gt;        myCommand.Parameters.Add("@SecondNumber", 5)&lt;br /&gt;&lt;br /&gt;        'The output and return parameters must be created as objects&lt;br /&gt;        Dim myAnswer As New SqlParameter("@Answer", SqlDbType.VarChar, 30)&lt;br /&gt;        myAnswer.Direction = ParameterDirection.Output&lt;br /&gt;&lt;br /&gt;        Dim mySum As New SqlParameter()&lt;br /&gt;        mySum.Direction = ParameterDirection.ReturnValue&lt;br /&gt;&lt;br /&gt;        'add them to the parameter collection&lt;br /&gt;        myCommand.Parameters.Add(myAnswer)&lt;br /&gt;        myCommand.Parameters.Add(mySum)&lt;br /&gt;&lt;br /&gt;        'execute the query&lt;br /&gt;        myCommand.ExecuteNonQuery()&lt;br /&gt;&lt;br /&gt;        'display the values&lt;br /&gt;        MsgBox(myAnswer.Value)&lt;br /&gt;        MsgBox(mySum.Value)&lt;br /&gt;    End Sub&lt;br /&gt;&lt;br /&gt;Run the form and click the button to see the output parameter and return values. &lt;br /&gt;&lt;br /&gt;Conclusion&lt;br /&gt;Using stored procedures is the best way for applications to access SQL data. This article explained, using a very simple example, how to use parameters with stored procedures."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-113897290738344736?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.sqlservercentral.com/columnists/kKellenberger/usingparameterswithstoredprocedures.asp' title='Using Parameters with Stored Procedures'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/113897290738344736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=113897290738344736&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113897290738344736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113897290738344736'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2006/02/using-parameters-with-stored.html' title='Using Parameters with Stored Procedures'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-113355244299313010</id><published>2005-12-02T11:40:00.000-08:00</published><updated>2005-12-02T11:40:43.003-08:00</updated><title type='text'>MSDN Replication Security Best Practices</title><content type='html'>Replication Security Best Practices &lt;br /&gt;&lt;br /&gt;Replication moves data in distributed environments ranging from intranets on a single domain to applications that access data between untrusted domains and over the Internet. It is important to understand the best approach for securing replication connections under these different circumstances.&lt;br /&gt;&lt;br /&gt;The following information is relevant to replication in all environments:&lt;br /&gt;&lt;br /&gt;Encrypt the connections between computers in a replication topology using an industry standard method, such as Virtual Private Networks (VPN), Secure Sockets Layer (SSL), or IP Security (IPSEC). We recommend using one of these encryption methods for the. For more information, see Encrypting Connections to SQL Server. For information about using VPN and SSL for replicating data over the Internet, see Securing Replication Over the Internet.&lt;br /&gt;If you use SSL to secure the connections between computers in a replication topology, specify a value of 1 or 2 for the -EncryptionLevel parameter of each replication agent (a value of 2 is recommended). A value of 1 specifies that encryption is used, but the agent does not verify that the SSL server certificate is signed by a trusted issuer; a value of 2 specifies that the certificate is verified. Agent parameters can be specified in agent profiles and on the command line. For more information, see:&lt;br /&gt;&lt;br /&gt;How to: Work with Replication Agent Profiles (SQL Server Management Studio)&lt;br /&gt;&lt;br /&gt;How to: View and Modify Replication Agent Command Prompt Parameters (SQL Server Management Studio)&lt;br /&gt;&lt;br /&gt;How to: Work with Replication Agent Profiles (Replication Transact-SQL Programming)&lt;br /&gt;&lt;br /&gt;Programming Replication Agent Executables&lt;br /&gt;&lt;br /&gt;Run each replication agent under a different Windows account, and use Windows Authentication for all replication agent connections. For more information about specifying accounts, see Managing Logins and Passwords in Replication.&lt;br /&gt;&lt;br /&gt;Grant only the required permissions to each agent. For more information, see the "Permissions Required by Agents" section of Replication Agent Security Model.&lt;br /&gt;&lt;br /&gt;Ensure all Merge Agent and Distribution Agent accounts are in the publication access list (PAL). For more information, see Securing the Publisher.&lt;br /&gt;&lt;br /&gt;Follow the principle of least privilege by allowing accounts in the PAL only the permissions they need to perform replication tasks. Do not add the logins to any fixed server roles that are not required for replication.&lt;br /&gt;&lt;br /&gt;Configure the snapshot share to allow read access by all Merge Agents and Distribution Agents. In the case of snapshots for publications with parameterized filters, ensure that each folder is configured to allow access only to the appropriate Merge Agent accounts.&lt;br /&gt;&lt;br /&gt;Configure the snapshot share to allow write access by the Snapshot Agent.&lt;br /&gt;&lt;br /&gt;If you use pull subscriptions, use a network share rather than a local path for the snapshot folder.&lt;br /&gt;&lt;br /&gt;If your replication topology includes computers that are not in the same domain or are in domains that do not have trust relationships with each other, you can use Windows Authentication or SQL Server Authentication for the connections made by agents (For more information about domains, see the Windows documentation). It is recommended as a security best practice that you use Windows Authentication.&lt;br /&gt;&lt;br /&gt;To use Windows Authentication:&lt;br /&gt;&lt;br /&gt;Add a local Windows account (not a domain account) for each agent at the appropriate nodes (use the same name and password at each node). For example, the Distribution Agent for a push subscription runs at the Distributor and makes connections to the Distributor and Subscriber. The Windows account for the Distribution Agent should be added to the Distributor and Subscriber.&lt;br /&gt;&lt;br /&gt;Ensure that a given agent (for example the Distribution Agent for a subscription) runs under the same account at each computer.&lt;br /&gt;&lt;br /&gt;To use SQL Server Authentication:&lt;br /&gt;&lt;br /&gt;Add a SQL Server account for each agent at the appropriate nodes (use the same account name and password at each node). For example, the Distribution Agent for a push subscription runs at the Distributor and makes connections to the Distributor and Subscriber. The SQL Server account for the Distribution Agent should be added to the Distributor and Subscriber.&lt;br /&gt;&lt;br /&gt;Ensure that a given agent (for example the Distribution Agent for a subscription) makes connections under the same account at each computer.&lt;br /&gt;&lt;br /&gt;In situations that require SQL Server Authentication, access to UNC snapshot shares is often not available (for example access might be blocked by a firewall). In this case, you can transfer the snapshot to Subscribers through file transfer protocol (FTP). For more information, see Transferring Snapshots Through FTP."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-113355244299313010?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/113355244299313010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=113355244299313010&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113355244299313010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113355244299313010'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2005/12/msdn-replication-security-best.html' title='MSDN Replication Security Best Practices'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-113267372570404186</id><published>2005-11-22T07:35:00.000-08:00</published><updated>2005-11-22T07:35:25.716-08:00</updated><title type='text'>Data Points: Inline Views Versus Temp Tables</title><content type='html'>&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/sql_id_com_admn2.asp"&gt;Data Points: Five Ways to Rev up Your SQL Performance&lt;/a&gt; "Inline Views Versus Temp Tables&lt;br /&gt;Queries sometimes need to join data to other data that may only be gathered by performing a GROUP BY and then a standard query. For example, if you want to return the information about the five most recently placed orders, you would first need to know which orders they are. This can be retrieved by using a SQL query that returns the orders' IDs. This data could be stored in a temporary table, a common technique, and then joined to the Product table to return the quantity of products sold on those orders:&lt;br /&gt;&lt;br /&gt;CREATE TABLE #Temp1 (OrderID INT NOT NULL, _&lt;br /&gt;                     OrderDate DATETIME NOT NULL)&lt;br /&gt;&lt;br /&gt;INSERT INTO #Temp1 (OrderID, OrderDate)&lt;br /&gt;SELECT     TOP 5 o.OrderID, o.OrderDate&lt;br /&gt;FROM Orders o ORDER BY o.OrderDate DESC&lt;br /&gt;&lt;br /&gt;SELECT     p.ProductName, SUM(od.Quantity) AS ProductQuantity&lt;br /&gt;FROM     #Temp1 t &lt;br /&gt;    INNER JOIN [Order Details] od ON t.OrderID = od.OrderID&lt;br /&gt;    INNER JOIN Products p ON od.ProductID = p.ProductID &lt;br /&gt;GROUP BY p.ProductName&lt;br /&gt;ORDER BY p.ProductName&lt;br /&gt;&lt;br /&gt;DROP TABLE #Temp1&lt;br /&gt;&lt;br /&gt;This batch of SQL creates a temporary table, inserts the data into it, joins other data to it, and drops the temporary table. This is a lot of I/O for this query, which could be rewritten to use an inline view instead of a temporary table. An inline view is simply a query that can be joined to in the FROM clause. So instead of spending a lot of I/O and disk access in tempdb on a temporary table, you could instead use an inline view to get the same result:&lt;br /&gt;&lt;br /&gt;SELECT p.ProductName, &lt;br /&gt;    SUM(od.Quantity) AS ProductQuantity&lt;br /&gt;FROM     (&lt;br /&gt;    SELECT TOP 5 o.OrderID, o.OrderDate&lt;br /&gt;    FROM     Orders o &lt;br /&gt;    ORDER BY o.OrderDate DESC&lt;br /&gt;    ) t &lt;br /&gt;    INNER JOIN [Order Details] od ON t.OrderID = od.OrderID&lt;br /&gt;    INNER JOIN Products p ON od.ProductID = p.ProductID &lt;br /&gt;GROUP BY&lt;br /&gt;    p.ProductName&lt;br /&gt;ORDER BY&lt;br /&gt;    p.ProductName&lt;br /&gt;&lt;br /&gt;This query is not only more efficient than the previous one, it's shorter. Temporary tables consume a lot of resources. If you only need the data to join to other queries, you might want to try using an inline view to conserve resources."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-113267372570404186?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/sql_id_com_admn2.asp' title='Data Points: Inline Views Versus Temp Tables'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/113267372570404186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=113267372570404186&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113267372570404186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113267372570404186'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2005/11/data-points-inline-views-versus-temp.html' title='Data Points: Inline Views Versus Temp Tables'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-113258766025900073</id><published>2005-11-21T07:41:00.000-08:00</published><updated>2005-11-21T07:41:02.666-08:00</updated><title type='text'>Global Variables and SQL statements in DTS</title><content type='html'>&lt;a href="http://www.sqldts.com/default.aspx?205"&gt;Global Variables and SQL statements in DTS&lt;/a&gt;: "Global Variables and SQL statements in DTS&lt;br /&gt;By Darren Green&lt;br /&gt;Version 7.0+/2000&lt;br /&gt;Level Advanced &lt;br /&gt;&lt;br /&gt;For those fortunate enough to have SQL 2000, using global variables with an Execute SQL Task, or as part of the source statement in the DataPump task is now a standard feature. For those still using SQL Server 7.0 this tedious process, but here are some examples of how it can be done. Even if you are using SQL Server 2000, you may still have a need for this due to certain syntax limitations imposed when using parameters. &lt;br /&gt;&lt;br /&gt;In SQL Server 7.0 the only way to integrate a global variable into your SQL is to actually code the value as a literal in the SQL statement. The simplest solution is to just build a new statement with the value embedded in it at run-time. You can do this from an ActiveX Script Task as illustrated below. &lt;br /&gt;&lt;br /&gt;This example amends the SELECT statement for a DataPump task, to filter based on the value of the global variable HireDate: &lt;br /&gt;&lt;br /&gt;' 205 (Change SourceSQLStatement)&lt;br /&gt;Option Explicit&lt;br /&gt;&lt;br /&gt;Function Main()&lt;br /&gt;	Dim oPkg, oDataPump, sSQLStatement&lt;br /&gt;&lt;br /&gt;	' Build new SQL Statement&lt;br /&gt;	sSQLStatement = "SELECT * FROM dbo.employee WHERE hire_date &gt; '" &amp; _&lt;br /&gt;		DTSGlobalVariables("HireDate").Value &amp; "'"&lt;br /&gt;&lt;br /&gt;	' Get reference to the DataPump Task&lt;br /&gt;	Set oPkg = DTSGlobalVariables.Parent&lt;br /&gt;	Set oDataPump = oPkg.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask&lt;br /&gt;&lt;br /&gt;	' Assign SQL Statement to Source of DataPump&lt;br /&gt;	oDataPump.SourceSQLStatement = sSQLStatement&lt;br /&gt;&lt;br /&gt;	' Clean Up&lt;br /&gt;	Set oDataPump = Nothing&lt;br /&gt;	Set oPkg = Nothing&lt;br /&gt;&lt;br /&gt;	Main = DTSTaskExecResult_Success&lt;br /&gt;End Function"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-113258766025900073?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.sqldts.com/default.aspx?205' title='Global Variables and SQL statements in DTS'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/113258766025900073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=113258766025900073&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113258766025900073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113258766025900073'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2005/11/global-variables-and-sql-statements-in.html' title='Global Variables and SQL statements in DTS'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-113198247676928810</id><published>2005-11-14T07:34:00.000-08:00</published><updated>2005-11-14T07:34:36.776-08:00</updated><title type='text'>SQL Server Best Practices Analyser Tool</title><content type='html'>&lt;a href="capability "&gt;SQL Server Best Practices Analyser Tool&lt;/a&gt;: "SQL Server Best Practices Analyser Tool &lt;br /&gt;&lt;br /&gt;Posted by poonam on Thursday, June 10, 2004 &lt;br /&gt;&lt;br /&gt;Microsoft's SQL Best Practice Analyser is here - and its a great little aid for DBA's  &lt;br /&gt;Microsoft released its ‘Best Practices Analyser Tool’ end of May. Though this tool has been in beta since late last year, it has entered the market softly, without any hype or fuss. This is certainly not the ‘Microsoft way’ – and it makes me wonder why, because this is a great little tool and its FREE!!!. You can download it from Best Practices Analyzer Tool for Microsoft SQL Server 2000 1.0&lt;br /&gt;&lt;br /&gt;For those of you who didn’t know about it – this is a graphical tool which scans through your database and verifies it against a set of pre-determined rules. For the most part the rules relate to administration functions and its going to be invaluable aid to a DBA’s arsenal. &lt;br /&gt;&lt;br /&gt;Just to see what the BPA can do, I have run this against a few production databases and a few development databases I have access to and the results were definitely worth the time.&lt;br /&gt;&lt;br /&gt;I discovered for instance, that a crucial table at a client site did not have either a primary key or a unique key constraint on it. I’m pretty sure this table at some point did have a unique constraint, but somewhere over the months and many schema changes, somehow it got dropped – and no one noticed because everyone was so sure it existed. This is just the sort of thing the BPA does so well – nothing earth shattering in terms of knowledge – we all know tables should have primary keys, but the BPA provides us a way to monitor databases effortlessly.&lt;br /&gt;&lt;br /&gt;Some database maintenance checks are nice to have – for instance the Index fragmentation, I currently have a stored procedure on a monthly schedule to do this – BPA I guess just makes it easier. Log file growth, virtual log file count – nothing we can’t do ourselves but this just makes it so easy to monitor my databases.&lt;br /&gt;&lt;br /&gt;Many of the rules in BPA pertain to Backup and Recovery options, this can be an eye opener sometimes. There are always backup plans in place for production databases – but I was embarrassed to find out when our development databases were last backed up. &lt;br /&gt;&lt;br /&gt;I also appreciate the SQL Server 2005 Readiness and depreciation check – it’s nice to know much ahead of time what wont work. &lt;br /&gt;&lt;br /&gt;As always, I have a wish list (don’t we all).&lt;br /&gt;&lt;br /&gt;I would love to be able to create my own rules. &lt;br /&gt;The ability to setup and schedule the scripts to run at pre-determined times and frequencies  would be nice. I have mixed feelings about this however – The best practice analyzer does have a command line interface, and with a bit of work, I can script this out for myself without having Microsoft have a cookie cutter solution for me. I’m probably in the minority when I say this, but I think it’s important that software engineers and DBA’s  have the capability to code for themselves, without always looking to Microsoft for a point and click interface. &lt;br /&gt;Can we have a ‘SQL Standard Edition’ compatibility check? So many of us develop on SQL developer edition and deploy to SQL standard edition. I would love to know, what is not supported in standard edition. &lt;br /&gt;I would love to be run this as a background service, keeping a track of database objects being accessed. I currently need to run a profiler trace for this. This not only has a considerable performance impact but profiler traces are not fun to read. It would be helpful to know which objects are now archaic &lt;br /&gt;Again if it can run as a background service, I want to know what indexes / statistics the optimizer is currently using. I want to know if I have unused indexes, ones which were scripted for a different time and now with application changes are not being used. &lt;br /&gt;All things considered – I love the best practice analyzer – it’s a great little tool, and has already pointed out a number of little problems which if I had to do manually would take me a long long time."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-113198247676928810?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/113198247676928810/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=113198247676928810&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113198247676928810'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113198247676928810'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2005/11/sql-server-best-practices-analyser.html' title='SQL Server Best Practices Analyser Tool'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-18803479.post-113155432617680414</id><published>2005-11-09T08:38:00.000-08:00</published><updated>2005-11-09T08:41:47.210-08:00</updated><title type='text'>Joe Sack: Importing files in SQL Server 2005 using OPENROWSET</title><content type='html'>From &lt;a href="http://www.sqljunkies.com/WebLog/joesack/default.aspx"&gt;http://www.sqljunkies.com/WebLog/joesack/default.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Importing files in SQL Server 2005 using OPENROWSET&lt;br /&gt;OPENROWSET has new BULK features which I'll definitely be taking advantage of in the future. With OPENROWSET you'll be able to return a result set from a file based on options in a format file (similar to bcp or BULK INSERT), or also import a file in its entirety as a single varbinary(max), varchar(max), or nvarchar(max) data type value.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;It is the file import functionality that I'm really looking forward to. This is built-in functionality, so you don't have to depend on external applications to import external files into your SQL Server tables. You use the SINGLE_BLOB, SINGLE_CLOB, or SINGLE_NCLOB to tell SQL Server what kind of single-row, single-column data is being read.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For example, in this query I create a new table that will hold product images and their associated descriptions. The ProductIMG column is using the new SQL Server 2005 varbinary(max) data type to hold gif files:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;CREATE TABLE dbo.ProductImage&lt;br /&gt;&lt;br /&gt;(ProductImageID int IDENTITY(1,1) NOT NULL PRIMARY KEY,&lt;br /&gt;&lt;br /&gt;ProductDESC varchar(255) NOT NULL,&lt;br /&gt;&lt;br /&gt;ProductIMG varbinary(max) NOT NULL)&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Next, I use OPENROWSET to import a gif file directly into the table from the file system (the BulkColumn is the actual exposed varbinary(max) data being returned):&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;INSERT dbo.ProductImage&lt;br /&gt;&lt;br /&gt;(ProductDESC, ProductIMG)&lt;br /&gt;&lt;br /&gt;SELECT 'Used to represent two databases.', -- ProductDESC&lt;br /&gt;&lt;br /&gt;BulkColumn -- ProductIMG&lt;br /&gt;&lt;br /&gt;FROM OPENROWSET( BULK 'C:\Program Files\Microsoft SQL Server\80\Tools\HTML\dbicon.gif',&lt;br /&gt;&lt;br /&gt;SINGLE_BLOB) as ExternalFile&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That is all it takes. The file is now stored in the table in a single column of a single row. You could then use SSIS's Export Column task to export the data from these rows into external files again, assuming you added a file path and name column for the transformation to use.&lt;br /&gt;&lt;br /&gt;In this example I imported a gif file - but definitely not a fan of serving image files from a database (storing maybe - but not serving). But this functionality definitely opens the door for those of us who don't or can't use third party applications to draw in external files. We can now use Transact-SQL instead.&lt;br /&gt;&lt;br /&gt;One uses I may consider is in archiving critical, original legacy data files along with the normalized data. Used within reason of course, this would allow you to maintain the original file alongside the shredded/normalized data in the database so you can troubleshoot data lineage questions and issues.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/18803479-113155432617680414?l=sql-server-notes.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.sqljunkies.com/WebLog/joesack/default.aspx' title='Joe Sack: Importing files in SQL Server 2005 using OPENROWSET'/><link rel='replies' type='application/atom+xml' href='http://sql-server-notes.blogspot.com/feeds/113155432617680414/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=18803479&amp;postID=113155432617680414&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113155432617680414'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18803479/posts/default/113155432617680414'/><link rel='alternate' type='text/html' href='http://sql-server-notes.blogspot.com/2005/11/joe-sack-importing-files-in-sql-server.html' title='Joe Sack: Importing files in SQL Server 2005 using OPENROWSET'/><author><name>Barry</name><uri>http://www.blogger.com/profile/10003569801219363145</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
