Is it possible to edit the query result in workbench? - mysql

I need to delete some records that comes out of the query result. But the query result is marked as Read Only. even when I query the primary key. The problem is my DB is so large (not much, 1.5 million record) that I can not right click on the table and choose Edit table data as I get the error no. 2008: mysql client ran out of memory which I could not solve (though, my pc has 8 GB RAM). My DB is loaded in the localhost so the client is the server. Please, help.

MySQL Workbench is by default set into secure mode (they call it "Safe updates" mode) meaning that one cannot update or delete rows within SQL editor until WHERE clause with (primary) key or LIMIT parameter is not explicitly defined:
So the query:
DELETE FROM table WHERE name='xyz'
will not work (will not really delete rows) until you define WHERE with PK:
DELETE FROM table WHERE id=100
or
DELETE FROM table WHERE name='xyz' LIMIT 1
To disable secure mode in Workbench go into Edit->Preferences->SQL Editor tab and uncheck "Safe updates" checkbox. But be careful then! :-)

To edit a big table:
You can right click the "Send to SQL Editor -> SELECT All Statement".
Then before running, this, add a LIMIT 100 in that SELECT or a WHERE condition to filter the rows returned.
You can also go to "Preferences -> SQL Editor" and mark the "Limit Rows" checkbox. If you set it to, say 1000, then the "Edit Table" command will fetch the first 1000 rows. You can then move to the next "page" by clicking on the "Fetch next frame of records from the data source" button.
Your other question:
It's not always possible to edit a result set. If it involves GROUP BY or data from more than one tables, then the result set may be Read-only. In that case, you could write a DELETE or UPDATE statement to do the deletion or updates for you.

Related

Update query does not return any values

When I try to create a simple update query with Subtraction or anything else in the same table, it doesn't return me any value, could it be something to do with formating?
This is SQL code: UPDATE Sales SET Sales.GrossProfit = [SubTot]-[Cost];
It doesn't return any value.
I have copied syntax from different databases (from colleagues) where the same type of query worked. Could it be something to do with my general Access settings?
UPDATE Sales SET Sales.GrossProfit = [SubTot]-[Cost];
I expect the query to update the GrossProfit column with the calculation "SubTot - Cost"
Strictly speaking, an UPDATE query does not "return" any columns. It only changes data in existing rows, but by itself does not return those changes back to you. (It is more accurately called an Update statement since it does not return data.)
For instance, if you were to execute the UPDATE statement in VBA code, you would not get a RecordSet of columns like with a SELECT query. To get the results after executing the UPDATE statement would require that you execute a separate SELECT query.
However, I assume that you are viewing the Update query in the Access query designer. Correct?
In that case, when you click on the View button (Datasheet View), Access tries to be smart & useful about the UPDATE and converts it temporarily into a SELECT query so that you can visualize the existing data in the columns. The Datasheet View does not actually run the UPDATE statement, nor does it show a preview of what will happen when you do run it.
While in Design View or SQL View for an Update query (or for Delete, Make Table, and Append queries), there is a Run button with a red exclamation point (on the Design ribbon/toolbar). Clicking that button will actually execute the query that changes the table values. Although it will not show you results row by row, you should get a pop-up telling you how many rows were changed due to the statement. (You may also get confirmation prompts that the statement is about to change data in the table.)

Rows keep showing #DELETED

