sql-delete

How to optimize DELETE .. NOT IN .. SUBQUERY in Firebird

断了今生、忘了曾经 提交于 2020-01-14 08:44:10
问题 I've this kind of delete query: DELETE FROM SLAVE_TABLE WHERE ITEM_ID NOT IN (SELECT ITEM_ID FROM MASTER_TABLE) Are there any way to optimize this? 回答1: You can use EXECUTE BLOCK for sequential scanning of detail table and deleting records where no master record is matched. EXECUTE BLOCK AS DECLARE VARIABLE C CURSOR FOR (SELECT d.id FROM detail d LEFT JOIN master m ON d.master_id = m.id WHERE m.id IS NULL); DECLARE VARIABLE I INTEGER; BEGIN OPEN C; WHILE (1 = 1) DO BEGIN FETCH C INTO :I; IF

Difference between DELETE and DELETE FROM in SQL?

冷暖自知 提交于 2020-01-14 07:15:29
问题 Is there one? I am researching some stored procedures, and in one place I found the following line: DELETE BI_Appointments WHERE VisitType != ( SELECT TOP 1 CheckupType FROM BI_Settings WHERE DoctorName = @DoctorName) Would that do the same thing as: DELETE FROM BI_Appointments WHERE VisitType != ( SELECT TOP 1 CheckupType FROM BI_Settings WHERE DoctorName = @DoctorName) Or is it a syntax error, or something entirely different? 回答1: Assuming this is T-SQL or MS SQL Server, there is no

Is it possible to Disable deletes on a table on MYSQL?

房东的猫 提交于 2020-01-13 02:53:09
问题 I'm using MySQL 5.0 and I would like to know if there's a way to disable deletes on a table. As in, not make it possible for ANY user to delete anything from the tablets, only update and insert. 回答1: Yes, see the MySQL manual for the GRANT syntax Here is an example of what you want: GRANT SELECT, INSERT ON mydb.mytbl TO 'someuser'@'somehost'; Which gives only SELECT and INSERT privilages to a specific user/host on a specified table. 回答2: You can use grant as proposed by others. Or you can

DELETE all where MySQL foreign key constraint does not fail

ぐ巨炮叔叔 提交于 2020-01-12 14:03:11
问题 I am trying to delete a few records but am getting the following error: Cannot delete or update a parent row: a foreign key constraint fails The thing is, the foreign key constraint is failing for only 1 or 2 of my 100 records I wish to delete. I wish to write a query which deletes these 98-99 records, skipping the 1 or 2 which failed , which I can later manually inspect and delete/modify. Not stopping because of some single problematic record, but continuing with the others, ignoring that.

DELETE all where MySQL foreign key constraint does not fail

て烟熏妆下的殇ゞ 提交于 2020-01-12 14:02:31
问题 I am trying to delete a few records but am getting the following error: Cannot delete or update a parent row: a foreign key constraint fails The thing is, the foreign key constraint is failing for only 1 or 2 of my 100 records I wish to delete. I wish to write a query which deletes these 98-99 records, skipping the 1 or 2 which failed , which I can later manually inspect and delete/modify. Not stopping because of some single problematic record, but continuing with the others, ignoring that.

Deleting a single SQLite row

岁酱吖の 提交于 2020-01-06 15:13:41
问题 I am trying to delete a single row using onLongClick of list item but sometime it deletes the row and sometimes doesn't. Maybe I am passing the wrong id to it I don't getting what actually problem is. I have tried some code and I am trying from last 2 days but unable to resolve this. Below is my code. @Override public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, final long id) { AlertDialog.Builder alert = new AlertDialog.Builder(FavouriteListActivity.this);

SQL Delete with Subquery

纵然是瞬间 提交于 2020-01-05 08:33:34
问题 I'm trying to delete from a table with the results of a subquery. The results return a unique tuple, and currently I end up deleting more than just the results returned because i'm only checking col1 results. DELETE FROM Table1 exTable WHERE exTable.col1 = ... AND exTable.col2 = ... (SELECT col1, col2 FROM ...) 回答1: Use a join to match more than 1 column. DELETE t1 FROM Table1 t1 inner join ( select col1, col2 from other_table where ... ) t2 on t2.col1 = t1.col1 and t2.col2 = t1.col2 来源:

Removing Duplicate Data from a Table using MySQL

白昼怎懂夜的黑 提交于 2020-01-05 07:05:25
问题 I am trying to remove duplicate data from my database. I found a nice example on here of how to do this on an oracle database. The bottom query from that answer (only selecting the duplicate rows) works in MySQL, but the delete query (see below) does not... "DELETE FROM studios as a WHERE a.id > ANY (SELECT b.id FROM studios as b WHERE a.name = b.name AND a.email = b.email )" The error I get is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server

DELETE FROM … reporting syntax error at or near “.”

自古美人都是妖i 提交于 2020-01-04 14:17:08
问题 I'm trying to delete just one data from my DB, but, when I write the command I keep getting that there's some syntax error, could you tell me where is the error? This are the commands I've tried: DELETE FROM database_userprofile WHERE user.username = 'some'; ERROR: syntax error at or near "." LINE 1: DELETE FROM database_userprofile WHERE user.username = 'some'... DELETE FROM database_userprofile USING database_user WHERE user.username="some"; ERROR: syntax error at or near "." LINE 1: ...

Add Delete Button to PHP results table

好久不见. 提交于 2020-01-01 07:24:14
问题 I have outputted the results of a MySQL table to an HTML table. In the last column, I want to add a delete option which calls another form and deletes the user. I can't seem to get it to work though. This is my code for the results page: <?php $contacts = mysql_query(" SELECT * FROM contacts ORDER BY ID ASC") or die( mysql_error() ); // If results if( mysql_num_rows( $contacts ) > 0 ) ?> <table id="contact-list"> <thead> <tr> <th>Name</th> <th>Email</th> <th>Telephone</th> <th>Address</th>