database-queries

How can I use check constraint in sql server 2005.

i want to check for a particular set of values. eg check columnname should be between 1 to 5 check columnname should be either 1 or 2 or 4 ...

Usng enum in drupal

I have a mysql table id,name,gender,age religion( enum('HIN','CHR','MUS') ,category(enum('IND','AMR','SPA') where last 2 are enum datatype and my code in drupal was $sql="SELECT * FROM {emp} WHERE age=".$age." and religion=".$rel." and category=".$categ; $result=db_query_range($sql,0,10); while($data=db_fetch_object($result)) ...

Join queries taking more execution time than their corresponding nested queries

Hello, I have 2 tables namely Person_Organization and Person_Organization_other and nested query is :- SELECT Person_Organization_id FROM Person_Organization_other WHERE company_name IN ( SELECT company_name from Person_Organization_other WHERE Person_Organization_id IN ( SELECT Person_Organization_Id FROM Person_O...

How to find the total number of SQL queries made by a django application?

Is there a way to find out how many SQL queries made by django app. when I try to load a page? What I like to do as I browse from page to page.. is to record the following in a text file... or see it in stdout. page url total queries total query execution time is there such tool/script? Cheers ...

Large Analytics Database Responsive Retrieval (MYSQL)

Hi Guys! I want to create a 'google analytics' type application for the web - i.e. a web-based tool to do some reporting and graphing for my database. The problem is that the database is HUGE, so I can't do the queries in real time because they will take too long and the tool will be unresponsive. How can I use a cron job to help me...

XQuery, fn:id and BD eXist

Does "fn:id" function return IDREFS when it is used in a FLOWER xquery with eXists database? I can't get any example... :( TIA ...

A database question for storing and computing with historical data.

I have an application that polls different bins at different times and computes the number of widgets in each bin based on the weight. Polling is done every few minutes and the result is timestamped and added to a MySQL table. The table contains the 3 columns below. The example shows 3 bins (A,B and C) but there could be anywhere from 1 ...

mySQL ORDER optimizing

I have a query in which I am ordering a league table by a number of fields to handle the situation that some fields in the result may have the same value. I am curious as to why when subsequent fields aren't required for secondary ordering the query is still conciderably slower. Case in point is a table of items that are voted on. It co...

ODBC iterate table without storing in memory

Hi, I need to have a way to iterate through a database table without actually storing it in memory anywhere. I want to essentially read through the rows like an input iterator. I've tried using cursors with a select statement (select * from table_name), but this retrieves the entire table and feeds it back to be one row at a time. So ...

database sort vs. programmatic java sort

hi, I want to get data from the database(MySQL) by JPA, I wand it sorted by some column value, So, what is the best practice, to: Retrieve the data from the database as list of objects (JPA), then sort it programmatically using some java APIs. OR Let the database sort it by using a sorting select query. ?? thanx in advance ...

EntityQuery.setRestrictions and Ejbql with parameters

Hello. It would be nice if anybody could show me how to use setRestrictions method whitch belongs to the EntityQuery object from the org.jboss.seam.framework.EntityQuery package. I have tried to use it this way: ... import org.jboss.seam.framework.EntityQuery; import org.jboss.seam.core.Expressions.ValueExpression; public class Lette...

Simple DB query on Google App Engine taking a lot of CPU time.

I'm fairly new to Google App Engine and Python, but I did just release my first real-world site with it. But now I'm getting problems with one path that is using significantly more CPU (and API CPU) time than the other paths. I've narrowed it down to a single datastore fetch that's causing the problem: Carvings.all().fetch(1000) Under t...

Displaying Scheduled Events

I had this problem some years ago and back then I implemented a "different logic" in order to deliver the project but the doubt remains in my mind and hopefully with your help I'll be able to understand it now. Suppose I have some scheduled events on my database that may or may not spawn over several days: id event start ...

Avoid SHOW FIELDS in ActiveRecord

Is there any way to prevent ActiveRecord from issued a SHOW FIELDS to the database when it's not needed? I'm working on database performance critical application, and just noticed that on a typical query my SELECT takes 0.5 ms and the related SHOW FIELDS takes 2 ms -- 4 times longer! Even more importantly, it's not needed because I'm al...

Setting the correct codepage for a database read operation

How can I change the codepage I want to use on an operation such as the one below? string foo = (string)sqlCommand.ExecuteScalar(); As I understand I can wrap the method call inside a String.Format(IFormatProvider, String). That would be grand. But how do I construct a IFormatProvider with a specific codepage so I can correctly read ...

How to perform INSERT/UPDATE to Linking (Join) table which has FKs to IDENTITY PKs

I am new to designing my own database. My project is orders/products/inventory type data, using SQL Server 2005. During my reading I came across several customer/order type of examples, and I decided to use linking-table (sometimes here called junction, or join table) for my Order_Details since I had many-to-many relationships between OR...

Django dynamic number of filter for a objects request

Hello How can I do something like this : products_list = Product.objects.all() for key in keywords: products_list = products_list.filter(name__icontains=q) This don't work. Thank you for your help ...

SQL Query Solution - Day By Day Balance

Hello, Every one. first of all, let me explain the table structure. It is as follows. Main Table - CategoryGroup Fields - CatGroupID, GroupName, GroupType Sample Data CatGroupID | GroupName | GroupType 1 | Utility | Expense 2 | Auto | Expense 3 | Misc. | Expense 4 ...

Hierarchical filtering in a relational database

I have a bunch of items in my program that all belong to a specific category. I'd like to return only the items that belong to that category. The problem is that categories can have parent categories. For example, let's say there's a category "Stuff" with the child category "Food" with the child category "Fruit". I have the items, Ap...

In mysql how do I find rows repeating with respect to all fields ?

+------------+------------+ | student | department | +------------+------------+ | 1234567890 | CS | | 1234567890 | ME | | 1234567890 | CS | | 000000001 | ME | +------------+------------+ How can I get rows that are repeating with respect to both fields? Thanks in advance. ...