Tuesday, June 29, 2004
Only one day into the main conference of Tech Ed Europe and it's already been a great week!
Tuesday, June 29, 2004 5:28:31 AM (Pacific Standard Time, UTC-08:00)  #    Comments [1]  | 
Thursday, June 24, 2004
This week I'm in Dubrovnik, Croatia for the PASS SQL Server Summer Academy... next week off to Amsterdam for Tech Ed Europe and that's why I've been a bit silent. Have many things to blog about now - like my nightmare travel to get here, the great location once I got here and then I'll throw in an invite to a SQL Server 2005 party invite for Tech Ed Amsterdam from Matt Nunn.
Wednesday, June 23, 2004 11:23:31 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
Friday, June 18, 2004
It's not been often that I've done non-technical blog entries but this one certainly warrants it. Last night I attended a special gathering at the new Seattle Public Library. I've been working a lot this week and I was NOT thinking that an evening at the Library was what I needed; I needed a beer! However, it was GREAT (and they had wine :). Seriously though, I'm REALLY impressed with the goals and long term thinking of the new library design (especially the "Books Spiral") and I was amazed at all the SQL Server references. You'll have to read more to know what the heck I'm talking about.
Friday, June 18, 2004 5:18:13 PM (Pacific Standard Time, UTC-08:00)  #    Comments [2]  | 
Wednesday, June 16, 2004
This was a question I was asked recently: Sometimes I use a construct in an SP such as WHERE (Col1 = @Param1 OR @Param1 IS NULL) to provide for optional parameters to stored procs. What are the performance ramifications of this?
Wednesday, June 16, 2004 7:53:01 AM (Pacific Standard Time, UTC-08:00)  #    Comments [7]  | 
Tuesday, June 15, 2004
That's all that's available right now (at least on MSDN). Hopefully, all of this will be archived on msdn but in the interim I've posted EVERYTHING here: demo scripts, the pdf, the Q&A (in html), information about the follow-on session I'll be delivering online in July, and a ton of other links!!! Here's the background - on June 11 Kimberly L. Tripp delivered a 1.5 hour webcast on SQL Server 2000 titled: Indexes from Every Angle - Finding the Right Balance. The webcast was well received and is now available for download. This entry brings ALL of the supplemental resources to one place!
Tuesday, June 15, 2004 10:34:17 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
Monday, June 14, 2004
In October, SQLskills will offer an exciting event: SQL Immersion. SQL Immersion Events are NOT like traditional conferences nor are they like traditional classes. SQL Immersion Events are indepth, focused events that cover one primary area of SQL Server. In October these events will focus on Performance Tuning. Monday-Thursday we will focus on server-side performance tuning (presented by Kimberly L. Tripp) and Friday we will focus on client/application tuning using ADO.NET (presented by William R. Vaughn).
Monday, June 14, 2004 12:59:18 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
Saturday, June 12, 2004
On June 11, Kimberly L. Tripp delivered a 1.5 hour webcast on SQL Server 2000 titled: Indexes from Every Angle - Finding the Right Balance. The webcast was well received and generated a TON of questions. Kimberly has compiled a series of blog entries which cover the different areas of questions: Related Resources, Tools, General, Index Creation, and Index Management/Maintenance. This blog entry answers all of the Index Maintenance and Management Questions.
Saturday, June 12, 2004 2:38:52 PM (Pacific Standard Time, UTC-08:00)  #    Comments [2]  | 
On June 11, Kimberly L. Tripp delivered a 1.5 hour webcast on SQL Server 2000 titled: Indexes from Every Angle - Finding the Right Balance. The webcast was well received and generated a TON of questions. Kimberly has compiled a series of blog entries which cover the different areas of questions: Related Resources, Tools, General, Index Creation, and Index Management/Maintenance. This blog entry answers all of the Index Creation Questions.
Saturday, June 12, 2004 2:30:16 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
On June 11, Kimberly L. Tripp delivered a 1.5 hour webcast on SQL Server 2000 titled: Indexes from Every Angle - Finding the Right Balance. The webcast was well received and generated a TON of questions. Kimberly has compiled a series of blog entries which cover the different areas of questions: Related Resources, Tools, General, Index Creation, and Index Management/Maintenance. This blog entry answers all of the General Questions.
Saturday, June 12, 2004 2:24:55 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
On June 11, Kimberly L. Tripp delivered a 1.5 hour webcast on SQL Server 2000 titled: Indexes from Every Angle - Finding the Right Balance. The webcast was well received and generated a TON of questions. Kimberly has compiled a series of blog entries which cover the different areas of questions: Related Resources, Tools, General, Index Creation, and Index Management/Maintenance. This blog entry answers all of the Tools Questions.
Saturday, June 12, 2004 2:18:37 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
On June 11, Kimberly L. Tripp delivered a 1.5 hour webcast on SQL Server 2000 titled: Indexes from Every Angle - Finding the Right Balance. The webcast was well received and generated a TON of questions. Kimberly has compiled a series of blog entries which cover the different areas of questions: Related Resources, Tools, General, Index Creation, and Index Management/Maintenance. This blog entry points to a bunch of Related Resources.
Saturday, June 12, 2004 2:15:26 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
Friday, June 11, 2004

