Measuring Query Performance : “Execution Plan Query Cost” vs “Time Taken”

The profiler trace puts it into perspective. Query A: 1.3 secs CPU, 1.4 secs duration Query B: 2.3 secs CPU, 1.2 secs duration Query B is using parallelism: CPU > duration eg the query uses 2 CPUs, average 1.15 secs each Query A is probably not: CPU < duration This explains cost relative to batch: … Read more

SQL providerName in web.config

System.Data.SqlClient is the .NET Framework Data Provider for SQL Server. ie .NET library for SQL Server. I don’t know where providerName=SqlServer comes from. Could you be getting this confused with the provider keyword in your connection string? (I know I was 🙂 ) In the web.config you should have the System.Data.SqlClient as the value of … Read more

The tail of the log for the database “DBName” has not been backed up

The error message you are getting tells you exactly what you need to do if you don’t care about the existing database or log. RESTORE DATABASE DAtabaseName FROM DISK = ‘C:\DBName-Full Database Backup’ WITH REPLACE In SQL Server Management Studio (Tasks > Restore), you can add the WITH REPLACE option by opening the page “Options” … Read more

“Adaptive Server is unavailable or does not exist” error connecting to SQL Server from PHP

1. See information about the SQL server tsql -LH SERVER_IP_ADDRESS locale is “C” locale charset is “646” ServerName TITAN InstanceName MSSQLSERVER IsClustered No Version 8.00.194 tcp 1433 np \\TITAN\pipe\sql\query 2. Set your freetds.conf tsql -C freetds.conf directory: /usr/local/etc [TITAN] host = SERVER_IP_ADDRESS port = 1433 tds version = 7.2 3 Try tsql -S TITAN -U … Read more

IF EXISTS, THEN SELECT ELSE INSERT AND THEN SELECT

You need to do this in transaction to ensure two simultaneous clients won’t insert same fieldValue twice: SET TRANSACTION ISOLATION LEVEL SERIALIZABLE BEGIN TRANSACTION DECLARE @id AS INT SELECT @id = tableId FROM table WHERE fieldValue=@newValue IF @id IS NULL BEGIN INSERT INTO table (fieldValue) VALUES (@newValue) SELECT @id = SCOPE_IDENTITY() END SELECT @id COMMIT … Read more

How can I force a query to not use a index on a given table?

SELECT * FROM MyTable WITH (INDEX(0)) WHERE MyIndexedColumn = 0 Query would normally use the index on MyIndexedColumn, but due to the table hint, it will instead tablescan. SELECT * FROM MyTable WITH (INDEX(IndexName)) WHERE MyIndexedColumn = 0 Query would normally use the index on MyIndexedColumn, but due to the table hint, it will instead … Read more

Sql Server 2005 how to change dbo login name

I figured it out. Within SQL Management Studio you have to right-click on the database -> Properties -> Files -> Owner field. Change this field to the login name/account that you want associated with the “dbo” username for that database. Please keep in mind that the login name/account you choose must already be setup in … Read more

Nested stored procedures containing TRY CATCH ROLLBACK pattern?

This is our template (error logging removed) This is designed to handle Paul Randal’s article “No such thing as a nested transaction in SQL Server” Error 266 Trigger Rollbacks Explanations: all TXN begin and commit/rollbacks must be paired so that @@TRANCOUNT is the same on entry and exit mismatches of @@TRANCOUNT cause error 266 because … Read more