1、
delete from company t1
where t1.ifend=0 and
not exists (select 1
from department t2
where t2.departmentid like t1.companyid +'%')
删除DEPARTMENT中的记录也一样。2、
delete from department t1
where not exists (select 1 from company t2 where t1.departmentid like t2.companyid +'%')
删除Employee中的记录也一样。
delete from company t1
where t1.ifend=0 and
not exists (select 1
from department t2
where t2.departmentid like t1.companyid +'%')
删除DEPARTMENT中的记录也一样。2、
delete from department t1
where not exists (select 1 from company t2 where t1.departmentid like t2.companyid +'%')
删除Employee中的记录也一样。
解决方案 »
- 求助:如何实现如下情况
- 问一句 SQL语句 修改某个逗号前的数字
- 小弟刚学SQL2000遇到了个问题!希望高手进来看下啊 !感激不尽啊!!
- MS-SQL-SERVER同样数据合并问题!!
- 如何用键盘输入空值
- 请教:在执行一个SELECT 语句时,如何让每行前加一列,此列为行号,即1 2 3 ... 谢谢!!
- 请教各位大虾,建立校园成绩查询系统需要哪些工具呢?
- 关于SQLSERVER中时间形式的转化问题....急...
- 为什么我就是没法连接我的SQL Server 2000!!!!!
- SQL Desktop 7.0版本只支持一个客户机与之相连吗??
- 我默认安装的sql server 2000,我在别的机器上为什么联不上sql server
- 实现以下功能 , 要求一条 UPDATE 语句搞掂 !
谢谢 icevi(按钮工厂),解释一下好吗?
delete from company t1 --“t1”是什么意思呀?
where t1.ifend=0 and
not exists (select 1 --“1”是什么意思?
from department t2
where t2.departmentid like t1.companyid +'%')
我在运行时报错“Incorrect syntax near 't1'.”
not exists(select DepartmentID from Department where DepartmentID like Company.CompanyID+'%')
delete Department where ifend=0 and
not exists(select EmployeeID from Employee where EmployeeID like Department.DepartmentID+'%')2 delete Employee
from Employee a,Department b
where a.EmployeeID not like b.DepartmentID+'%'
delete Department
from Department a,company b
where a.DepartmentID not like b.companyID+'%'
-----------------------------------------------------------
未经调试,大意是这样。
从逻辑上考虑,先作2
这个应该从上往下进行:
delete Department d
where not exixts (select CompanyID from Company c
where d.DepartmentID like c.CompanyID +'%')delete Employee e
where not exixts (select DepartmentID from Department d
where e.EmployeeID like d.DepartmentID + '%')1.你的这个删除逻辑上应该是从下往上进行的。
delete Department d
where not exists(select DepartmentID from Employee e
where e.EmployeeID like d.DepartmentID + '%')
and d.ifned = 0delete Company c
where not exists(select CompanyID from Department d
where d.DepartmentID like c.CompanyID + '%')
and c.ifned = 0大概就是这样,没有测试。试一试吧。--“t1”是什么意思呀? 这个是起一个别名。
from company ti,department t2
where t1.ifend=0 and t2.departmentid not like t1.companyid +'%'
--------------------------------------------------------
我替按钮改改。
谢谢各位,我在问题中是想表达的意思是like CompanyID+'%',因为CompanyID为0001,DepartmentID为000101所以DepartmentID like CompanyID+'%'.