ERROR 1452: Cannot add or update a child row: a foreign key constraint fails

I have created tables in MySQL Workbench as shown below : ORDRE table: PRODUKT table: and ORDRELINJE table: so when I try to insert values into ORDRELINJE table i get: Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (srdjank.Ordrelinje, CONSTRAINT Ordrelinje_fk FOREIGN KEY (Ordre) REFERENCES Ordre (OrdreID)) I’ve … Read more

Simple Random Samples from a Sql database

There’s a very interesting discussion of this type of issue here: http://www.titov.net/2005/09/21/do-not-use-order-by-rand-or-how-to-get-random-rows-from-table/ I think with absolutely no assumptions about the table that your O(n lg n) solution is the best. Though actually with a good optimizer or a slightly different technique the query you list may be a bit better, O(m*n) where m is the number … Read more

how to overcome ERROR 1045 (28000): Access denied for user ‘ODBC’@’localhost’ (using password: NO) permanently

for some reason, the ODBC user is the default username under windows even if you didn’t create that user at setup time. simply typing without specifying a username will attempt to connect with the non-existent ODBC username, and give: Error 1045 (28000): Access denied for user ‘ODBC’@’localhost’ (using password: NO) Instead, try specifying a username … Read more

mysql: SOURCE error 2?

Assuming you mean that you are trying to use the source command in order to execute SQL statements from a text file, the error number given appears to be passed through from the POSIX layer. Therefore, using this resource, we can deduce that the error value of 2 means “no such file or directory”. In short, you got the path … Read more

How can I loop through all rows of a table? (MySQL)

Since the suggestion of a loop implies the request for a procedure type solution. Here is mine. Any query which works on any single record taken from a table can be wrapped in a procedure to make it run through each row of a table like so: First delete any existing procedure with the same … Read more

Getting “Lock wait timeout exceeded; try restarting transaction” even though I’m not using a transaction

You are using a transaction; autocommit does not disable transactions, it just makes them automatically commit at the end of the statement. What is happening is, some other thread is holding a record lock on some record (you’re updating every record in the table!) for too long, and your thread is being timed out. You … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)