我必須寫一個查詢來刪除表2表從2個表中刪除記錄
DELETE FROM [Policies],[BackupSpec] WHERE [PolicyID] = @original_PolicyID
PloicyID是策略 中的PK和Backupspec中的FK
任何建議?
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["SumooHAgentDBConnectionString"].ConnectionString;
string sql = "DELETE FROM [Policies],[BackupSpec] WHERE [PolicyID] = @original_PolicyID";
string sql1 = "DELETE FROM [Backupspec] WHERE [PolicyID] = @original_PolicyID";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlCommand cmd1 = new SqlCommand(sql1, conn);
cmd.Parameters.AddWithValue("@original_PolicyID", item);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
是不是有一個查詢來做到這一點.. ?? – user175084 2009-10-19 05:59:27
不在SQL Server中(例如,有一種方法可以在MySQL中執行此操作)。 – 2009-10-19 06:08:40