Jump to content

Normalization Question


webweever

Recommended Posts

Does this look like good DB structure?

 

CREATE TABLE `item` (
  `item_id` int(11) NOT NULL auto_increment,
  `user_id` int(20) NOT NULL,
  `date` date NOT NULL,
  `store` varchar(30) collate latin1_general_ci NOT NULL,
  `item` varchar(30) collate latin1_general_ci NOT NULL,
  `itemprice` decimal(10,2) unsigned NOT NULL,
  `itemnumber` tinyint(20) NOT NULL,
  `itemtotalprice` decimal(10,2) NOT NULL,
  `item_id` int(11) NOT NULL,
  PRIMARY KEY  (`item_id`)
  Foreign Key (user_id) references members(id));
) ENGINE=MyISAM AUTO_INCREMENT=91 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=91 ;

 

CREATE TABLE `members` (
  `id` int(11) NOT NULL auto_increment,
  `usr` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL,
  `pass` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL,
  `email` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
  `regip` varchar(15) character set utf8 collate utf8_unicode_ci NOT NULL,
  `dt` datetime NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `usr` (`usr`),
  UNIQUE KEY `email` (`email`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

 

CREATE TABLE `lists` (
  `list_id` int(11) NOT NULL auto_increment,
  `name` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL,
  `dt` datetime NOT NULL,
  `user_id` int(11) NOT NULL,
  PRIMARY KEY  (`id`),
  Foreign Key (user_id) references members(id)); 
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

Link to comment
Share on other sites

Does this look more appropriate?

 

CREATE TABLE `item` (
  `id` int(11) NOT NULL auto_increment,
  `date` date NOT NULL,
  `store_id` int(11) NOT NULL,
  `item` varchar(30) collate latin1_general_ci NOT NULL,
  `itemprice` decimal(10,2) unsigned NOT NULL,
  `itemnumber` tinyint(20) NOT NULL,
  `itemtotalprice` decimal(10,2) NOT NULL,
  `user_id` int(11) NOT NULL,
  `item_id` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
  Foreign Key (item_id) references members(id));
) ENGINE=MyISAM AUTO_INCREMENT=91 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=91 ;


CREATE TABLE `members` (
  `id` int(11) NOT NULL auto_increment,
  `usr` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL,
  `pass` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL,
  `email` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
  `regip` varchar(15) character set utf8 collate utf8_unicode_ci NOT NULL,
  `dt` datetime NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `usr` (`usr`),
  UNIQUE KEY `email` (`email`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


CREATE TABLE `lists` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL,
  `dt` datetime NOT NULL,
  `user_id` int(11) NOT NULL,
  PRIMARY KEY  (`id`),
  Foreign Key (user_id) references members(id)); 
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


CREATE TABLE `store` (
  `id` int(11) NOT NULL auto_increment,
  `store_name` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`id`), 
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

Link to comment
Share on other sites

no...

 

this is what you have (gif attached)... you will see that the relations are not correct based on your description.

 

Edit: I saw that you added a store entity... good... now think about the item table.... should be the item name (apparently field `item`) be present in that table?

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.