The document contains SQL statements to create multiple tables for a database including tables for devices, device groups, users, locations, and more. It also includes statements to create foreign key constraints to link the tables together and sample insert statements to add initial data to the tables.
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
20 views
SQL
The document contains SQL statements to create multiple tables for a database including tables for devices, device groups, users, locations, and more. It also includes statements to create foreign key constraints to link the tables together and sample insert statements to add initial data to the tables.
CREATE TABLE IF NOT EXISTS `devices` ( `id` int(11) NOT NULL, `name` varchar(255) NOT NULL, `external_supply` int(1) NOT NULL, `last_id` int(11) NOT NULL, `state` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
-- Creación de la tabla 'device_group'
CREATE TABLE IF NOT EXISTS `device_group` ( `id` int(11) NOT NULL, `name` varchar(255) DEFAULT NULL, `device_group_count` int(11) UNSIGNED NOT NULL DEFAULT 0, `user_group_count` int(11) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`id`) )ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
-- Creación de la tabla 'device_group_assign'
CREATE TABLE IF NOT EXISTS `device_group_assign` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `device_group_id` int(11) UNSIGNED NOT NULL, `device_id` int(11) UNSIGNED NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`device_group_id`) REFERENCES `device_group` (`id`), FOREIGN KEY (`device_id`) REFERENCES `devices` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
-- Creación de la tabla 'device_info'
CREATE TABLE IF NOT EXISTS `device_info` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `utc` datetime NOT NULL, `device_id` int(11) UNSIGNED NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`device_id`) REFERENCES `devices` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
-- Creación de la tabla 'geofences'
CREATE TABLE IF NOT EXISTS `geofences` ( `id` int(11) NOT NULL, `name` varchar(255) NOT NULL, `tipo` varchar(255) DEFAULT NULL, `vertices` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;