sql-delete

MySQL Multi-Delete. Is it possible to multi-delete referenced rows?

守給你的承諾、 提交于 2019-12-11 10:34:55
问题 If I have a parent table and a child table, is it possible to multi-delete the rows in them without having a "ON DELETE CASCADE" constraint? In this example: create table a(id int primary key); create table b(id int primary key, a_id int, constraint fkb foreign key (a_id) references a(id)); Is it not possible to do something like this in order to delete rows in tables a and b? :-( delete a, b from b inner join a on a.id = b.a_id where a.id = ?; Error Code: 1451. Cannot delete or update a

How to delete rows of database results using checkbox

杀马特。学长 韩版系。学妹 提交于 2019-12-11 10:18:53
问题 I'm trying to delete rows of MySQL date using Checkboxes. When I apply the script below it doesn't do what I want it to do. Action is not performed.. And I get Undefined variable: checkbox in C:\wamp\www\project\topics.php on line 108 I tried echoing out the actual sql that is being sent for execution and it gave this DELETE FROM forum_topics WHERE topic_id = intval() PHP <?php $topics = mysql_query(" SELECT topic_id , topic_head , topic_tags , topic_owner , topic_date FROM forum_topics ") or

Checkbox inside a php foreach loop to delete whatever is checked

微笑、不失礼 提交于 2019-12-11 09:03:09
问题 echo "<form name='input' action='admin_selecteren_voor_verwijderen.php' method='post'>"; $sql_bestelling= "SELECT * FROM producten"; foreach($dbh->query($sql_bestelling) as $row) { $product_id=$row['product_id']; $product_naam=$row['product_naam']; $prijs=$row['prijs']; $foto=$row['foto']; echo " <br> <img src='$foto' height='70' width='50' border='0'> <b>$product_naam</b> <input type='checkbox' name='$product_naam' value='$product_naam'></br> </br></br></br>"; //if (isset($_POST['submit'])){

Better method to delete multiple rows in a MySQL database with PHP?

为君一笑 提交于 2019-12-11 08:58:15
问题 Let's say I have an array with a bunch of ids for a mysql table: $idList = array('1','2','3','4','5'); I want to delete the rows associated with each id. Which method is more preferable/better/faster (IYO)? $idListString = implode(",",$idList); mysql_query("DELETE FROM this_table WHERE id IN ($idListString)"); or foreach($idList as $value) { mysql_query("DELETE FROM this_table WHERE id = '$value'"); } 回答1: I'm no expert, but I believe $idListString = implode(",",$idList); mysql_query("DELETE

Delete all rows but one with the greatest value per group

和自甴很熟 提交于 2019-12-11 08:24:03
问题 So, I just recently asked a question: Update using a subquery with aggregates and groupby in Postgres and it turns out I was going about my issue with flawed logic. In the same scenario in the question above, instead of updating all the rows to have the max quantity, I'd like to delete the rows that don't have the max quantity (and any duplicate max quantities). Essentially I need to just convert the below to a delete statement that preserves only the largest quantities per item_name. I'm

DELETE query with WHERE EXISTS in MySQL [duplicate]

狂风中的少年 提交于 2019-12-11 05:50:11
问题 This question already has answers here : MySQL Error 1093 - Can't specify target table for update in FROM clause (15 answers) Closed 3 years ago . I am executing the query with "where exists" using one table in MySql. It works fine with SELECT *, but fails when I try to do DELETE instead of SELECT *. How to perform the same query with delete? Many thanks in advance! select * from MyTable t1 where exists ( select * from MyTable t2 where t1.user_id = t2.user_id and t1.object_id <> t2.object_id

All Row has a Delete Button in Gridview

邮差的信 提交于 2019-12-11 05:21:03
问题 I have a simple page like this. ( EKLE = ADD , SİL = DELETE ) And my AVUKAT Table like this. Simplify, When i choose first dropdown MUSTERI and second dropdown AVUKAT , add the database (getting HESAP (number) automaticly) or delete the database and gridview. This is my code. ADD Click protected void Add_Click(object sender, EventArgs e) { string strConnectionString = ConfigurationManager.ConnectionStrings["SqlServerCstr"].ConnectionString; SqlConnection myConnection = new SqlConnection

Move data from one table to another

核能气质少年 提交于 2019-12-11 04:35:19
问题 This question seems to be answered multiple times. However none match the criteria I need. Is it possible to select (and insert them in another table) and delete rows from the original table in Mysql without running the selected criteria twice? For example I could do this: INSERT INTO main (SELECT * FROM temp WHERE age > 30) DELETE FROM cache WHERE age > 30 However with a very complex and long running query the 'match part' of the query would be executed twice, whilst I think that there

Deleting large amounts of data from SQL Server 2008

两盒软妹~` 提交于 2019-12-11 04:07:21
问题 I have a scenario where I have to update in multiple tables, that are dependent to each other e.g has relationship, with large data from a web page, where lot of textboxes, checkboxes and dropdownlists are there. I am using jQuery.ajax to save the data. New data save method is written there and it is working. Now it is very difficult to handle large amount of data for update purpose. I have an idea that I will delete all data and save it as new row. Is this a good idea or not? What should I

Deleting from sqlite database using IN

眉间皱痕 提交于 2019-12-11 03:59:11
问题 I am deleting from an sqlite database using the ids of the records like this (the dirID is an array of the IDs): Dim i As Integer = 0 Dim conn As New SQLiteConnection("Data Source=" & DBPath) Dim cmd As New SQLiteCommand("DELETE FROM directory WHERE id IN (@ID)", conn) cmd.Parameters.AddWithValue("@ID", Join(dirID, ",")) 'conn.SetPassword(dbPassword) conn.Open() Try mytransaction = conn.BeginTransaction() '// delete directory // If dirID IsNot Nothing Then cmd.ExecuteNonQuery() End If