SQL Server with Mr. Denny:

Config

Mar 13 2008   8:00AM GMT

SQL 2008 prevents schema changes if the table must be dropped



Posted by: mrdenny
SSMS, Config, SQL, SQL Server 2008

When editing the table schema in the SQL Server 2008 UI and the required change requires that the table needs to be dropped and recreated by default the UI will not let you make the change.

The kinds of changes that would require that the table be dropped and recreated would be inserting a column in the middle of the table, or changing the size of a column.

This setting can be overwritten by clicking on the Tools drop down menu and selecting Options.  Under the Designers menu option, select the “Table and Database Designers” menu option and uncheck the “Prevent saving changes that require table re-creation” option.  After clicking OK you will be able to save the changes.

I recommend that you leave this setting enabled normally so that you don’t make table changes which require the object to be dropped by accident on production systems.

Denny

Mar 2 2008   4:43AM GMT

New Article: Create an upgrade plan for your move to SQL Server 2005



Posted by: mrdenny
Article, Config, SQL, SQL Server 2005, Installation, SQL Server 2008

I’ve published a new tip over on SearchSQLServer.com entitled “Create an upgrade plan for your move to SQL Server 2005“.

While it’s based on upgrading to SQL Server 2005 it can be used to upgrade to SQL Server 2008 as well.

Denny


Feb 18 2008   8:00AM GMT

So I’ve heard about endpoints, but what are they and how do I use them?



Posted by: mrdenny
Config, SQL, Endpoints, SQL Server 2005, SQL Server 2008

In a nutshell Endpoints are ways that people, or applications can connect to the SQL Server.  There are several different kinds of end points which can be created; four to be specific.  Two are system specific, the SERVICE_BROKER and DATABASE_MIRRORING endpoints can only be used for the SQL Service Broker and Database Mirroring respectively. The other two are for general use.  They are the SOAP and TSQL endpoints.

Without knowing it you use an endpoint to connect to the SQL Server each time you connect.  There are actually 5 endpoints created by default on each instance of SQL Server.  You can check then out by querying the sys.endpoints DMV.  When you connect to the SQL Server using TCP (port 1433 by default) you are using the TSQL Default TCP endpoint.  By default all users have the rights to connect to this endpoint.  You can create other TCP endpoints on different ports for specific users to connect to.  This would be handy if you have several applications coming into the SQL Server from a single server, and you wanted to be able to separate there traffic through the firewall so that the network admins could watch the traffic in the event of an issue.  You could create a TCP endpoint for each application, and assign only that application IP rights to use that endpoint.  You then have the application specify the port number that it will be connecting through in the connection string.

The SOAP endpoints are used in a similar way, but instead of allowing regular TSQL connections they allow SOAP calls to be made directly against the database.  (I’m not that up to speed on SOAP so that’s about all I’ve got on that topic.)

 Endpoints are created with the CREATE ENDPOINT command with various switches depending on what kind of endpoint you are creating and how much security you require on the endpoint.

The endpoint that I’ve used the most would have to be the service broker endpoint.  It’s used to allow SQL Server service broker on one SQL Server to talk to the Service Broker of another SQL Server.

One thing to remember about endpoints is that they are used for inbound connections only.  Outbound connections do not require or use an endpoint.

Denny


Feb 11 2008   8:00AM GMT

Getting those memory setting in SQL Server just right.



Posted by: mrdenny
SQL, Config, Microsoft Windows, RAM, Windows Computing

When using 64bit SQL Server getting the memory settings right is pretty easy.  Simply set the maximum to what you want and you are good to go.

Getting them right in the 32bit versions of SQL Server is a bit harder.  You have to deal with the OS level of enabling the Physical Address Extensions (PAE) and the 3GB switches.  You then need to enable AWE within SQL Server and then set the max memory setting.

If you are using Windows 2003 SP1 or later PAE will enable for you automatically.  The /3GB switch however won’t.  Since I have to add the /3GB switch I like to add the /PAE switch in there as well.  My theory is why make Windows decide to do something automatically when I can simply override the logic and turn it on every time, especially when it’s something that I’m going to want enabled every time the server boots.

 Now as to the max memory setting for SQL Server… There are pretty much two prevailing schools of thought. 

  1. Give Windows between .5 and 1 Gig of memory and give SQL the rest.
  2. Give SQL 75% of the physical memory and leave the rest for Windows.

