What is best practice for referencing data rows within stored procedures – via PK, code column or data value?

Suppose you have a table for colours with columns:

  • id = automatically incrementing integer, primary key
  • code = short code reference for the colour, unique
  • colour = human-readable name of colour, unique

Example values might be:

  • 1, BL, Blue
  • 2, GR, Green

Now imagine you have a stored procedure that, at some point, needs to reference this table. Let’s say the business logic says to obtain the colour "Green". To achieve this, you could have any of the following three WHERE clauses:

  • WHERE id = 2
  • WHERE code = GR
  • WHERE colour = Green

Now, if the system is designed such that it is agreed that a code value, once created, never changes, then, in my view, that is the best column to reference because:

  • It is an alternate key
  • It is human-readable for people who maintain the code
  • It will not be impacted when the business decides to change the colour value to ‘Sea Green’

However, if a legacy table lacks such code values, what, in your opinion, is best practice? To reference the id column, or the colour column?

If you reference the id column, the code is not readable unless you then also add comments – you shouldn’t have to comment simple things like this. It sucks figuring out what statements like WHERE id not in (1, 7, 17, 24, 56) mean.

I’m not sure how often, in reality, the id value might change – but consider if you run a script during development to insert new colours but then delete those and insert some more. If your stored procedure references the id values from that last set of colours inserted but when you create your new colours in your next environment you skip the step that inserted the colours which ended up deleted, then the id values won’t match in that next environment. Bad practice, but it can happen – a developer develops their script on a dev instance not thinking that the id values will conflict with production (which, for example, may have had additional colours created manually by the business before your colour creation script runs).

If you reference the colour column, you run the risk that if the business does ask to update the description from ‘Green’ to ‘Sea Green’, that your procedure will begin to fail.

I suppose a further solution is to implement the code column when you need it, if it isn’t there already – probably the best solution?

My Plot is empty when I run code

ee = 0.5; g = 0.1; gs = Sqrt[g]; f = (Sin[gs*x])^2; low = gs*Pi/2 ; up = -low ; ode = { y''[x] + (2ee - f/g)*y[x] == 0 , y[low]==0 , y[up]==0 }  sol = NDSolve[ode, y[x], {x, low , up}]  Plot[y[x] /. sol, {x, low, up}] 

Boundary conditions are y[low]=y[up]=0. But when I plot this, it shows an empty plot.

Write the SQL code to find the average charge by the family medicine physicians

We need to write the script to find the average charge of physicians who specialize in "family medicine.

But i’m confused on how to write this because when we look at the appointment table, where we find the appointment_charge, it only gives us the physician_ID. How to link that to the specialize table. Can anyone help me solve this problem?

This link below contains the diagram, tables and question. I am stuck at number 13. Take a look, it will make more sense 🙂 >>>>


Which Part Adsense Code To Remove

I am using a custom Blogger template and the Layout widgets are not working. I need to remove a Adsense Link ad.

I tried removing the code, but the whole site disappeared. Could someone tell me which part of the code should I delete.

The HTML code is:

<b:widget id='HTML3' locked='false' title='' type='HTML' version='1'>
<b:widget-setting name='content'>&lt;center&gt;&lt;script async…

Which Part Adsense Code To Remove

Data being edited in .opvn config when vpn app http gets .opvn files from my host. Adds my wordpress site code and removes the config

I have a VPN app that pulls .ovpn files from a folder on my website /home/mywebsitename/public_html/remoteovpn When I add the .opvn files to this folder and my app pulls them from https request. You can go to the files in the browser link, you can see them and read all the config no problem even dl them. But when my app pulls the files it gets the file names and makes the .opvn files, but edits the files with my website wp theme data, not the .ovpn config data. I can’t figure why it is doing this. Any help would be appreciated been trying for 2 days

VPS with CentOS 7 and cPanel with wordpress theme

Want to edit HTML code of website

Hello there,
I want to edit HTML code of my website and do some changes accordingly and thereafter want to save it. Does using any HTML editor plugin will help in case i uninstall it. Whether the changes will remain there or will be cleared. Any other option which does not involves using plugin and being non-technical I don't want to help of any web development company due to budget issue.

Thanks in advance!

Formatting code in .wl and .m files from the command-line?

I use an external editor (Sublime Text) to edit my .wl and .m files and run them with WolframKernel from the command line. This means everything I do is outside of Mathematica. Is there a way I can format a file using something like the official code formatter where I input the code in the file through the command line as standard input and receive the formatted text as standard output (something like cat /my/file.wl | formatting_util)? Thanks for reading.

Why doesn’t the Gutenberg code editor allow code to be nested in sections?

I’m trying to add my own HTML code in the Gutenberg code editor, but unfortunately when trying to save the editor automatically moves the closing tag </section> to the end of the first line. What is this about ? Why can’t I nest my code this way normally ? To illustrate the problem I attach a picture.

enter image description here

I would like the section closing tag to be at the end of all code.