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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:52:48+00:00 2026-06-13T23:52:48+00:00

I have a table: CREATE TABLE pupils ( id INTEGER PRIMARY KEY AUTOINCREMENT NOT

  • 0

I have a table:

  CREATE TABLE pupils (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 
     name TEXT, surname TEXT, address TEXT, score INTEGER
  );

where score is a percentage.

Is it more efficient to have the integer value in there or a foreign key to a table that is just a table like this?

  CREATE TABLE score (percentage INTEGER PRIMARY KEY NOT NULL);

Obviously the table would be populated with 0-100.

My thoughts were if you have 1000’s of pupils that keeping it as an integer column would mean queries were faster, but more space used and using the foreign key would mean less space used, but slower queries.

Not sure if this is correct?

So I thought I would throw it out there!

  • 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-06-13T23:52:49+00:00Added an answer on June 13, 2026 at 11:52 pm

    If you use the FOREIGN KEY to protect the score value in the pupils table, you still need to have a score column in pupils. You can’t have a FOREIGN KEY relationship without columns in both tables.

    The only advantage of the FOREIGN KEY is that it would let you restrict the values allowed in the score column to integers between 1 and 100. The same thing can be done, however, with a CHECK constraint on the column, without the need for the extra table.

    If you use the FOREIGN KEY, your DDL would look like this:

    CREATE TABLE pupils (
     id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 
     name TEXT, surname TEXT, address TEXT, score INTEGER REFERENCES score(percentage)
    );
    

    Note that the score column is still there.

    In this case the FOREIGN KEY approach adds an whole table and two indexes that have to be maintained. Much more efficient to use one table and a CHECK constraint.

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

Sidebar

Related Questions

I have sqlite table CREATE TABLE IF NOT EXISTS [app_status]( [id] INTEGER PRIMARY KEY
I have this table create table utilizator( utilizatorId bigint not null auto_increment primary key,
I have this table: CREATE TABLE `test` ( `ID` int(11) NOT NULL auto_increment, `text`
i have this table create table eveniment( + evenimentId bigint not null auto_increment primary
I have this table: create table demo ( key number(10) not null, type varchar2(3)
I have a table: CREATE TABLE [Lines] ( [Value] TEXT NOT NULL, [AddedOn] TIMESTAMP
I have such table: CREATE TABLE employee ( id INTEGER DEFAULT NEXTVAL('ids'::regclass) NOT NULL,
I have a table like: CREATE TABLE test( id integer not null default nextval('test_id_seq'::regclass),
I have a table: CREATE TABLE `data_table` ( `data_id` INT NOT NULL AUTO_INCREMENT PRIMARY
I have a table: create table A ( KEY VARCHAR(1024) not null ); where

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.