Thanks for being there! If you were there then you know - it's was quite fun and you had a lot of questions - questions that I didn't see until the session ended (whooops!). My Q&A dialog box was only showing a subset of questions so I didn't know..... Well, now I do (that's for sure)! I've got a huge list that I'm working through (I did get most of them in my 20 mins of text responses) but I will post the entire written-up Q&A over the weekend - to my blog - and then to my website and to MSDN shortly thereafter. The demo scripts are already on www.SQLskills.com under Current Events (which will move within a couple of days to Past Events).

And - I guess I just wanted to say THANKS?! The great comments you posted in the Q&A (in addition to the great questions) really make my job fun! I really wouldn't do what I do if it weren't for everyone's great support!!!

So - the entire audio presentation w/powerpoint presentation, demo scripts, Q&A and [not sure if they'll do a] transcript should be posted to MSDN by mid-week next week. I'll provide all of these links as soon as they're available. AND - I think I'm going to request another webcast on Index Maintenance. Seems like that's something everyone wants to spend more time on!

Friday, June 11, 2004 5:17:40 PM (Pacific Standard Time, UTC-08:00)  #    Comments [1]  | 
Tuesday, June 08, 2004

This Friday I'll deliver an MSDN webcast on SQL Server Indexing - for people who are not SQL Server experts. It's a good overview of what you should look for, what you should do and which tools will give you the best bang for the buck when used correctly... Here's the MSDN link: http://msevents.microsoft.com/cui/eventdetail.aspx?eventid=1032252961&culture=en-us. See you there!

Tuesday, June 08, 2004 8:00:46 PM (Pacific Standard Time, UTC-08:00)  #    Comments [3]  | 

This is pretty exciting... Today we moved the blog over from the test site (where I added all of the other entries) to SQLskills... I guess I better start blogging. In fact, I think I'll try and blog most of the questions I get in email. In fact, I got two today. Stay tuned....

Tuesday, June 08, 2004 11:55:45 AM (Pacific Standard Time, UTC-08:00)  #    Comments [6]  | 
Sunday, June 06, 2004

Today Michele and I were chatting about Security. She's focused a lot on it these days and is chatting with everyone about their best practices... I thought I'd mention a few important links/ideas here:

Login Mode:

  • Allow windows authentication only - making sure that the sa account has a strong password set (regardless of the fact that with Windows Only set it's effectively disabled)
  • When that's not possible and you need to allow SQL Authentication then make sure to use SSL so that the passwords are not transmitted in clear text.

Default Accounts Allowed Access - should you remove any?

  • Do not remove the sa account - only make sure it has a strong password.
  • Consider removing Builtin\Administrators (which is local machine\administrators group) BUT make sure that you have the following accounts setup as administrator or you could end up finding yourself locked out:
    • YOU!
    • Your SQLAgent
    • Your Cluster Admin - if you're running SQL Server on a Cluster

NOTE: if you do find yourself locked out with no way in... and have your server set to windows authentication only then as an NT Admin you can atleast set your SQL Server to Windows/SQL Auth and then login with the sa account (hopefully you know the password and hopefully you've set the password, realize that if your password is blank AND you do this there's nothing that will remind you that you have a blank SA password. If you change the authentication mode in SQLEM (but remember in this strange case you have no way to get in) then at least that prompts you for an SA password). PLEASE - get in and set the SA password ASAP. The registry key change is detailed in this KB Article in the section titled: Turn on Mixed Mode Authentication After You Install MSDE.

Interesting related link: PRB: Unsecured SQL Server with Blank (NULL) SA Password Leaves Vulnerability to a Worm

Above all - make sure that you adhere to many of the common best practices recommended:

 

Sunday, June 06, 2004 4:27:43 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 

All sorts of purposes: maintenance, rebuilding the database objects, dropping/recreating the database in test environments, changing a state option like readonly (did you know that no users can be using the database when you make this change to RO)....

Anyway, lots of reasons and this has always been the case. In previous releases we used to create sp_ (you know this is a special naming convention for objects in master that can be referenced in any database WITHOUT three-part naming) stored procedures that would detect the users using a database and either KILL spid directly or do a net send and then use WAITFOR DELAY to give the users a couple of seconds/minutes/whatever, to complete. Well, procedures like that are still useful (because you can set the database to “dbo use only,” warn the user, and then give them some time... However, warning them typically uses xp_cmdshell (which a lot of you don't allow) and sometimes you don't want to wait and/or give them much time :) :).

So - did you know that ALTER DATABASE in SQL Server 2000 has been changed to allow termination options for STATE changes. The termination options allow one of three types of termination:

  • Give the users n number of seconds to wrap things up
    • ALTER DATBASE dbname SET READ_ONLY WITH ROLLBACK AFTER
  • Kick them out immediately
    • ALTER DATBASE dbname SET READ_ONLY WITH ROLLBACK IMMEDIATE
  • Or, optionally you can have your process NOT WAIT
    • ALTER DATBASE dbname SET READ_ONLY WITH NO_WAIT

If no options are set and the process cannot get exclusive use of the database then it will till it can - indefinitely. Some database option changes generate a “could not get exclusive use” error but READ_ONLY (and a few others) don't. If this is in an automated script/process this can cause you a lot of grief. (In fact, I'm adding this note about 90 minutes after I created this blog entry...because my QA window is still trying to get exclusive access to pubs - which I was setting to readonly just to see if it would eventually time out....well, 90 minutes and still running it hasn't. I think I'm going to kill it!)

For a good example of how to change certain state changes when creating batch processes see, DB Alter for Batch Operation.sql (6.3 KB).

Sunday, June 06, 2004 4:02:11 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
Have you ever been watching a profiler trace only to find what you're looking for, select it and then all of a sudden get "auto-scrolled" down to the end... UGH - that's the default! But - Profiler does have an icon for stopping that behavior. (and since I generally (and personally) HATE most icons cause I can't ever seem to tell what the heck they are) I'll just tell you it's the 5th one from the RIGHT. It's titled auto scroll window (at least I like the "tool-tips"). Click it to turn the option off (I wish that were the default)!
Sunday, June 06, 2004 2:17:22 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
OK, so I can't tell you how fast I type... I have no clue! But - I do know that people get made at me on IM chats because they (well, most of them) cannot keep up (especially my Father!!!)... And the key reason for why??! I tend to stay on the keyboard instead of constantly going for the mouse; I love learning shortcuts/keystrokes, etc. and I like creating them as well... SO - first, did you know that the SQL UE (User Education) Team documented many of the keyboard shortcuts? In the books online click on the small keyboard at the top of the right pane window. It links to "Using the SQL Server Tools, User Interface Reference, Keyboard Shortcuts."
 
Second, did you know that you can create your own keyboard keystrokes within Query Analyzer? Check out Tools, Customize. In fact, Alt+F1 already exists (and cannot be changed) as object help. Highlight an object in the QA window and then press Alt+F1 - this will execute sp_help objectname. If you want keyword help (meaning a SQL keyword), highlight the keyword (like SELECT) and press Shift+F1 - this will give you context sensitive books online entry. I typically setup Ctrl+F1 as sp_helpindex (be careful - if you get an extra space in there it won't work!) and Ctrl+3 as sp_helpconstraint.
Sunday, June 06, 2004 2:15:18 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
First, do you have the latest version of the SQL Server Books Online? Make sure you do: http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Second, do you ever need the info when you're not at your desk? Make sure you know where they are: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/startsql/portal_7ap1.asp
Sunday, June 06, 2004 2:14:53 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
After a group of RDs started chatting about stored procedures I finally felt like I could join in. Often they talk about .Net and client stuff and well, quite honestly, I don't care what you do with the data...only that I serve it up quickly. Ok, I'm really kidding here but my primary focus is backend server tuning and availability, so when the group started talking about stored procedures, I had to chime in. It all started because someone had blogged that stored procedures are not precompiled and are therefore of no use... which is COMPLETELY wrong. However, the irony is that I don't even believe that they should be compiled (and saved and therefore reused) ALL the time. In fact, a precompiled plan is also an optimized plan and that plan may or may not always be the best plan for every execution....... So, here's a bunch of stuff about sprocs. You definitely want to use them - but use them effectively!!!!
 
Benefits of stored procedures:
  • Centralized logic which can be changed with minimal client impact
  • Logic on the server so roundtrips are minimized
  • Compiled plans saved in cache. Not every plan is saved, not every plan should be saved. However, the default is that stored procedure plans are compiled and saved - on first exection. The plan is NOT created when the stored procedure is created (I've also seen this written up incorrectly before) NOR is this plan saved permanently. There are many reasons for why the procedure's plan may fall out of cache:
    • Server restart
    • Falls out of cache due to low re-use (and not enough cache to keep it around)
    • Specifically being removed from cache by:
      • Executing DBCC FREEPROCCACHE to kick ALL plans out of cache (fyi - you can see what's in cache by querying master.dbo.syscacheobects)
      • DATA on which the procedure depends changing enough to cause the statistics to be invalidated and therefore sql server proactively invalidate the plan
      • Executing an sp_recompile (on the object(s) on which the procedure depends. This last one is also nice and something I sometimes force (off hours when a lot of indexes are being rebuilt and/or added). You can execute sp_recompile tname and it will cause all plans which access this table to be invalidated.
Stored Procedures for Security:
  • Stored Procedures can be secure AND easier to manage - in terms of permissions.
  • If I am the owner of a table and I create a procedure based on my table - I can give people access to the procedure withOUT giving base table permissions. This will allow better security and minimize the accidental "oh darns" when someone forgets a where clause on a delete. Imagine a user who types in DELETE Sales WHERE invnum = 1234 BUT highlights ONLY the DELETE Sales...whose problem is that? Mine as the DBA. We can all argue that users should not have ad-hoc access to the server (and I agree) BUT stored procedures create a layer of abstraction which is ALWAYS good especially if you are using DYNAMIC SQL.
Dynamic sql has many connotations... There is "Dynamic String Execution" which can be WITHIN a stored procedure and there's Dynamic SQL which is what an application builds and sends off to the server. As for a client who sends an ad-hoc string to the server or for a dynamically built string within a stored procedure - BOTH REQUIRE that the user have the ability to execute the command directly - which means there's more room for error. However, if it doesn't need to be in a dynamic string (and many statements can be parameterized) then it could be in a stored procedure WITHOUT dynamic string exection withOUT the possible room for HUGE SQL injection problems/errors. Speaking of SQL Injection - IF you use stored procedures and mostly only allow for Identifiers as parameters (i.e. tablename, viewname column names, etc.) then you can use the QUOTENAME() function to significantly reduce SQL injection.
Caching (in General) for better Performance:
 
There are really three areas that need to be understood to really get the issues related to stored procedures:
  • Ad-hoc statement caching (that was new in SQL Server 7.0 and higher)
  • Forced statement caching (through sp_executesql)
  • Stored procedure caching (by creating stored procedures)
Ad-hoc Statement Caching
When a statement is deemed "safe" sql server will take EVEN ad-hoc statements and store a plan of execution in cache for subsequent users to use. For the plan to be re-used the statement has to be almost an identical match, the parameter has to be the EXACT same data type, the objects cannot be ambiguous and MOST statements won't really benefit from this. If you want to see an example of ad-hoc statement caching do the following:
-- 1) Clear Cache with
DBCC FREEPROCCACHE

-- 2) Look at what executable plans are in cache
SELECT sc.*
FROM master.dbo.syscacheobjects AS sc
WHERE sc.cacheobjtype = 'Executable Plan'

-- 3) execute the following statement
SELECT t.*
FROM pubs.dbo.titles AS t
WHERE t.price = 19.99

-- 4) Look again at what executable plans are in cache and you'll find that there's a
--     plan for a NUMERIC(4,2) (look at the "sql" column in output - far RIGHT)

SELECT sc.*
FROM master.dbo.syscacheobjects AS sc
WHERE sc.cacheobjtype = 'Executable Plan'
 
-- 5) If you execute the EXACT same statement with a 4,2 then you will get THAT plan
--     but if you execute with a 5,2 you'll get a new plan (the plan is not safe). Execute this:

SELECT t.*
FROM pubs.dbo.titles AS t
WHERE price = 199.99

-- 6) Look again at what executable plans are in cache...

