database-design

How do we give constraint on foreign key column based on ERD cardinality?

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-22 21:32:11
问题 Let's say I have a 2 tables like below : Department : DeptId Name Employee : EmpId Name DeptId Here I have a 0-to-many relationship between Department and Employee table. Now when I read the relationship from Department to Employee , it says 1 department can have 0 or more employees. Does this mean while creating Employee table, I will set DepartmentId (foreign key) as null due to zero or many relationship? And how do we represent 1 or many relationship like for eg If relationship in ERD says

How to store users's notifications options?

送分小仙女□ 提交于 2020-07-21 19:43:08
问题 I'm creating a database users . I want to let users to choose notifications they want to receive by email. Now I have the next columns in table users (boolean type): notification_comment_photo . notification_comment_comment . notification_vote_photo . notification_vote_comment . notification_pm . notification_followed . notification_news . What do you think, should I normalise table users and create another table notifications , considering that this table would have one-to-one relationship

How to store users's notifications options?

可紊 提交于 2020-07-21 19:35:46
问题 I'm creating a database users . I want to let users to choose notifications they want to receive by email. Now I have the next columns in table users (boolean type): notification_comment_photo . notification_comment_comment . notification_vote_photo . notification_vote_comment . notification_pm . notification_followed . notification_news . What do you think, should I normalise table users and create another table notifications , considering that this table would have one-to-one relationship

How to replicate a SCH_S, SCH_M deadlock

大城市里の小女人 提交于 2020-07-15 20:56:04
问题 I have a large migration script (about 2000 lines) that fails because of a deadlock on some metadata, and the lock types are SCH_S and SCH_M according to some xEvents data I've captured on it. The script is quite complicated, so I'm trying to recreate the same scenario using minimal scripting, so I can investigate it further. One difference between my scenario and some of the ones I've found online is that my migration script is being executed in a single process, as opposed to many examples

Explain Like I am Five -> How a Primary Key Satisfies First Normal Form

那年仲夏 提交于 2020-07-09 09:55:35
问题 Thank you for your knowledge in advance. I am studying for the Microsoft Technology Exam and one of the practice questions is : Creating a primary key satisfies the first normal form. True or False? I personally think it is False because the first normal form is to get rid of duplicate groups. But there is a sentence in the text (Database Fundamentals, Exam 98-364 by Microsoft Press) that says the following: "The first normalized form (1NF) means the data is in an entity format, which

Shared Primary Key

橙三吉。 提交于 2020-07-08 12:51:38
问题 I would guess this is a semi-common question but I can't find it in the list of past questions. I have a set of tables for products which need to share a primary key index. Assume something like the following: product1_table: id, name, category, ...other fields product2_table: id, name, category, ...other fields product_to_category_table: product_id, category_id Clearly it would be useful to have a shared index between the two product tables. Note, the idea of keeping them separate is because

mySQL - Should I denormalise?

强颜欢笑 提交于 2020-07-03 03:49:25
问题 Overview (Sorry its vague - I think if I went into more detail it would just over complicate things) I have three tables, table one contains an id, table two contains its own id and table one's id and table three contains its own id and table two's id. I have spent a lot of time pondering and I think it would be more efficient for table three to also contain the related table ones id. -It will mean I will not have to join three tables, I can just query table three (for a query that will be

mySQL - Should I denormalise?

房东的猫 提交于 2020-07-03 03:49:19
问题 Overview (Sorry its vague - I think if I went into more detail it would just over complicate things) I have three tables, table one contains an id, table two contains its own id and table one's id and table three contains its own id and table two's id. I have spent a lot of time pondering and I think it would be more efficient for table three to also contain the related table ones id. -It will mean I will not have to join three tables, I can just query table three (for a query that will be

Table design for multiple time series data

五迷三道 提交于 2020-06-17 07:45:22
问题 I have more than 200 separate time series data(each represent one variable) that I gather from different sources/REST API calls. The frequency of each variable is different. Example temperature data is coming at very high frequency, but status data is very less frequent. I am looking for suggestions for scalable table design to store these data. If I store all the data in one table with timestamp being the key, I think the table will have so much nulls. 回答1: Based on your description, my

How can I parse delimited list in string to rows?

我们两清 提交于 2020-06-17 06:21:48
问题 This is my previous question: How can I merge two strings of comma-separated numbers in MySQL? I tried to use delimited list with these reasons: the data is more than 2000 rows. I have just one day. this is not production level I need to parse the data with my hands. I thought I don't have any choice. But I found this: SQL split values to multiple rows So, I got some hopes from it. But it's quite difficult to apply it to my table. Mine is different form. I have multiple columns and I'd like