Sql Server根据记录集批量更新数据库
update t1 set t1.value=t2.value from t2 where t1.id=t2.id
update jbsite_class set topicnum = count
from (select t2.classid,count from (
select distinct classid,count(*) as count
from jbsite_product
group by classid) t2
inner join jbsite_product on jbsite_product.id = t2.classid
) b where jbsite_class.id=b.classid
相关文档:
游标是从数据库中提取出来的数据,以临时表的形式存放在内存中,在游标中有一个数据指针,在初始状态下指向首记录, 利用fetch语句移动该指针,从而对游标中的数据进行各种操作。
1.定义游标
cursor 游标名 is select语句;
2.打开游标
open 游标名;
3.提取游标数据
fetch 游标名 into 变量名1, 变量名2, ....;
或
......
一个简单的小实例就明白~!
user表
在这张表中建立触发器
Create trigger tiggername
on user
for delete
as
begin ......
在SQL Server2005/2008中可以使用一下四个命令来调优sql语句以及检查调优的结果
set
statistics time on
set
statistics IO on
set
statistics profile on
set
statistics xml on
......
Sql代码:Powered by chenjiazi
--查询当天:
select * from info where DateDiff(dd,datetime,getdate())=0
--查询24小时内的:
select * from info where DateDiff(hh,datetime,getDate())<=24
--info为表名,datetime为数 ......
1
、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select
*
from
people
where
peopleId
in
(
select
peopleId
from
people
group
by
peopleId
having
cou ......