将项目计数保存到数据库或运行“选择计数"语句? [英] Save Items Count to database or run Select Count statement?

查看:104
本文介绍了将项目计数保存到数据库或运行“选择计数"语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我有5个项目,数据库中有5个不同的表.登录时,显示编号的页面.用户已保存的项目数将显示给他.

为此,
(1)我应该保存编号吗? (int)在数据库中为每一个添加一列并更新编号.每次添加或删除项目

OR

(2)每次调用该页面时,我都应该运行包含5个不同的SELECT COUNT(*)查询的Stored Procedure吗? 请清除我的疑问.

据我说,我应该使用第一个选项将列添加到数据库中并更新它们,并避免时不时地运行SELECT COUNT(*)查询.
如果我错了,请纠正我.

但是,要么您的数据库设计很奇怪,要么描述得很糟糕.如果(从描述中看起来)每个表中只能有一行,为什么要为不同的对象有五个表?


Hello everyone!

I have 5 items for which 5 different tables are made in the database. On login, the page showing the no. of items the user has saved will be shown to him.

For this,
(1) should I save the no. (int) in the database adding one more column for each one and updating the no. each time an item is added or deleted

OR

(2) should I run a Stored Procedure containing 5 different SELECT COUNT(*) queries each time that page is called?
Please clear my doubt.

According to me, I should go with the first option to add columns to the database and update them and Avoid running SELECT COUNT(*) queries every now and then.
Please correct me if I am wrong.

解决方案

I would not add a column to tell how many items - use count as it can''t get out of step.

But either your database design is very odd, or you have described it very badly. Why would you have five tables for different objects if (as it seems from the description) you can only have one row in each table?


这篇关于将项目计数保存到数据库或运行“选择计数"语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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