skip to Main Content

I want to create a table.

I’m having long and hard time about naming columns.

If there are 3 columns having same characteristics.

ex) tag_1, tag_2, tag_3

->

CREATE TABLE BOARD (
    BOARD_ID   bigint not null
        primary key,
    TAG_1      varchar(10) null,
    TAG_2      varchar(10) null,
    TAG_3      varchar(10) null
)

Is it a best practice to naming like examples above?

2

Answers


  1. Nothing wrong with your notation. However, as your columns look really identical, you might wanna take a look into normalizing them. It might make sense in many cases and it will keep your schema cleaner.

    Login or Signup to reply.
  2. It should be something like this:

    CREATE TABLE BOARDS
    (
        BOARD_ID BIGINT
       ,name ...
       ,description ...
    
    );
    
    CREATE TABLE TAGS
    (
        TAG_ID INT
       ,TAG VARCHAR(10)
    );
    
    CREATE TABLE BOARDSTAGS
    (
        BOARD_ID BIGINT
       ,TAG_ID INT
    );
    

    You have one table for describing board properties and one of tag properties. Some of the tags can be shared across many boards. So, we need third table for telling which board, which tags has.

    In this case, when you need additional tags, you do not need to add new column in the board table.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search