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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:26:13+00:00 2026-05-26T14:26:13+00:00

I have a table foo which contains the following columns create table foo (

  • 0

I have a table foo which contains the following columns

create table foo (
id integer not null auto_increment unique,
name varchar(255),
desc varchar(255),
modified_time datetime not null,
type tinyint(1)
)

Are there any best practices in following a ordering convention for all the columns (e.g. in a alphabetical fashion or not nulls at the top and rest of the columns at the bottom)

  • 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-26T14:26:14+00:00Added an answer on May 26, 2026 at 2:26 pm

    Certainly the primary key first.
    The name of that column is usually tablename_id (traditional) or just ‘id’ (preferred by frameworks such as rails).

    If used, usually a name/description field next, as you have it.

    I tend to put foreign keys after that (parents first, children after that) as they tend to be more critical during development.

    Then I group other data, e.g. address line, city, state, zip together.

    When no other rule fits, I tend to prefer required fields higher up for increased visibility.

    timestamps (some/all of created_on, updated_on, removed_on, etc.) usually last

    So in your example I would actually do:

    create table foo (
    id integer not null auto_increment unique,
    name varchar(255),
    type tinyint(1),
    desc varchar(255),
    modified_time datetime not null
    )
    

    Note – As Kolink noted, use description over desc because desc is a reserved word meaning descending, e.g. order desc

    However… big disclaimer…

    if your table changes over time (i.e. real world) and you have existing production data, you will not have the fields ordered as initially ‘planned’. This can be avoided by export and re-import but in many cases its best to accept that ordering is just a convention for initial creation for programmer convenience and that alone.

    Another popular topic here is column name naming conventions. That’s a whole ‘nother topic but I’ll tip my toe in by saying don’t abbreviate unless forced!

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

Sidebar

Related Questions

Let's say I have SELECT name FROM table which gives me something like foo
I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT
I have table with a name filed which is string. I need to create
Assuming I have an SQL table with this schema: CREATE TABLE( foo INTEGER, bar
I have a table called foo with columns like the following: id usedId (id
I have a database table which contains an ID column and a Name column.
Let's say I have a table Foo . This table has the columns ID
I have my own type: CREATE TYPE MyType AS TABLE ( foo INT )
I have a table A with 2 columns Foo and Bar. I have a
I have a notifications table which contains different types of notifications for different events.

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.