relational-database

MySQL: Two n:1 relations, but not both at once

泄露秘密 提交于 2019-12-01 05:45:21
Sorry for the title, it's difficult to explain. I need a data model similar to this: As you can see, a set can belong to both a user or a school. My problem: It should only be allowed to belong either to a user OR a school. But never both at the same time. How can I solve this problem? Your current design is called exclusive arcs where the sets table has two foreign keys, and needs exactly one of them to be non-null. This is one way to implement polymorphic associations, since a given foreign key can reference only one target table. Another solution is to make a common "supertable" that both

Does Google BigQuery/ Amazon Redshift use column-based relational database or NoSQL database?

寵の児 提交于 2019-12-01 04:57:06
I'm still not very clear about the difference between a column-based relational database vs. column-based NoSQL database. Google BigQuery enables SQL-like query so how can it be NoSQL? Column-based relational database I know of are InfoBright, Vertica and Sybase IQ. Column-based NoSQL database I know of are Cassandra and HBase. The following article about Redshift starts with saying "NoSQL" but ends with PostgreSQL (which is relational) being used: http://nosqlguide.com/column-store/intro-to-amazon-redshift-a-columnar-nosql-database/ A few things to clarify here mostly about Google BigQuery.

Is it bad to use redundant relationships?

自古美人都是妖i 提交于 2019-12-01 04:50:37
Suppose I have the following tables in my database: Now all my queries depend on Company table. Is it a bad practice to give every other table a (redundant) relationships to the Company table to simplify my sql queries? Edit 1: Background is a usage problem with a framework. See Django: limiting model data . Edit 2: No tuple would change his company. Edit 3: I don't write the mysql queries. I use a abstraction layer (django). It is bad practice because your redundant data has to be updated independently and therefore redundantly. A process that is fraught with potential for error. (Even

Difference between Relational Algebra and Relational calculus

孤街醉人 提交于 2019-12-01 04:44:36
What is the exact difference between relational algebra and relational calculus. At most of the reference, it will be Relational algebra is procedural and calculus is non procedural . So, what is these stands for. However, we can solve all the problems using relational algebra. Then why we would use relational calculus. Except definition, Explanation with example is much appreciated. TL;DR: Queries calling RA (relational algebra) operators & queries of the two relational calculi (RCs) TRC (tuple RC) & DRC (domain RC) are different syntax for the same thing: a relation value or the property

Find all sets which are a subset of a superset in SQL

吃可爱长大的小学妹 提交于 2019-12-01 04:15:09
问题 I'm pondering the design of an application where the main feature revolves around the ability to find the set of all sets which are subsets of a given set. For example, given the input set A={1,2,3...50} and the set of sets B={ B1={3,5,9,12}, B2={1,6,100,123,45} ... B500={8,67,450} }, return all Bs which are a subset of A. I guess it's similar to a search engine, except that I don't really have the luxury of set A being small and the Bs being large; in my case Bs are usually smaller than A. I

Dynamic column names in view (Postgres)

做~自己de王妃 提交于 2019-12-01 02:15:12
I am currently programming an SQL view which should provide a count of a populated field for a particular month. This is how I would like the view to be constructed: Country | (Current Month - 12) Eg Feb 2011 | (Current Month - 11) | (Current Month - 10) ----------|----------------------------------|----------------------|--------------------- UK | 10 | 11 | 23 The number under the month should be a count of all populated fields for a particular country. The field is named eldate and is a date (cast as a char) of format 10-12-2011. I want the count to only count dates which match the month. So

Is it bad to use redundant relationships?

不羁岁月 提交于 2019-12-01 01:37:20
问题 Suppose I have the following tables in my database: Now all my queries depend on Company table. Is it a bad practice to give every other table a (redundant) relationships to the Company table to simplify my sql queries? Edit 1: Background is a usage problem with a framework. See Django: limiting model data. Edit 2: No tuple would change his company. Edit 3: I don't write the mysql queries. I use a abstraction layer (django). 回答1: It is bad practice because your redundant data has to be

Does Google BigQuery/ Amazon Redshift use column-based relational database or NoSQL database?

梦想与她 提交于 2019-12-01 01:35:22
问题 I'm still not very clear about the difference between a column-based relational database vs. column-based NoSQL database. Google BigQuery enables SQL-like query so how can it be NoSQL? Column-based relational database I know of are InfoBright, Vertica and Sybase IQ. Column-based NoSQL database I know of are Cassandra and HBase. The following article about Redshift starts with saying "NoSQL" but ends with PostgreSQL (which is relational) being used: http://nosqlguide.com/column-store/intro-to

How to relate 3 tables depending on event

假装没事ソ 提交于 2019-12-01 01:16:36
I have a table that have information about different types of events that can be done by persons in two categories civil and worker so for each one of them I have their respective tables civil{ civil_id, name, age,telephone...} the primary key is civil_id worker{ worker_id, name, duty, department...} the primary key is worker_id then the event table has a list of all possible events event {type_of_event} the primary key is type_of_event then I am planing to store information in other table with eventype, the person that did the job (worker or civil) id event_type date person ------------------

Relational database design - “cyclic” graphs

放肆的年华 提交于 2019-12-01 01:07:11
In relational database design, should one worry about one (or more) "cyclic graphs" posing problems? (Simplified) E.g., tables T1( T1_Id , ...) T2( T2_Id , T1_Id_Fk, ...) T3( T1_Id_Fk, T2_Id_Fk , ..) Primary keys are bolded. Rows in T1 have a double role. A T1 row r1 can be in relationship T3 with a row r2 in T2, but it can also be a parent row for a (possibly the same) row r2' in T2. These two relationships are orthogonal. I came up with something like this: T1_Base( T1_Id , ...) T1_Child1( T1_C1_Id , ...) T1_Child2( T1_C2_Id , ...) T2( T2_Id , T1_C1_Id_Fk, ...) T3( T1_C2_Id_Fk, T2_Id_Fk , ..