哪种条件或光标最好用? [英] Which is best use for Where condition or cursor ?

查看:99
本文介绍了哪种条件或光标最好用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过id管理所有记录。使用单独的逗号在表格中的产品ID中添加记录。

Expamle



ProductId: -

15 ,11,16,22,21,8,13,1,12,7,9,19,4



搜索最佳记录条件或光标?



推荐我













Brijesh Kumar

*********



:删除手机号码

解决方案

不要。

存储逗号分隔的id字符串是一个坏主意:它使它们成为一个噩梦,因为SQL不擅长字符串操作。



有单独的表格链接记录:要与ID列表关联的行的ID,以及要与其关联的ID。因此,对于您的字符串,您将在关联表中有13行。看起来似乎很辛苦,但想一想:这是最简单的:

1)从你的字符串中删除id21而不影响其他任何其他

或者

2)这:

  DELETE   FROM  AssociationTable  WHERE  BaseId = 1  AND  AssocId =  21  


I am manage all record by id. Add Record in column in table only product Id with separate comma.
Expamle

ProductId:-
15,11,16,22,21,8,13,1,12,7,9,19,4

Searching for record which is best Where condition or cursor ?

Suggest me






Brijesh Kumar
*********

[Edit]: Removed Mobile number

解决方案

Don't.
storing commas separated strings of ids is a bad idea: it makes them a nightmare to use as SQL is not good at string manipulations.

Have separate table which "links" the records: the id of the row you want to associate with the id list, and the id you want to associate it with. So for your string, you would have 13 rows in the association table. It may seem like hard work, but think about it: which is easiest:
1) Removing id "21" from your string without affecting anythign else
Or
2) This:

DELETE FROM AssociationTable WHERE BaseId=1 AND AssocId = 21


这篇关于哪种条件或光标最好用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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