relational-database

How to set up Primary Keys in a Relation?

最后都变了- 提交于 2019-12-10 09:57:02
问题 I wish to know how to correctly set up Primary Keys in a Relation . E.g. we have ER-diagram which contain elements: Key attributes Weak key attributes Identifying relationships Associative entities In order to translate it into Relational Model we should do some tricks. All elements above deal with Primary Keys of relations but they all are Natural Keys - so we can leave them as is or replace with Surrogate Keys . Consider some cases. Case 1 Key Attribute is a name - so it must be of type

Relationship between orders, customers and products?

穿精又带淫゛_ 提交于 2019-12-10 09:46:34
问题 I am trying to construct an e-commerce database but I don't understand relationship between orders, products and customers. There are lots of database examples but they are too complex. Is there a simpler explanation or an example about possible tables and relationships. Thanks. 回答1: This is the simplest form if customers can have more than one order and orders can be for more than one product: The ORDER table has information about the date and status of the order. The ORDER ITEM table has

What are the common issues surrounding storage of XML data in a relational databases?

别来无恙 提交于 2019-12-10 09:08:45
问题 In relation to a discussion started at this question, I've decided to put this up as a community wiki question. The root of the question is, therefore, is it appropriate to store XML data in a relational database? Are there generally better ways to implement the same goal? What database engines provide good support for XML data types (such as SQL Server), and what are the issues surrounding so-called "XML indexes"? 回答1: Databases are for storing data. XML is data. Therefore, under the right

Yii2 how to check if two models are already linked

大城市里の小女人 提交于 2019-12-10 07:46:42
问题 I have two models related through a junction table. $model->link() is the method used to establish the relationship between the two models. It basically populates the junction table with the corresponding keys of both models. If two models are linked and I try to link them again, there will be an error because the key pair already exists in the junction table. Then I'd need to check if this relation exists before attempting to link the models. I think I could just create a model for the

Does Eloquent relation sync also remove?

让人想犯罪 __ 提交于 2019-12-10 03:00:44
问题 When updating a model and I sync a relationship, if I don't pass in all the ids that already exist, will that relationship be removed? 回答1: You decide: sync has 2nd parameter that defaults to true and is responsible for detaching: $model->relationship()->sync([1,2,3]); $model->relationship()->sync([4,5,6]); // attached [4,5,6], detached [1,2,3] $model->relationship()->getRelatedIds(); // [4,5,6] // but: $model->relationship()->sync([4,5,6], false); // attached [4,5,6], detached [] $model-

Mapping for self referencing entity in EF Code First

我的未来我决定 提交于 2019-12-09 18:15:47
问题 In my database I have a table Category, with columns Id, CategoryName, ParentCategoryId, where ParentCategoryId has a constraint on Category.Id. I'm using entity framework code first, where the entity looks like: public class Category { public long Id { get; private set; } public string CategoryName { get; private set; } public long? ParentCategoryId { get; private set; } public Category ParentCategory { get; private set; } public virtual ICollection<Category> SubCategories { get; private set

What's the proper way to store this data in a MySQL schema?

假如想象 提交于 2019-12-09 16:28:47
问题 I have a movie in a MySQL database. A movie contains data attributes that will never change, such as the following: Barcode: 025192018626 Format: DVD Runtime: 121 min. Discs: 1 Title: 12 Monkeys Year: 1995 It's one single row in a table. But I want to give my user's complete customization over this information in case something is incorrect according to them or if they just want to modify how the data is displayed in some way. I don't care why, I just want to give my users an option to do

What's the best way to store an array in a relational database?

。_饼干妹妹 提交于 2019-12-09 15:58:54
问题 I'm currently trying to design a database and I'm not too sure about the best way to approach a dynamically sized array field of one of my objects. My first thought is to use a column in my object to store an array of integers. However the more I read, the more I think this isn't the best option. Concrete example wise, I have a player object that stores 0 to many items, which are represented by an integer. What is the best way to represent this? 回答1: If that collection of values is atomic,

Relational data modeling for sub types

六月ゝ 毕业季﹏ 提交于 2019-12-09 07:06:59
问题 I am learning the Relational Model and data modeling. And I have some confusion in my mind regarding sub types. I know that data modeling is an iterative process and there are many different ways to model things. But I don't know how to choose between different options. Example Suppose we want to model the particles (molecule, atom, proton, neutron, electron, ...). Let's ignore Quark and other particles for simplicity. Since all particles of the same type behave the same, we are not going to

Using AngularFire, is it possible to to create relational-style databases? Or access the UniqueIDs?

自古美人都是妖i 提交于 2019-12-09 06:45:58
问题 I saw this post on Firebase's blog explaining the best way to create relational data objects using their platform. I'm struggling to translate these concepts to AngularFire, their integration with the AngularJS platform. Specifically, I'm trying to display two linked data sets that have a one way pointer reference similar to how they described it in this example from their post: var commentsRef = new Firebase("https://awesome.firebaseio-demo.com/comments"); var linkCommentsRef = new Firebase(