Hot answers tagged

8

Using names as FKs is unorthodox at the least. Usually FKs point to the FK of the parent table. You might as well make name the PK of both tables and get rid of the ID altogether You've found one of the disadvantages of using surrogate PKs where good business keys exist. You should be able to read and understand the association table. After all the data ...


6

Your mistake is you want to use the Name instead of ID because Name is more Readable. What you should doing is making your ID more readable. Think of it as RoleCode instead of RoleID Role(RoleCode Pk, Name, Other_Columns) Command(CommandID PK, RoleCode FK, Other_Columns) Sample Data RoleCode Name Other_Columns -------- ---- ...


4

Each technology has its advantages. The advantages of relational databases is that the RDBMS does some things for you, like: Enforcing referential integrity ( not allowing the insertion of an invoice detail if the invoice it belongs to doesn't exist) Avoid redundancy: things are stored only once. Complex queries can be done with a declarative language (...


3

Given the fact that your files are just text files containing text lines, my suggestion is this: Don't save links to the files Don't save the files themselves Save the list items to the database Here's a simple physical model to store lists: In the case we were talking about large files like video files or large images, it's better to just store the ...


3

If you profess to knowing nothing about cars, would I be happy with you servicing the brakes on mine? I think not. Databases are noticeably different from the data structures that you're used to working with in programming. They have their own oddities and idiosyncrasies and other things that will bite you in the Application Performance if you don't have ...


2

You absolutely need to know. For example, if your database is storing dates, you need to know what kind of precision you can expect. If you're storing a timestamp in a DATE field, you should know if the database is going to truncate your value to the nearest second (or worse, the nearest day). You should also know that values coming from a NUMBER(9,2) column ...


2

I think there is a third alternative. You should consider that the films_genres table has a primary key that is a compound (key) consisting of both the film_id together with the genre_id, and then deal with updates to the films_genres table from that perspective. In other words, you should consider that the films-genres table, in some sense, has only two ...


2

For your particular case, MongoDB sounds like a good choice, but there are plenty of scenarios (probably most of them) where it wouldn't be the best choice. MongoDB is more suited in scenarios that call for reading/writing a lot of data, without much emphasis on transaction safety (if some data occasionally gets lost in a server crash, it's not a big deal), ...


2

Using the id as the file name works fine for most applications. This assumes you are processing the image (resizing, cropping) and saving every image as the same file format. Otherwise you'll also want to store the file type in the table as well. That said, a couple of the possible drawbacks to be aware of: You'll have to overwrite existing files when ...


1

This is not a good idea, because the user Id is likely a surrogate key generated by a sequence (if using Oracle) or an IDENTITY value (used by a number of database technologies). For instance, sequences in Oracle are not guaranteed to provide the same values in different databases, since a range of values get cached. Furthermore, the order in which you ...


1

2 is the Best option. The only issue you have to worry about is load - One site can take down the other. I see no other downside. Option 1 has much more breakage points. I can't imagine why you feel it may be less stable


1

It's really hard to give you an answer that sufficiently solves your question. The reality is that the point of using a relational database is to model real world relationships between entities. A school database can be quite complex. It has to take into account a lot more than just a few courses, students, etc. And normalizing that data (removing ...


1

Your current scores table (with 4 test scores in it) isn't going to work. What if you have five scores? Or none? Database tables always have one record per entity. In the case of a Scores table, that means you have one score per record. Do that, and I think you'll find that you can write a SQL query for whatever you want, including the grade, average ...


1

Note: The top part of this answer is an answer to the question before the view-example has been posted by the original poster. For an updated version, taking the view in mind, check the bottom of this answer, under the line. I don't like you passing a query to a database abstraction layer actually covering two databases. An abstraction layer dealing ...


1

My two cents: Note: don't confuse concatenating multiple values into a single string and use it as a PK with having multi-column PK. That said: Concatenating multiple non-key data into a string to populate a key column has several disadvantages: People could guess IDs for hacking purposes When the non-key data changes the key is left outdated and has to ...


1

Although its a 3 years old thread, still I'm replying it thinking that it might be helpful to somebody. Table Structure Table_Offer -------- ID FK Name start time end time MandatoryGroup -------- ProductId (FK to product) MixGroup1 -------- ProductId (FK to product) MixGroup2 -------- ProductId (FK to product) Table_offerDetails --------------...


1

Your idea of groups look good at first glance, but it's actually a complexity overkill. Imagine we are in a relational DB, you have groups and words in a N/N relationship. That means in order to fetch a synonym, you would have to fetch his groups links, then extract linked groups, then extracs all the groups links from all groups, then get the word list - ...


1

I guess what your sources are refering to is ACID compliance. There are lots of SQL databases which provide ACID. Most NoSQL databases, however, do not provide this for the sake of better scalability. Here is an article on Quora which might give you an explanation. For both categories of databases, however, if one wants data not to get lost, regular backups ...


1

Yes. Other answers are missing the fact that PHP is single-threaded and blocking. You generally process one HTTP request per process at a time. You can use more than one connection at a time if you really need to, but usually you won't. So it's perfectly fine to have a single connection per process. Now if this was, say, Node.js, then yes, you should use ...


1

What you have here is using the Singleton Pattern to ensure that all callers receive the same instance of the connection object. Sounds efficient to being with and, so long as your application is purely single-threaded and never tries to do more than one [database-related] thing at a time, it will probably work quite well. If this is a particularly long-...



Only top voted, non community-wiki answers of a minimum length are eligible