Everytime I enter data into one of the SQL linked tables, some of the rows keep saying #deleted no matter what I do. The data is fine in the actual SQL server but not within Access. I never have used Access before so I have no idea what I'm doing. Please use the most non-tech savy dialog as possible... This is all so new to me and I am not good with technology at all.
I have tried refreshing the tables by going to the "Linked Table Manager" thing but that hasn't helped. I tried completely deleting the data from both Access and the SQL Server, re-entering it into the SQL server, and creating a new linked table within Access. I have tried exporting the data into Excel from the server and importing it into Access. None of it has worked. It's only the first 10 rows of data though... The rest of the table is completely fine and all the data has similar structure so I don't know why only the first 10 rows are being affected.
Ok, there are 3 things that often cause this.
1 - Make sure the sql table has a PK column. This is often (useally) a autonumber (incrementing by 1 integer column). So when you create the column in sql server, set it as primry key (a button in the menu can be hit to set PK using the sql manager). Then change in the property sheet the column to identify "yes" and it will set the starting number (1) and the increment (1) for you. Now add the other columns.
So Access needs a PK column.
If above was not your issue, then next up that is common is if you have a "bit" column in sql eerver. These can't be null, or access goes crazy. so if you have a bit column, then MAKE sure you set the default for that in the sql table designer as (0).
If the above don't fix your issue? Then number 3 on the list is to add what is called a row version column to the sql table. Simply add a timestamp column (this is NOT a date column, but is a time stamp row).
In ALL of the above cases, after you make the change to the sql server table, you have to re-link the access table. It is sufficient to right click on the table in Access, choose linked table manager, and then check box the table in queston, and hit ok. The link will be refreshed for you.
So the above are the 3 main issues. In most cases, the PK is the issue. However, if the table on SQL also has a trigger (that inserts) to other tables, then that table trigger has to be changed - but lets take this 1 step and soluion at a time.
As a general rule, Access needs a PK column when working with sql server. If you have that, then check the null "bit" issue - sql server tables need a default setting of 0 for those columns, and if they are null, then Access don't like that.
If both above issues are NOT your issue, then adding a column of timestamp to the sql table will fix this.

DELETE query results in 'Query Interrupted' MySQL Workbench?

I can successfully delete records manually by click-selecting & deleting row(s) but executing delete queries result in 'Query Interrupted'.
My deletion queries are in the form:
DELETE FROM table where column = value;
The select statement uses the same values:
SELECT * FROM table WHERE column = value;
and returns desired results.
What could be causing the delete statement to fail? Are there limits on the amount of records you can delete at once in workbench?
If you wish to delete the entire contents of a table you can use Truncate.
TRUNCATE [TABLE] tbl_name
Please see the docs: https://dev.mysql.com/doc/refman/5.7/en/truncate-table.html
Using the DELETE function is usually used for deleting single rows.
According to the documentation, in the Preferences >> SQL Editor >> Other, the Safe Updates setting is on by default.
Safe Updates (rejects UPDATEs and DELETEs with no restrictions)
Enabled by default. Prevents UPDATE and DELETE queries that lack a corresponding key in a WHERE clause, or lack a LIMIT clause, from executing. This option requires a MySQL server reconnection.
When selected, this preference makes it possible to catch UPDATE and DELETE statements with keys that are not used properly and that can probably accidentally change or delete a large number of rows.
I think what this says is that if the setting is on, then the column you are filtering by in the DELETE or UPDATE statement must be the primary key, it cannot be just any column.
If you change the setting to off, then you might need to restart MySQL Workbench for the change to take effect (at least under Linux).
There is a default thousand-row limit in MySQL-Workbench. The SELECT query will return results but DELETE will fail if the number of records to be deleted exceeds one thousand. One option is to limit the results in the query itself or you can adjust the settings as stated in the documentation.

Unable to edit or delete fields using phpmyadmin

I have installed phpMyadmin 4.5.0.2 on Mac book Pro. I am not able to delete rows from my table using "Delete" button nor edit values by double clicking on them. The SQL generated to do this not correct where in it is omitting where clause like below
DELETE FROM Dimn_Observation WHERE LIMIT 1
If I manually type SQL statements it executes Ok. but I am not able to select few rows directly and neither modify or delete rows.
How do I solve this issue.

One of my MySQL database tables empties every night, how do I make it stop?

For the last two nights I've lost all of the data in just one of my tables. I don't have any cron jobs setup. I checked crontab -e for both root and my primary user on my ec2 server and they are empty. Please help.
Also, in past experience emptying a table causes the id's of newly inserted rows to start over at 0. The id's of rows that i'm inserting into the emptied table now are continuing from where the old data left off, perhaps suggesting that the old data is still there?
P.S.
There are no triggers s, but when I go to the SQL query section of phpmyadmin I found the following line of code: SELECT * FROM articles WHERE 1; It had "do not overwrite this query from outside this window" selected as well as "show this query here again". It just so happens that my articles table is what was being deleted. Could this be the source of my problem?
After deleting the SELECT code which was stored in the query box, the table emptying ceased to occur.