database-design

How to make a composite key to be unique?

泪湿孤枕 提交于 2020-01-01 09:10:09
问题 I am making a database of students in one school.Here is what I have so far: If you don't like reading jump to the "In short" part The problem is that I'm not happy with this design. I want the combination of grade , subgrade and id_class to be unique and to serve as a primary key for the students table. I can remove the student_id and make a composite key from the 3 but I don't want that either. Maybe I should make another table lets say combination_id where grade , subgrade and id_class are

Normalize or Denormalize: Store Contact Details (Phone Numbers) in separate Table? Search Performance?

谁都会走 提交于 2020-01-01 06:10:31
问题 I'm designing a database application which stores simple contact information (First/Last Name etc.) and I also have to store phone numbers. Besides phone numbers I have to store what they are for (mobile, business etc.) and possibly an additional comment for each. My first approach was to normalize and keep the phone numbers in a separate table, so that I have my 'Contacts' and my 'PhoneNumbers' table. The PhoneNumbers table would be like this: Id int PK ContactId int FK<->Contacts.Id

Is the usage of stored procedures a bad practice?

北城余情 提交于 2020-01-01 04:34:10
问题 We have an application that is written in C# that is connected to a ms sql server. We use to make a stored procedure for every database call, but then we've noticed that using stored procedures gives us a very big disadvantage, we don't know what stored procedures we need to update if we change our database. Now I was wondering if using stored procedures is a bad thing or a good thing? 回答1: That's not a SP problem, that's an issue of your development process. If you have no information you

Does JSONB make PostgreSQL arrays useless?

被刻印的时光 ゝ 提交于 2020-01-01 04:19:32
问题 Suppose that you want to store "tags" on your object (say, a post). With release 9.4 you have 3 main choices: tags as text[] tags as jsonb tags as text (and you store a JSON string as text) In many cases, 3rd would be out of question since it wouldn't allow query conditional to 'tags' value. In my current development, I don't need such queries, tags are only there to be shown on posts list, not to filter posts. So, choice is mostly between text[] and jsonb . Both can be queried. What would

What's the best way to create a 'history' type model in django?

帅比萌擦擦* 提交于 2020-01-01 03:57:22
问题 I'd like to create a feature for my Django app similar to Django admin's 'Recent Actions', in order to store history information on my other models. For example say I have two models called Book and Author. I want to have a third model that stores information such as what action was performed on a given object in a model (add, modify, delete, etc.) by who and when. Who, when and the action are easy, I'm just unsure about how to store information regarding what object the action was performed

Most efficient way to store a 20 Meg file in a SQL Server 2005 IMAGE Column

左心房为你撑大大i 提交于 2020-01-01 03:39:07
问题 We store documents in an SQL Server 2005 database table with a column format of "Image". Every time I try to store a PDF file which is greater than 1 Meg, it somehow gets corrupted. Is there any particularly efficient method in .NET to serialize and store large files (~10megs) into a database? [Edit] Microsoft actually says the max file size is about 2G Variable-length binary data from 0 through 2^31-1 (2,147,483,647) bytes. http://msdn.microsoft.com/en-us/library/ms187993.aspx 回答1: A quick

How would I store a date that can be partial (i.e. just the year, maybe the month too) and output it later with the same specifity?

房东的猫 提交于 2020-01-01 03:37:27
问题 I want to let users specify a date that may or may not include a day and month (but will have at least the year.) The problem is when it is stored as a datetime in the DB; the missing day/month will be saved as default values and I'll lose the original format and meaning of the date. My idea was to store the real format in a column as a string in addition to the datetime column. Then I could use the string column whenever I have to display the date and the datetime for everything else. The

Difference between super key and composite key

六月ゝ 毕业季﹏ 提交于 2020-01-01 03:29:08
问题 I need to understand the difference between super key and composite key. The examples I found made more confused. Can you please simply clarify what is the difference? Thanks 回答1: A super key uniquely identifies a row. It could be made up of one column or many. A composite key is a key made of more than one column. If a Super Key is made of more than one column it is also a composite. If a composite key uniquely identifies a row it is also a Super key. I don't see the name 'Super key' used

Have you extended nested sets for hierarchical data modeling involving multiple parent nodes for a child node? What are your experiences?

风格不统一 提交于 2020-01-01 03:27:07
问题 I am looking to use this concept in one of my upcoming project. More info: Managing Hierarchical Data in MySQL. Please share your experiences good or bad with examples. I am adding more information to make it more broad: I have child items that can have more than one parent (example: a user can belong to city and also a group called UserDefinedRegion), which the typical hierarchical models do not support, whether it is adjacency list or nested sets. I am pasting the use case here for clarity:

How would one represent scheduled events in an RDBMS?

喜你入骨 提交于 2020-01-01 03:17:25
问题 I have to store scheduled events, (like say class times, for example) that can be organized on a weekly, daily or monthly basis. Events can occur, say, every Monday and Wednesday, or every second Thursday of the month. Is there a way to store this information in an RDBMS that adheres to 3NF? EDIT: This is not homework; I'm building something with a friend for our own edification and we want it in 3NF. To be specific, I'm trying to store the schedules for mass and confession times at RC