Note that there are some explanatory texts on larger screens.

plurals
  1. POPolicy query execution
    primarykey
    data
    text
    <p>When I insert a new record in the users table, first check email and nickname were not already added. There is a possibility that another user who registers with the same data simultaneously me false result? To clarify:</p> <p><strong>Connect 1:</strong></p> <pre><code> &gt; SELECT * FROM account WHERE username = 'test'; </code></pre> <p><em>Empty set (0.00 sec)</em></p> <p><strong>Connect 2:</strong></p> <pre><code>&gt; SELECT * FROM account WHERE username = 'test'; </code></pre> <p><em>Empty set (0.00 sec)</em></p> <pre><code>&gt; INSERT INTO account(username) VALUES ('test'); </code></pre> <p><em>Query OK, 1 row affected (0.01 sec)</em></p> <p><strong>Connect 1:</strong></p> <pre><code>&gt; INSERT INTO account(username) VALUES ('test'); </code></pre> <p><em>Error. Duplicate key</em></p> <p>What I want to know is if MySQL works this way, by running queries when they come, and best practices to use. I noticed that during a transition, the changes made ​​by other connections are not visible. Why? You can use SELECT ... FOR UPDATE outside the transitions? The massive use of foreign key to ensure data integrity is a recommended practice?</p> <p><strong>edit:</strong> Put another way. Ignore the stupid example. I want the next user who registers has an age greater than all those already</p> <pre><code>&gt; SELECT MAX (age) FROM account; </code></pre> <p>[... Check if a user's age is higher ...]</p> <pre><code>&gt; INSERT INTO accounts (age) VALUES ('$ var'); </code></pre> <p>How do I make sure that there is a risk to have two users with the same field camp?</p>
    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.
    1. This table or related slice is empty.
    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