While I worked with SQL database queries for some time, I am still new to creating good tables. One thing that I often encounter is primary keys.
In the table that I am creating now to register errors on some signaling equipment, I need 5 columns. The park and code tables uniquely identify the site (although the park column is not used). Then there is a serial column identifying the equipment in question and an error containing an error code. Finally, there is a timestamp when an error is logged.
Each site has several different pieces of equipment, and some of the equipment may report several errors. When the error is fixed, the row is deleted from the table.
Thus, in order to uniquely identify the error, we need to check park , code , serial and fault . They all look like good candidates for indexes based on queries that can be run. However, it seems to me impractical to define them all as a combined primary key, because they are almost all the columns in the table!
I struggled with similar problems several times, and I never felt that I had found a good solution. Anyone can suggest some good practices for tables like this, where most (or even all) columns are needed to uniquely identify a row?
source share