relational-database

Normalisation into BCNF

大憨熊 提交于 2020-01-13 19:42:07
问题 I have a relation looks like: R = (X,Y,C,D) and functional dependencies: FD = {XY -> CD, YC -> D, D -> X} I found out that the candidate keys are XY, YC, YD. In this case, I have 3 candidate keys... so how do I use them when I decompose the relation into BCNF? I've never done decomposition of the relation with more than one key... Thanks. 回答1: Relation 1: (Y,C,D) Relation 2: (D,X) 回答2: @KeyM 1.Find out the FD that violates BCNF In this case its D->X 2.Decompose into two relations R1,R2 R1(D,X

Should I use EAV database design model or a lot of tables

末鹿安然 提交于 2020-01-12 10:14:11
问题 I started a new application and now I am looking at two paths and don't know which is good way to continue. I am building something like eCommerce site. I have a categories and subcategories . The problem is that there are different type of products on site and each has different properties . And site must be filterable by those product properties. This is my initial database design: Products{ProductId, Name, ProductCategoryId} ProductCategories{ProductCategoryId, Name, ParentId}

Should I use EAV database design model or a lot of tables

梦想与她 提交于 2020-01-12 10:08:26
问题 I started a new application and now I am looking at two paths and don't know which is good way to continue. I am building something like eCommerce site. I have a categories and subcategories . The problem is that there are different type of products on site and each has different properties . And site must be filterable by those product properties. This is my initial database design: Products{ProductId, Name, ProductCategoryId} ProductCategories{ProductCategoryId, Name, ParentId}

Any reason to still use snake case for database tables and columns?

爷,独闯天下 提交于 2020-01-12 07:57:05
问题 Back when I started with database design, for some reason it was recommended that you always use snake case (my_table_name) for tables and columns. I think this was especially true in MySQL. The reasoning was there were instances where capitalization would be lost or enforced. Flash forward to today and I see a lot of people using Pascal Case ("MyTableName"), which I would prefer. Is there any reason to still use snake case for table and column names? Are there any instances where

What is the most efficient way to model the relationship between these entities?

自闭症网瘾萝莉.ら 提交于 2020-01-11 14:20:10
问题 I have a database with entities as follows: 1. User entity 2. Event entity (musical concert etc.) 3. Ticket entity 3. Notification entity The notification entity has a direct relationship with both Ticket and Event (1:N [Ticket/Event : Notification]). Notifications will be stored in a database and user will have access to them via Notification tab. User can be notified with a notification related to his ticket(e.g. "We just sent your ticket to you!") or regarding some event (e.g. "Event xy is

in a relational database, can we have a table without any relation with the other tables?

孤街醉人 提交于 2020-01-11 05:16:09
问题 in a relational database, can we have a table without any relation with the other tables? 回答1: Yes. The way relations are expressed are with foreign keys. If a table you generate has no Foreign keys, and no foreign keys in other tables point to this table, it has no relationships. It can still be given a relationship later though so don't worry about shooting yourself in the foot. 回答2: Of course. Even you can create a table without fields. 回答3: Yes you can. Tables do not have to have any

Django teacher students easy solution. Use separate tables, or permissions and groups? How? Other ideas?

隐身守侯 提交于 2020-01-11 04:06:06
问题 How would you cope with following problem? There are teachers, and students. Student can not view pages dedicated to teachers, and teachers can view pages dedicated to students. Teachers can have list of just students they teach. I want both teachers and students to use build in User to let them login. I have following ideas: Separate table for teacher and student with foreign key to build in user? - but the question is, can I easily render pages and distinguish who is teacher and who is

How to query graph/hierarchical data in mysql

血红的双手。 提交于 2020-01-10 02:16:06
问题 Suppose I have a table of objects structured in a hierarchy: A |--B |--C | +--D +--E They are stored in a "parent-child" table thus: parent child A B A C C D A E How do I query this to get the structure defined above? I think I need something that produces info like this: object full_path A NULL B A C A D A.C E A I cannot figure out how to do the objects nested more than one level deep. It feels like I might need to iterate over the table (no idea if this is possible in SQL), or otherwise use

MySQL query, MAX() + GROUP BY

十年热恋 提交于 2020-01-08 17:12:57
问题 Daft SQL question. I have a table like so ('pid' is auto-increment primary col) CREATE TABLE theTable ( `pid` INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, `timestamp` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `cost` INT UNSIGNED NOT NULL, `rid` INT NOT NULL, ) Engine=InnoDB; Actual table data: INSERT INTO theTable (`pid`, `timestamp`, `cost`, `rid`) VALUES (1, '2011-04-14 01:05:07', 1122, 1), (2, '2011-04-14 00:05:07', 2233, 1), (3, '2011-04-14 01:05:41', 4455, 2), (4, '2011-04-14 01:01:11', 5566, 2),

How to set a foreign key which is dependent on the relation of other two tables?

我怕爱的太早我们不能终老 提交于 2020-01-07 14:02:12
问题 I have 3 tables; teachers table, subjects table and events table. 1.There is one to many relationship between subjects and teachers, that is each teacher can teach only one subject but, many teachers can teach same subjects. 2.There is a many to many relationship between teachers and events. Example of subjects table id(PK) | name ------------------- 1 | php ------------------- 2 | java ------------------- 3 | python ------------------- 4 | c++ -------------------- 5 | c# Example of teachers