I’ve tried both and both seam to work fine.  If you have less memory to work with you will probably want to stick to option 1.  When you start working with huge amounts of RAM (64 Gigs plus) is when Option 2 starts to look more workable.

These rules obviously all start to change when you have more than one instance installed as you need to balance your max memory between the instances.

If you are using less then 2 Gigs of RAM for the instance don’t enable AWE on the instance.  I’ve seen it lead to SQL Server acting strangely and performing very strangely.  When setting your max memory setting for more than one instance don’t forget to add up the max memory for all the instances and make sure to leave Windows room to work with or your server will suffer.

Don’t forget about my post on setting the min server memory setting in SQL Server.

Denny


Jan 28 2008   11:56PM GMT

Slide Decks and Sample Code from SoCal Code Camp



Posted by: mrdenny
Cache, Config, In Person Events, CLR, SQL, Resource Governor, SQL Server 2005, SQL Server 2008, SSMS, Query tuning, Beta

The SoCal Code Camp was this last weekend.  I had a great time attending and speaking at the code camp this time around.   I hope that everyone who attended my sessions had as much fun attending the sessions as I did speaking at them.  I did my best to make them as much fun and interactive as I could.

As promised here are the slide decks and sample T/SQL code from the four sessions.  Everything is within a single ZIP file.  I’ve included two copies of each slide deck.  One in the Office 2007 format, and one in the Office 97-2003 format.  They are identical to each other, but I wanted to include both so that people with the older version of Microsoft Office can see the deck without having to download and install the patch which allows Office 2003 to view Office 2007 files.

The sample scripts which I’ve included are all run against the AdventureWorks database or the AdventureWorksDW database (check the USE commands at the top of the scripts).  If they need a different database they will create the new database.

Session 1 - SQL Server Query Tuning (SQL 2000+)

Session 2 - SQL Server 2008 Resource Governor (SQL 2008 CTP5+ only)

Session 3 - SQL Server Service Broker in the Real World (SQL 2005+) (I’ve fixed the problem with the single server script that we were having at the Code Camp.  Turns out I had left the route in place which is why the message never showed up.  The first script didn’t run correctly because I had run the server to server script on my virtual machine and the route was left by accident.)

Session 4 - SQL Server 2008 What’s on the Horizon (SQL 2008 CTP5+)

If you have any questions about these slide decks or sample code feel free to post a comment here, or drop me an email.

Denny


Jan 11 2008   6:40PM GMT

New Article: Determining SQL Server database storage requirements



Posted by: mrdenny
Article, Config, DataManagement, SQL, SQL Server 2005, SQL Server 2008

I’ve published a new tip over on SearchSQLServer.com entitled “Determining SQL Server database storage requirements“.

Denny


Jan 10 2008   8:00AM GMT

SQL CLR: The What, When, Why and How.



Posted by: mrdenny
CLR, Config, SQL

There are two camps when it comes to SQL CLR.  The DBA camp, which says don’t use it, it’ll kill your SQL Server and the Developer camp which says that it will save you loads of time and that you should use it for everything.  These two different camps also represent the different messages which Microsoft is giving out as well.  I highly recommend that DBAs sit in on a Microsoft developer track session and that developers sit in on a DBA track session some time.  You’ll see a wide difference in the message about CLR in the sessions.

SQL CLR while powerful can not save the world as we know it from T/SQL.  SQL CLR has it’s uses, and it has times when it is the wrong option.  It can most definitely not do everything.  First of all, you’ll notice that I call it SQL CLR not just CLR.  This is because only a subset of the .NET CLR is supported by SQL Server.  This subset it called the SQL CLR.  The official list of supported libraries can be found here.  If it isn’t on that list it’s not officially supported by Microsoft.  What do I mean by supported?  Well in basic terms if you are using a .NET CLR library which isn’t on that list and you start having performance issues, Microsoft can require that you remove the CLR code from the SQL Server before troubleshooting the issue.  The official support policy from Microsoft can be found in MSKB article 922672.

