relational-database

Normalize an Address

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 15:17:21
问题 I am trying to normalize an address. The diagram below shows the relevant tables for this question I believe. I want to know how ZipCodes should be integrated into the model. This would be for international addresses so I know that a Zip/PostalCode is not used everywhere. I think City::ZipCode is 1::0-n (I have read others saying this is not always the case but they never provided evidence). If they are correct then I guess this would be a many-to-many relationship. Since each Address can

Implementing table level check constraint

心已入冬 提交于 2019-12-07 13:32:36
问题 We have a table that contains prices that are depending on a base amount. As an example let say that if the base amount is less or equal to 100 then the price is 10 but if the base amount is greater that 100 but less or equal to 1000 then the price is 20 and finally if the base amount is greater than 1000 then the price is 30. A simplified version of our table for this should be something like this: PRICE_CODE START_RANGE END_RANGE PRICE_AMOUNT 100 0,00 100,00 10,00 100 100,01 1000,00 20,00

Why lucene doesn't require composite index, but relation database does?

点点圈 提交于 2019-12-07 13:10:25
问题 Lucene stores index for each field separetly. So when we perform query "fld1:a AND fld2:b" we iterate over Termdocs for first term and second term. This can't be faster. In case of database two separete indexes for fld1 and fld2 will work slow and only one will be used. In that case DB requres composite key for fld1 and fld2. My question is. Why Can't DB utilize Lucene index algorithm for executing Boolean queries if it as fast as DB index and dosn't requires different combinations of columns

Mysql order by on column with unicode characters

余生长醉 提交于 2019-12-07 12:23:08
问题 I am running a select query on mysql table and trying to order it by the "name" column in the table. The name column contains both English character names and names with Latin character like â. I am running into the below problem. The query I run returns the results ordered in the below manner i.e. Eg: if Name contains "archer", "aaakash", "â hayden", "bourne", "jason" The results returned by the query is ordered as below "aaakash", "archer", "â hayden", "bourne", "jason" However I want to

How to create multiple sequences in one table?

风格不统一 提交于 2019-12-07 08:57:02
问题 I have a table "receipts". I have columns customer_id (who had the receipt) and receipt_number. The receipt_number should start on 1 for each customer and be a sequence. This means that customer_id and receipt_number will be unique. How can I elegantly do this. Can I use the built-in sequeance functionality with CREATE SEQUENCE or similar? It seems like I would have to create a sequence for each customer, which of course is not an elegant solution. EDIT: There must be a thread-safe and idiot

Using Oracle database links without unreadable dynamic SQL

情到浓时终转凉″ 提交于 2019-12-07 08:54:58
问题 How can I write a neat PL/SQL stored procedure that can execute against a given database link? It gets really messy, writing stuff like this: PROCEDURE my_proc(aDbLink IN VARCHAR2) IS BEGIN EXECUTE IMMEDIATE ' SELECT mycolumn, anothercolumn FROM MYTABLE@' || aDbLink || ' WHERE such-and-such...' END as the query gets bigger. What else might I do? I'm stuck using stored procedures, and expect that my procedures will execute against one of several db links. 回答1: The simplest way to avoid using

Reasons for cascading soft deletes [closed]

僤鯓⒐⒋嵵緔 提交于 2019-12-07 08:32:12
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . In a relational database it seems quite common to use soft-deletes. My pondering comes to if it is really necessary to cascade these deletes? The reason I wonder is that it seems to me that cascading a soft delete wouldn't add any additional information. I.e. lets say we have a

CakePHP find list with related model conditions

若如初见. 提交于 2019-12-07 07:25:51
问题 I'm trying to get a list of IDs (a la find('list') ), but can't figure out how to do it with related model conditions. My associations are: Product hasAndBelongsToMany Category Product belongsTo Manufacturer I want to find a list of product IDs that are in a list of category IDs and have a certain manufacturer seo_url. I've tried tons of contains with conditions, conditions referencing other models, even tried using find('all') to see if my conditions would work, but couldn't get anything. I

Multiple toMany relationships to a single table

喜夏-厌秋 提交于 2019-12-07 06:26:00
问题 I'm new to greenDAO and I'm working on writing the DaoGenerator. One issue that I've run into is that I have a user table and a wallpost table. I would like to be able to have two columns in the wallpost table that are toMany relations to the user table (the wall owner and the posting user) they may or may not be the same user, but so far it doesn't look like it is possible to have two toMany relations that point to a single table in the same table. Is there a better way to do this/a way to

mysql one-to-many query with negation and/or multiple criteria

柔情痞子 提交于 2019-12-07 04:21:42
问题 I thought a query like this would be pretty easy because of the nature of relational databases but it seems to be giving me a fit. I also searched around but found nothing that really helped. Here's the situation: Let's say I have a simple relationship for products and product tags. This is a one-to-many relationship, so we could have the following: productid | tag ======================== 1 | Car 1 | Black 1 | Ford 2 | Car 2 | Red 2 | Ford 3 | Car 3 | Black 3 | Lexus 4 | Motorcycle 4 | Black