易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL查询问题 - MS-SQL Server / 基础类

有表t,表b,其中t有id,title,content,表b有id,tid,title,content.其中t的id与b的tid是关联的.
现在我想删b中content为空的b记录和t中相应的记录?
该怎么写?
有一天
你这个意思是用触发器?

删b中content为空的b记录和t中相应的记录

同时删除吗?

SQL code:
delete b where content is null
go
delete t where not exists(select 1 from b where tid=t.id)
go


SQL code:
delete b where content is null
delete t from t inner join b on t.id=b.tid where b.content is null


引用
删b中content为空的b记录和t中相应的记录

同时删除吗?


是的..要两个表中的那些数据同时删除!

同时删除要触发器把!
我试试3楼和4楼的方法!

SQL code:
delete t from t inner join b on t.id=b.tid where b.content is null
delete b where content is null


试一下
SQL code:

delete t ,b
from
b left join t on b.id = t.id where b.content is null




首先的问题是tid是主键还是T表中ID是主键?
如果要删除


相关问答:

Asp+sql server问题 - Web 开发 / ASP

我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例: ......

sql小小的疑问 - .NET技术 / C#

可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......

ASP链接SQL的简单登陆界面 - .NET技术 / ASP.NET

protected void btnLogin_Click(object sender, EventArgs e)
  {
  SqlConnection conn = new SqlConnection("Server = (local);user id = sa;pwd = 1;database = Login");
&nb ......

求一个SQL语句 - MS-SQL Server / 基础类

字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......

求一SQL写法 - MS-SQL Server / 基础类

id                           url                   rank     ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号