database-design

MongoDB Schema Design - Many small documents or fewer large documents?

萝らか妹 提交于 2019-12-28 04:40:08
问题 Background I'm prototyping a conversion from our RDBMS database to MongoDB. While denormalizing, it seems as if I have two choices, one which leads to many (millions) of smaller documents or one which leads to fewer (hundreds of thousands) large documents. If I could distill it down to a simple analog, it would be the difference between a collection with fewer Customer documents like this (in Java): class Customer { private String name; private Address address; // each CreditCard has hundreds

Does a Postgres UNIQUE constraint imply an index?

岁酱吖の 提交于 2019-12-28 04:31:07
问题 When adding a unique constraint to a Postgres table does that imply that an index has also been added to that table? Meaning, if I add a UNIQUE constraint on a text column, does that text column now have an index or does an index have to be added separately? 回答1: Yes. UNIQUE constraints are implemented using a btree index in Postgres. Details: How does PostgreSQL enforce the UNIQUE constraint / what type of index does it use? 来源: https://stackoverflow.com/questions/29655439/does-a-postgres

Storing long binary (raw data) strings

风流意气都作罢 提交于 2019-12-28 04:27:03
问题 We are capturing a raw binary string that is variable in size (from 100k to 800k) and we would like to store these individual strings. They do not need to be indexed (duh) and there will be no queries on the contents of the field. The quantity of these inserts will be very large (they are for archival purposes), let's say 10,000 per day. What is the best field type for large binary strings like these? Should it be text or blob or something else? 回答1: As far as PostgreSQL is concerned, type

How to call Stored Procedure in a View?

你离开我真会死。 提交于 2019-12-28 02:44:10
问题 How would I call a Stored Procedure that returns data in a View? Is this even possible? 回答1: This construction is not allowed in SQL Server. An inline table-valued function can perform as a parameterized view, but is still not allowed to call an SP like this. Here's some examples of using an SP and an inline TVF interchangeably - you'll see that the TVF is more flexible (it's basically more like a view than a function), so where an inline TVF can be used, they can be more re-eusable: CREATE

What is the best database schema to support values that are only appropriate to specific rows?

怎甘沉沦 提交于 2019-12-28 00:50:54
问题 I have a db table called Calendar with fields Id (PK) Name Description CalendarTypeId (FK into CalendarType table) I have another table called CalendarType with fields Id (PK) Name Description The issue is that i need to store an additional field for every calendar where the calendar Type is 2. (but this field would be irrelevant for any other calendar type). Should i just create a new field in the Calendar table and ignore that field for all other calendar that have a different

Entity-Attribute-Value Table Design

若如初见. 提交于 2019-12-27 11:42:59
问题 I am currently designing a database structure for the products section of an ecommerce platform. It needs to be designed in such a way that makes it possible to sell an infinite number of different types of products with an infinite number of different attributes. E.g. The attributes of a laptop would be RAM, Screen Size, Weight, etc. The attributes of a book would be Author, ISBN, Publisher, etc. It seems like an EAV structure would be most suitable. Select a product Product belongs to

How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?

人盡茶涼 提交于 2019-12-27 08:54:18
问题 Can anyone explain how to implement one-to-one, one-to-many and many-to-many relationships while designing tables with some examples? 回答1: One-to-one: Use a foreign key to the referenced table: student: student_id, first_name, last_name, address_id address: address_id, address, city, zipcode, student_id # you can have a # "link back" if you need You must also put a unique constraint on the foreign key column ( addess.student_id ) to prevent multiple rows in the child table ( address ) from

How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?

♀尐吖头ヾ 提交于 2019-12-27 08:48:12
问题 Can anyone explain how to implement one-to-one, one-to-many and many-to-many relationships while designing tables with some examples? 回答1: One-to-one: Use a foreign key to the referenced table: student: student_id, first_name, last_name, address_id address: address_id, address, city, zipcode, student_id # you can have a # "link back" if you need You must also put a unique constraint on the foreign key column ( addess.student_id ) to prevent multiple rows in the child table ( address ) from

How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?

和自甴很熟 提交于 2019-12-27 08:48:06
问题 Can anyone explain how to implement one-to-one, one-to-many and many-to-many relationships while designing tables with some examples? 回答1: One-to-one: Use a foreign key to the referenced table: student: student_id, first_name, last_name, address_id address: address_id, address, city, zipcode, student_id # you can have a # "link back" if you need You must also put a unique constraint on the foreign key column ( addess.student_id ) to prevent multiple rows in the child table ( address ) from

Database design for answer table in quiz app

僤鯓⒐⒋嵵緔 提交于 2019-12-25 18:48:45
问题 I am designing a quiz app and i am stuck on how to design the answers table. Assume i have the following tables: User(user_id,...other columns) Question(question_id,user_id,...other columns) QuestionAnswers(question_id,answer_id... other columns) Now what to do about the UserAnswers table? The structure I have in mind is this: UserAnswers(user_id,question_id,answer_id,.. other columns) The structure that I have made works great at start, but the performance starts degrading once I reach 10