relational-database

Which normal form does this table violate?

怎甘沉沦 提交于 2019-11-30 17:35:29
问题 Consider this table: +-------+-------+-------+-------+ | name |hobby1 |hobby2 |hobby3 | +-------+-------+-------+-------+ | kris | ball | swim | dance | | james | eat | sing | sleep | | amy | swim | eat | watch | +-------+-------+-------+-------+ There is no priority on the types of hobbies, thus all the hobbies belong to the same domain. That is, the hobbies in the table can be moved on any hobby# column. It doesn't matter on which column, a particular hobby can be in any column. Which

Mapping Many to Many Relationship w/ Foreign Key Reference

别来无恙 提交于 2019-11-30 14:59:40
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] bridge table. If someone could guide me on how to achieve the above schema using EF4 code-first I'd

SQLServer - How to find dependent tables on my table?

前提是你 提交于 2019-11-30 14:14:08
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 . 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 objects (not just tables) that depend on your table, and on which your table depends. The way to get ONLY

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

我是研究僧i 提交于 2019-11-30 13:02:40
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, Person_House, Person_Restaurant. Relationships 1 - n: Person -> Person_Job, Person -> Person_House, Person

has_many :through multiple has_one relationships?

旧时模样 提交于 2019-11-30 12:17:37
问题 I'm writing a mentorship program for our church in rails (im still farily new to rails).. And i need to model this.. contact has_one :father, :class_name => "Contact" has_one :mother, :class_name => "Contact" has_many :children, :class_name => "Contact" has_many :siblings, :through <Mother and Father>, :source => :children So basically an objects "siblings" needs to map all the children from both the father and mother not including the object itself.. Is this possible? Thanks Daniel 回答1: It's

Can't get Laravel associate to work

大憨熊 提交于 2019-11-30 11:05:52
I'm not quite sure if I understand the associate method in Laravel. I understand the idea, but I can't seem to get it to work. With this (distilled) code: class User { public function customer() { return $this->hasOne('Customer'); } } class Customer { public function user() { return $this->belongsTo('User'); } } $user = new User($data); $customer = new Customer($customerData); $user->customer()->associate($customer); I get a Call to undefined method Illuminate\Database\Query\Builder::associate() when I try to run this. From what I can read, I do it exactly as is stated in the docs. What am I

What are the reasons *not* to use a GUID for a primary key?

回眸只為那壹抹淺笑 提交于 2019-11-30 10:59:17
问题 Whenever I design a database I automatically start with an auto-generating GUID primary key for each of my tables (excepting look-up tables) I know I'll never lose sleep over duplicate keys, merging tables, etc. To me it just makes sense philosophically that any given record should be unique across all domains, and that that uniqueness should be represented in a consistent way from table to table. I realize it will never be the most performant option, but putting performance aside, I'd like

Can a database attribute be primary and foreign key?

[亡魂溺海] 提交于 2019-11-30 09:48:48
I have 2 tables, User and Employee . Each user is given a User_ID and that is a primary key in the User table and a foreign key in the Employee table. Can that attribute in the Employee table also be a primary key? If you have a one-to-one relation between two tables, then the primary key of the details table is a foreign key as well. master detail (1 : 1) +----------+ 1:1 +-------------+ | PK id |<---o| PK FK id | +----------+ +-------------+ | col1 | | col1 | | col2 | | col2 | | etc. | | etc. | +----------+ +-------------+ If you have a m-to-n relation, the junction table has columns

How to set up a typical users HABTM roles relationship

混江龙づ霸主 提交于 2019-11-30 09:41:10
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? 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 really mean there would be a User model, Role model, users table, roles table, and a roles_users table. Don

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

老子叫甜甜 提交于 2019-11-30 09:13:46
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 granted those permissions a member of an organization that has been granted those permissions or as a