sql-delete

PDO query is always returning 1 or true

旧城冷巷雨未停 提交于 2019-12-31 02:44:51
问题 I am trying to check if a row exists before I delete it. The row in my table doesn't exist but it always returns 1 : $orders = $this->db->prepare("SELECT * FROM orders WHERE id=? AND user=?"); $check = $orders->execute(array($message,$this->model->checkapi($data,$message))); echo $check; if($check){ $deleteorder = $this->db->prepare("DELETE FROM orders WHERE id=? AND user=?"); $deleteorder->execute(array($message,$this->model->checkapi($data,$message))); array_push($result, array('success' =>

I can´t use alias in sql delete

只愿长相守 提交于 2019-12-30 10:49:33
问题 I tried execute this sql sentence delete from reclamo r where exists ( select 1 from reclamo r join cliente c on r.cod_cliente = c.cod_cliente join localidad l on c.cod_localidad = l.cod_localidad where l.descripcion = 'San Justo'); for remove all the claims made by customers of the town of 'San justo' but it says "Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'r where exists ( select 1

SQL Server DELETE is slower with indexes

蹲街弑〆低调 提交于 2019-12-30 04:47:09
问题 I have an SQL Server 2005 database, and I tried putting indexes on the appropriate fields in order to speed up the DELETE of records from a table with millions of rows ( big_table has only 3 columns), but now the DELETE execution time is even longer ! (1 hour versus 13 min for example) I have a relationship between to tables, and the column that I filter my DELETE by is in the other table. For example DELETE FROM big_table WHERE big_table.id_product IN ( SELECT small_table.id_product FROM

Oracle sql merge to insert and delete but not update

雨燕双飞 提交于 2019-12-30 04:03:12
问题 Is there a way to use oracle merge to insert and delete but not update? I have a table representing a set of values related to a single row in another table. I could change the set of values by deleting them all and adding back the new set, or by selectively deleting some and adding others, but I am interested in making it a single statement if possible. Here is a working example with update. In order to make this work, I had to add dummy so that a column was available to update that was not

“The total number of locks exceeds the lock table size” Deleting 267 Records

帅比萌擦擦* 提交于 2019-12-29 07:34:09
问题 I'm trying to delete 267 records out of about 40 million. The query looks like: delete from pricedata where pricedate > '20120413' pricedate is a char(8) field. I know about adjusting innodb_buffer_pool_size , but if I can do select from pricedata where pricedate > '20120413' and get 267 records (and that's all there are), no errors, why does it choke on the delete? And if adjusting innodb_buffer_pool_size doesn't work, what should I do? 回答1: It seems that you don't have an index on pricedate

MYSQL delete all results having count(*)=1

回眸只為那壹抹淺笑 提交于 2019-12-29 04:24:08
问题 I have a table taged with two fields sesskey (varchar32 , index) and products (int11), now I have to delete all rows that having group by sesskey count(*) = 1. I'm trying a fews methods but all fails. Example: delete from taged where sesskey in (select sesskey from taged group by sesskey having count(*) = 1) The sesskey field could not be a primary key because its repeated. 回答1: DELETE si FROM t_session si JOIN ( SELECT sesskey FROM t_session so GROUP BY sesskey HAVING COUNT(*) = 1 ) q ON q

INSERT deleted values into a table before DELETE with a DELETE TRIGGER

大憨熊 提交于 2019-12-29 01:34:24
问题 For some reason I can't find the exact answer that I need. I searched for at last 20 minutes in here. I know it's simple. VERY simple. But I can't fire the trigger for some reason.. I have a table with two columns dbo.HashTags |__Id_|_name_| | 1 | Love | I want to insert the deleted values into another table called dbo.HashTagsArchive on a DELETE query. Example: DELETE FROM [dbo].[HashTags] WHERE Id=1 After this example I should have the deleted row in dbo.HashTagsArchive and the row with Id

TSQL Try / Catch within Transaction or vice versa?

不想你离开。 提交于 2019-12-28 03:42:10
问题 I'm writing a script that will delete records from a number of tables, but before it deletes it must return a count for a user to confirm before committing. This is a summary of the script. BEGIN TRANSACTION SCHEDULEDELETE BEGIN TRY DELETE -- delete commands full SQL cut out DELETE -- delete commands full SQL cut out DELETE -- delete commands full SQL cut out PRINT 'X rows deleted. Please commit or rollback.' --calculation cut out. END TRY BEGIN CATCH SELECT ERROR_NUMBER() AS ErrorNumber,

How to delete a row in mysql?

跟風遠走 提交于 2019-12-25 14:10:15
问题 Is it possible to delete one or more rows from a table in MySql ? I want to delete the last two rows from the following table. +-------+--------------+-----------+--------------------+---------------+ | gp_no | no_of_member | amount | current_instalment | starting_date | +-------+--------------+-----------+--------------------+---------------+ | 1 | 15 | 375000.00 | 2 | 2015-05-01 | | 2 | 10 | 300000.00 | 1 | 2015-07-01 | | 3 | 15 | 450000.00 | 5 | 2015-04-01 | | 4 | 10 | 400000.00 | 0 | 2015

How to delete a row in mysql?

五迷三道 提交于 2019-12-25 14:10:06
问题 Is it possible to delete one or more rows from a table in MySql ? I want to delete the last two rows from the following table. +-------+--------------+-----------+--------------------+---------------+ | gp_no | no_of_member | amount | current_instalment | starting_date | +-------+--------------+-----------+--------------------+---------------+ | 1 | 15 | 375000.00 | 2 | 2015-05-01 | | 2 | 10 | 300000.00 | 1 | 2015-07-01 | | 3 | 15 | 450000.00 | 5 | 2015-04-01 | | 4 | 10 | 400000.00 | 0 | 2015