Now with all that said what exactly can SQL CLR functions and procedures be used for?

SQL CLR code is extremely powerful, and when it comes to some kinds of work can be much faster than T/SQL code.  Some examples are advanced math, string manipulation, string searching, pattern matching, etc.  Places where SQL CLR will be slower than native T/SQL will be when general data manipulation and data searching.  When writing SQL CLR functions and procedures do remember that if the .NET code has to go back to the database for any reason that data access will not be slower than doing the data access natively within T/SQL.  If nothing else you have to account for the additional time to connect to the SQL Server, check credentials and move into the correct database.  All of which takes time.  When updating records from .NET code you have to process the records one at a time.  While .NET is great at processing records row by row, SQL isn’t.  SQL will be very slow when it comes to actually processing the updates as it is optimized for record set processing not row by row processing.

Now that I know what I can do with it, when should I?

When deciding to write a .NET SQL CLR function or procedure you first need to decide; Is the SQL Server the right place to do this?  Often times the front end, or middle end (if you have an N tier application) may be a better place to do the work.  For example formatting phone numbers via a .NET function should be done on the front end, not in the database.  Encrypting a credit card number should be done in the middleware or the SQL Server (if you have a middleware layer do it there).  You probably don’t want to install the encryption method and certificate that you use to encrypt data on the end users computer.  The general rule that I like to live by is to put as much .NET code outside of the SQL Server as possible, either in the middleware or in the front end.  Now there are also times when putting the code within the SQL Server is the right place to put it.  Say that you are doing a data warehouse load and you need to parse the text of a NVARCHAR(MAX) field looking for specific key words or phrases, and if these key words or phrases exist you need to add rows somewhere else.  T/SQL may not be the best option for this.  A Full Text search will be inefficient as you will have to search the entire table every time.  A regular T/SQL LIKE command will be very slow as indexes can’t be used, and searching through large pieces of text takes SQL a lot of time.  But if you use a SQL CLR function this can be done with very little CPU time using what are called Regular Expressions.  Regular Expressions are a basic .NET function which allows you to quickly and easily search a block of text.  (Since I’m not a .NET programmer I’m not going to dive into using regular expressions, however here is an MSDN article on the topic.)

Other excellent uses of SQL CLR would include procedures or functions which involve advanced mathematics functions which SQL Server does not include.  These functions could be easily put into a SQL CLR procedure or function and executed within the .NET environment with the result then being used within the SQL Server.  While normally I would recommend putting this in the client tier or middle tier if the function or procedure was needed for in row processing of a query then the SQL Server may be the right place for the CLR code.

While the SQL CLR isn’t the end all solution that some people were looking for, and want it so desperately to be, when used correctly it can be an extremely powerful tool.  But it must be used carefully as when used incorrectly it can hamper performance of your SQL Server.

Denny


Oct 22 2007   10:17AM GMT

How SQL decides how much procedure cache and how much buffer cache to use.



Posted by: mrdenny
SQL, Config, Cache

There are two main types of cache which SQL Server deals with, the buffer cache and the procedure cache.  The procedure cache is where the execution plans for procedures and queries are stored.  The buffer cache is where the actual data is cached so that SQL Server doesn’t have to go to disk to get often accessed data.

The version of SQL Server that you are running will determine how SQL calculates the maximum size of the procedure cache.

SQL 2000 - 50% of the memory or 1 Gig which ever is lower

SQL 2005 RTM to SP1 - 75% of the first 8 Gigs of RAM + 50% of the next 56 Gigs of RAM + 25% of the ram over 64 Gigs.

SQL 2005 SP2 and up - 75% of the first 4 Gigs of RAM + 10% of the ram over 4 Gigs

As I understand the reason for the change the original settings were causing SQL Server to lockup for some customers as not enough RAM was left over for the buffer cache.

If you are using SQL 2005 in a Win32 platform these calculations change again as the procedure cache must remain within the first 2 Gigs of memory giving you a max of 2 Gigs of procedure cache no matter how much memory you install.

Denny