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

  • SEARCH
  • Home
  • 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 6994377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:53:05+00:00 2026-05-27T19:53:05+00:00

Most forums do not specify any default value for the ID column. I wonder

  • 0

Most forums do not specify any default value for the ID column.
I wonder why they don’t do that.

For example SMF. They specify for every column a default value except for the (PRIMARY KEY) ID column.

EDIT: I now see that ^this^ part of the question was a bit ‘stupid’.

  • Is there an performance advantage by specifying a default value?
  • Why shouldn’t you specify by default an empty value?
  • Will ‘NOT NULL’ complain if you use the value: (similar to $var = ”; in php)

EDIT: But I assume that you want a database to complain if it doesn’t get, for example, a username. Of course, I’ll not allow registration fields to be left empty (and I do validate them server-side), but if I’m not mistaken, than, if by magic the input to the database is still empty, the database will accept this. Assuming the database uses NOT NULL and a default value. Question: So what than is the use of NOT NULL, in combination with a default value?

Thanks in advance.
Please keep in mind that I am Dutch an therefore I may have made some mistakes.

  • 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-27T19:53:06+00:00Added an answer on May 27, 2026 at 7:53 pm

    If we assume that a default value for an id, primary key, column in a database made sense (and was even valid), think what the consequences would be:

    1. First off, it would allow the user, or the DB scripts, to supply no id information (which is fine, since most scripts rely on the database to deal with that aspect anyway), but
    2. it would also allow the database not to ‘deal with’ it, and to simply insert the new record with the default value, whatever that might be. This means that
    3. in many situations multiple records are likely to be inserted which have the same id value/primary key. If multiple entries, into for example a forum Database, have the same value, how would you tell your users apart? How would you identify them?

    The reason that no ‘default’ is used is because, a: it wouldn’t make sense to allow it in the first place, and b: it’d be invalid (albeit b is a consequence of a).

    Is there a performance benefit to supplying a default value?

    Not so much a ‘performance’ benefit, but it does mean that if no value is supplied the software has, at least, some idea what to expect (whether that default is a string, a number, an enum…).

    Why shouldn’t you specify by default an empty value?

    I think that all entries to the database should be controlled, whether that’s the values you allow to be inserted, or the values inserted in the event of an error, or a failure of the user to supply a value. Allowing null-entries to your database likely a controllable situation, but it seems needlessly complex to compensate for null entries, when a default can be specified.

    Will ‘NOT NULL’ complain if you use the value: (similar to $var = ”; in php)?

    It’s been a while since I last used MySQL, but null is not similar to an empty string (in the way that JavaScript assesses '' to be ‘falsy’), it means, absolutely, nothing. Empty. A whole vacuum, and non-existence, of information. NOT NULL, then, requirese some (albeit it doesn’t specify exactly what) information. This is why a default should be supplied, since it specifies precisely what will be found in the database in the even of the user specifying no data.


    Edited in response to comments from OP (below):

    But I assume that you want a database to complain if it doesn’t get, for example, a username. Of course, I’ll not allow registration fields to be left empty (and I do validate them serverside), but if I’m not mistaken, than if by magic the input to the database is still empty, the database will accept this. If it uses NOT NULL and a default value. So what than is the use of NOT NULL, in combination with a default value?

    I can’t speak to all situations, or to the choices made by all database-/web-admins, but in my personal use-cases I’d suggest a consideration of:

    1. First, would an empty-value make sense for this field, and:
    2. Second, if an empty field doesn’t make sense, should a default value be used?

    In some situations I don’t need the details from a user (their gender, for example) has almost no impact on me, or any services I provide, so I don’t care whether they supply it, or not. In this case a default isn’t used.

    In other cases, such as their age, it might make a difference (I cant’ remember the name of the law, but I recall some mention of Facebook, and other online societies, being required to only allow those of age 13, or older, to participate). In this case I ask my users to say agree that they are, in fact, over the age of 13 (via a checkbox) and then later offer them an input to insert their actual age/date-of-birth. In the absence of a supplied data-point (and, honestly, other than the (presumed) legal obligation I really don’t care how old my users are) my database defaults to thirteen (or in the case of birthday it defaults to thirteen-years-ago today (albeit with help from the php scripts).

    Now, the the aspect of NOT NULL and a default value? There’d be no sense, so far as I can see.

    The whole concept of NOT NULL is to ensure a user-supplied value (otherwise the record isn’t created, and the user can’t join (or whatever) the service for which they’re registering). The default value is to supply a fall-back value in this absence. And, logically, if the two are allowed together on the same field? The default would be inserted before the NOT NULL condition is triggered. So…why bother? Do you have evidence that somebody, or some software, used both conditions on the same field? I can’t, honestly, think why.

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

Sidebar

Related Questions

First, I could not ask this on most hardware forums, because they are mostly
I have a couple of simple forms that send an html-only email. Most clients
I'm working on a web crawler (please don't suggest an existing one, it's not
I have an ASP.Net MVC web app that includes a set of Forums. In
Hi Sometimes a website do not have a mobile version, for example, stackoverflow.com or
From the MSDN forums , even copying and pasting the simplest example from the
This should not create any Issues with the NDA as I am not asking
I want support for a new API that is normally not supported by V8
Most of my programming experience has either been using forms (Windows Forms, or ASP.NET)
I'm looking for most elegant way to ajaxify my forms (with jQuery). How do

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.