Skip to content
Advertisement

Is ID column always required in SQL?

to be more specific, I’ve created a news module with a tag system. As each tag is unique (you are not allowed, as an admin, to create 2 identical tags), is the id column still useful? I guess no, but I was wondering about the performances.

id | mews_title | date … <————-> news_id | tag_id <———-> id | tag_name

VS

id | mews_title | date … <————-> news_id | tag_tag_name <———-> tag_name

Thanks a lot!

Advertisement

Answer

The performance difference is insignificant.

Advantages to using a numeric id for the tags in your example would be:

  • to make the intersection table somewhat smaller because integers are smaller on average than a string
  • to allow changing the spelling of a tag name by updating one row instead of many rows

These may not be important considerations for your case. So no, it’s not required to use a numeric id.

I also wrote about this in a chapter titled “ID Required” in my book, SQL Antipatterns: Avoiding the Pitfalls of Database Programming.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement