-
-
On Monday we opened session for the next SQLBits conference at Celtic Manor near Newport. Chris Webb’s blog post has all the details about how to do this so I won’t repeat it!
Already there are some very interesting submissions http://www.sqlbits.com/information/PublicSessions.aspx from some excellent speakers and everything is shaping up to be a great conference.
All the sessions so far have been submitted by people who have presented before, but one of the reasons behind these conferences is to offer a speaking opportunity to people who are not the “usual suspects”. To help new speakers we will offer help and support to any speaker leading up to the conference, so you can give a presentation to be proud of. If you want to know more don’t delay and contact us.
-
-
Some time ago I published a blog post on how to execute all files in a directory against a given database. This took a single line on the command prompt, today I saw an implementation of this in T-SQL which had 86 lines of code.
As I’ve recently been looking at improving my Powershell skills, I thought it would be a good idea to try an produce a solution using that, and here is what I came up with:
foreach ($f in Get-ChildItem -path "C:\temp\SQLScripts\" -Filter *.sql | sort-object -desc )
{
$out = "C:\temp\SQLScripts\OUTPUT\" + $f.name.split(".")[0] + ".txt" ;
invoke-sqlcmd -InputFile $f.fullname | format-table | out-file -filePath $out
}
This may not be the most elegant of solutions, but here is what it does:
Get-Childitem will return all the files in the "C:\temp\SQLScripts\" directory, using the *.sql filter it will only get files with that extension (just in case there are other files which we don’t want to execute!).
Piping this through a sort will mean I do not have to execute the files in alphabetical order if the sort order can be identified through one of the file’s attributes e.g the order in which the files were created or as in the example, descending alphabetical file name order.
Then for each file I construct the name output the file where I want the output to go, the split function in conjunction with the 0 index takes the left part of the sql script’s filename up to the first dot (.).
I then use the cmdlet invoke-sqlcmd to execute the script. The above code assumes that you are in the context of the database where you wish the script the be run e.g
SQLSERVER:\SQL\ComputerName\InstanceName\Databases\DatabaseName
but you may want to specify the server, database, username and password parameters if this is not the case. It would be very easy to run all the scripts against every database on a given instance or a specific database on all instances of SQL Server on the given computer. This for me, is one of the attractions of Powershell, as trying to find a solution in T-SQL or at the command prompt will be much harder.
-
-
Monday saw a couple of cumulative updates released for SQL Server 2008 which seems to have gone unnoticed by most, including SQL Server Central and wasn't included in Steve's build list on Wednesday!
Cumulative update 3 for SQL Server 2008 SP1
Cumulative update 6 for SQL Server 2008 RTM
-
-
In my posting about NOCOUNT and linked servers I provided a script to create the necessary shell procedures that enabled NOCOUNT to be set ON and avoiding the problems of ROWCOUNTs being returned by linked servers.
One of the problems I encountered when creating the script was that there is no metadata held on whether the procedure parameter was optional i.e. it had a default. To get around this I gave all parameters default values which is not the ideal solution, but in the circumstances was the best solution I could think of.
Following a recent post in the newsgroup by MVP Aaron Bertrand I have become aware that this problem does have a connect item already raised for it at http://connect.microsoft.com/sql/feedback/ViewFeedback.aspx?FeedbackID=234143. Aaron has attached a work around to the connect item. which parses the T-SQL code and could be incorporated into my script. Anyone wishing to see expanded meta data for stored procedure parameters may want to add their vote.
-
-
One of the tips from the SQL Nuggets competition I ran at the Leeds Area user group this week was to use the –NOSPLASH option to speed up the start up of Management Studio. Adding this to your shortcuts or menu options will reduce the time before you are able to use the application.
This is not the only option you can specify for SSMS.exe. Books Online gives additional options such as specifying the filename for a project, script or solution to open as well as the options for specifying a database, server, username and password or windows authentication to be used when SSMS is started. Specifying a server and windows authentication allows me to open a query window when SSMS starts up. As this is quite often the first thing I do, it looks like being a very useful thing to know as there is no login dialog to slow the start up down.
This got me looking at what options can be specified for start up on the Environment-General tab of Tools/Options dialog. These are:
Open Object Explorer
Open New Query Window
Open Object Explorer and new query
Open Object Explorer and Activity Monitor
Open Empty Environment
Of these the fastest start up option is the empty environment as no connections are made. One advantage of changing the option here is that it will have the same effect if you start Management Studio from the menu, a shortcut or at a command prompt.
-
-
Thanks to everyone who attended Monday’s meeting.
I really enjoyed Martin’s talk, and I'm sure you also found it useful.
I’d like to thank Martin for taking the time and effort to come to Leeds and present to us.
http://sqlblogcasts.com/blogs/martinbell/Misc/Size%20does%20matter!.zip
-
-
In a previous post I compared how GUIDS can have an adverse effect on fragmentation. One of the new SQL Server 2008 features available in the Enterprise and Developer editions is data compression. Apart from GUIDs taking more bytes than an integer, I expected that because of the nature of GUIDs they would not compress very well, and tried to set out and prove it.
I created the following script which uses the TransactionHistory table in the Adventureworks2008 database as the main source of data. To do so I have three tables containing five copies of the data from the TransactionHistory table. In two of the tables the four columns that contain identifiers (TransactionID, ProductID, ReferenceOrderID and ReferenceOrderLineID) are changed to be uniqueidentifiers with defaults using the NEWID or NEWSEQUENTIALID functions depending on the table. I then used the function sp_estimate_data_compression_savings to see what the estimated savings would be if I added row or page compression. These are the results I obtained (full results are here):
| object_name |
Type |
% When compressed |
| TransactionHistory_int |
PAGE |
35.14 |
| TransactionHistory_int |
ROW |
56.87 |
| TransactionHistory_sequentialguid |
PAGE |
56.21 |
| TransactionHistory_guid |
PAGE |
67.58 |
| TransactionHistory_guid |
ROW |
73.42 |
| TransactionHistory_sequentialguid |
ROW |
73.03 |
As I expected page compression when using integers would produce the most compressed data, but this is almost twice as compressed as the page compression obtained using GUIDs. This example also showed that for row compression there is no benefit in having sequential GUIDs.
-
-
Plan caching is something that most DBAs would probably never look at until it becomes a problem on a live system. I thought this recent post by Simon Sabin on his blog was very interesting, as it shows that something which may seem so insignificant during developement could have a huge adverse effect.
I tested this myself and found that if you try the collation solution with a database_default collation the problem does not occur, which may be a more portable solution. If you use a UDT equivalent to nvarchar(max) the problem will still occur.