select t1.* from table1 t1 where not exists (select t2.c1 from table2 t2 where t2.c1 = t1.c1)
select t1.* from table1 t1 where t1.c1 not in (select t2.c1 from table2 t2)
truncate table dbo.Employe1 --快速全表清空,无日志删除方法
delete dbo.employe1 where id = 1 --主键值未全部清空,记录日志,可以有选择的删除
drop table dbo.employe2 --删除表及其保存的数据
select case p.bPub when 1 then '是'
when 0 then '否'
else '无'
end from tbl_Publish_Object p --case when then
update A_emp set company=d.company from A_emp e,A_dept d where e.deptid=d.id --跨表更新数据
select * into dbo.employe4 from dbo.employe where 1=1 --复制表结构建新表,并且复制数据
select * into dbo.employe4 from dbo.employe where 1=2 --复制表结构建新表,并且不复制数据
insert into dbo.employe4 select * from dbo.employe where id =2 --按条件插入数据到已存在的表中
DATEDIFF ( datepart , startdate , enddate )
datePart = enddate - startDate
select datediff(year,'2008-04-01','2008-04-23') from tbl_work
结果为 0 表示所差年份为0
select datediff(month,'2008-02-01','2008-04-23') from tbl_work
结果为 2 表示所差年份为2
select datediff(month,'2008-02-01','2008-01-23') from tbl_work
结果为 -1
select datediff(day,'2008-02-01','2008-02-23') from tbl_work
结果为 22 表示所差天数为22
select datediff(hour,'2008-02-01 15:51:54','2008-02-02 01:51:54') from tbl_work
结果为 10,表示相差10个小时