是否应该在User表中设计created_by和last_update_by?

发布于 2024-09-14 06:43:12 字数 1431 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趁微风不噪 2024-09-21 06:43:12

这个答案不会与我们非常技术相关:我们还为我们的客户使用不同的 CMS,他们在几乎所有与用户、产品、帖子相关的论文表中都有一个“created_at”和“updated_at”列......一周之前,我被要求从应用程序中获取一些统计数据。我应该了解有多少用户处于活跃状态,以及用户何时、何时登录以及他是否在 X 期间返回。对于不超过 1 个月的用户(当然是指应用程序而言),有多少用户在网站等。

当然,有类似的专门工具,但数据足以提供各个方面的相当详细的信息,这些信息从财务角度以及规划和重新思考某些方面非常重要。

如前所述,这并不是真正的数据库设计答案,但我确信每个从事经济部分的人都会对其中的一些数据感兴趣。因此,保留它不会伤害任何人,但可以为您提供廉价的(因为它“已经在那里”)信息,供您下次与客户经理或任何人会面时使用。

This answer won't we very tech related: We also using different CMS for our customers and they have a "created_at" and "updated_at" column in almost all of theis tables that relate to users, products, posts, ... One week ago, I was asked to get some stats from the application. I should get how many users were active and when, when did a user log-in and did he returned in period X. From users that are not older than 1 month (speaking application wise of course) how many have actively done something on the site and so on.

There are specialized tools for something like that, of course but the data was more than enough to provide pretty detailed information on various aspects that were very important from a financial point of view as well as planning and re-thinking some aspects.

As mentioned, this is not really a datebase-design answer but I'm sure everyone who does the econimical part will be interrested in some of this data at one point. So keeping it doesn't hurt anybody but can give you cheap (because it's "already there") information for a next meeting with the customers manager or whoever.

迷乱花海 2024-09-21 06:43:12

如果您使用的是 SQL Server,则可以像这样创建第一个用户。它对我来说效果很好,但你可能需要稍微调整一下。

DECLARE @currentId int
SET @currentId = ident_current('[dbo].[User]') + 1;  
INSERT INTO [dbo].[User] (ExternalId, [CreatedById], [UpdatedById]) VALUES ('system',  @currentId, @currentId)

示例:

SELECT
  CASE
    WHEN (SELECT
        COUNT(1)
      FROM tablename) = 0 THEN 1
    ELSE IDENT_CURRENT('tablename') + 1
  END AS Current_Identity;

来源:

如何从 SQL Server 获取下一个标识值

If you are using SQL Server the first user could be created like this. It has worked well for me but you might have to tweak it a bit.

DECLARE @currentId int
SET @currentId = ident_current('[dbo].[User]') + 1;  
INSERT INTO [dbo].[User] (ExternalId, [CreatedById], [UpdatedById]) VALUES ('system',  @currentId, @currentId)

Example:

SELECT
  CASE
    WHEN (SELECT
        COUNT(1)
      FROM tablename) = 0 THEN 1
    ELSE IDENT_CURRENT('tablename') + 1
  END AS Current_Identity;

Source:

How to get the next identity value from SQL Server

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文