1,将表中的某一列(CostTime)中的post days 全部替换成Tage
update SYS_Delivery set CostTime = REPLACE(CostTime,'post days','Tage' )
2.将有一个表的数据更新相对应的字段。
select * from SYS_ProtectionVal
Select * from SYS_ProtectionVal$
update SYS_ProtectionVal set ProtectionVal = SYS_ProtectionVal$.ProtectionVal
from SYS_ProtectionVal$
Where SYS_ProtectionVal.DID = SYS_ProtectionVal$.DID
使用excel将数据导入到数据库中。
3.创一个表中的数据复制到新创建的另外一个表中去。
select * into NewTable from OldTable
应用:当做临时表来使用
4实现数据的二次查询(可用临时表来替换)
select * from (select * from tableNew) as b where "条件"
5.跨数据库中的访问,将一个数据库中的某一个表的数据存放到另外一张表。
insert into tableneed(name) select name from [数据库名].[dbo].[tablegive]
6.说明:两张关联表,删除主表中已经在副表中没有的信息
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )
应用:可以将没有下过单的用户的信息删除掉。在数据库中只保留有下过单账号。
7.将一个星期前的数据显示出来
select * from table where datediff(D,startTime,getdate)>7