1

I'm creating my own website with a capability to CRUD posts and other related stuff like category, tags and other things (I believe it's similar to the first two mentioned).

Posts: (current create post query)

id                BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
uid               BIGINT(20) UNSIGNED NOT NULL,
title             VARCHAR(50) NOT NULL UNIQUE,
content           LONGTEXT NOT NULL DEFAULT '',
postname          VARCHAR(255) NOT NULL UNIQUE,
posttype          VARCHAR(10) NOT NULL,
status            VARCHAR(20) NOT NULL DEFAULT '',
created_at        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at        TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

FOREIGN KEY(uid) REFERENCES ct_users(id)

Now my additional requirement is to have a category, tags and other future possibilities/properties.

My problem is the design, should I create new tables for each, like category table?

If so, Category would have something like:

id                BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name              VARCHAR(50) NOT NULL UNIQUE,
parent_id         BIGINT(20) UNSIGNED NULL

For Tags:

// This will have a relationship table between this and post table.
id                BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name              VARCHAR(50) NOT NULL UNIQUE,
description       VARCHAR(255) NOT NULL DEFAULT ''

Or should I make a complex relationship table that can support my requirements? Example is wordpress' wp_term, wp_term_relationship& wp_term_taxonomy.

Now for general database question. Rule of thumb.

Is it okay, or is it good to have many tables, possibly few records on some, used in 'your' application? Example is, refer to Categorytable at top.

Or is it much better to do it with things like wp_terms etc? To reduce the number of database tables.

Which one is more optimized? Or good in performance? Good and bad of...

If you could also provide links to good read articles and tutorials, would be much appreciated. As I've been googling, most of the stuff I find are basic queries and more info of features/functions with examples like JOIN, UNION and others.

Craftein
  • 151
  • 1
  • 4
  • 1
    Google Normalization Try – david strachan Feb 08 '14 at 12:20
  • 1
    What you are referring to is commonly known as entity-attribute-value or EAV for short. See http://dba.stackexchange.com/questions/20759/is-there-a-name-for-this-database-structure – Hannah Vernon Feb 08 '14 at 15:20
  • thanks for both of your answers. i know normalization, but if you'll just try to understand what is my 'problem in life' better, you'd figure that i know some of it and that's not really what my worries at. but i still thank you, this might be an indication that i should reread about it again.

    for EAV, great! first time hearing about it and IT IS one of my worries. i never knew there was a name for it but knowing it now, i can do further study tnen i might able to provide the answer by myself. -- although the link you provided me with answered 90% of my question. :)

    – Craftein Feb 08 '14 at 22:26

0 Answers0