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 549839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:13:32+00:00 2026-05-13T11:13:32+00:00

I have this database that I’m designing. It needs to contain a couple dozen

  • 0

I have this database that I’m designing.

It needs to contain a couple dozen tables with records that we provide (a bunch of defaults) as well as records that the user can add. In order to keep the user from shooting himself in the foot, it’s necessary to keep him from modifying the default records.

There are lots of ways to facilitate this, but I like the idea of giving protected records negative integer indexes, while reserving 0 as an invalid record id and giving user records positive integer indexes.

CREATE TABLE t1 (
    ixt1  integer AUTOINCREMENT,
    d1    double,
    CONSTRAINT pk_ixt1 PRIMARY KEY (ixt1),
    CONSTRAINT ch_zero CHECK (ixt1 <> 0)
);

-2 | 171.3 <- canned record
-1 | 100.0 <- canned record
 1 | 666.6 <- user record

Reasons this seems good:

  • it doesn’t use significantly more space

  • it’s easy to understand

  • it doesn’t require lots of additional tables to implement

  • “select * from table” gets all the pertinent records, with no additional indirection

  • the canned records can grow in the negative direction, and the user records can grow in the positive direction

However, I’m relatively new to database design. And after using this solution for a little while, I’m starting to worry that using negative indexes might be bad, because

  • Negative indexes might not be supported consistently among different DBMSs, making it difficult to write code that is database-agnostic

  • It might be just too easy to screw stuff up by inserting something at recid 0

  • It might make it hard to use tools (like db grids, perhaps) that expect integer indexes with nonnegative values.

And maybe there are some other really obvious reasons that would make this a Very Bad Idea.

So what’s the definitive answer? Are negative integer indexes evil?

  • 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-13T11:13:32+00:00Added an answer on May 13, 2026 at 11:13 am

    The most important flaw in this is the “Intelligent Key” problem.

    Negative integers work fine as a key. In all databases.

    No tool requires positive integer index values.

    It’s relatively easy to screw this up because the index has a “rule” which isn’t obvious and no one will remember after you’ve won the lottery and left.

    Further, when you invent a third status code (‘pre-canned’ vs. ‘customer-specific canned’ vs. ‘the other canned invented by a product line’ vs. ‘the old canned before version 3’) you’re doomed.

    The issue with “Intelligent keys” is that you’re asking the key to do two unrelated jobs.

    1. It’s the unique identifier for a record. That’s what an key is supposed to be.

    2. You’re also asking it to provide status, control and authorization to change properties. Oops. This is fraught with danger. You can’t expand the meaning because it’s a single bit buried in a key.

    Just add a column with “owned by”. If it’s owned by “magical super user”, then it’s not shown to users. Use a VIEW to assure this, if you can’t trust your application developers to enforce it.

    If it is owned by “magical super user”, then it’s the default data, and whatever rules apply to that ownership.

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

Sidebar

Related Questions

I have this database table that contains emails like 300 records, emails{email,name,join_date); and I
I have a database that has four columns like this level_1, level_2, level_3, level_4
I have a database that contains a table that looks a bit like this:
I have a database that is currently sharded. This is the first time that
I have data in an MYSQL database that looks like this: Project Date Time
I have this function on my controller (Im using CodeIgniter) that reads the database,
I have a table in a MSSQL database that looks like this: Timestamp (datetime)
say i have a nvarchar field in my database that looks like this 1,
I have a database file that is generated on a PC using Sqlite. This
We have a database library in C# that we can use like this: DatabaseConnection

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.