如何使用多个表删除sql中的记录
我在sql中遇到问题,谁能帮我 我有3张桌子 sublocation、postingdetail 和员工
我必须从 sublocation 表中删除 sublocid 但首先我必须检查是否有任何员工在 postsdetail 表中处理该子位置,如果是,则不应删除该记录。
表子定位
sublocid
子地址名
mainlocid
表 postsdetail
empid
子区域
mainloc
表员工
empid
员工姓名
亚定位
mainlocid
I'm having a problem in sql, can anyone help me
I have 3 tables
sublocation, postingdetail and employee
I have to delete sublocid from sublocation table
but first i have to check that is there any employee working on that sublocation from postingdetail table, if yes then the record shouldn't be deleted.
table sublocation
sublocid
sublocname
mainlocid
table postingdetail
empid
subloc
mainloc
table employee
empid
empname
sublocid
mainlocid
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
像这样的东西
可能会起作用。
Something like
That might work.
好吧,我不熟悉 sql-server,我自己是 MySQL 用户,但我知道 sql-server 确实有存储过程...这就是存储过程的用途...
这里有一个关于存储过程的小教程。
Well I am not familiar with sql-server, I am a MySQL user myself, but I know sql-server does have stored procedures... and that's what stored procedures were made to do...
Here is a little tutorial on stored procedures.
我不明白postingdetail表的含义,也不明白为什么我们从表employee而不是postingdetail中获取sublocid,但是您的查询应该如下所示:
I don't understand the meaning of the postingdetail table, and why we are taking the sublocid from table employee rather than postingdetail, but you query should look something like this: