Showing posts with label project. Show all posts
Showing posts with label project. Show all posts

Friday, March 30, 2012

Launch condition to detect SQL CE?

I have written a .NET application that uses SQL Server Compact Edition. It's deployed by a MSI file (setup project in VS - not ClickOnce).

How do I add a SQL CE launch condition to my setup project?

Never mind. I'm now using the bootstrapper and added the SQL CE requirement there.sql

Launch condition to detect SQL CE?

I have written a .NET application that uses SQL Server Compact Edition. It's deployed by a MSI file (setup project in VS - not ClickOnce).

How do I add a SQL CE launch condition to my setup project?

Never mind. I'm now using the bootstrapper and added the SQL CE requirement there.

Friday, March 9, 2012

Large updates and locks

Hi there,
I am looking over some code in a project I just joined and found
something that I am not sure about. The are processes which update or
delete many rows of data and the approach chosen to perform these
updates and deletes was through cursors. The setup looks something
like this:
Example:
DECLARE Orders CURSOR FOR select order_id from order where order_Date +
10 < getdate();
loop
begin
fetch orders into @.OrderId;
delete orderdetail where order_id = @.OrderId;
end;
Instead of:
delete orderdetail from orderdetail join orders where orders.order_date
+ 10 < getdate();
The motivation for it is that the locks will be more granular and other
processes will be able to access the tables instead of being locked out
for the duration of the process. The cursor approach is obviously
slower by few orders of magnitude to execute but that aside does this
approach make sense?
ThanksThis might make sense in some cases. Batching data modifications is a
common method of getting around locking issues. But whether it's necessary
or not is difficult to know based on the information you've given so far.
What percentage of the rows are being deleted each time? Is there an index
to support the deletion? Currently, your predicate (order_date + 10 <
getdate()) cannot use indexes, so the answer to the latter question is no.
You may have better luck with:
DELETE FROM orderdetail
WHERE EXISTS
(
SELECT *
FROM orders
WHERE orders.order_id = orderdetail.order_id
AND orders.order_date <= GETDATE() - 10
)
This will be able to take advantage of an index on the order_date column,
and therefore may perform better (and take more granular locks) than a
non-cursor approach using (order_date + 10).
Adam Machanic
SQL Server MVP
http://www.datamanipulation.net
--
"boblotz2001" <boblotz2001@.yahoo.com> wrote in message
news:1124715871.853196.33820@.g44g2000cwa.googlegroups.com...
> Hi there,
> I am looking over some code in a project I just joined and found
> something that I am not sure about. The are processes which update or
> delete many rows of data and the approach chosen to perform these
> updates and deletes was through cursors. The setup looks something
> like this:
> Example:
> DECLARE Orders CURSOR FOR select order_id from order where order_Date +
> 10 < getdate();
> loop
> begin
> fetch orders into @.OrderId;
> delete orderdetail where order_id = @.OrderId;
> end;
> Instead of:
> delete orderdetail from orderdetail join orders where orders.order_date
> + 10 < getdate();
> The motivation for it is that the locks will be more granular and other
> processes will be able to access the tables instead of being locked out
> for the duration of the process. The cursor approach is obviously
> slower by few orders of magnitude to execute but that aside does this
> approach make sense?
> Thanks
>

Monday, February 20, 2012

Large Keyword Search

I'm working on a project that will allow a user to search through approx 100,000 records in a SQL table. Three of the columns are 'text' fields that hold paragraphs of text. The user interface has a 'general search' option so that they can enter a number of key words and the database will return a count of the records found containing the keywords.

At the moment I split the input and then build a query based on their input. For instance if they enter 'hello world' the input is split into two strings 'hello' and 'world'. I then build the query in a loop and get a query like so:

Select Count(ID) as myCount FROM myTable WHERE (colOne like '%hello%' AND colOne like '%world%') OR (colTwo like '%hello%' AND colTwo like '%world%') OR (colThree like '%hello%' AND colThree like '%world%')

Unfortunately this query runs EXTREMELY slowly and just seems wrong. Is there a more efficient way I should be doing these types of searching? This method works ok on 100 records, but this is the first time I have worked on such a large database.

Is it also possible to search a text column and look for exact matches?

For instance I have 2 records with their textfield containing:

Rec 1: the news for today is blah blah.
Rec 1: this is a new item

If I currently search for 'new' (select colID from myTable where colOne like '%new%') I will get both these records, but I'd really only like to pull out the second record.

Any help would be great appreciated! :)

You could use Full Text and use Microsoft proprietry CONTAINS, FREETEXT and CONTAINSTABLE and FREETEXTTABLE. The former are predicate and the later are row functions. They are dependent on Full Text index which require the Microsoft Search Service to be populated. Hope this helps.

Sample

SELECT product_id, product_name, From products
WHERE FREETEXT (description, 'manage')

SELECT product_id, product_name, From products
WHERE CONTAINS (description, ' "config" ')

Kind regards,

Gift Peddie