Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 861443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:58:45+00:00 2026-05-15T08:58:45+00:00

It is necessary to implement a logging, messages are planned to store in DB

  • 0

It is necessary to implement a logging, messages are planned to store in DB in a “log” table. Among other fields each message will have a “status” field: 0 – successful, 1 – wrong data, 2 – wrong user, 3 – whatever, 4 – etc…

The straightforward idea is to store the “Status” field as “int” column in the same table… To push data in table special enumeration will be created, something like this (let’s use C#.NET for example, but any language will work too):

enum LogStatusEnum
{
    Successful=0,
    WrongData=1,
    WrongUser=2,
}
void main()
{
    LogStatusEnum status = LogStatusEnum.Successful;
    int statusValue = (int)status;
    string query = "INSERT INTO log (Status, ...) VALUES ("+statusValue+",...)";
}

There is also another approach: to create additional table, something like “log_status” with fields “StatusId” (int, autoincrement), “StatusCode” (varchar), “StatusDescription” (varchar) that will contain a separate record for each status field (with a foreign key applied to both tables). In this case before adding data into “log” table ID for the required “code” should be fetched in advance with query:

query = "SELECT Id FROM LogStatus WHERE StatusCode='"+GetStatusCode(status)+"'";

and this (received) ID will be used to populate “log” table.

In both cases you need to keep in sync both DB side and application side. But from my perspective, the 2nd approach is a little bit better:

  1. more safe: you need to be sure that
    your “status” is really present in
    DB before adding data, you will have
    a constrain (wrong status won’t be
    added).
  2. more data-driven (it is hard to say
    for me why it is better, but I fill
    that).

In order to get these benefits you need to pay: perform a request to DB to get status ID by status code.

Do you think it is reasonable to implement the 2nd approach? Or the 1st will fit too? Do you see any other pros of the 2nd approach or cons of the 1st one?

Any thoughts are welcome.

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:58:46+00:00Added an answer on May 15, 2026 at 8:58 am

    The second approach is usually better. If you need a new status type, you only need to update the database and not data structures in your application code.

    If you are doing a lot of inserts, you shouldn’t query for the status id every time, but cache it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are CDATA tags ever necessary in script tags and if so when? In other
Is it necessary for setter methods to have one argument? Usually setter methods accept
Are hints really necessary for every sql statement? We have a dba who is
Is it necessary or advantageous to write custom connection pooling code when developing applications
The question gives all necessary data: what is an efficient algorithm to generate a
Is it necessary to set large objects to null when implementing a Dispose() method?
Is it really necessary to release COM components from Office PIA, when you don't
Is it necessary to use Nothing keyword to initialize a DataSet in VB.NET?
Sometimes it's necessary to modify Windows registry settings during an application install. I've recently
Is it necessary to register a compiled DLL (written in C# .NET) on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.