Created
June 29, 2012 11:31
-
-
Save rockymontana/3017478 to your computer and use it in GitHub Desktop.
SQL question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Table structure for table `apartments` | |
-- | |
CREATE TABLE IF NOT EXISTS `apartments` ( | |
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, | |
`name` varchar(8) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, | |
`rooms` varchar(2) COLLATE utf8_swedish_ci NOT NULL, | |
`floor` int(2) NOT NULL, | |
`m2` int(5) NOT NULL, | |
`address` varchar(64) COLLATE utf8_swedish_ci NOT NULL, | |
`house` varchar(16) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, | |
`available` tinyint(1) NOT NULL, | |
`date_of_arrival` date DEFAULT '0000-00-00', | |
`rent` int(5) NOT NULL COMMENT 'monthly cost', | |
`description` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci AUTO_INCREMENT=6 ; | |
-- | |
-- Dumping data for table `apartments` | |
-- | |
INSERT INTO `apartments` (`id`, `name`, `rooms`, `floor`, `m2`, `address`, `house`, `available`, `date_of_arrival`, `rent`, `description`) VALUES | |
(1, '0102', '3', 1, 78, 'Kringelvägen 2B', 'Draken', 0, NULL, 5700, 'Mucket fein leilighet!!'), | |
(3, '0101', '3', 1, 79, 'Kringelvägen 2B', 'Draken', 0, NULL, 5700, 'En likadant lägenhet!'), | |
(4, '0103', '3', 2, 79, 'Kringelvägen 2B', 'Draken', 0, NULL, 5900, 'Ännu en likadant lägenhet!'), | |
(5, '0104', '3', 2, 79, 'Kringelvägen 2B', 'Draken', 0, NULL, 5900, 'Ännu en likadant lägenhet!'); | |
-- -------------------------------------------------------- | |
-- | |
-- Table structure for table `apartment_fields` | |
-- | |
CREATE TABLE IF NOT EXISTS `apartment_fields` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`name` varchar(128) COLLATE utf8_bin NOT NULL, | |
PRIMARY KEY (`id`), | |
UNIQUE KEY `name` (`name`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=3 ; | |
-- | |
-- Dumping data for table `apartment_fields` | |
-- | |
INSERT INTO `apartment_fields` (`id`, `name`) VALUES | |
(2, 'area'), | |
(1, 'district'); | |
-- -------------------------------------------------------- | |
-- | |
-- Table structure for table `apartment_field_data` | |
-- | |
CREATE TABLE IF NOT EXISTS `apartment_field_data` ( | |
`apartment_field_id` int(11) NOT NULL, | |
`apartment_id` int(11) unsigned NOT NULL, | |
`value` varchar(128) NOT NULL, | |
KEY `apartment_id` (`apartment_id`), | |
KEY `apartment_field_id` (`apartment_field_id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |
-- | |
-- Dumping data for table `apartment_field_data` | |
-- | |
INSERT INTO `apartment_field_data` (`apartment_field_id`, `apartment_id`, `value`) VALUES | |
(1, 1, 'Mjärden'), | |
(2, 1, 'Maria'), | |
(1, 3, 'Mjärden'), | |
(2, 3, 'Maria'), | |
(1, 4, 'Mjärden'), | |
(2, 4, 'Maria'), | |
(1, 5, 'Mjärden'), | |
(2, 5, 'Maria'); | |
-- | |
-- Constraints for dumped tables | |
-- | |
-- | |
-- Constraints for table `apartment_field_data` | |
-- | |
ALTER TABLE `apartment_field_data` | |
ADD CONSTRAINT `apartment_field_data_ibfk_1` FOREIGN KEY (`apartment_field_id`) REFERENCES `apartment_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, | |
ADD CONSTRAINT `apartment_field_data_ibfk_2` FOREIGN KEY (`apartment_id`) REFERENCES `apartments` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kudos till lillem4n ( https://github.com/lillem4n ) för denna lösningen: