SQL Server Performance Tuning

My manager has asked me to put together a plan for a backup server for our production server running SQL Server. Should I use log shipping or clustering?

Most of the production SQLServersI have run across don’t have any easy or quick way to failover to a working server should they fail. Generally, most people hope their production SQL Server never fails. And in the back of their minds, they think they know what to do to recover should the worst happen, but […]

How do I find the most frequently occurring value for all data in a table? How do I find that value per group?

As always, there is more than one way to get a correct result. But which way gives you the best performance? Let’s first build a simplified test scenario to illustrate what we’re after. CREATE TABLE #t (ArticleGroup CHAR(2), Price DECIMAL(8,2)) INSERT INTO #t VALUES(‘SP’, 1.2) INSERT INTO #t VALUES(‘SP’, 1.2) INSERT INTO #t VALUES(‘SP’, 2.1) […]

How can I determine the maximum value for each data? And which option provides the best performance?

One of the most common requirements is to generate a list of, say, customers along with their last order date. Or, generally speaking, a list of distinct values in one table along with a corresponding maximum value from another table. To solve such problems you basically have three different alternatives. Let’s have a look at […]

Which is faster when using SQL Server 2000 or 2005, temp tables or the table datatype?

Generally speaking, if the data you are dealing with is not large, then the table datatype will often be faster than using a temp table. But if the amount of data is large, then a temp table most likely will be faster. Which method is faster is dependent on the amount of RAM in your […]

How do I estimate how large a database will grow?

QuestionBeing a developer, I am not an expert at SQL Server (I know just enough to get done what I need); however, many of our clients are asking us for growth estimations of our database. How much MBs/GBs will a database take up? Also, does SQL Server have the ability to estimate how big it […]

My application makes heavy use of temp tables. Should I be creating temp tables as needed, or should I be using a permanent table over and over instead?

Assuming everything is the same, both tables will produce very similar access speeds. If your application makes heavy use of temp tables, you might consider using a permanent table for these reasons:  A regular table already exists. A temp table has to be created, which takes time and overhead. For example, if you need to […]

I don’t know how to transfer an array to a table, and I even if I can, I don’t know if it will be any faster than using INSERT INTO?

QuestionI have an INSERT INTO SELECT query which appends about 500,000 rows of data to a table. The query takes about 22 minutes to run. I would like it to run in less than 5 minutes, if possible.One solution I thought of was to append the 500,000 rows of data to an array (instead of […]

Is is more efficient to use SELECT DISTINCT or GROUP BY to perform the same function?

Question The following two queries produce the same results. Is one or the other versions of these two queries more efficient than the other? SELECT DISTINCT productcode FROM sales SELECT productcode FROM sales GROUP BY productcode Answer The goal of both of the above queries is to produce a list of distinct product codes from […]

I want to add an identity or unique identifier column to a table in order to ensure that each row is unique. For best performance, which one should I use?

One of the key aspects of database table design is to ensure what is called entity integrity. What this means is that you need to ensure that each row in your database tables is unique. If you don’t take the proper precautions, it is possible that one or more rows of your table might be […]

Should I use the old Microsoft JOIN syntax, or the ANSI JOIN syntax for the best JOIN performance?

Question Which of the following joins will produce better performance? ANSI JOIN Syntax SELECT fname, lname, departmentFROM names INNER JOIN departments ON names.employeeid = departments.employeeid Former Microsoft JOIN Syntax SELECT fname, lname, departmentFROM names, departmentsWHERE names.employeeid = departments.employeeid AnswerSQL Server supports two variations of performing JOINs: the ANSI JOIN syntax and the former Microsoft JOIN […]