如何在MySQL中移动然后删除字段 [英] How to move then delete field in MySQL

查看:104
本文介绍了如何在MySQL中移动然后删除字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一个字段从一个表移动到另一个表,然后从第一个表中删除它.我遇到的问题是,它可以很好地移动数据,但不能将其从第一个表中删除.

I am trying to move a field from one table to another and then delete it from the first table. The problem I am having is that it moves the data fine, but it is not deleting it from the first table.

这是我的代码:

"INSERT INTO out_tickets SELECT * FROM tickets";
        "DELETE FROM tickets WHERE * FROM tickets";

不确定我在做什么错吗?

Not sure what I am doing wrong?

编辑

更新代码:

<?php
// Process delete operation after confirmation
if(isset($_POST["id"]) && !empty($_POST["id"])){
// Include config file
require_once 'config.php';

// Prepare a select statement
$sql = "INSERT INTO out_tickets SELECT * FROM tickets";
        "DELETE FROM tickets";

if($stmt = mysqli_prepare($link, $sql)){
    // Bind variables to the prepared statement as parameters
    mysqli_stmt_bind_param($stmt, "i", $param_id);

    // Set parameters
    $param_id = trim($_POST["id"]);

    // Attempt to execute the prepared statement
    if(mysqli_stmt_execute($stmt)){
        // Records deleted successfully. Redirect to landing page
        header("location: technical.php");
        exit();
    } else{
        echo "Oops! Something went wrong. Please try again later.";
    }
}

推荐答案

据我了解,您试图将 ALL 列从一个表(t1)移至另一个具有相同结构的表(t2)(或到表,其中包含与第一个相同的列),然后您要从移至t2的table1中删除数据? 如果正确,请使用下一个SQL

As I understand you trying to move ALL columns from one table (t1) to another table (t2) with same structure (or to table, that contain same columns like in first) and than you want to delete data from table1 that you moved to t2? If correct use next SQL

INSERT INTO t2 SELECT * FROM t1;
DELETE FROM t1 WHERE 1;

这篇关于如何在MySQL中移动然后删除字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