database

Foreign key on table A --> B, AND foreign key on table B --> A. How is this done?

Hi, I have two tables - 'business' and 'business_contacts'. The business_contact table has a many-to-one relationship with the business table. Furthermore, each business has a 'primary contact' field - which I'd assume is a one-to-many relationship with the business_contacts table. The problem, of course, is that this creates a catch-...

Optimal size for Database partitions

Hi all, I am creating a very simple, very large Postgresql database. The database will have around 10 billion rows, which means I am looking at partitioning it into several tables. However, I can't find any information on how many partitions we should break it into. I don't know what type of queries to expect as of yet, so it won't be ...

NHibernate query with Projections.Cast to DateTime

I'm experimenting with using a string for storing different kind of data types in a database. When I do queries I need to cast the strings to the right type in the query itself. I'm using .Net with NHibernate, and was glad to learn that there exists functionality for this. For the example I'm using this simple class: public class Foo...

MySQL ORDER BY rand(), name ASC

I would like to take a database of say, 1000 users and select 20 random ones (ORDER BY rand(),LIMIT 20) then order the resulting set by the names. I came up with the following query which is not working like I hoped. SELECT * FROM users WHERE 1 ORDER BY rand(), name ASC LIMIT 20 ...

Solving the problem of finding parts which work well with each other

Hi, I have a database of items. They are for cars and similar parts (eg cam/pistons) work better than others in different combinations (eg one product will work well with another, while another combination of 2 parts may not). There are so many possible permutations, what solutions apply to this problem? So far, I feel that these are ...

Convert dependencies to point to View instead of Table

I currently have a SQL Server 2008 database in which I am planning to separate out some tables to other databases. I want to be able to replace all references to the separated tables from the original database using views. Is there a better way (other than manually changing all FK and SProc references) to switch all the dependencies to...

Doctrine + SQL Server Stored Procedures.

How can I call a stored procedure using Doctrine? ...

PHP 5.2 Function needed for GENERIC sorting of a recordset array

Somebody must have come up with a solution for this by now. We are using PHP 5.2. (Don't ask me why.) I wrote a PHP class to display a recordset as an HTML table/datagrid, and I wish to expand it so that we can sort the datagrid by whichever column the user selects. In the below example data, we may need to sort the recordset array by Na...

SQL Server stored procedure meaning

Hi. I'm developing a simple database architecture in VisualParadigm and lately ran over next code excerpt. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'getType') AND type in (N'P', N'PC')) DROP PROCEDURE getType; Next goes my stored procedure: CREATE PROCEDURE getType @typeId int AS SELECT * FROM type t WHERE ...

MySQL: Data query from multiple tables with views

I want to create a query result page for a simple search, and i don't know , should i use views in my db, would it be better if i would write a query into my code with the same syntax like i would create my view. What is the better solution for merging 7 tables, when i want to build a search module for my site witch has lots of users an...

Django forms I cannot save picture file

i have the model: class OpenCv(models.Model): created_by = models.ForeignKey(User, blank=True) first_name = models.CharField(('first name'), max_length=30, blank=True) last_name = models.CharField(('last name'), max_length=30, blank=True) url = models.URLField(verify_exists=True) picture = models.ImageField(help_text...

Simple check for SELECT query empty result

Hi. Can anyone point out how to check if a select query returns non empty result set? For example I have next query: SELECT * FROM service s WHERE s.service_id = ?; Should I do something like next: ISNULL(SELECT * FROM service s WHERE s.service_id = ?) to test if result set is not empty? ...

Spring - How to insert a nested bean using a SimpleJdbcDaoSupport class

I have two beans (POJOs) - a Customer and an address class defined like this: public class Customer { private String name = null; private Address address = null; public Customer() { address = new Address(); } public String getName() { return name; } public void setName(name) { this.name = name; } //addit...

Looking for a good course/book/resource on modern databases

This is slightly embarrassing. I'm a professional developer working at one of the big tech companies and I've never used a database. I've got an idea for a website I want to build as a learning experience and possibly as a business, but I don't have the faintest idea what database to use, let alone how to fix/debug the database when I ru...

How do Relational Databases Work Under the Hood?

I've always been interested in how you can throw some SQL at at database, and it nearly instantaneously returns your results in an orderly manner without thinking about it as anything other than a black box. What is really going on? I'm pretty sure it has something to do with how values are laid out regularly in memory, similar to an a...

Secure database connection. DAL .net architecture best practice

We have several applications that are installed in several departments that interact with database via Intranet. Users tend to use weak passwords or store login/password written on a sheets of paper where everybody can see them. I'm worried about login/password leakage & want to minimize consequences. Minimizing database-server attack s...

Populate Android Database From CSV file?

Is it possible to take a csv file stored in the res/raw resource directory and use it to populate a table in the sqlite3 database? My thought was that, if there was a way to do a bulk import for the entire file into the table then that would be cleaner and faster than iterating over each line in the file and executing individual insert ...

Sync database from desktop system to remote server and vice versa?

I make a application, which has to interfaces. one is desktop and other is web application. both have their own databases (which are same is structure). I want to sync the database from desktop to remote server and also from remote server to desktop but i have no idea that how it does. I use the MYSql database. and my desktop applicati...

How sync the MYSQL database to remote server and from remote to desktop server

I make a application, which has to interfaces. one is desktop and other is web application. both have their own databases (which are same is structure). I want to sync the database from desktop to remote server and also from remote server to desktop but i have no idea that how it does. I use the MYSql database. and my desktop applicati...

database vs flat file, which is a faster structure for "regex" matching with many simultaneous requests

Hi, which structure returns faster result and/or less taxing on the host server, flat file or database (mysql)? Assume many users (100 users) are simultaneously query the file/db. Searches involve pattern matching against a static file/db. File has 50,000 unique lines (same data type). There could be many matches. There is no writing to...