How can I improve my Mysql database design?

Discussion in 'MySQL' started by hawkal, Jan 15, 2009.

  1. #1
    Hi, I am new to database design and for a while now I have been creating an arcade script.

    I was hoping someone with more experience would be willing to look at a sql dump of my tables and suggest any way in which I could improve it.

    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
    
    CREATE TABLE IF NOT EXISTS `categories` (
      `Id` smallint(1) NOT NULL auto_increment,
      `Name` varchar(20) NOT NULL,
      PRIMARY KEY  (`Id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
    
    CREATE TABLE IF NOT EXISTS `games` (
      `Id` mediumint(6) NOT NULL auto_increment,
      `Category` tinyint(1) NOT NULL default '0',
      `Swf` varchar(10) NOT NULL,
      `Name` varchar(30) NOT NULL,
      `Thumb` varchar(10) NOT NULL,
      `Width` varchar(3) NOT NULL,
      `Height` varchar(3) NOT NULL,
      `Description` text NOT NULL,
      `Plug` varchar(1) NOT NULL default '0',
      `Enabled` tinyint(1) NOT NULL default '1',
      PRIMARY KEY  (`Id`),
      KEY `Name` (`Name`),
      KEY `Swf` (`Swf`),
      KEY `Thumb` (`Thumb`),
      KEY `Plug` (`Plug`),
      KEY `Height` (`Height`),
      KEY `Width` (`Width`),
      KEY `Category` (`Category`),
      KEY `Enabled` (`Enabled`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
    
    CREATE TABLE IF NOT EXISTS `gamesplugs` (
      `Id` smallint(3) NOT NULL auto_increment,
      `Name` varchar(30) NOT NULL,
      `Url` text NOT NULL,
      `Traderid` varchar(10) NOT NULL,
      `Hits` mediumint(10) NOT NULL,
      PRIMARY KEY  (`Id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
    
    CREATE TABLE IF NOT EXISTS `links` (
      `Id` smallint(5) unsigned NOT NULL auto_increment,
      `Password` varchar(20) NOT NULL,
      `Email` varchar(40) NOT NULL,
      `Url` varchar(255) NOT NULL,
      `Name` varchar(255) NOT NULL,
      `Ref` varchar(200) NOT NULL default 'http://www.nosite.com/index.php',
      `In2` mediumint(5) unsigned NOT NULL default '0',
      `Out2` mediumint(5) unsigned NOT NULL default '0',
      `Enabled` smallint(1) NOT NULL default '0',
      `Credits` decimal(10,2) NOT NULL default '0.00',
      PRIMARY KEY  (`Id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 PACK_KEYS=1 AUTO_INCREMENT=0 ;
    Code (markup):
    Any idea's?

    Thanks for looking.
     
    hawkal, Jan 15, 2009 IP
  2. mapAffiliation

    mapAffiliation Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What kind of improvement you mean?
    The structure is just normal.
    I would only not use smallint for ID. Simply int.

    And one thing : i do not see on which field tables are connected to each other. This should be clear from the beginning.
     
    mapAffiliation, Jan 16, 2009 IP
  3. hawkal

    hawkal Peon

    Messages:
    97
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well my aim is to get the database running as quickly and efficiently as possible. I have a good caching system between the front end and database but it is when the cache gets updated that I would like to improve things.

    I don't understand what you mean by this, please can you give an example?
     
    hawkal, Jan 16, 2009 IP
  4. mapAffiliation

    mapAffiliation Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Than you need good indexing. But indexing depend on what kind of SQL requests you will have. You can start with this DB design and if you face to slow SQL simply add correct keys (with "explain" you can find where is the prioblem)

    Sorry, I see now that you have in "games" refference to "categories" by field "Category", so it seems everythings is ok.
     
    mapAffiliation, Jan 18, 2009 IP
  5. gnp

    gnp Peon

    Messages:
    137
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hello,

    i have highlighted what i understood to be key and foreign keys (relations between your table). If indeed these fields are linked (the ones with same color) then you should have them be of the same datatype..
     
    gnp, Jan 19, 2009 IP
  6. hawkal

    hawkal Peon

    Messages:
    97
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thank you both very much for your help and suggestions.
     
    hawkal, Jan 19, 2009 IP