SELECT sc.*
FROM master.dbo.syscacheobjects AS sc
WHERE sc.cacheobjtype = 'Executable Plan'
OK - so the fact that SQL Server can cache the plan is good... How often is something actually deemed safe - well, it's not that likely. A better way of getting better plan re-use IS either of the two following BUT in these two cases it's ALWAYS cached - which might not ALWAYS be good....
 
Forced Statement Caching (through sp_executesql)
This is good IF you know the plans are consistent (more on this coming up) and IF you want to type the data more strictly. Remember how SQL Server had to type the data above (numeric(4,2) or numeric(5,2), etc.). Well here you can type the parameters and force the plan to be cached. All subsequent uses will get the same plan:
DECLARE @ExecStr    nvarchar(4000)
SELECT @ExecStr = N'SELECT t.* FROM dbo.titles AS t WHERE t.price = @price'
EXEC sp_executesql @ExecStr, N'@price money', 19.99
BUT this falls into the category of being hard to know and there are better ways with stored procedures. Generally, I recommend stored procedures over statement caching...
 
Stored procedure caching (by creating stored procedures)
OK - I could go on for hours here and I'll make it sufficient to say that NOT all procedures should be cached but MANY should. The ONLY way to get the security and consistency desired from stored procedures is to know when to save them and when not to. It also requires that you typically have more smaller stored procedures rather than fewer larger procedures (i.e. modular code is a KEY component to better performance). Anyway, having said this... IF the first person who executes the procedure (and there isn't a plan for the procedure already in cache (and just to make this even more clear - stored procedure plans - when saved - are ONLY in cache they are NEVER saved to disk)) then a plan will be generated - and used for ALL subsequent users (unless a recompile is forced or occurs due to issues in third bullet in first section :). So now that there's a plan - will that plan be perfect...not necessarily. I have a great script that shows this and it's hard to explain over a short blog but the key point is this:  (I took this small section from yet another of my emails so forgive the duplication):
I would say that forced statement caching and stored procedure caching have the same problem(s) and that's that NOT all statements should be cached. There are certain strategies that can help to minimize costly overhead and there are certainly tips/tricks that we use to see if a plan should be saved or not. I think the number one thing I'd recommend is more modular procedures where the data returned SIGNIFICANTLY varies. The key reason is that smaller procedures tend to be more controllable. And - when a complex procedure is separately out then you can set that smaller more modular proc to be recompiled on each execution. That's probably the easiest way. There are certainly other things you can do to more effectively determine the cause of the problem (and that would be better) but I'd say that forcing recompilation on a smaller piece of code that generates widely varying sizes/sets of data is a good and generic solution.
So - having gotten through all of this... If you really want to play with this A LOT more below are a couple of scripts that I think are VERY useful. I use these in my lectures on Optimizing Stored Procedure performance. Regardless, this is the correct order to read/review/learn these scripts:
 
