0

I have a database name test.dbo. In the database it have two table named Equipment and backup. I want to move some data in the table Equipment to table backup and delete the data in the table Equipment. So, what is the query to use to do it?

I have use this query but it only move the data to table backup without deleting it in table Equipment. Moreover, if i use the query again , error show that the table name already exits.

protected void Button5_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection("Data Source=5CG50749V3\\SQLEXPRESS;Initial Catalog=test;Integrated Security=True");
    con.Open();
    SqlCommand cmd = new SqlCommand("select * into test.dbo.[backup] from test.dbo.[Equipment] where (SerialNumber = '" + TextBox2.Text + "' or EquipmentID = '" + TextBox1.Text + "' )", con);
    cmd.ExecuteNonQuery();
    con.Close();
}
naz Edyra
  • 35
  • 2
  • 8
  • Possible duplicate of [Move SQL data from one table to another](http://stackoverflow.com/questions/1612267/move-sql-data-from-one-table-to-another) – sudheeshix Jan 23 '17 at 02:57

1 Answers1

0

For this, instead of the SELECT * INTO, use a DELETE statement with an OUTPUT INTO clause.

Reference: https://msdn.microsoft.com/en-us/library/ms177564.aspx

sudheeshix
  • 1,541
  • 2
  • 17
  • 28