database

NULL vs Empty when dealing with user input

Yes, another NULL vs empty string question. I agree with the idea that NULL means not set, while empty string means "a value that is empty". Here's my problem: If the default value for a column is NULL, how do I allow the user to enter that NULL. Let's say a new user is created on a system. There is a first and last name field; last na...

What is the best practices in database design when I want to store a value that is either selected from a dropdown list or entered by the user if not found in the dropdown list?

I am trying to find the best way to design the database in order to allow the following scenario: The user is presented with a dropdown list of Universities (for example) The user selects his/her university from the list if it exists If the university does not exist, he should enter his own university in a text box (sort of like Other:...

Fetch two next and two previous entries in a single SQL query

Hi, I want to display an image gallery, and on the view page, one should be able to have a look at a bunch of thumbnails: the current picture, wrapped with the two previous entries and the two next ones. The problem of fetching two next/prev is that I can't (unless I'm mistaken) select something like MAX(id) WHERE idxx. Any idea? no...

What are the limitations to SQL Server Compact? (Or - how does one choose a database to use on MS platforms?)

The application I want to build using MS Visual C# Express (I'm willing to upgrade to Standard if that becomes required) that needs a database. I was all psyched about the SQL Server Compact - because I don't want the folks who would be installing my application on their computers to have to install the whole of SQL Server or something ...

How to test for multiple row actions in a SQL Server trigger?

My kindergarten SQL Server taught me that a trigger may be fired with multiple rows in the inserted and deleted pseudo tables. I mostly write my trigger code with this in mind, often resulting in some cursor based cludge. Now I'm really only able to test them firing for a single row at a time. How can I generate a multirow trigger and wi...

Reference counting in PHP

I'd like to implement database caching functionality in PHP based on reference counts. For example, code to access the record in table foo with an ID of 1 might look like: $fooRecord = $fooTable->getRecord(1); The first time this is called, $fooTable fetches the appropriate record from the database, stores it in an internal cache, an...

Anyone know of a decent free DB schema reverse engineering tool?

Looking for a tool that will automatically create a graphical representation of a MySQL DB schema from a live database, showing tables, columns, and relationships (an ER diagram). Ideally something that would run on OS X would be great but I'll take what I can get and run it on a different machine if necessary. I checked Google and del....

What is the best way to do Incremental backups in Mysql ?

We are using MySql version 5.0 and most of the tables are INNODB. We run replication to a slave server. We are thinking of backup the MySql log files on a dally bases. QUESTIONS: • Is there any other way of doing an Incremental backup without using the log files? • What are the best practices when doing Incremental backups ? ...

Why is PostgreSQL eating up all my precious HD space?

Hi again, I just finished transferring as much link-structure data concerning wikipedia (English) as I could. Basically, I downloaded a bunch of SQL dumps from wikipedia's latest dump repository. Since I am using PostgreSQL instead of MySQL, I decided to load all these dumps into my db using pipeline shell commands. Anyway, one of thes...

Why is ActiveRecord issuing a separate query per join?

I'm doing an ActiveRecord find operation (via the "will_paginate" library) like this: contacts = Contact.paginate(:all, :conditions => conditions_specified, :select => "DISTINCT contacts.*", :joins => joins, :include => [:addresses, :emails, :phone_numbers, {:addresses => :organization}], :page => page, :per_pa...

Test User Data (Fake Data)

Does anyone know of a large formatted collection of fake user data (names, email address, locations, etc.) that can be used for testing an application? It can be clearly fake, this will be limited to the development server. But I'm sure anything would be better than what I could come up with. ...

Flex Matching Many Database Records (Quicksilver-like or Launchy-like matching)

Assume I have a database table with many names. I'd like to "flex match" against these names. I'm not sure if "flex match" is the proper term to use, but let's go with that for now. There have been similar discussions on "fuzzy matching," but I'm not really interested in phonetic matching. I'm interested in what I'd call ordered-subs...

How do you not do joins?

I've been reading a lot lately about how joins in DB queries slow things down. Evidently Google App Engine doesn't even allow them. I'm wondering how people design an app with no joins though. For example I'm working on an app that has contacts and organizations. A contact can be in many organizations and an organization can have many c...

Which open source database is the best option for an accounting-related system?

I am in the early stages of planning and designing a custom accounting application for my firm. My goal is to utilize an open source relational database for the data storage portion and I'm aware of two solid databases that are widely supported: MySQL and PostgreSQL. For a system that will require transactions, stored procedures, functi...

Google Gears - To what level is synchronization supported?

Hi All, I have a few questions about data synchronization. The architecture does not seem to be clear about this: Does Google Gears provide from automatic synchronization of data (from client to server and server to client)? If it does provide for automatic data synchronization, then can i write functions to hook into the sync mechani...

Automating the deployment of a CLR database project to the database

We have a CLR database project in VS08. Right now, everytime we do a build there are multiple manual steps that have to be performed in order to deploy this project as part of our build process. I ended up writing a utility that automates parts of this process. I am wondering if there are are better tools - or even devenv switch that I a...

How to manage hobby project database?

What would be the best way to manage the databases of hobby projects? Requirements: It should be as easy as possible. If it is hard, the project will stall. It should provide easy way to get testing copy to avoid doing development in production. It should provide reliable way to upgrade the production database schema to new version. I...

Linq vs. database views

Here’s an interesting question. Suppose we have related tables in the database, for example, Instrument and Currency. Instrument table has a currency_id field that is mapped to entry in Currency table. In Linq land what’s the better way: a) Create Instrument and Currency entities in the DataContext and then create association or simply ...

Best practices re sharing IDbConnection or connection string/factory in your .Net code

Hi guys, I'm wondering what would be the best prectice regarding mainataining connections to the database in .Net application (ADO.NET but I guess the practice should be the same for any data layer). Should I create a database connection and propagate it throughout my application, or would it be better to just pass connection strings/fac...

Selecting most recent date between two columns

If I have a table that (among other columns) has two DATETIME columns, how would I select the most recent date from those two columns. Example: ID Date1 Date2 1 1/1/2008 2/1/2008 2 2/1/2008 1/1/2008 3 1/10/2008 1/10/2008 If I wanted my results to look like ID MostRecentDate 1 2/1/2008 2 ...