Note that there are some explanatory texts on larger screens.

plurals
  1. POShould I use a unique ID for a row in a junction table?
    primarykey
    data
    text
    <p>I am using SQL Server 2008.</p> <p>A while back, I asked the question "should I use RecordID in a junction table". The tables would look like this:</p> <pre><code>// Images ImageID// PK // Persons PersonID // pk // Images_Persons RecordID // pk ImageID // fk PersonID // fk </code></pre> <p>I was strongly advised NOT to use RecordID because it's useless in a table where the two IDs create a unique combination, meaning there will be no duplicate records. </p> <p>Now, I am trying to find a random record in the junction table to create a quiz. I want to pull the first id and see if someone can match the second id. Specifically, I grab a random image and display it with three possible choices of persons.</p> <p>The following query works, but I've quite a bit of negativity that suggests that it's very slow. My database might have 10,000 records, so I don't think that matters much. I've also read that the values generated aren't truly random. </p> <pre><code>SELECT TOP 1 * FROM Images_Persons ORDER BY newid(); </code></pre> <p>Should I add the RecordID column or not? Is there a better way to find a random record in this case?</p> <p>Previous questions for reference</p> <ul> <li><a href="https://stackoverflow.com/questions/5248816/should-i-use-recordid-as-a-column-name">Should I use &quot;RecordID&quot; as a column name?</a></li> <li><a href="https://stackoverflow.com/questions/7457643/sql-what-is-the-best-table-design-to-store-people-as-musicians-and-artists">SQL - What is the best table design to store people as musicians and artists?</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload