database-design

Database Design Question - Categories / Subcategories

北城以北 提交于 2020-01-09 07:11:11
问题 I have a question for how I would design a few tables in my database. I have a table to track Categories and one for Subcategories: TABLE Category CategoryID INT Description NVARCHAR(500) TABLE Subcategory SubcategoryID INT CategoryID INT Description NVARCHAR(500) A category might be something like Electronics, and its Subcategories might be DVD Players, Televisions, etc. I have another table that is going to be referencing the Category/Subcategory. Does it need to reference the SubcategoryID

Defining multiple foreign keys in one table to many tables

时光怂恿深爱的人放手 提交于 2020-01-08 12:29:26
问题 I have 3 models: Post : id title body Photo : id filepath Comment : id post_id body and corresponding tables in DB. Now, if I want to have comments only for my posts I can simply add following foreign key: ALTER TABLE comment ADD FOREIGN KEY (post_id) REFERENCES post (id) . But I want to have comments for other models (photo, profile, video, etc) and keep all comments in one table. How can I define foreign keys (i definitely need FKs for ORM) in such case? 回答1: You could do this: post: * post

Good design for modifying various combination of columns in a table

不羁岁月 提交于 2020-01-07 09:03:44
问题 I have a database table with multiple (~ 15) columns. I have requirement where where data is updated in a row, in combinations of columns, for the given primary key. Eg. Update Col1,Col2,Col3 where PK is something Update Col4 where PK is something Update Col5,Col7,Col9,Col10 where PK is something Update Col5,Col10 where PK is something I used Python and wrote raw queries to handle such cases. I wrote separate functions to manage each requirements. They look like this : requirement1( Col5,val1

Table with two foreign keys pointing to the same column of another table

时间秒杀一切 提交于 2020-01-07 08:55:17
问题 I wonder whether it is possible or ideal from a design standpoint to have a table with 2 foreign keys, each one pointing to the same field of another table. The table Case has two fields that are FK referencing the PK of the table Client (Every case has two clients) client table: ------------------ PK:client_id first_name last_name case table: ------------------ PK:case_id party1 (client_id) party2 (client_id) 回答1: Yes it's perfectly possible to have 2 FKs each pointing to the same field of

Can a table be in 3NF with no primary keys?

我的未来我决定 提交于 2020-01-07 08:09:23
问题 1. A table is automatically in 3NF if one of the following holds: (i) If a relation consists of two attributes. (ii) If 2NF table consists of only one non key attribute. 2. If X → A is a dependency, then the table is in 3NF, if one of the following conditions exists: (i) If X is a superkey (ii) If A is a part of superkey I got the above claims from this site. I think that in both the claims, 2nd subpoint is wrong. The first one says that a table in 2NF will be in 3NF if we have all non-key

Database design without a 1 column table

隐身守侯 提交于 2020-01-07 08:09:08
问题 I have been working on a database design and I'm stuck hitting a wall. I'm ending up with what I'm reading is not a normalized database structure but I'm having issues trying to find a "more correct" design and if this design is acceptable how do I execute it in Access? TLDR: If a table with a single column set as an auto number is an acceptable design, how do you go about inserting a record in it using Access? The segment of the database of concern is creating a structure for storing

Database design without a 1 column table

狂风中的少年 提交于 2020-01-07 08:08:04
问题 I have been working on a database design and I'm stuck hitting a wall. I'm ending up with what I'm reading is not a normalized database structure but I'm having issues trying to find a "more correct" design and if this design is acceptable how do I execute it in Access? TLDR: If a table with a single column set as an auto number is an acceptable design, how do you go about inserting a record in it using Access? The segment of the database of concern is creating a structure for storing

Report from Double Entry Accounting [closed]

a 夏天 提交于 2020-01-07 08:03:43
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 7 days ago . My reputation is not enough to comment on this post: Relational Data Model for Double-Entry Accounting. For the data model from the linked question, can anyone explain the calculation for the closing balance on the AccountStatement, any sample SQL? And a small clarification, correct me if I'm wrong.

MySQL index design with table partitioning

荒凉一梦 提交于 2020-01-07 06:41:05
问题 I have 2 MySQL tables with the following schemas for a web site that's kinda like a magazine. Article (articleId int auto increment , title varchar(100), titleHash guid -- a hash of the title articleText varchar(4000) userId int) User (userId int autoincrement userName varchar(30) email etc...) The most important query is; select title,articleText,userName,email from Article inner join user on article.userId = user.UserId where titleHash = <some hash> I am thinking of using the articleId and

Rails models has_many

有些话、适合烂在心里 提交于 2020-01-07 06:36:28
问题 Im starting to learn rails today and not quite sure how this would work: Lets say I have a Company, the company may have many subsidiaries. A subsidiary is a Company. A company cannot be its own subsi diary for obvious reasons. A subsidiary cannot have a subsidiary that is also a subsidiary of the company So a subsidiary can also have subsidiaries, so its unlimitedly nested what im also not sure about below is that a subsidiary is a company class Company < ActiveRecord::Base has_many