Welcome Guest, Not a member yet? Register   Sign In
Working with Multi-Select & Dropdowns and SQL
#23

[eluser]Philipp Gérard[/eluser]
This would be a normalized database layout reflecting your structure. I wasn't sure about varchar(ticket), if this is also an entry that can be external, then you should also normalize this field.

Code:
CREATE TABLE `outages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ticket` varchar(128) DEFAULT NULL,
  `starttime` datetime DEFAULT NULL,
  `endtime` datetime DEFAULT NULL,
  `summary` varchar(128) DEFAULT NULL,
  `details` text,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `locations` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(128) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `services` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(128) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `outages_locations` (
  `outage_id` int(11) DEFAULT NULL,
  `location_id` int(11) DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `outages_services` (
  `outage_id` int(11) DEFAULT NULL,
  `service_id` int(11) DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Exemplary content:

Code:
INSERT INTO `outages` (`id`, `ticket`, `starttime`, `endtime`, `summary`, `details`) VALUES (1, 'ABC123', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'My summary', 'My details');
INSERT INTO `services` (`id`, `name`) VALUES (1, 'Example service');
INSERT INTO `locations` (`id`, `name`) VALUES (1, 'Boston');
INSERT INTO `outages_locations` (`outage_id`, `location_id`) VALUES (1, 1);
INSERT INTO `outages_services` (`outage_id`, `service_id`) VALUES (1, 1);

(1 outage that is connected to 1 location and 1 service by the outages_locations/outages_services tables)


Messages In This Thread
Working with Multi-Select & Dropdowns and SQL - by El Forum - 06-30-2010, 04:31 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 06-30-2010, 04:42 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 06-30-2010, 10:28 PM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 12:14 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 01:59 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 02:13 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 02:22 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 02:35 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 02:50 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 02:55 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 03:01 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 03:17 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 03:21 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 03:28 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 03:31 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 03:44 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 03:49 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 03:53 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 03:59 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 04:12 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 04:21 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 05:19 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-01-2010, 05:26 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-02-2010, 12:37 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-02-2010, 01:28 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-02-2010, 01:42 AM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-14-2010, 05:43 PM
Working with Multi-Select & Dropdowns and SQL - by El Forum - 07-14-2010, 10:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB