relational-database

How do I remove redundancy from this database layout's 1:M relationship and still be able to excerpt the data needed?

邮差的信 提交于 2019-12-11 19:36:39
问题 The database looks like this: CREATE TABLE artists ( artist_id SERIAL PRIMARY KEY, artist TEXT UNIQUE NOT NULL ); CREATE TABLE artistalias ( artistalias_id SERIAL PRIMARY KEY, artist_id SERIAL REFERENCES artists (artist_id), alias TEXT UNIQUE NOT NULL ); CREATE TABLE songs ( song_id SERIAL PRIMARY KEY, song TEXT NOT NULL, artist_id SERIAL REFERENCES artists (artist_id) ); one artist can have zero, one or many aliases one alias belongs to exactly one artist one song has one artist one artist

Relating two database tables (associating an employee with an activity)

此生再无相见时 提交于 2019-12-11 19:28:46
问题 I am trying to develop a database to store data collected by a web based application that tracks employee activities. I have an employee table that looks like this Employee -------- id name position email And and multiple activity tables, each with different columns. An example of one: OutreachAndTraining ----- id date county city type ... ProfessionalDevelopment ------ id date comments I want to be able to keep track of which employees were a part of each activity but only want to log the

How to make two relations between two tables?

佐手、 提交于 2019-12-11 19:17:58
问题 I have an Article that have a creator and a modifier from User table. Here is the model: public class Article { public int ArticleId { get; set; } public string Name { get; set; } public int UserId { get; set; } public int ModifierId { get; set; } public virtual User User { get; set; } public virtual User Modifier { get; set; } } And here is the User model: public class User { public int UserId { get; set; } public string Username { get; set; } public string Password { get; set; } public

Adding a sub query to an already giant query

只愿长相守 提交于 2019-12-11 19:16:45
问题 This question is kind of a follow up to this question I asked a month ago. Here are my three tables. Fighters fighter_id | name ----------------------- 1 | John 2 | Steve 3 | Bill 4 | Bobby Events event_id | event_name | event_date ------------------------------------------- 1 | MMA | 01/01/2010 2 | Cool | 02/20/2010 3 | Yeaa! | 04/15/2010 Fights fight_id | fighter_a | fighter_b | winner | method | event ----------------------------------------------------------------------- 1 | 1 | 2 | 1 |

Building the tables for an Auto-drop subscription system

我的未来我决定 提交于 2019-12-11 17:59:43
问题 I'm building a system that will auto-drop someone from one or more mailing lists, when they subscribe to another mailing list. I have a table 'lists' containing the list names. Each list will have one or more children in the form of 'exclusions', which are basically other lists. Here is my table: I'm wondering how best to achieve this. I originally thought of having another table called 'exclusions' linked via a lookup table with a many-to-many relationship, then I could grab all the

Creating relational database

若如初见. 提交于 2019-12-11 17:48:03
问题 E diagram which i need to turn into databse. I know my primary keys but do not really understand how to link the different tables together. So I have operator table with name as primary key. Each operator can operate certain proportion of those trains. e.g operator "a" 30 = 30% of those services and operator b 70% of those services 100 all of them etc... This is the part im stuck with. Do I need another table to link these two tables together ? for each train i need to store which station it

SQL database design for web internal exchange platform

。_饼干妹妹 提交于 2019-12-11 16:17:27
问题 I am working on a small web application that allows users to trade credit to each other. I would like to have your comments on my initial design (efficiency, flexibility, security etc.) In particular, a typical transaction happens as follow: User A can offer to do a job in exchange for X credits. Users B and C can accept the offer. A total of X credits will be subtracted from B and C's accounts. When the job is completed, X credits will be added to A's account. A can use earned credits to

Yii Framework : Help to translate relational Sql query

自作多情 提交于 2019-12-11 15:58:46
问题 I encountered a problem to write this query in a Yii model oriented style. I have a 3 main tables : questions, categories, countries and relational tables : questions_has_categories, questions_has_countries. Now i try to search questions that belongs to country, category. With normal SQL statement i write : SELECT q.id, q.question, c.name, co.name FROM questions AS q, categories AS c, countries AS co, questions_has_countries AS ta, questions_has_categories AS qhc WHERE q.id = qhc.questions_id

MySQL: Why is NULL ignored in MySQL?

醉酒当歌 提交于 2019-12-11 15:11:55
问题 I have a table with the following possible values for the column field_value. But when I try to select all values which are not 'CB', the query result also ignores all NULL values. Why does this happen? mysql> select distinct field_value from TableName; +--------------+ | field_value | +--------------+ | S | | NULL | | CA | | CB | +--------------+ 4 rows in set (6.32 sec) mysql> select distinct field_value from TableName where field_value!='CB'; +--------------+ | field_value | +-------------

How to keep data for existing records unchanged

亡梦爱人 提交于 2019-12-11 15:07:15
问题 Consider designing a database for the traffic department. There is a table for: violations, legalities, and drivers. In legalities table we have attributes for fine cost, clause number, explanation, reason, etc.... Now if we change the cost & clause number in future, I don't want this to affect the already existing records. But the tables violation and legalities are already in a relationship together, and hence this will change the old records if query for them. I gave a simple example to