August 2010 Entries
So, the question was posed on how to do this with LINQPad, and thus with LINQ. Here is one way. This is basically the same thing I did in my last post about searching for this kind of value. This also shows how to return an arbitrary result from a linq query to a very generic class object for later processing. Note that I was not able to use params because the table name couldn't be a param. I'm sure there is probably some more elegant way to do this, but this works fine and hopefully this is one of...
-- try and do dirty reads, and turn off the record counting unless you want
-- spam in the middle of your prints below. you can also just do a select
-- instead of a print.
-- vars to hold the commands to queue up and the command var for the one we'll run
-- identity is used to preserve order in case we decide to have a particular order
-- otherwise it will just run in the order we create the commands
declare @command nvarchar(max), @id int
declare @commands table(id int
CLUSTERED, command nvarchar(max))
-- strint to look for
I am a huge fan of LINQPad. Something on my wish-list, as far as my own personal knowledge, for a longtime with it was how to query Active Directory information when I needed it. This was more for convenience because quite often I need to look up some AD info when I am looking at a scrub for some data regarding a user. Normally I just net use or dsquery/dsget etc. The key is System.DirectoryServices.AccountManagement. Note this is a .NET 3.5 and 4.0 only library so earlier than that, sorry. You aren't out of luck, but the other ways seem...
apparently you can use a transaction scope for this and just wrap everything that way. but to me that seems more complicated than just enabling it with execute command.
some LINQ code like (note that ‘this’ is a data context):
this.ExecuteCommand("set transaction isolation level read uncommitted");
Produces this sql code:
set transaction isolation level read uncommitted
SELECT TOP 5 <fieldnames…> FROM [MyTable] AS [t0]
That’s what I want to see, so yay. =)
ps. trying to use livewriter today. so far, not excited about it and still like word more =P hopefully i’ll get elightened.
After my recent post, I had a couple of conversations and an email exchange with a colleague of mine and I was reminded of the fact that I went originally out to search for my 'original' table space used script. I couldn't find it online (even though I found it on my hdd) and that prompted me to put together the newer method. Which is considerably shorter. But here is my original script which essentially I wrote by looking at what was in sp_spaceused and just formatting it more to my liking.
-- view all table sizes
-- author: royashbrook - email@example.com