sql-server

Please can anyone why explain dropping and recreating stored procedures in SQL Server 2005 causes much more of an initial slow down than expected?

My first post here, please be gentle. =) I work for a company that inherited the maintenance of a bespoke system used by one of our customers. The previous developer (no longer with us) encrypted all the database objects (WITH ENCRYPTION). The system has been plagued with various timeout issues well before we took ownership of it, and ...

LLBLGen Cascading Delete?

Is there any easy way to do what seems best described as a "Cascading Delete" in LLBLGen? An example of what I'm looking for: You've got these tables: Customer: -Id Order: -Id -CustomerId OrderDetail: -Id -OrderId Now, I want to delete a specific Customer and all the things that depend on it (all its orders, and all its orde...

How to: Manage multiple overlapping indexes in SQL Server 2005

For the sake of example, I have a table with columns A B C D E F G H. I have created two indexes on the table that correspond to the most used queries. The first is on columns B C D and E. The second is on B C D E and F. The queries that use these columns are called the same number of times and they are each optimized with respect to...

Automapping SQL Server timestamp columns to byte[] using Fluent nHibernate

I am starting to use Fluent nHibernate on a project and am trying to get the automapping to work. At the time I am stuck with the mapping of our database's timestamp fields into byte-arrays. We are using SQL Server 2008 as the database, and we are not generating the database from code. What I have: public class Entity { publi...

C# Adding an array to SQL CE database

This may be to general of a question, and I apologize if it is. I'm trying to add data from an array to a SQL CE database. The array is 30 columns by up to 360 rows. I've found samples of different ways to do it, but are all inefficient on an array of the size I'm working with as they require each element of the array to be added individ...

.NET database calls slow when using COM Interop, fast via query analyser

I have an Sql query that looks up a person based on SSN and returns the PersonID (identity column). There is a index on the SSN column in the persons table. I have an old VB 6 application that uses COM/.NET interop to call this query. When it does it runs relatively slow. I set up a trace using SQL Profiler and each call has a duration ...

Why are my spatial searches slower in SQL Server than PostGIS?

I'm working on moving some spatial searching capabilities from Postgres with PostGIS to SQL Server and I'm seeing some pretty terrible performance, even with indexes. My data is around a million points, and I want to find out which of those points are within given shapes, so the query looks something like this: DECLARE @Shape GEOMETRY ...

Select one row from a range of rows in SQL Server

Hi all, I've come across a very interesting problem.. quite lost actually. Suppose I have a table with range of values, like: id.........From........To 1..........0...........5 2..........6...........10 3..........11...........15 4..........16...........29 So now I have an integer say @MyInt = 8, I want to select that single row in w...

How to check if a list have any different value

Hello, I have a table like the following: (date1, date2, date3, date4, date5) and I want to check if ANY of these dates is different than any other. The trivial solution is: WHERE date1 <> date2 OR date1 <> date3 OR date1 <> date4 OR date1 <> date5 OR date2 <> date3 OR date2 <> date4 OR date2 <> date5 OR date3 <>...

Fluent Nhibernate with SQL Compact: Schema Issue

Good evening people, I have been using Fluent Nhibernate for a while, I've never really dug too deep into its functionality or the many ways it can be configured. In every project I have used it in I have configure it as follows: if (nhConfig == null) { nhConfig = new NHibernate.Cfg.Configuration(); ...

How to fix this stored procedure problem.

Hi I have 2 tables. The following are just a stripped down version of these tables. TableA Id <pk> incrementing Name varchar(50) TableB TableAId <pk> non incrementing Name varchar(50) Now these tables have a relationship to each other. Scenario User 1 comes to my site and does some actions(in this case adds rows to Table A). So I...

Automatic retry of failed connection in NHibernate

Is there a way to ask NHibernate to automatically retry failed connections to a database? Specifically, if my network connection is too unreliable, sometimes NH will fail to connect to my remote SQL Server. ...

SQL server retrieve table rows based on a single column that contains special/garbage characters

Hi, I have a InsuranceDetails SQL table, one of the column is VIN whose type is varchar(20). Ideally this column should contain only Alphanumeric values (Upper case and lower case allowed) as you might know about a typical VIN number. For some reason this field gets some garbage values during insert. I need to write a query that will g...

IsNull() on bigint's min value?

Why does the following expression in SQL Server return -9223372036854775808 and not 123? I am calling this from a stored proc where I can't pass null parameters declare @t bigint; set @t = -9223372036854775808; --min value for bigint / long select ISNULL(@t, 123) ...

Efficient Ad-hoc SQL OLAP Structure

Over the years I have read a lot of people's opinions on how to get better performance out of their SQL (Microsoft SQL Server, just so we are all on the same page...) queries. However, they all seem to be tightly tied to either a high-performance OLTP setup or a data warehouse OLAP setup (cubes-galore...). However, my situation today is ...

Suggestion for a tag cloud algorithm

Hi, I have a MSSQL 2005 table: [Companies]( [CompanyID] [int] IDENTITY(1,1) NOT NULL, [Title] [nvarchar](128), [Description] [nvarchar](256), [Keywords] [nvarchar](256) ) I want to generate a tag cloud for this companies. But I've saved all keywords in one column separated by commas. Any suggestions for how to generate...

TSQL, case, convert, replace end.

Need help understanding what I am doing with the syntax here, please help! I not only need to convert from float to decimal but I also need to override the original data being migrated to the same format and data (in this case) where necessary to match the newer data. ,CASE WHEN fInvReqMargin IS NOT NULL THEN (CONVERT(DECIM...

SQL Server 2008 - Stored Procedure Gets Stuck When Called From WPF Service Using a SqlDataAdapter

This has me pulling my hair out. We have a workflow, hosted as a WCF service, which makes a call to another WCF service which then calls a stored procedure. Store procedure calls a merge, then iterates through a cursor that calls another sproc. The cursor count is the same as the source count in the merge. If the source count is high...

SQL non-clustered index

I have a table that maps a user's permissions to a given object. So, it is essentially a join table to 3 different tables. (Object, User, and Permission) The values of each row will always be unique for all 3 columns, but not any 2. I need to create a non-clustered index. I want to put the index on the foreign keys to the object and u...

SQL Server connection arbitrarily returns 233 or 18456 error codes

While trying to test an invalid connection string against a SQL Server 2008 Express instance, I found this weird behavior: specifying an invalid Initial Catalog raises an SQLException whose Number is sometimes 233, and sometimes 18456. Code may illustrate it better. // The following connection string has a purposely incorrect initial c...