Menu

[f1bb48]: / examples / exampledb.sql  Maximize  Restore  History

Download this file

206 lines (165 with data), 6.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* phpMyEdit - instant MySQL table editor and code generator
*
* examples/exampledb.sql - create example database for testing
* ____________________________________________________________
*
* Copyright (c) 1999-2002 John McCreesh <jpmcc@users.sourceforge.net>
* Copyright (c) 2001-2002 Jim Kraai <jkraai@users.sourceforge.net>
* Versions 5.0 and higher developed by Ondrej Jombik <nepto@php.net>
* Versions 5.7.2 and higher developed by Yves De Billoëz
* Copyright (c) 2002-2006 Platon Group, http://platon.sk/
* All rights reserved.
*
* See README.md file for more information about this software.
* See COPYING file for license information.
*
* Download the latest version from
* https://sourceforge.net/projects/phpmariaedit/
*/
USE `phpMyEditExamples`;
/* $Platon: phpMyEdit/examples/exampledb.sql,v 5.7.6 2024-01-15 12:57:07 Yves $ */
/* countries table */
/* we need to drop taxrates before dropping countries */
DROP TABLE IF EXISTS `taxrates`;
DROP TABLE IF EXISTS `countries`;
CREATE TABLE `countries` (
`co_name` VARCHAR(60) NOT NULL,
`co_name_en` VARCHAR(60),
`co_code` CHAR(2) NOT NULL,
`co_alpha3code` CHAR(3),
`co_numcode` CHAR(3),
`co_telprefix` CHAR(6),
`co_internetsuffix` VARCHAR(30),
`co_flagimg` BLOB,
`co_imgfromsky` BLOB,
`co_introduction` TEXT,
`co_centre` POINT,
`co_area` POLYGON,
`creation_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE `countries`
ADD `rowid` INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY FIRST;
ALTER TABLE `countries` MODIFY COLUMN `co_imgfromsky` LONGBLOB;
ALTER TABLE `countries`
COMMENT = 'specific test for TEXT, BLOB, POINT and POLYGON fields, unique key';
ALTER TABLE `countries`
ADD UNIQUE KEY `co_code_ukey` (`co_code`);
INSERT INTO `countries`
(`co_name`, `co_name_en`, `co_code`, `co_telprefix`, `co_internetsuffix`)
VALUES
('België/Belgique/Belgien', 'Belgium', 'BE', '+32', '.be'),
('Canada', 'Canada', 'CA', '+1', '.ca'),
('France', 'France', 'FR', '+33', '.fr'),
('India', 'India', 'IN', '+91', '.in'),
('La République Démocratique du Congo', 'Democratic Republic of Congo (DRC)', 'CD', '+243', '.cd'),
('United States of America', 'United States of America', 'US', '+1', '.us'),
('United Kingdom', 'United Kingdom', 'UK', '+44', '.uk');
/* taxrates table */
DROP TABLE IF EXISTS `taxrates`;
CREATE TABLE `taxrates` (
`tr_name` VARCHAR(60) NOT NULL,
`tr_name_en` VARCHAR(60),
`tr_code` CHAR(8) NOT NULL,
`tr_country_code` CHAR(2),
`tr_rate` DECIMAL(5,2) NOT NULL DEFAULT 0.0,
`creation_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE `taxrates`
ADD `rowid` INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY FIRST;
ALTER TABLE `taxrates`
COMMENT = 'specific test for foreign key to countries, unique key constraint';
ALTER TABLE `taxrates`
ADD UNIQUE KEY `taxrates_ukey` (`tr_code`, `tr_country_code`);
ALTER TABLE `taxrates`
ADD CONSTRAINT `FK_taxrates_countries`
FOREIGN KEY (`tr_country_code`) REFERENCES `countries`(`co_code`);
INSERT INTO `taxrates`
(`tr_name`, `tr_name_en`, `tr_code`, `tr_country_code`, `tr_rate`)
VALUES
('BTW/TVA', 'Value Added Tax (VAT)', 'VAT1', 'BE', 21.5),
('TVA', 'Value Added Tax (VAT)', 'VAT1', 'CD', 16.0),
('Taxe sur le revenue', 'Revenue tax', 'ART15', 'CD', 0.0);
/* products table */
DROP TRIGGER IF EXISTS `products_before_insert`;
DROP TRIGGER IF EXISTS `products_before_update`;
DROP TABLE IF EXISTS `products`;
CREATE TABLE `products` (
`pr_code` CHAR(8) NOT NULL COMMENT 'the product code, uppercase',
`pr_name` VARCHAR(60) NOT NULL COMMENT 'the product code',
`status_code` CHAR(1) DEFAULT 'C' COMMENT 'valid codes: see table pme_statuscodes'
);
ALTER TABLE `products`
COMMENT = 'specific test for no primary key, comments on table and column';
ALTER TABLE `products`
ADD UNIQUE KEY `pr_code_ukey` (`pr_code`);
ALTER TABLE `products`
ADD CONSTRAINT `FK_products_statuscodes`
FOREIGN KEY (`status_code`) REFERENCES `pme_statuscodes`(`code`);
DELIMITER $$
CREATE TRIGGER `products_before_insert` BEFORE INSERT
ON `products` FOR EACH ROW
BEGIN
IF (NEW.`pr_code` IS NULL) THEN SET NEW.`pr_code` = NEW.`pr_name`; END IF;
SET NEW.`pr_code` = UPPER(NEW.`pr_code`);
IF (NEW.`status_code` IS NULL) THEN SET NEW.`status_code` = 'C'; END IF;
END
$$
CREATE TRIGGER `products_before_update` BEFORE UPDATE
ON `products` FOR EACH ROW
BEGIN
IF NEW.`status_code` = OLD.`status_code` THEN
/* set status code only if it has not been changed by the
statement
*/
SET NEW.`status_code` = 'M';
END IF;
IF (NEW.`pr_code` IS NULL) THEN SET NEW.`pr_code` = NEW.`pr_name`; END IF;
IF NEW.`pr_code` != OLD.`pr_code` THEN
SET NEW.`pr_code` = UPPER(NEW.`pr_code`);
END IF;
END
$$
DELIMITER ;
INSERT INTO `products`
(`pr_code`, `pr_name`)
VALUES
('Poule', 'Poule'),
('Chevre', 'Chevre'),
('Vache', 'Vache');
/* incidents table */
DROP TABLE IF EXISTS `incidents`;
CREATE TABLE `incidents` (
`nmbr` INT(10) NOT NULL,
`title` VARCHAR(60) NOT NULL,
`summary` TEXT,
`full_desciption` TEXT,
`importance` ENUM('very', 'normal', 'n.a.') DEFAULT 'normal' COMMENT 'single select',
`impacts` SET('client software', 'server software') COMMENT 'multi-select',
`reporting_year` YEAR,
`opening_date` DATE,
`opening_time` TIME,
`approx_percentage` FLOAT(10) COMMENT 'approximate value',
`absolute_percentage` DECIMAL(6,2) COMMENT 'real value, -100.00 - +100.00',
`total_csost` NUMERIC COMMENT 'real value',
`mask_special` BIT(15) COMMENT 'bitmask',
`metadata` JSON COMMENT 'structured data',
`system_dump` BLOB COMMENT 'binary image',
`creation_date` TIMESTAMP DEFAULT current_timestamp() COMMENT 'created on',
`modification_date` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'last updated on'
);
ALTER TABLE `incidents`
ADD `rowid` INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY FIRST;
-- tables are modfied after creation, as certain types might not be
-- supported, so script fails on specific unsupported type
ALTER TABLE `incidents` MODIFY COLUMN `summary` TINYTEXT;
ALTER TABLE `incidents` MODIFY COLUMN `full_desciption` LONGTEXT;
ALTER TABLE `incidents` MODIFY COLUMN `system_dump` LONGBLOB;
ALTER TABLE `incidents`
MODIFY COLUMN `modification_date` timestamp NOT NULL DEFAULT current_timestamp()
ON UPDATE current_timestamp();
ALTER TABLE `incidents`
COMMENT = 'test different field types';
ALTER TABLE `incidents`
ADD UNIQUE KEY `nmbr_ukey` (`nmbr`);
/* eof */
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.