relational-database

Can I use a counter in a database Many-to-Many field to reduce lookups?

偶尔善良 提交于 2019-12-29 01:59:10
问题 I am trying to figure out the fastest way to access data stored in a junction object. The example below is analagous to my problem, but with a different context, because the actual dataset I am dealing with is somewhat unintuitive in its relationships. We have 3 classes: User , Product , and Rating . User has a many-to-many relationship to Product with Rating as the junction/'through' class. The Rating object stores the answers to several questions which are integer ratings on a scale of 1-5

Difference between Relational Algebra and Relational calculus

血红的双手。 提交于 2019-12-29 01:37:15
问题 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. 回答1: TL;DR: Queries calling RA (relational algebra) operators & queries of the two relational calculi (RCs)

Difference between Relational Algebra and Relational calculus

旧巷老猫 提交于 2019-12-29 01:35:53
问题 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. 回答1: TL;DR: Queries calling RA (relational algebra) operators & queries of the two relational calculi (RCs)

How to perform the same aggregation on every column, without listing the columns?

天大地大妈咪最大 提交于 2019-12-29 00:25:07
问题 I have a table with N columns. Let's call them c1 , c2 , c3 , c4 , ... cN . Among multiple rows, I want to get a single row with COUNT DISTINCT(cX) for each X in [1, N]. c1 | c2 | ... | cn 0 | 4 | ... | 1 Is there a way I can do this (in a stored procedure) without writing every column name into the query manually? Why? We've had a problem where bugs in application servers mean we rewrite good column values with garbage inserted later. To solve this, I'm storing the information log-structure,

What is the difference between Views and Materialized Views in Oracle?

核能气质少年 提交于 2019-12-28 03:15:30
问题 What is the difference between Views and Materialized Views in Oracle? 回答1: Materialized views are disk based and are updated periodically based upon the query definition. Views are virtual only and run the query definition each time they are accessed. 回答2: Views They evaluate the data in the tables underlying the view definition at the time the view is queried . It is a logical view of your tables, with no data stored anywhere else. The upside of a view is that it will always return the

Does an empty SQL table have a superkey? Does every SQL table?

本秂侑毒 提交于 2019-12-28 02:16:13
问题 I know what the term "SuperKey" in SQL stands for, but I cannot understand a specific thing and I would like some help. In a table with no data , is there a superkey? In any table, will there always exists one? 回答1: TL;DR "Superkey" is a RM (Relational Model of Data) term. There's no standard use in SQL. The superkeys of an SQL table might reasonably informally be said to be the column sets that you could declare primary key or unique not null , plus maybe {} when a table holds at most one

Table VS xml / json / yaml - table requires less storage if data is any related? more efficient than compression

无人久伴 提交于 2019-12-25 18:48:12
问题 To add a field to a XML object it takes the length of the fieldname + 3 characters (or 7 when nested) and for JSON 4 (or 6 when nested) <xml>xml</xml> xml="xml" {"json":json,} "json": json, Assume the average is 4 and fieldname average is 11 - to justify the use of XML/JSON over a table in use of storage, each field must in average only appear in less than 1/15 of objects, in other words there must be ~15 times more different fields within the whole related group of objects, than one object

Rails database setup Polymorphism

我只是一个虾纸丫 提交于 2019-12-25 18:28:39
问题 We have to create a request system which will have roughly 10 different types of requests. All of these requests will belong to the 'accounting' aspect of our application. Therefore we've called them "Accounting requests". All requests share maybe only a few columns and each has up to 20 columns individually. We started to wonder if having separate tables for each request type would be practical in terms of speed when we start to have to do very complicated joins or queries, for example,

Why does the m: n relationship in the DB design have to create a new relation?

梦想的初衷 提交于 2019-12-25 17:45:26
问题 I recently learned about DB design. However, in the m: n relation, we need to create a new relation. I do not understand this reason well. I also wonder why I place a foreign key in n relations instead of 1 when I have a 1: n relationship. 回答1: Originally, Chen's method for mapping the entity-relationship model to the relational model prescribed that every relationship map to a separate relation (table). However, it's become common practice to denormalize one-to-one and one-to-many

MySQL foreign key using more than one field to reference to a primary key from another table

旧巷老猫 提交于 2019-12-25 17:45:03
问题 I want to reference 2 of my columns in one table to a primary key from another table. Here is how it looks like in the db structure: Users uid (INT) name (VARCHAR) 1 John Doe 2 Jane Doe SystemProcesses uid (INT) name (VARCHAR) 1 Hitman 2 Cron Logs uid (INT) modelType (VARCHAR) modelUID (INT) Action 1 Users 2 Jane Doe did this 2 Users 1 John Doe did that 3 SystemProcesses 1 Hitman just killed John Doe How do I reference modelType and modelUID in Logs table to those Users and SystemProcesses?