relational-database

Relational database design - “cyclic” graphs

天大地大妈咪最大 提交于 2019-12-19 04:42:32
问题 In relational database design, should one worry about one (or more) "cyclic graphs" posing problems? (Simplified) E.g., tables T1( T1_Id , ...) T2( T2_Id , T1_Id_Fk, ...) T3( T1_Id_Fk, T2_Id_Fk , ..) Primary keys are bolded. Rows in T1 have a double role. A T1 row r1 can be in relationship T3 with a row r2 in T2, but it can also be a parent row for a (possibly the same) row r2' in T2. These two relationships are orthogonal. I came up with something like this: T1_Base( T1_Id , ...) T1_Child1(

Average posts per hour on MySQL?

心不动则不痛 提交于 2019-12-18 19:27:11
问题 I have a number of posts saved into a InnoDB table on MySQL. The table has the columns "id", "date", "user", "content". I wanted to make some statistic graphs, so I ended up using the following query to get the amount of posts per hour of yesterday: SELECT HOUR(FROM_UNIXTIME(`date`)) AS `hour`, COUNT(date) from fb_posts WHERE DATE(FROM_UNIXTIME(`date`)) = CURDATE() - INTERVAL 1 DAY GROUP BY hour This outputs the following data: I can edit this query to get any day I want. But what I want now

SQLServer - How to find dependent tables on my table?

蓝咒 提交于 2019-12-18 16:58:34
问题 Using SQLServer : I have a table user : id name email There are some other tables (about 200 more tables), some of which use user.id as foreign key on cascade delete . So, I want to find out - Which tables use this foreign key ( user.id ) ? I am accessing my sql-server with SQL Server Management Studio . 回答1: In SQL server management studio, you can right click your table in the object explorer, and then select 'View Dependencies'. This will open a new window in which you can see all other

Mapping Many to Many Relationship w/ Foreign Key Reference

a 夏天 提交于 2019-12-18 16:57:14
问题 This should be a simple question for the well versed EF user. I have the following schema (in my head) of how the relationships between the tables should look. [FooBar] [Foo] [Bar] FooId PK,FK Id PK Id PK BarId PK,FK BarId FK Name IsRead Name Description Description Though, when I try to generate the schema using EF code-first it fails to interpret the relationships between the entities as I've interpreted them (adds foreign key FooId to the [bar] table) and fails to fully create the [FooBar]

Mapping Many to Many Relationship w/ Foreign Key Reference

我只是一个虾纸丫 提交于 2019-12-18 16:57:07
问题 This should be a simple question for the well versed EF user. I have the following schema (in my head) of how the relationships between the tables should look. [FooBar] [Foo] [Bar] FooId PK,FK Id PK Id PK BarId PK,FK BarId FK Name IsRead Name Description Description Though, when I try to generate the schema using EF code-first it fails to interpret the relationships between the entities as I've interpreted them (adds foreign key FooId to the [bar] table) and fails to fully create the [FooBar]

How to model a database with many m:n relations on a table

心已入冬 提交于 2019-12-18 15:35:24
问题 I am currently setting up a database which has a large number of many-to-many relations. Every relationship was modeled via a link table. Example: A person has a number of jobs, jobs are fulfilled by a number of persons. A person has a number of houses, houses are occupied by a number of persons. A person has a number of restaurants he likes, restaurants have a number of persons who like the restaurant. First I designed this as follows: Tables: Person, Job, House, Restaurant, Person_Job,

How to set up a typical users HABTM roles relationship

烈酒焚心 提交于 2019-12-18 13:33:22
问题 I'm quite new to this and I'm using cancan + devise for my user auth. However I'm not really sure what it means to set up a typical users HABTM roles relationship nor do I really understand what a HABTM relationship is. Can anyone explain it really well or point me to a good tutorial or example? 回答1: HABTM means has and belongs to many. You basically need a table as a middle man to track multiple id's (called a through table). When referenced as a typical users HABTM roles relationship, they

How do I model (GitHub-like) permissions relationally?

自闭症网瘾萝莉.ら 提交于 2019-12-18 13:22:33
问题 tl;dr: how do i implement a permissions model like (e.g.) github's Updated to try to address some of @philipxy's comments: I am planning to implement a permissions model similar to github's: users users can be in groups users can be in organizations groups can be in organizations a user will be permitted any of C, R, U, and D operations on an asset, group, or organization as : an individual user who has been permitted those (any of C, R, U, D) operations a member of a group which has been

Normalize table to 3rd normal form

為{幸葍}努か 提交于 2019-12-18 12:34:47
问题 This questions is obviously a homework question. I can't understand my professor and have no idea what he said during the election. I need to make step by step instructions to normalize the following table first into 1NF, then 2NF, then 3NF. I appreciate any help and instruction. 回答1: Okay, I hope I remember all of them correctly, let's start... Rules To make them very short (and not very precise, just to give you a first idea of what it's all about): NF1 : A table cell must not contain more

How to understand the 5th Normal Form?

自作多情 提交于 2019-12-18 10:14:00
问题 I'm using two online sources for gaining an understanding of the 5NF, without any rigor of Math and proofs. A Simple Guide to Five Normal Forms in Relational Database Theory (by Kent. This one seems to have been reviewed and endorsed in one of his writings by none other than CJ Date himself) Fifth Normal Form (Wikipedia article) However, I'm unable to understand either of these references! Let's first examine Reference #1 (Kent's). It says: "But suppose that a certain rule was in effect: if