Friday 15 March 2013

sql server 2008 - Can I first SELECT and then DELETE records in one t-SQL transaction? -


I do not understand that this is an acceptable operation. I have to select a record from the database of SQL Server 2008 and then have to delete them, as a transaction from all the ASP.NET code. Note that the .NET code should be able to retrieve previously received data.

Something like this:

  SELECT * FROM [tbl] WHERE [id] & gt; 6; DELETE FROM [TBB] WHERE [id] & gt; 6   

I am with SQL Bedle but then if I do:

  SELECT * FROM [tbl]   < P> I get a full table as if nothing was destroyed.  

Edit below is requested to complete the records below. The NET code is:

  string strSQLStatement = "SELECT * FROM [TBB] WHERE [ID]> 6;" + "DELETE FROM [TBB] WHERE [ID]> 6"; (SqlDataReader rdr = cmd.ExecuteReader ()) {while (rdr.Read ()) {// value read val0 = rdr.GetInt32 (0); (SqlCommand cmd = new SqlCommand (strSQLStatement, connectionString)) Val3 = rdr.GetInt32 (3); //e.t.c. }}}}    

This selection will be deleted and deleted together: < Exclude> Deletion [tbl] Output Deleted * WHERE [id] & gt; 6

No comments:

Post a Comment