-
Notifications
You must be signed in to change notification settings - Fork 15
/
sample.dbs
1026 lines (1001 loc) · 55.4 KB
/
sample.dbs
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8" ?>
<project name="MySql" id="Project-3ee" database="MySql" >
<schema name="sakila" >
<table name="Baseboard" row_count="0" spec="" >
<column name="id" type="BIGINT" jt="-5" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="name" type="VARCHAR" length="45" jt="12" mandatory="y" />
<column name="axapta_article_number" type="VARCHAR" length="15" jt="12" />
<column name="board_model" type="VARCHAR" length="4" jt="12" />
<column name="board_type" type="VARCHAR" length="15" jt="12" />
<column name="board_version" type="VARCHAR" length="20" jt="12" />
<column name="ems_serial" type="VARCHAR" length="15" jt="12" />
<column name="info_version" type="VARCHAR" length="15" jt="12" />
<column name="pic_sw_version" type="VARCHAR" length="15" jt="12" />
<column name="date" type="TIMESTAMP" jt="93" >
<defo><![CDATA[now()]]></defo>
</column>
<index name="pk_baseboard" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<index name="idx_baseboard_board_type" unique="NORMAL" options="(`board_type`, `board_version`)" >
<column name="board_type" />
<column name="board_version" />
</index>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="actor" row_count="300" spec="" >
<comment><![CDATA[Details about actors.]]></comment>
<column name="actor_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="first_name" type="VARCHAR" length="45" jt="12" mandatory="y" />
<column name="last_name" type="VARCHAR" length="45" jt="12" mandatory="y" />
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_actor" unique="PRIMARY_KEY" >
<column name="actor_id" />
</index>
<index name="idx_actor_last_name" unique="NORMAL" options="(`last_name`)" >
<column name="last_name" />
</index>
<options><![CDATA[ENGINE=InnoDB AUTO_INCREMENT=301 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Details about actors.']]></options>
</table>
<table name="address" row_count="311" spec="" >
<comment><![CDATA[Some comment]]></comment>
<column name="address_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="address" type="VARCHAR" length="50" jt="12" mandatory="y" />
<column name="address2" type="VARCHAR" length="50" jt="12" />
<column name="district" type="VARCHAR" length="20" jt="12" mandatory="y" />
<column name="city_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" />
<column name="postal_code" type="VARCHAR" length="10" jt="12" />
<column name="phone" type="VARCHAR" length="20" jt="12" mandatory="y" />
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_address" unique="PRIMARY_KEY" >
<column name="address_id" />
</index>
<index name="idx_fk_city_id" unique="NORMAL" options="(`city_id`)" >
<column name="city_id" />
</index>
<fk name="fk_address_city" to_schema="sakila" to_table="city" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="city_id" pk="city_id" />
</fk>
<options><![CDATA[ENGINE=InnoDB AUTO_INCREMENT=329 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Some comment']]></options>
</table>
<table name="category" row_count="116" spec="" >
<column name="category_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="name" type="VARCHAR" length="25" jt="12" mandatory="y" />
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_category" unique="PRIMARY_KEY" >
<column name="category_id" />
</index>
<options><![CDATA[ENGINE=InnoDB AUTO_INCREMENT=117 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="city" row_count="750" spec="" >
<column name="city_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="city" type="VARCHAR" length="50" jt="12" mandatory="y" />
<column name="country_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" />
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_city" unique="PRIMARY_KEY" >
<column name="city_id" />
</index>
<index name="idx_fk_country_id" unique="NORMAL" options="(`country_id`)" >
<column name="country_id" />
</index>
<fk name="fk_city_country" to_schema="sakila" to_table="country" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="country_id" pk="country_id" />
</fk>
<options><![CDATA[ENGINE=InnoDB AUTO_INCREMENT=751 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="country" row_count="209" spec="" >
<column name="country_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="country" type="VARCHAR" length="50" jt="12" mandatory="y" />
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_country" unique="PRIMARY_KEY" >
<column name="country_id" />
</index>
<index name="idx_country" unique="NORMAL" options="(`last_update`, `country`)" >
<column name="last_update" />
<column name="country" />
</index>
<options><![CDATA[ENGINE=InnoDB AUTO_INCREMENT=210 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="customer" row_count="599" spec="" >
<column name="customer_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
<comment><![CDATA[column comment]]></comment>
</column>
<column name="store_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" />
<column name="first_name" type="VARCHAR" length="45" jt="12" mandatory="y" />
<column name="last_name" type="VARCHAR" length="45" jt="12" mandatory="y" />
<column name="email" type="VARCHAR" length="50" jt="12" />
<column name="address_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" />
<column name="active" type="TINYINT" length="1" jt="-6" mandatory="y" >
<defo><![CDATA['1']]></defo>
</column>
<column name="create_date" type="DATETIME" jt="93" mandatory="y" />
<column name="last_update" type="TIMESTAMP" jt="93" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_customer" unique="PRIMARY_KEY" >
<column name="customer_id" />
</index>
<index name="idx_fk_store_id" unique="NORMAL" options="(`store_id`)" >
<column name="store_id" />
</index>
<index name="idx_fk_address_id" unique="NORMAL" options="(`address_id`)" >
<column name="address_id" />
</index>
<index name="idx_last_name" unique="NORMAL" options="(`last_name`)" >
<column name="last_name" />
</index>
<fk name="fk_customer_address" to_schema="sakila" to_table="address" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="address_id" pk="address_id" />
</fk>
<fk name="fk_customer_store" to_schema="sakila" to_table="store" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="store_id" pk="store_id" />
</fk>
<options><![CDATA[ENGINE=InnoDB AUTO_INCREMENT=600 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="film" row_count="167" spec="" >
<column name="film_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="title" type="VARCHAR" length="128" jt="12" mandatory="y" />
<column name="description" type="TEXT" jt="-1" />
<column name="release_year" type="YEAR" jt="4" />
<column name="language_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" />
<column name="original_language_id" type="TINYINT" jt="-6" unsigned="y" />
<column name="rental_duration" type="TINYINT" jt="-6" mandatory="y" unsigned="y" >
<defo><![CDATA['3']]></defo>
</column>
<column name="rental_rate" type="DECIMAL" length="4" decimal="2" jt="3" mandatory="y" >
<defo><![CDATA['4.99']]></defo>
</column>
<column name="length" type="SMALLINT" jt="5" unsigned="y" />
<column name="replacement_cost" type="DECIMAL" length="5" decimal="2" jt="3" mandatory="y" >
<defo><![CDATA['19.99']]></defo>
</column>
<column name="rating" type="ENUM" jt="12" >
<defo><![CDATA['G']]></defo>
<enumeration><![CDATA['G','PG','PG-13','R','NC-17']]></enumeration>
</column>
<column name="special_features" type="SET" jt="12" >
<enumeration><![CDATA['Trailers','Commentaries','Deleted Scenes','Behind the Scenes']]></enumeration>
</column>
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_film" unique="PRIMARY_KEY" >
<column name="film_id" />
</index>
<index name="idx_title" unique="NORMAL" options="(`title`)" >
<column name="title" />
</index>
<index name="idx_fk_language_id" unique="NORMAL" options="(`language_id`)" >
<column name="language_id" />
</index>
<index name="idx_fk_original_language_id" unique="NORMAL" options="(`original_language_id`)" >
<column name="original_language_id" />
</index>
<fk name="fk_film_language" to_schema="sakila" to_table="language" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="language_id" pk="language_id" />
</fk>
<fk name="fk_film_language_original" to_schema="sakila" to_table="language" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="original_language_id" pk="language_id" />
</fk>
<options><![CDATA[ENGINE=InnoDB AUTO_INCREMENT=180 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="film_actor" row_count="225" spec="" >
<column name="actor_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" />
<column name="film_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" />
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_film_actor" unique="PRIMARY_KEY" >
<column name="actor_id" />
<column name="film_id" />
</index>
<index name="idx_fk_film_id" unique="NORMAL" options="(`film_id`)" >
<column name="film_id" />
</index>
<fk name="fk_film_actor_actor" to_schema="sakila" to_table="actor" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="actor_id" pk="actor_id" />
</fk>
<fk name="fk_film_actor_film" to_schema="sakila" to_table="film" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="film_id" pk="film_id" />
</fk>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="film_category" row_count="225" spec="" >
<column name="film_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" />
<column name="category_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" />
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_film_category" unique="PRIMARY_KEY" >
<column name="film_id" />
<column name="category_id" />
</index>
<index name="fk_film_category_category" unique="NORMAL" options="(`category_id`)" >
<column name="category_id" />
</index>
<fk name="fk_film_category_category" to_schema="sakila" to_table="category" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="category_id" pk="category_id" />
</fk>
<fk name="fk_film_category_film" to_schema="sakila" to_table="film" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="film_id" pk="film_id" />
</fk>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="film_text" row_count="167" spec="" >
<column name="film_id" type="SMALLINT" jt="5" mandatory="y" />
<column name="title" type="VARCHAR" length="255" jt="12" mandatory="y" />
<column name="description" type="TEXT" jt="-1" />
<column name="age" type="INT" jt="4" />
<column name="tutorial" type="TEXT" jt="-1" />
<index name="pk_film_text" unique="PRIMARY_KEY" >
<column name="film_id" />
</index>
<index name="idx_title_description" unique="INDEX1" >
<column name="title" />
<column name="description" />
</index>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="inventory" row_count="0" spec="" >
<column name="inventory_id" type="MEDIUMINT" jt="4" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="film_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" />
<column name="store_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" />
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_inventory" unique="PRIMARY_KEY" >
<column name="inventory_id" />
</index>
<index name="idx_fk_film_id" unique="NORMAL" options="(`film_id`)" >
<column name="film_id" />
</index>
<index name="idx_store_id_film_id" unique="NORMAL" options="(`store_id`, `film_id`)" >
<column name="store_id" />
<column name="film_id" />
</index>
<fk name="fk_inventory_film" to_schema="sakila" to_table="film" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="film_id" pk="film_id" />
</fk>
<fk name="fk_inventory_store" to_schema="sakila" to_table="store" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="store_id" pk="store_id" />
</fk>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="language" row_count="100" spec="" >
<column name="language_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="name" type="CHAR" length="20" jt="1" mandatory="y" />
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_language" unique="PRIMARY_KEY" >
<column name="language_id" />
</index>
<options><![CDATA[ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="payment" row_count="0" spec="" >
<column name="payment_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="customer_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" />
<column name="staff_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" />
<column name="rental_id" type="INT" jt="4" />
<column name="amount" type="DECIMAL" length="5" decimal="2" jt="3" mandatory="y" />
<column name="payment_date" type="DATETIME" jt="93" mandatory="y" />
<column name="last_update" type="TIMESTAMP" jt="93" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_payment" unique="PRIMARY_KEY" >
<column name="payment_id" />
</index>
<index name="idx_fk_staff_id" unique="NORMAL" options="(`staff_id`)" >
<column name="staff_id" />
</index>
<index name="idx_fk_customer_id" unique="NORMAL" options="(`customer_id`)" >
<column name="customer_id" />
</index>
<index name="fk_payment_rental" unique="NORMAL" options="(`rental_id`)" >
<column name="rental_id" />
</index>
<fk name="fk_payment_customer" to_schema="sakila" to_table="customer" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="customer_id" pk="customer_id" />
</fk>
<fk name="fk_payment_rental" to_schema="sakila" to_table="rental" delete_action="setNull" update_action="cascade" options="" >
<fk_column name="rental_id" pk="rental_id" />
</fk>
<fk name="fk_payment_staff" to_schema="sakila" to_table="staff" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="staff_id" pk="staff_id" />
</fk>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="persons" row_count="100" spec="" >
<column name="id" type="INT" jt="4" mandatory="y" />
<column name="firstname" type="VARCHAR" length="100" jt="12" mandatory="y" />
<column name="lastname" type="VARCHAR" length="100" jt="12" />
<column name="description" type="TEXT" jt="-1" >
<comment><![CDATA[This is a sample]]></comment>
</column>
<column name="description2" type="TEXT" jt="-1" />
<index name="pk_persons" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<index name="idx_persons_firstname" unique="NORMAL" options="(`firstname`, `lastname`)" >
<column name="firstname" />
<column name="lastname" />
</index>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="rental" row_count="0" spec="" >
<column name="rental_id" type="INT" jt="4" mandatory="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="rental_date" type="DATETIME" jt="93" mandatory="y" />
<column name="inventory_id" type="MEDIUMINT" jt="4" mandatory="y" unsigned="y" />
<column name="customer_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" />
<column name="return_date" type="DATETIME" jt="93" />
<column name="staff_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" />
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_rental" unique="PRIMARY_KEY" >
<column name="rental_id" />
</index>
<index name="rental_date" unique="UNIQUE_KEY" >
<column name="rental_date" />
<column name="inventory_id" />
<column name="customer_id" />
</index>
<index name="idx_fk_inventory_id" unique="NORMAL" options="(`inventory_id`)" >
<column name="inventory_id" />
</index>
<index name="idx_fk_customer_id" unique="NORMAL" options="(`customer_id`)" >
<column name="customer_id" />
</index>
<index name="idx_fk_staff_id" unique="NORMAL" options="(`staff_id`)" >
<column name="staff_id" />
</index>
<fk name="fk_rental_customer" to_schema="sakila" to_table="customer" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="customer_id" pk="customer_id" />
</fk>
<fk name="fk_rental_inventory" to_schema="sakila" to_table="inventory" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="inventory_id" pk="inventory_id" />
</fk>
<fk name="fk_rental_staff" to_schema="sakila" to_table="staff" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="staff_id" pk="staff_id" />
</fk>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="sample1" row_count="0" spec="" >
<column name="id" type="INT" jt="4" mandatory="y" />
<column name="firstname" type="VARCHAR" length="100" jt="12" />
<index name="pk_sample1" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="sample1_0" row_count="0" spec="" >
<column name="id" type="INT" jt="4" mandatory="y" />
<column name="firstname" type="VARCHAR" length="100" jt="12" />
<index name="pk_sample1_0" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="staff" row_count="0" spec="" >
<comment><![CDATA[The staff members are listed here2.]]></comment>
<column name="staff_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="first_name" type="VARCHAR" length="45" jt="12" mandatory="y" />
<column name="last_name" type="VARCHAR" length="45" jt="12" mandatory="y" >
<comment><![CDATA[The last name]]></comment>
</column>
<column name="address_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" />
<column name="picture" type="BLOB" jt="2004" />
<column name="email" type="VARCHAR" length="50" jt="12" />
<column name="store_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" />
<column name="active" type="TINYINT" length="1" jt="-6" mandatory="y" >
<defo><![CDATA['1']]></defo>
</column>
<column name="username" type="VARCHAR" length="16" jt="12" mandatory="y" />
<column name="password" type="VARCHAR" length="40" jt="12" >
<column_options><![CDATA[CHARACTER SET utf8mb4 COLLATE utf8mb4_bin]]></column_options>
</column>
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_staff" unique="PRIMARY_KEY" >
<column name="staff_id" />
</index>
<index name="idx_fk_store_id" unique="NORMAL" options="(`store_id`)" >
<column name="store_id" />
</index>
<index name="idx_fk_address_id" unique="NORMAL" options="(`address_id`)" >
<column name="address_id" />
</index>
<fk name="fk_staff_address" to_schema="sakila" to_table="address" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="address_id" pk="address_id" />
</fk>
<fk name="fk_staff_store" to_schema="sakila" to_table="store" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="store_id" pk="store_id" />
</fk>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='The staff members are listed here2.']]></options>
</table>
<table name="store" row_count="0" spec="" >
<column name="store_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="manager_staff_id" type="TINYINT" jt="-6" mandatory="y" unsigned="y" />
<column name="address_id" type="SMALLINT" jt="5" mandatory="y" unsigned="y" />
<column name="last_update" type="TIMESTAMP" jt="93" mandatory="y" >
<defo><![CDATA[CURRENT_TIMESTAMP]]></defo>
<column_options><![CDATA[ON UPDATE CURRENT_TIMESTAMP]]></column_options>
</column>
<index name="pk_store" unique="PRIMARY_KEY" >
<column name="store_id" />
</index>
<index name="idx_unique_manager" unique="UNIQUE_KEY" >
<column name="manager_staff_id" />
</index>
<index name="idx_fk_address_id" unique="NORMAL" options="(`address_id`)" >
<column name="address_id" />
</index>
<fk name="fk_store_address" to_schema="sakila" to_table="address" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="address_id" pk="address_id" />
</fk>
<fk name="fk_store_staff" to_schema="sakila" to_table="staff" delete_action="restrict" update_action="cascade" options="" >
<fk_column name="manager_staff_id" pk="staff_id" />
</fk>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="test_autoincrement" row_count="0" spec="" >
<column name="id" type="INT" jt="4" mandatory="y" >
<identity><![CDATA[AUTO_INCREMENT]]></identity>
</column>
<column name="firstname" type="VARCHAR" length="100" jt="12" />
<column name="lastname" type="VARCHAR" length="100" jt="12" />
<column name="newcolumns" type="BOOLEAN" length="1" jt="16" />
<index name="pk_test_autoincrement" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="test_data_gen" row_count="0" spec="" >
<column name="id" type="INT" jt="4" mandatory="y" />
<column name="startdate" type="DATE" jt="91" />
<column name="enddate" type="DATE" jt="91" />
<index name="pk_test_data_gen" unique="PRIMARY_KEY" >
<column name="id" />
</index>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<table name="медве́дь" row_count="100" spec="" >
<column name="關於數字和表格的呈現方式?" type="INT" jt="4" mandatory="y" />
<column name="details" type="VARCHAR" length="12" jt="12" />
<column name="other" type="VARCHAR" length="12" jt="12" />
<index name="pk_медве́дь" unique="PRIMARY_KEY" >
<column name="關於數字和表格的呈現方式?" />
</index>
<options><![CDATA[ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci]]></options>
</table>
<view name="actor_info" >
<comment><![CDATA[VIEW]]></comment>
<view_script><![CDATA[CREATE VIEW ${fullName} AS select `a`.`actor_id` AS `actor_id`,`a`.`first_name` AS `first_name`,`a`.`last_name` AS `last_name`,group_concat(distinct concat(`c`.`name`,': ',(select group_concat(`f`.`title` order by `f`.`title` ASC separator ', ') from ((`sakila`.`film` `f` join `sakila`.`film_category` `fc` on((`f`.`film_id` = `fc`.`film_id`))) join `sakila`.`film_actor` `fa` on((`f`.`film_id` = `fa`.`film_id`))) where ((`fc`.`category_id` = `c`.`category_id`) and (`fa`.`actor_id` = `a`.`actor_id`)))) order by `c`.`name` ASC separator '; ') AS `film_info` from (((`sakila`.`actor` `a` left join `sakila`.`film_actor` `fa` on((`a`.`actor_id` = `fa`.`actor_id`))) left join `sakila`.`film_category` `fc` on((`fa`.`film_id` = `fc`.`film_id`))) left join `sakila`.`category` `c` on((`fc`.`category_id` = `c`.`category_id`))) group by `a`.`actor_id`,`a`.`first_name`,`a`.`last_name`]]></view_script>
<column name="actor_id" type="SMALLINT" />
<column name="first_name" type="VARCHAR" />
<column name="last_name" type="VARCHAR" />
<column name="film_info" type="TEXT" />
</view>
<view name="customer_list" >
<comment><![CDATA[VIEW]]></comment>
<view_script><![CDATA[CREATE VIEW ${fullName} AS select `cu`.`customer_id` AS `ID`,concat(`cu`.`first_name`,' ',`cu`.`last_name`) AS `name`,`a`.`address` AS `address`,`a`.`postal_code` AS `zip code`,`a`.`phone` AS `phone`,`sakila`.`city`.`city` AS `city`,`sakila`.`country`.`country` AS `country`,if(`cu`.`active`,'active','') AS `notes`,`cu`.`store_id` AS `SID` from (((`sakila`.`customer` `cu` join `sakila`.`address` `a` on((`cu`.`address_id` = `a`.`address_id`))) join `sakila`.`city` on((`a`.`city_id` = `sakila`.`city`.`city_id`))) join `sakila`.`country` on((`sakila`.`city`.`country_id` = `sakila`.`country`.`country_id`)))]]></view_script>
<column name="ID" type="SMALLINT" >
<comment><![CDATA[column comment]]></comment>
</column>
<column name="name" type="VARCHAR" />
<column name="address" type="VARCHAR" />
<column name="zip code" type="VARCHAR" />
<column name="phone" type="VARCHAR" />
<column name="city" type="VARCHAR" />
<column name="country" type="VARCHAR" />
<column name="notes" type="VARCHAR" />
<column name="SID" type="TINYINT" />
</view>
<view name="film_list" >
<comment><![CDATA[VIEW]]></comment>
<view_script><![CDATA[CREATE VIEW ${fullName} AS select `sakila`.`film`.`film_id` AS `FID`,`sakila`.`film`.`title` AS `title`,`sakila`.`film`.`description` AS `description`,`sakila`.`category`.`name` AS `category`,`sakila`.`film`.`rental_rate` AS `price`,`sakila`.`film`.`length` AS `length`,`sakila`.`film`.`rating` AS `rating`,group_concat(concat(`sakila`.`actor`.`first_name`,' ',`sakila`.`actor`.`last_name`) separator ', ') AS `actors` from ((((`sakila`.`category` left join `sakila`.`film_category` on((`sakila`.`category`.`category_id` = `sakila`.`film_category`.`category_id`))) left join `sakila`.`film` on((`sakila`.`film_category`.`film_id` = `sakila`.`film`.`film_id`))) join `sakila`.`film_actor` on((`sakila`.`film`.`film_id` = `sakila`.`film_actor`.`film_id`))) join `sakila`.`actor` on((`sakila`.`film_actor`.`actor_id` = `sakila`.`actor`.`actor_id`))) group by `sakila`.`film`.`film_id`,`sakila`.`category`.`name`]]></view_script>
<column name="FID" type="SMALLINT" />
<column name="title" type="VARCHAR" />
<column name="description" type="TEXT" />
<column name="category" type="VARCHAR" />
<column name="price" type="DECIMAL" />
<column name="length" type="SMALLINT" />
<column name="rating" type="ENUM" />
<column name="actors" type="TEXT" />
</view>
<view name="nicer_but_slower_film_list" >
<comment><![CDATA[VIEW]]></comment>
<view_script><![CDATA[CREATE VIEW ${fullName} AS select `sakila`.`film`.`film_id` AS `FID`,`sakila`.`film`.`title` AS `title`,`sakila`.`film`.`description` AS `description`,`sakila`.`category`.`name` AS `category`,`sakila`.`film`.`rental_rate` AS `price`,`sakila`.`film`.`length` AS `length`,`sakila`.`film`.`rating` AS `rating`,group_concat(concat(concat(upper(substr(`sakila`.`actor`.`first_name`,1,1)),lower(substr(`sakila`.`actor`.`first_name`,2,length(`sakila`.`actor`.`first_name`))),' ',concat(upper(substr(`sakila`.`actor`.`last_name`,1,1)),lower(substr(`sakila`.`actor`.`last_name`,2,length(`sakila`.`actor`.`last_name`)))))) separator ', ') AS `actors` from ((((`sakila`.`category` left join `sakila`.`film_category` on((`sakila`.`category`.`category_id` = `sakila`.`film_category`.`category_id`))) left join `sakila`.`film` on((`sakila`.`film_category`.`film_id` = `sakila`.`film`.`film_id`))) join `sakila`.`film_actor` on((`sakila`.`film`.`film_id` = `sakila`.`film_actor`.`film_id`))) join `sakila`.`actor` on((`sakila`.`film_actor`.`actor_id` = `sakila`.`actor`.`actor_id`))) group by `sakila`.`film`.`film_id`,`sakila`.`category`.`name`]]></view_script>
<column name="FID" type="SMALLINT" />
<column name="title" type="VARCHAR" />
<column name="description" type="TEXT" />
<column name="category" type="VARCHAR" />
<column name="price" type="DECIMAL" />
<column name="length" type="SMALLINT" />
<column name="rating" type="ENUM" />
<column name="actors" type="TEXT" />
</view>
<view name="sales_by_film_category" >
<comment><![CDATA[VIEW]]></comment>
<view_script><![CDATA[CREATE VIEW ${fullName} AS select `c`.`name` AS `category`,sum(`p`.`amount`) AS `total_sales` from (((((`sakila`.`payment` `p` join `sakila`.`rental` `r` on((`p`.`rental_id` = `r`.`rental_id`))) join `sakila`.`inventory` `i` on((`r`.`inventory_id` = `i`.`inventory_id`))) join `sakila`.`film` `f` on((`i`.`film_id` = `f`.`film_id`))) join `sakila`.`film_category` `fc` on((`f`.`film_id` = `fc`.`film_id`))) join `sakila`.`category` `c` on((`fc`.`category_id` = `c`.`category_id`))) group by `c`.`name` order by `total_sales` desc]]></view_script>
<column name="category" type="VARCHAR" />
<column name="total_sales" type="DECIMAL" />
</view>
<view name="sales_by_store" >
<comment><![CDATA[VIEW]]></comment>
<view_script><![CDATA[CREATE VIEW ${fullName} AS select concat(`c`.`city`,',',`cy`.`country`) AS `store`,concat(`m`.`first_name`,' ',`m`.`last_name`) AS `manager`,sum(`p`.`amount`) AS `total_sales` from (((((((`sakila`.`payment` `p` join `sakila`.`rental` `r` on((`p`.`rental_id` = `r`.`rental_id`))) join `sakila`.`inventory` `i` on((`r`.`inventory_id` = `i`.`inventory_id`))) join `sakila`.`store` `s` on((`i`.`store_id` = `s`.`store_id`))) join `sakila`.`address` `a` on((`s`.`address_id` = `a`.`address_id`))) join `sakila`.`city` `c` on((`a`.`city_id` = `c`.`city_id`))) join `sakila`.`country` `cy` on((`c`.`country_id` = `cy`.`country_id`))) join `sakila`.`staff` `m` on((`s`.`manager_staff_id` = `m`.`staff_id`))) group by `s`.`store_id` order by `cy`.`country`,`c`.`city`]]></view_script>
<column name="store" type="VARCHAR" />
<column name="manager" type="VARCHAR" />
<column name="total_sales" type="DECIMAL" />
</view>
<view name="staff_list" >
<comment><![CDATA[VIEW]]></comment>
<view_script><![CDATA[CREATE VIEW ${fullName} AS select `s`.`staff_id` AS `ID`,concat(`s`.`first_name`,' ',`s`.`last_name`) AS `name`,`a`.`address` AS `address`,`a`.`postal_code` AS `zip code`,`a`.`phone` AS `phone`,`sakila`.`city`.`city` AS `city`,`sakila`.`country`.`country` AS `country`,`s`.`store_id` AS `SID` from (((`sakila`.`staff` `s` join `sakila`.`address` `a` on((`s`.`address_id` = `a`.`address_id`))) join `sakila`.`city` on((`a`.`city_id` = `sakila`.`city`.`city_id`))) join `sakila`.`country` on((`sakila`.`city`.`country_id` = `sakila`.`country`.`country_id`)))]]></view_script>
<column name="ID" type="TINYINT" />
<column name="name" type="VARCHAR" />
<column name="address" type="VARCHAR" />
<column name="zip code" type="VARCHAR" />
<column name="phone" type="VARCHAR" />
<column name="city" type="VARCHAR" />
<column name="country" type="VARCHAR" />
<column name="SID" type="TINYINT" />
</view>
<procedure name="film_in_stock" id="Procedure-211a" isSystem="false" params_known="n" >
<string><![CDATA[CREATE PROCEDURE `film_in_stock`(IN p_film_id INT, IN p_store_id INT, OUT p_film_count INT)
READS SQL DATA
BEGIN
SELECT inventory_id
FROM inventory
WHERE film_id = p_film_id
AND store_id = p_store_id
AND inventory_in_stock(inventory_id);
SELECT COUNT(*)
FROM inventory
WHERE film_id = p_film_id
AND store_id = p_store_id
AND inventory_in_stock(inventory_id)
INTO p_film_count;
END]]></string>
</procedure>
<procedure name="film_not_in_stock" id="Procedure-21f5" isSystem="false" params_known="n" >
<string><![CDATA[CREATE PROCEDURE `film_not_in_stock`(IN p_film_id INT, IN p_store_id INT, OUT p_film_count INT)
READS SQL DATA
BEGIN
SELECT inventory_id
FROM inventory
WHERE film_id = p_film_id
AND store_id = p_store_id
AND NOT inventory_in_stock(inventory_id);
SELECT COUNT(*)
FROM inventory
WHERE film_id = p_film_id
AND store_id = p_store_id
AND NOT inventory_in_stock(inventory_id)
INTO p_film_count;
END]]></string>
</procedure>
<procedure name="rewards_report" id="Procedure-6e6" isSystem="false" params_known="n" >
<string><![CDATA[CREATE PROCEDURE `rewards_report`(
IN min_monthly_purchases TINYINT UNSIGNED
, IN min_dollar_amount_purchased DECIMAL(10,2)
, OUT count_rewardees INT
)
READS SQL DATA
COMMENT 'Provides a customizable report on best customers'
proc: BEGIN
DECLARE last_month_start DATE;
DECLARE last_month_end DATE;
/* Some sanity checks... */
IF min_monthly_purchases = 0 THEN
SELECT 'Minimum monthly purchases parameter must be > 0';
LEAVE proc;
END IF;
IF min_dollar_amount_purchased = 0.00 THEN
SELECT 'Minimum monthly dollar amount purchased parameter must be > $0.00';
LEAVE proc;
END IF;
/* Determine start and end time periods */
SET last_month_start = DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH);
SET last_month_start = STR_TO_DATE(CONCAT(YEAR(last_month_start),'-',MONTH(last_month_start),'-01'),'%Y-%m-%d');
SET last_month_end = LAST_DAY(last_month_start);
/*
Create a temporary storage area for
Customer IDs.
*/
CREATE TEMPORARY TABLE tmpCustomer (customer_id SMALLINT UNSIGNED NOT NULL PRIMARY KEY);
/*
Find all customers meeting the
monthly purchase requirements
*/
INSERT INTO tmpCustomer (customer_id)
SELECT p.customer_id
FROM payment AS p
WHERE DATE(p.payment_date) BETWEEN last_month_start AND last_month_end
GROUP BY customer_id
HAVING SUM(p.amount) > min_dollar_amount_purchased
AND COUNT(customer_id) > min_monthly_purchases;
/* Populate OUT parameter with count of found customers */
SELECT COUNT(*) FROM tmpCustomer INTO count_rewardees;
/*
Output ALL customer information of matching rewardees.
Customize output as needed.
*/
SELECT c.*
FROM tmpCustomer AS t
INNER JOIN customer AS c ON t.customer_id = c.customer_id;
/* Clean up */
DROP TABLE tmpCustomer;
END]]></string>
</procedure>
<trigger name="del_film" table="film" id="Trigger-dfa" isSystem="false" >
<string><![CDATA[CREATE TRIGGER sakila.del_film AFTER DELETE ON film FOR EACH ROW BEGIN
DELETE FROM film_text WHERE film_id = old.film_id;
END;]]></string>
</trigger>
<trigger name="ins_film" table="film" id="Trigger-25b9" isSystem="false" >
<string><![CDATA[CREATE TRIGGER sakila.ins_film AFTER INSERT ON film FOR EACH ROW BEGIN
INSERT INTO film_text (film_id, title, description)
VALUES (new.film_id, new.title, new.description);
END;]]></string>
</trigger>
<trigger name="upd_film" table="film" id="Trigger-3ed" isSystem="false" >
<string><![CDATA[CREATE TRIGGER sakila.upd_film AFTER UPDATE ON film FOR EACH ROW BEGIN
IF (old.title != new.title) OR (old.description != new.description) OR (old.film_id != new.film_id)
THEN
UPDATE film_text
SET title=new.title,
description=new.description,
film_id=new.film_id
WHERE film_id=old.film_id;
END IF;
END;]]></string>
</trigger>
<function name="get_customer_balance" id="Function-89a" isSystem="false" params_known="n" >
<string><![CDATA[CREATE FUNCTION `get_customer_balance`(p_customer_id INT, p_effective_date DATETIME) RETURNS decimal(5,2)
READS SQL DATA
DETERMINISTIC
BEGIN
#OK, WE NEED TO CALCULATE THE CURRENT BALANCE GIVEN A CUSTOMER_ID AND A DATE
#THAT WE WANT THE BALANCE TO BE EFFECTIVE FOR. THE BALANCE IS:
# 1) RENTAL FEES FOR ALL PREVIOUS RENTALS
# 2) ONE DOLLAR FOR EVERY DAY THE PREVIOUS RENTALS ARE OVERDUE
# 3) IF A FILM IS MORE THAN RENTAL_DURATION * 2 OVERDUE, CHARGE THE REPLACEMENT_COST
# 4) SUBTRACT ALL PAYMENTS MADE BEFORE THE DATE SPECIFIED
DECLARE v_rentfees DECIMAL(5,2); #FEES PAID TO RENT THE VIDEOS INITIALLY
DECLARE v_overfees INTEGER; #LATE FEES FOR PRIOR RENTALS
DECLARE v_payments DECIMAL(5,2); #SUM OF PAYMENTS MADE PREVIOUSLY
SELECT IFNULL(SUM(film.rental_rate),0) INTO v_rentfees
FROM film, inventory, rental
WHERE film.film_id = inventory.film_id
AND inventory.inventory_id = rental.inventory_id
AND rental.rental_date <= p_effective_date
AND rental.customer_id = p_customer_id;
SELECT IFNULL(SUM(IF((TO_DAYS(rental.return_date) - TO_DAYS(rental.rental_date)) > film.rental_duration,
((TO_DAYS(rental.return_date) - TO_DAYS(rental.rental_date)) - film.rental_duration),0)),0) INTO v_overfees
FROM rental, inventory, film
WHERE film.film_id = inventory.film_id
AND inventory.inventory_id = rental.inventory_id
AND rental.rental_date <= p_effective_date
AND rental.customer_id = p_customer_id;
SELECT IFNULL(SUM(payment.amount),0) INTO v_payments
FROM payment
WHERE payment.payment_date <= p_effective_date
AND payment.customer_id = p_customer_id;
RETURN v_rentfees + v_overfees - v_payments;
END]]></string>
</function>
<function name="inventory_held_by_customer" id="Function-2583" isSystem="false" params_known="n" >
<string><![CDATA[CREATE FUNCTION `inventory_held_by_customer`(p_inventory_id INT) RETURNS int
READS SQL DATA
BEGIN
DECLARE v_customer_id INT;
DECLARE EXIT HANDLER FOR NOT FOUND RETURN NULL;
SELECT customer_id INTO v_customer_id
FROM rental
WHERE return_date IS NULL
AND inventory_id = p_inventory_id;
RETURN v_customer_id;
END]]></string>
</function>
<function name="inventory_in_stock" id="Function-2473" isSystem="false" params_known="n" >
<string><![CDATA[CREATE FUNCTION `inventory_in_stock`(p_inventory_id INT) RETURNS tinyint(1)
READS SQL DATA
BEGIN
DECLARE v_rentals INT;
DECLARE v_out INT;
#AN ITEM IS IN-STOCK IF THERE ARE EITHER NO ROWS IN THE rental TABLE
#FOR THE ITEM OR ALL ROWS HAVE return_date POPULATED
SELECT COUNT(*) INTO v_rentals
FROM rental
WHERE inventory_id = p_inventory_id;
IF v_rentals = 0 THEN
RETURN TRUE;
END IF;
SELECT COUNT(rental_id) INTO v_out
FROM inventory LEFT JOIN rental USING(inventory_id)
WHERE inventory.inventory_id = p_inventory_id
AND rental.return_date IS NULL;
IF v_out > 0 THEN
RETURN FALSE;
ELSE
RETURN TRUE;
END IF;
END]]></string>
</function>
</schema>
<connector name="MySql" database="MySql" driver_class="com.mysql.jdbc.Driver" driver_jar="mysql-connector-java-8.0.29.jar" driver_desc="Standard" host="localhost" port="3306" instance="sakila" user="dbschema" passwd="ZGJzY2hlbWExMg==" useSystemProxy="false" />
<layout name="Main Layout" id="Layout-1ab2" show_relation="name" >
<entity schema="sakila" name="Baseboard" color="BED3F4" x="464" y="1232" />
<entity schema="sakila" name="actor" color="C7F4BE" x="2352" y="752" />
<entity schema="sakila" name="actor_info" color="C7F4BE" x="2560" y="752" />
<entity schema="sakila" name="address" color="F4DDBE" x="1472" y="416" />
<entity schema="sakila" name="category" color="C7F4BE" x="2608" y="208" />
<entity schema="sakila" name="city" color="BEBEF4" x="1040" y="1040" />
<entity schema="sakila" name="country" color="BEBEF4" x="1248" y="1040" />
<entity schema="sakila" name="customer" color="F4DDBE" x="1712" y="208" />
<entity schema="sakila" name="customer_list" color="F4DDBE" x="1920" y="208" />
<entity schema="sakila" name="film" color="C7F4BE" x="2144" y="208" />
<entity schema="sakila" name="film_actor" color="C7F4BE" x="2144" y="560" />
<entity schema="sakila" name="film_category" color="C7F4BE" x="2400" y="208" />
<entity schema="sakila" name="film_list" color="C7F4BE" x="2144" y="752" />
<entity schema="sakila" name="film_text" color="C7F4BE" x="2352" y="1024" />
<entity schema="sakila" name="inventory" color="F4DDBE" x="1456" y="704" />
<entity schema="sakila" name="language" color="C7F4BE" x="2400" y="560" />
<entity schema="sakila" name="nicer_but_slower_film_list" color="BED3F4" x="736" y="1232" />
<entity schema="sakila" name="payment" color="F4DDBE" x="1040" y="528" />
<entity schema="sakila" name="persons" color="BED3F4" x="736" y="1536" />
<entity schema="sakila" name="rental" color="F4DDBE" x="1264" y="528" />
<entity schema="sakila" name="sales_by_film_category" color="BED3F4" x="464" y="1536" />
<entity schema="sakila" name="sales_by_store" color="BED3F4" x="464" y="1712" />
<entity schema="sakila" name="sample1" color="BED3F4" x="272" y="1536" />
<entity schema="sakila" name="sample1_0" color="BED3F4" x="272" y="1712" />
<entity schema="sakila" name="staff" color="F4DDBE" x="1232" y="208" />
<entity schema="sakila" name="staff_list" color="F4DDBE" x="1072" y="256" />
<entity schema="sakila" name="store" color="F4DDBE" x="1440" y="208" />
<entity schema="sakila" name="test_autoincrement" color="BED3F4" x="240" y="1344" />
<entity schema="sakila" name="test_data_gen" color="BED3F4" x="48" y="1536" />
<entity schema="sakila" name="медве́дь" color="BED3F4" x="160" y="1040" />
<callout x="2144" y="80" pointer="Round" >
<comment><![CDATA[A layout is a diagram with data and query tools.
- Get a better understanding of the schema by creating multiple layouts
- Drag tables to the layout from the project tree. One table may show in multiple layouts
- Right-click the layout to create new tables
- Double-click table headers, columns, or foreign keys to edit]]></comment>
</callout>
<group name="Baseboard" color="ECF0F7" >
<entity schema="sakila" name="Baseboard" />
<entity schema="sakila" name="nicer_but_slower_film_list" />
<entity schema="sakila" name="sales_by_film_category" />
<entity schema="sakila" name="sample1" />
<entity schema="sakila" name="медве́дь" />
<entity schema="sakila" name="test_data_gen" />
<entity schema="sakila" name="sales_by_store" />
<entity schema="sakila" name="sample1_0" />
<entity schema="sakila" name="test_autoincrement" />
<entity schema="sakila" name="persons" />
</group>
<group name="city" color="ECECF7" >
<entity schema="sakila" name="city" />
<entity schema="sakila" name="country" />
</group>
<group name="film" color="EEF7EC" >
<entity schema="sakila" name="film" />
<entity schema="sakila" name="film_category" />
<entity schema="sakila" name="language" />
<entity schema="sakila" name="film_actor" />
<entity schema="sakila" name="category" />
<entity schema="sakila" name="actor" />
<entity schema="sakila" name="film_list" />
<entity schema="sakila" name="film_text" />
<entity schema="sakila" name="actor_info" />
</group>
<group name="staff" color="F7F2EC" >
<entity schema="sakila" name="customer" />
<entity schema="sakila" name="address" />
<entity schema="sakila" name="rental" />
<entity schema="sakila" name="payment" />
<entity schema="sakila" name="staff_list" />
<entity schema="sakila" name="customer_list" />
<entity schema="sakila" name="store" />
<entity schema="sakila" name="inventory" />
<entity schema="sakila" name="staff" />
</group>
</layout>
<layout name="~Layout with Sample Tools" id="Layout-1c86" show_column_type="y" show_relation="name" >
<entity schema="sakila" name="Baseboard" color="BED3F4" x="544" y="1072" />
<entity schema="sakila" name="actor" color="C7F4BE" x="2896" y="592" />
<entity schema="sakila" name="actor_info" color="C7F4BE" x="3168" y="592" />
<entity schema="sakila" name="address" color="F4DDBE" x="1760" y="256" />
<entity schema="sakila" name="category" color="C7F4BE" x="3264" y="48" />
<entity schema="sakila" name="city" color="BEBEF4" x="1200" y="880" />
<entity schema="sakila" name="country" color="BEBEF4" x="1472" y="880" />
<entity schema="sakila" name="customer" color="F4DDBE" x="2048" y="112" />
<entity schema="sakila" name="customer_list" color="F4DDBE" x="2320" y="48" />
<entity schema="sakila" name="film" color="C7F4BE" x="2624" y="48" />
<entity schema="sakila" name="film_actor" color="C7F4BE" x="2624" y="400" />
<entity schema="sakila" name="film_category" color="C7F4BE" x="2992" y="48" />
<entity schema="sakila" name="film_list" color="C7F4BE" x="2624" y="592" />
<entity schema="sakila" name="film_text" color="C7F4BE" x="2896" y="864" />
<entity schema="sakila" name="inventory" color="F4DDBE" x="1760" y="624" />
<entity schema="sakila" name="language" color="C7F4BE" x="2992" y="400" />
<entity schema="sakila" name="nicer_but_slower_film_list" color="BED3F4" x="896" y="1072" />
<entity schema="sakila" name="payment" color="F4DDBE" x="1200" y="368" />
<entity schema="sakila" name="persons" color="BED3F4" x="896" y="1376" />
<entity schema="sakila" name="rental" color="F4DDBE" x="1488" y="368" />
<entity schema="sakila" name="sales_by_film_category" color="BED3F4" x="544" y="1376" />
<entity schema="sakila" name="sales_by_store" color="BED3F4" x="544" y="1552" />
<entity schema="sakila" name="sample1" color="BED3F4" x="272" y="1376" />
<entity schema="sakila" name="sample1_0" color="BED3F4" x="272" y="1552" />
<entity schema="sakila" name="staff" color="F4DDBE" x="1488" y="48" />
<entity schema="sakila" name="staff_list" color="F4DDBE" x="1216" y="96" />
<entity schema="sakila" name="store" color="F4DDBE" x="1760" y="48" />
<entity schema="sakila" name="test_autoincrement" color="BED3F4" x="272" y="1184" />
<entity schema="sakila" name="test_data_gen" color="BED3F4" x="48" y="1376" />
<entity schema="sakila" name="медве́дь" color="BED3F4" x="208" y="880" />
<script name="SQL Editor" id="Editor-20c" language="SQL" >
<string><![CDATA[SELECT film_id, title, description, release_year, language_id, original_language_id, rental_duration, rental_rate, length,
replacement_cost, rating, special_features, last_update
FROM
sakila.film m;]]></string>
</script>
<browser id="Browse-1280" name="Relational Data Explorer" confirm_updates="y" >
<browse_table schema="sakila" entity="film" x="20" y="20" width="400" height="300" >
<browse_table schema="sakila" entity="film_actor" fk="fk_film_actor_film" x="440" y="20" width="500" height="350" >
<browse_table schema="sakila" entity="actor" fk="fk_film_actor_actor" x="960" y="20" width="500" height="350" record_view="y" />
</browse_table>
</browse_table>
</browser>
<query id="Query-cf" name="Query Builder" >
<query_table schema="sakila" name="film" alias="f" x="48" y="48" >
<column name="film_id" />
<column name="title" />
<column name="description" />
<column name="release_year" />
<column name="language_id" />
<column name="original_language_id" />
<column name="rental_duration" />
<column name="rental_rate" />
<column name="length" />
<column name="replacement_cost" />
<column name="rating" />
<column name="special_features" />
<column name="last_update" />
<query_table schema="sakila" name="film_actor" alias="fa" x="272" y="48" fk="fk_film_actor_film" type="Inner Join" >
<column name="actor_id" />
<column name="film_id" />
<column name="last_update" />
<query_table schema="sakila" name="actor" alias="a" x="448" y="48" fk="fk_film_actor_actor" type="Inner Join" >
<column name="actor_id" />
<column name="first_name" />
<column name="last_name" />
<column name="last_update" />
</query_table>
</query_table>
</query_table>
</query>
<form name="Report" id="Report-b81" template="Page" css="container-fluid" view="frame" >
<var name="samplePageNumber" type="4" value="0" mandatory="n" />
<var name="sampleRecordsPerPage" type="4" value="100" mandatory="n" />
<body name="Body" template="Grid" pos="0,0,0,0,f,f" layout="{{-2,-2,-2,-2,-1},{-2,-2,-2,-2}}" scroll="n" html="n" >
<cell type="label" name="Film Data" template="H3" pos="0,0,1,0,l,c" />
<cell type="chart" name="Pie" template="Pie" pos="0,1,4,1,l,c" max_records="20" >
<form_script type="DataSource" language="SQL" >
<var name="film_id" type="5" />
<var name="title" type="-1" />
<var name="description" type="-1" />
<var name="release_year" type="4" />
<var name="language_id" type="-6" />
<var name="original_language_id" type="-6" />
<var name="rental_duration" type="-6" />
<var name="rental_rate" type="3" />
<var name="length" type="5" />
<var name="replacement_cost" type="3" />
<var name="rating" type="-1" />
<var name="special_features" type="-1" />
<var name="last_update" type="93" />
<script ><![CDATA[SELECT * FROM sakila.film]]></script>
</form_script>
<param name="i0" value="title" />
<param name="width" value="100%" />
<param name="v0" value="replacement_cost" />
<param name="title" value="Sample Chart" />
<param name="height" value="400px" />
</cell>
<tableview name="sample" template="Table" css="table table-striped table-sm table-hover" pos="0,2,4,2,f,f" layout="{{-2,-2,-2,-2,-2,-2,-2},{-2,-2}}" scroll="n" html="n" header_rows="1" >
<form_script type="DataSource" language="SQL" >
<var name="film_id" type="5" />
<var name="title" type="-1" />
<var name="description" type="-1" />
<var name="release_year" type="4" />
<var name="language_id" type="-6" />
<var name="original_language_id" type="-6" />
<var name="rental_duration" type="-6" />
<var name="rental_rate" type="3" />
<var name="length" type="5" />
<var name="replacement_cost" type="3" />
<var name="rating" type="-1" />
<var name="special_features" type="-1" />
<var name="last_update" type="93" />
<script ><![CDATA[SELECT * FROM sakila.film]]></script>
</form_script>
<cell type="label" name="film_id" pos="0,0,0,0,c,c" />
<cell type="label" name="title" pos="1,0,1,0,c,c" />
<cell type="label" name="description" pos="2,0,2,0,c,c" />