relational-database

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

跟風遠走 提交于 2019-11-28 14:28:15
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 (Example questions: How is the quality of the Product , how is the value of the Product , how user

The three schema of the database

人走茶凉 提交于 2019-11-28 13:35:13
问题 I have created a database in Access and right know i have to write a report. I know that the databasesystem has three forms of schemas: physical, conceptual and external. Does the following ER diagram (by using the method normalization ) belongs to the conceptual level?: Or does this belong to the conceptual level?(incl. ref integrity): As for the phisical schema, does this include the integrity rules? 回答1: The Three-level ANSI-SPARC Architecture aka three schema approach: An external schema

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

和自甴很熟 提交于 2019-11-28 12:26:59
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, where each row represents a logical UPDATE query. Then, when given a signal that the record is

relationships between 3 entities in ER diagram--is a ternary enough or are 2 binaries also needed?

一世执手 提交于 2019-11-28 12:25:48
I'm trying to draw an ER diagram for my project management software describing the following. It contains these entities: project - software projects tasks - software projects that can be broken into a number of tasks employees - employees that belong to this software And: A project can be divided into tasks. (Tasks can be created by the admin user, who can assign those tasks to selected projects. Here there is only assignment of tasks to projects, not assignment of employees to projects.) Employees can be assigned to projects. (An employee can be assigned to projects. Here there is only

Insert multiple rows in one table based on number in another table

青春壹個敷衍的年華 提交于 2019-11-28 12:24:19
I am creating a database for the first time using Postgres 9.3 on MacOSX. Let's say I have table A and B . Table A starts off as empty and Table B as filled. I would like the number of entries in column all_names in table B to equal the number for each names in table A like table B below. Thus names should contain each unique entry from all_names and number its count. I am not used to the syntax yet so I do not really know how to go about it. The birthday column is redundant. A names | number -------+------------ Carl | 3 Bill | 4 Jen | 2 B all_names | birthday -------+------------ Carl | 17

Database changes for products in woocommerce 3

醉酒当歌 提交于 2019-11-28 11:48:34
Woocommerce v2.6 stores the following meta_key values in the wp_postmeta table: _sku _price _regular_price _sale_price _manage_stock _stock_status _featured Does Woocommerce v3.x, still store are all of the above in an identical manner as v2.6 or have any of the above been relocated to another table and/or modified in any way? In WooCommerce 3+ everything listed is the same, except for _featured that doesn't work any more. The " feature " product functionality in WooCommerce 3+: Since version 3, WooCommerce generates a featured term (name and slug) located in wp_terms table, which custom

Entity Framework database mapping relationships (Duplicate creation using Seed() method)

≡放荡痞女 提交于 2019-11-28 11:22:05
问题 I created a post with an issue and another issue. These can be looked at for references but i consider them as handled. My question arising from these issues and the action i (need or not need) to apply bothers me because i don't quite understand EF its behavior and expectations. I have a Product, PurchasePrice and SalesPrice entity where my initial thought was that 1 Product can have multiple PurchasePrices but that 1 PurchasePrice only can exist in 1 Product (same for SalesPrice). Therefore

What is the performance difference in MySQL relational division (IN AND instead of IN OR) implementations?

落花浮王杯 提交于 2019-11-28 11:12:40
问题 Because MySQL does not have a built in relational division operator, programmers must implement their own. There are two leading examples of implementations which can be found in this answer here. For posterity I'll list them below: Using GROUP BY/HAVING SELECT t.documentid FROM TABLE t WHERE t.termid IN (1,2,3) GROUP BY t.documentid HAVING COUNT(DISINCT t.termid) = 3 The caveat is that you have to use HAVING COUNT(DISTINCT because duplicates of termid being 2 for the same documentid would be

What's the point of a candidate key?

天大地大妈咪最大 提交于 2019-11-28 09:06:33
I'm fairly new to database management and this question never seems to be answered in more than one sentence. All other SO answers say "A candidate key is a minimal super key." That means nothing to me. A candidate key is supposed to specify uniqueness of a db record, correct? And a primary key is a candidate key. If a primary key already specifies uniqueness, what's point of adding more candidate keys? I have seen example records like the following: Employee(ID, Name, PhoneNumber) where ID is the primary key and PhoneNumber is a candidate key. From what I see, the ID is enough to specify the

Difference between using REFERENCES with and without FOREIGN KEY?

☆樱花仙子☆ 提交于 2019-11-28 07:37:10
Basically I'd like to know the difference between using REFERENCES with or without a foreign key. I have these 2 examples: CREATE TABLE Employee ( id INT, name VARCHAR(50), birthYear INT, boss INT REFERENCES Employees(id), worksAt INT NOT NULL REFERENCES Department(id) ON DELETE CASCADE, PRIMARY KEY (id,worksAt) ); Example 2: CREATE TABLE Department ( id INT PRIMARY KEY, name VARCHAR(50), numberOfEmployees INT, location INT NOT NULL, country INT NOT NULL, manager INT, FOREIGN KEY (location,country) REFERENCES Location(locId,countryId), UNIQUE KEY (manager) ); What I'm asking here is why does