MySQL多表删除查询 [英] MySql multiple table delete query
本文介绍了MySQL多表删除查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在sql查询中执行多表删除,但似乎无法正确执行.查询如下.任何帮助将不胜感激. ''id''
已从代码的不同部分进行设置.
I am trying to execute a multi table delete in on sql query but I cant seem to get it right. the query is below. any help will be deeply appreciated. The ''id''
is already set from a different portion of the code.
connection = Properties.Settings.Default.cvmanagerConnectionString;
sql = "delete from apps, contacts, dept using apps join contacts, join dept where apps.FileLoc = contacts.FileLoc AND apps.FileLoc = dept.FileLoc AND apps.FileLoc = ''" + id + "''";
try
{
SqlConnection conn = new SqlConnection(connection);
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
推荐答案
从示例using apps join contacts join dept where
Judging from the examples here, it looks like you have an extra '','' in your query. I think it should be using apps join contacts join dept where
private void button1_Click(object sender,EventArgs e)
{
SqlConnection con =新的SqlConnection(数据源= jcs-pc;初始目录= deepak;持久安全信息=真实;用户ID = sa;密码= jcs#");
SqlCommand cmd =新的SqlCommand();
字符串s1 =插入深(id,name)values(1,''sandeep'')";
字符串s2 =插入深(id,name)values(1,''sandeep'')";
字符串s3 =插入sany(id,name'')values(1,''sandeep'')";
cmd.CommandText = s1 + s2 + s3;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
(sandeep.k115@gmail.com)
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=jcs-pc;Initial Catalog=deepak;Persist Security Info=True;User ID=sa;Password=jcs#");
SqlCommand cmd = new SqlCommand();
string s1 = "insert into deep (id,name)values(1,''sandeep'')";
string s2 = "insert into deep (id,name)values(1,''sandeep'')";
string s3 = "insert into sany (id,name'')values(1,''sandeep'')";
cmd.CommandText = s1 + s2 + s3;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
(sandeep.k115@gmail.com)
这篇关于MySQL多表删除查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文