Create the Credit database (you can use CreditSampleDB.zip (55.79 KB) to create it)
Use "RecompilationIssues.sql (3.67 KB)" to get insight into bad plans being created/saved/re-used
Use "ModularProcedures.SQL (4.28 KB)" to get insight into what happens even with procedures that use conditional logic - not that there's anything wrong with that?!
Sunday, June 06, 2004 2:13:50 PM (Pacific Standard Time, UTC-08:00)  #    Comments [2]  | 
In a discussion with Scott about the "text in row" option for LOB (Large Object Data types: text, ntext, and image) data he questioned whether or not it was really a good idea to set... Well, I have mixed feelings about it really. In general I don't recommend it unless EVERY query tends to want the LOB data and if the LOB data is in general - narrow (meaning very few bytes). Yes, you do skip the extra lookup into the text/image b-tree but you also make all of the rows wider. If you don't want the text info most of the time (i.e. the description is only needed when they [occassionally] click on that button for the request, etc.) then you're putting all of those descriptions into memory when you don't really need to. It's [potentially] a great way to waste a large percentage of your cache.
 
So - I'd say that there really isn't a byte limit more than a usage rule. BUT - if you do want to skip that lookup (because most of the time you DO want to return the description) then I'd start to look at the data and see what the "average" byte length is. If most of the descriptions are small but they want to use the text datatype for the very rare and very large description then this is a GREAT feature to keep the small (and very frequently accessed descriptions) with the data row and avoid the lookups!
 
(fyi - the b-tree index is just like any other; it's the "index" associated with the table (object_id('tablename') = id) and has an indid of 255 in sysindexes. Each table has only ONE btree for all LOB columns of that table and seeing the indexes, statistics, etc. that each table has is interesting if you ever look at the system tables.)
Sunday, June 06, 2004 2:12:31 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
And the reason that Clemens blogged about me was actually a good one for all to know... Best Practices Analyzer has released. Everyone should be looking at whether or not their SQL Servers are adhering to roughly 70 or so commonly mispracticed practices. Have fun.
Sunday, June 06, 2004 2:11:52 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0]  | 
After Clemens blogged about my not having a blog... I guess I couldn't not blog any longer. And so I begin... In the past I've written content in the form of presentations, articles or classes, etc. They would go through editors, friends, anyone who would read it. Often they'd remove my sarcasm, bad spelling and/or polically incorrect 4-lettered phrases (that's all I'll say for now :) and following all of that there was often a delay in my opinions getting to anyone... Which is probably safer for me - but what the heck, time to have fun. Thanks Clemens?!
Sunday, June 06, 2004 2:10:25 PM (Pacific Standard Time, UTC-08:00)  #    Comments [5]  | 

Theme design by Jelle Druyts

Pick a theme: