relational-database

Advice on design relations between tables

邮差的信 提交于 2019-12-01 12:24:11
I have information about music albums that I want to organise in RDBMS tables with relations between them. I have the following info for each album: artist, album name, year, label, genre, style, rating. So far I think to make 4 tables - artists, albums (name, year, label, rating), genre1 and genre2 (each genre with its styles). On the diagram it looks as follows: But don't know yet how can I establish a connection between albums and the other three tables? I.e., when I will run a query select name from artists I would like to receive an album with corresponding artist and genre-style. How

Can all SQL queries be represented in Relational Algebra, Domain and Tuple relational calculus

旧时模样 提交于 2019-12-01 11:54:21
问题 My query includes a having and count or all in. How are these represented in RA/DRC/TRC? Would I have to simplify my SQL query even more? Here is a simplified example: empl(employee (primary key), city) managers(employee (primary key), manager (foreign key of employee)) If I were to find all the employees who are managers (from any city) of ALL the employees in city X.. I would need to use having/count. Not sure how this would be done in RA/DRC/TRC. I know the need for such a query might not

Can all SQL queries be represented in Relational Algebra, Domain and Tuple relational calculus

帅比萌擦擦* 提交于 2019-12-01 11:49:36
My query includes a having and count or all in. How are these represented in RA/DRC/TRC? Would I have to simplify my SQL query even more? Here is a simplified example: empl(employee (primary key), city) managers(employee (primary key), manager (foreign key of employee)) If I were to find all the employees who are managers (from any city) of ALL the employees in city X.. I would need to use having/count. Not sure how this would be done in RA/DRC/TRC. I know the need for such a query might not make sense but assume it is sensible for the purpose of this question. Thanks Your query was stated a

MySQL wrong results with GROUP BY and ORDER BY

假如想象 提交于 2019-12-01 11:41:57
问题 I have a table user_comission_configuration_history and I need to select the last Comissions configuration from a user_id . Tuples: I'm trying with many queries, but, the results are wrong. My last SQL: SELECT * FROM( SELECT * FROM user_comission_configuration_history ORDER BY on_date DESC ) AS ordered_history WHERE user_id = 408002 GROUP BY comission_id The result of above query is: But, the correct result is: id user_id comission_id value type on_date 24 408002 12 0,01 PERCENTUAL 2014-07-23

Should junction tables have more than one primary keys from another indentifying table?

扶醉桌前 提交于 2019-12-01 11:20:38
Here's an exmaple: Originally I have 3 tables. Table B references Table A. So now Table B has two primary keys. One used as the original primary key and the other one to enforce its relationship with Tabe A. Then I want Table B to have a many-to-many relationship with Table X. As I'm adding the relationship, MySQL Workbench added Table Y with both of Table B primary keys and one primary key in Table X. So Table Y now has three primary keys. It seems like the second primary key from Table B in the junction table is unnecessary since I can identify Table B with the original primary key. So do I

What is the difference between theta join and inner join?

拈花ヽ惹草 提交于 2019-12-01 10:14:36
问题 theta join and inner join look identical to me: they are Cartesian product followed by an arbitrary selection. Or am I missing their differences? Thanks. The above wikipedia link says a theta-join takes a comparison & two attributes. But that is not correct. Instead, a theta-join can take any selection condition. From Database System Concept which is supposed to follow the SQL standard and more coherent and reliable than wikipedia: The theta join operation is a variant of the natural-join

Are multiple foreign keys in a single field possible?

狂风中的少年 提交于 2019-12-01 09:38:35
I want to know if there is a way to have multiple values in a single field in a MySQL database where each value is a foreign key referencing one other table. I am designing a database with a product table and a product certification table. I am using InnoDB and foreign key constraints. The "product" table contains the details about specific instances of the product. One of the details contained in the product table is the column “product_certification_id”, which is a foreign key referencing an index in the two column “product_certification” table. The product certification table contains the

Should junction tables have more than one primary keys from another indentifying table?

痞子三分冷 提交于 2019-12-01 08:16:09
问题 Here's an exmaple: Originally I have 3 tables. Table B references Table A. So now Table B has two primary keys. One used as the original primary key and the other one to enforce its relationship with Tabe A. Then I want Table B to have a many-to-many relationship with Table X. As I'm adding the relationship, MySQL Workbench added Table Y with both of Table B primary keys and one primary key in Table X. So Table Y now has three primary keys. It seems like the second primary key from Table B in

Can good Object Orientated Design be formalised as good relational database design has been?

荒凉一梦 提交于 2019-12-01 06:30:22
In the database world, we have normalisation. You can start with a design, crank the steps and end up with a normal form of the database. This is done on the basis of the semantics of the data and can be thought of as a series of design refactorings. In object orientated design, we have the SOLID principals and various other adhoc guidelines towards good design. Do you think it is possible to define the equivalent of normal forms for OO, such that a series of refactoring steps could move a procedural piece of code (or poorly factored OO design) into a correct (in some well-defined sense)

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

眉间皱痕 提交于 2019-12-01 06:29:39
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 found a similar question here , but was wondering if there was anything more efficient / standard.