sqlserver中的游标 [英] cursors in sqlserver

查看:89
本文介绍了sqlserver中的游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要你的帮助....


我有2张桌子,

1.usertable与列(用户标识,用户名,用户类型)

在这里我们可以给usertype = employee或customer,如果它是uerdetails表中的雇员,我需要更新emp count = 1,
包括在内,我需要将此记录更新为以前所有已注册的用户记录...如链式系统

2.userdetails带有列的表(userid,userscount,emp.count,cust.count)


在这里,主要是如果我是新的注册用户,那么所有特定计数都应更新为以前的注册用户.


i required some help from you....


i have 2 tables,

1.usertable with columns (userid,username,usertype)

here we can give usertype=employee or customer,if it is employee in uerdetails table i need to update emp count = 1,
include with this i need to update this records to all previous registered user records...like a chain system

2.userdetails table with columns(userid,userscount,emp.count,cust.count)


here,main thing is if iam a new registered user,then all particular counts should be updated to previous registered users.

推荐答案

如果我正确理解,您想根据其他表更新某些表中的计算信息.如果是这种情况,我建议您不要这样做.将计算结果(例如计数,乘法等)存储在数据库中通常会导致问题.

取而代之的是在获取数据时进行计算.这样,您始终可以获得正确的结果,并且在插入/更新阶段执行的SQL语句更少.
If I understood correctly, you would like to update calculated information in some table based on other tables. If that''s the case I suggest you don''t do that. Storing calculation (such as count, multiplications etc) results in the the database will typically lead to problems.

Instead do the calculations when you fetch the data. This way you always get the right results and you have less SQL statements to execute in insert/update phase.


以下是简单的示例:
Microsoft SQL Server中的简单游标示例
SQL SERVER游标的简单示例
声明光标
游标:概述
内置函数-游标函数
Following are simple examples:
Simple cursor Example in Microsoft SQL Server
SQL SERVER Simple Example of Cursor
DECLARE CURSOR
Cursors: An Overview
Built-in Functions - Cursor Functions


这篇关于sqlserver中的游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