-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.txt
More file actions
1104 lines (949 loc) · 36.3 KB
/
sql.txt
File metadata and controls
1104 lines (949 loc) · 36.3 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
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
Last login: Tue Oct 20 18:15:27 on ttys000
rsh@rsh ~
mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.6-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> exit
Bye
rsh@rsh ~
brew services start mariadb
Service `mariadb` already started, use `brew services restart mariadb` to restart.
rsh@rsh ~
mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.5.6-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.017 sec)
MariaDB [(none)]> CREATE USER 'study'@'localhost' IDENTIFIED BY '1111';
Query OK, 0 rows affected (0.019 sec)
MariaDB [(none)]> CREATE USER 'study'@'localhost' IDENTIFIED BY '1111';
ERROR 1396 (HY000): Operation CREATE USER failed for 'study'@'localhost'
MariaDB [(none)]> desc mysql.user;
+------------------------+---------------------+------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+---------------------+------+-----+----------+-------+
| Host | char(60) | NO | | | |
| User | char(80) | NO | | | |
| Password | longtext | YES | | NULL | |
| Select_priv | varchar(1) | YES | | NULL | |
| Insert_priv | varchar(1) | YES | | NULL | |
| Update_priv | varchar(1) | YES | | NULL | |
| Delete_priv | varchar(1) | YES | | NULL | |
| Create_priv | varchar(1) | YES | | NULL | |
| Drop_priv | varchar(1) | YES | | NULL | |
| Reload_priv | varchar(1) | YES | | NULL | |
| Shutdown_priv | varchar(1) | YES | | NULL | |
| Process_priv | varchar(1) | YES | | NULL | |
| File_priv | varchar(1) | YES | | NULL | |
| Grant_priv | varchar(1) | YES | | NULL | |
| References_priv | varchar(1) | YES | | NULL | |
| Index_priv | varchar(1) | YES | | NULL | |
| Alter_priv | varchar(1) | YES | | NULL | |
| Show_db_priv | varchar(1) | YES | | NULL | |
| Super_priv | varchar(1) | YES | | NULL | |
| Create_tmp_table_priv | varchar(1) | YES | | NULL | |
| Lock_tables_priv | varchar(1) | YES | | NULL | |
| Execute_priv | varchar(1) | YES | | NULL | |
| Repl_slave_priv | varchar(1) | YES | | NULL | |
| Repl_client_priv | varchar(1) | YES | | NULL | |
| Create_view_priv | varchar(1) | YES | | NULL | |
| Show_view_priv | varchar(1) | YES | | NULL | |
| Create_routine_priv | varchar(1) | YES | | NULL | |
| Alter_routine_priv | varchar(1) | YES | | NULL | |
| Create_user_priv | varchar(1) | YES | | NULL | |
| Event_priv | varchar(1) | YES | | NULL | |
| Trigger_priv | varchar(1) | YES | | NULL | |
| Create_tablespace_priv | varchar(1) | YES | | NULL | |
| Delete_history_priv | varchar(1) | YES | | NULL | |
| ssl_type | varchar(9) | YES | | NULL | |
| ssl_cipher | longtext | NO | | | |
| x509_issuer | longtext | NO | | | |
| x509_subject | longtext | NO | | | |
| max_questions | bigint(20) unsigned | NO | | 0 | |
| max_updates | bigint(20) unsigned | NO | | 0 | |
| max_connections | bigint(20) unsigned | NO | | 0 | |
| max_user_connections | bigint(21) | NO | | 0 | |
| plugin | longtext | NO | | | |
| authentication_string | longtext | NO | | | |
| password_expired | varchar(1) | NO | | | |
| is_role | varchar(1) | YES | | NULL | |
| default_role | longtext | NO | | | |
| max_statement_time | decimal(12,6) | NO | | 0.000000 | |
+------------------------+---------------------+------+-----+----------+-------+
47 rows in set (0.017 sec)
MariaDB [(none)]> CREATE USER 'study'@'localhost' IDENTIFIED BY '1111';
ERROR 1396 (HY000): Operation CREATE USER failed for 'study'@'localhost'
MariaDB [(none)]> CREATE USER 'study'@'%' IDENTIFIED BY '1111';
Query OK, 0 rows affected (0.011 sec)
MariaDB [(none)]> CREATE DATABASE studydb
-> DEFAULT CHARACTER SET utf8
-> DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected (0.005 sec)
MariaDB [(none)]> GRANT ALL ON studydb.* TO 'study'@'localhost';
Query OK, 0 rows affected (0.014 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| studydb |
+--------------------+
4 rows in set (0.000 sec)
MariaDB [(none)]> select Host, User from mysql.user;
+-----------+-------------+
| Host | User |
+-----------+-------------+
| % | study |
| localhost | mariadb.sys |
| localhost | root |
| localhost | rsh |
| localhost | study |
+-----------+-------------+
5 rows in set (0.007 sec)
MariaDB [(none)]> exit
Bye
rsh@rsh ~
mysql -u study -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.5.6-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| studydb |
+--------------------+
2 rows in set (0.001 sec)
MariaDB [(none)]> exit
Bye
rsh@rsh ~
mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.5.6-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE USER 'user1'@'localhost' IDENTIFIED BY '1111';
Query OK, 0 rows affected (0.015 sec)
MariaDB [(none)]> CREATE USER 'user1'@'%' IDENTIFIED BY '1111';
Query OK, 0 rows affected (0.011 sec)
MariaDB [(none)]> CREATE USER 'user2'@'%' IDENTIFIED BY '1111';
Query OK, 0 rows affected (0.011 sec)
MariaDB [(none)]> CREATE USER 'user3'@'%' IDENTIFIED BY '1111';
Query OK, 0 rows affected (0.010 sec)
MariaDB [(none)]> CREATE USER 'user4'@'%' IDENTIFIED BY '1111';
Query OK, 0 rows affected (0.013 sec)
MariaDB [(none)]> CREATE USER 'user5'@'%' IDENTIFIED BY '1111';
Query OK, 0 rows affected (0.014 sec)
MariaDB [(none)]> CREATE DATABASE studydb
-> DEFAULT CHARACTER SET utf8
-> DEFAULT CHARACTER SET utf8
-> DEFAULT COLLATE utf8_general_ci;
ERROR 1007 (HY000): Can't create database 'studydb'; database exists
MariaDB [(none)]> CREATE DATABASE user1db
-> DEFAULT CHARACTER SET utf8
-> DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> CREATE DATABASE user2db
-> DEFAULT CHARACTER SET utf8
-> DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> CREATE DATABASE user3db
-> DEFAULT CHARACTER SET utf8
-> DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> CREATE DATABASE user4db
-> DEFAULT CHARACTER SET utf8
-> DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> CREATE DATABASE user5db
-> DEFAULT CHARACTER SET utf8
-> DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> GRANT ALL ON userdb1.* TO 'user1'@'%';
Query OK, 0 rows affected (0.013 sec)
MariaDB [(none)]> GRANT ALL ON userdb1.* TO 'user1'@'localhost';
Query OK, 0 rows affected (0.011 sec)
MariaDB [(none)]> GRANT ALL ON userdb2.* TO 'user2'@'localhost';
ERROR 1133 (28000): Can't find any matching row in the user table
MariaDB [(none)]> GRANT ALL ON user2db.* TO 'user2'@'localhost';
ERROR 1133 (28000): Can't find any matching row in the user table
MariaDB [(none)]> GRANT ALL ON user2db.* TO 'user2'@'%';
Query OK, 0 rows affected (0.011 sec)
MariaDB [(none)]> GRANT ALL ON user3db.* TO 'user3'@'%';
Query OK, 0 rows affected (0.013 sec)
MariaDB [(none)]> GRANT ALL ON user4db.* TO 'user4'@'%';
Query OK, 0 rows affected (0.013 sec)
MariaDB [(none)]> GRANT ALL ON user5db.* TO 'user5'@'%';
Query OK, 0 rows affected (0.014 sec)
MariaDB [(none)]> GRANT ALL ON userdb5.* TO 'user5'@'%';
Query OK, 0 rows affected (0.011 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| studydb |
| user1db |
| user2db |
| user3db |
| user4db |
| user5db |
+--------------------+
9 rows in set (0.001 sec)
MariaDB [(none)]> select user from mysql.user;
+-------------+
| User |
+-------------+
| study |
| user1 |
| user2 |
| user3 |
| user4 |
| user5 |
| mariadb.sys |
| root |
| rsh |
| study |
| user1 |
+-------------+
11 rows in set (0.001 sec)
MariaDB [(none)]> select Host, User from mysql.user;
+-----------+-------------+
| Host | User |
+-----------+-------------+
| % | study |
| % | user1 |
| % | user2 |
| % | user3 |
| % | user4 |
| % | user5 |
| localhost | mariadb.sys |
| localhost | root |
| localhost | rsh |
| localhost | study |
| localhost | user1 |
+-----------+-------------+
11 rows in set (0.001 sec)
MariaDB [(none)]> drop user user1@localhost;
Query OK, 0 rows affected (0.013 sec)
MariaDB [(none)]> select Host, User from mysql.user;
+-----------+-------------+
| Host | User |
+-----------+-------------+
| % | study |
| % | user1 |
| % | user2 |
| % | user3 |
| % | user4 |
| % | user5 |
| localhost | mariadb.sys |
| localhost | root |
| localhost | rsh |
| localhost | study |
+-----------+-------------+
10 rows in set (0.001 sec)
MariaDB [(none)]> drop user user1@%;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%' at line 1
MariaDB [(none)]> drop user user1;
Query OK, 0 rows affected (0.012 sec)
MariaDB [(none)]> select Host, User from mysql.user;
+-----------+-------------+
| Host | User |
+-----------+-------------+
| % | study |
| % | user2 |
| % | user3 |
| % | user4 |
| % | user5 |
| localhost | mariadb.sys |
| localhost | root |
| localhost | rsh |
| localhost | study |
+-----------+-------------+
9 rows in set (0.001 sec)
MariaDB [(none)]> drop user user2;
Query OK, 0 rows affected (0.012 sec)
MariaDB [(none)]> drop user user3;
Query OK, 0 rows affected (0.012 sec)
MariaDB [(none)]> drop user user4;
Query OK, 0 rows affected (0.016 sec)
MariaDB [(none)]> drop user user5;
Query OK, 0 rows affected (0.012 sec)
MariaDB [(none)]> select Host, User from mysql.user;
+-----------+-------------+
| Host | User |
+-----------+-------------+
| % | study |
| localhost | mariadb.sys |
| localhost | root |
| localhost | rsh |
| localhost | study |
+-----------+-------------+
5 rows in set (0.001 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| studydb |
| user1db |
| user2db |
| user3db |
| user4db |
| user5db |
+--------------------+
9 rows in set (0.002 sec)
MariaDB [(none)]> DROP DATABASE user1db
-> ;
Query OK, 0 rows affected (0.013 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| studydb |
| user2db |
| user3db |
| user4db |
| user5db |
+--------------------+
8 rows in set (0.000 sec)
MariaDB [(none)]> DROP DATABASE user2db;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> DROP DATABASE user3db;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> DROP DATABASE user4db;
Query OK, 0 rows affected (0.003 sec)
MariaDB [(none)]> DROP DATABASE user5db;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| studydb |
+--------------------+
4 rows in set (0.000 sec)
MariaDB [(none)]> create table test01 (
-> name varchar(50) not null,
-> kor int not null,
-> eng int not null,
-> math int not null,
-> sum int not null,
-> aver float not null
-> );
ERROR 1046 (3D000): No database selected
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| studydb |
+--------------------+
4 rows in set (0.002 sec)
MariaDB [(none)]> create table test01 (
-> name varchar(50) not null,
-> kor int not null,
-> eng int not null,
-> math int not null,
-> sum int not null,
-> aver float not null
-> );
ERROR 1046 (3D000): No database selected
MariaDB [(none)]> create table studydb.test01 (
-> name varchar(50) not null,
-> kor int not null,
-> eng int not null,
-> math int not null,
-> sum int not null,
-> aver float not null
-> );
Query OK, 0 rows affected (0.031 sec)
MariaDB [(none)]> drop table studydb.test01;
Query OK, 0 rows affected (0.008 sec)
MariaDB [(none)]> use studydb;
Database changed
MariaDB [studydb]> create table test01 (
-> name varchar(50) not null,
-> kor int not null,
-> eng int not null,
-> math int not null,
-> sum int not null,
-> aver float not null
-> );
Query OK, 0 rows affected (0.018 sec)
MariaDB [studydb]> show tables;
+-------------------+
| Tables_in_studydb |
+-------------------+
| test01 |
+-------------------+
1 row in set (0.000 sec)
MariaDB [studydb]> describe test01
-> ;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(50) | NO | | NULL | |
| kor | int(11) | NO | | NULL | |
| eng | int(11) | NO | | NULL | |
| math | int(11) | NO | | NULL | |
| sum | int(11) | NO | | NULL | |
| aver | float | NO | | NULL | |
+-------+-------------+------+-----+---------+-------+
6 rows in set (0.003 sec)
MariaDB [studydb]> desc table test01;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'table test01' at line 1
MariaDB [studydb]> desc test01
-> ;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(50) | NO | | NULL | |
| kor | int(11) | NO | | NULL | |
| eng | int(11) | NO | | NULL | |
| math | int(11) | NO | | NULL | |
| sum | int(11) | NO | | NULL | |
| aver | float | NO | | NULL | |
+-------+-------------+------+-----+---------+-------+
6 rows in set (0.003 sec)
MariaDB [studydb]> drop table test01;
Query OK, 0 rows affected (0.003 sec)
MariaDB [studydb]> show tables;
Empty set (0.000 sec)
MariaDB [studydb]> create table test1(
-> no int not null,
-> name varchar(20)
-> );
Query OK, 0 rows affected (0.019 sec)
MariaDB [studydb]> desc test01
-> ;
ERROR 1146 (42S02): Table 'studydb.test01' doesn't exist
MariaDB [studydb]> desc test1;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| no | int(11) | NO | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.003 sec)
MariaDB [studydb]> insert into test1(no, name) values(1, 'aaa');
Query OK, 1 row affected (0.003 sec)
MariaDB [studydb]> select * from test1;
+----+------+
| no | name |
+----+------+
| 1 | aaa |
+----+------+
1 row in set (0.001 sec)
MariaDB [studydb]> insert into test1(no2, name) values(1, 'aaa');
ERROR 1054 (42S22): Unknown column 'no2' in 'field list'
MariaDB [studydb]> insert into test1(no, name) values(1);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
MariaDB [studydb]> insert into test1(no, name) values('aaa', 1);
ERROR 1366 (22007): Incorrect integer value: 'aaa' for column `studydb`.`test1`.`no` at row 1
MariaDB [studydb]> insert into test1(no, name) values(null, 'bbb');
ERROR 1048 (23000): Column 'no' cannot be null
MariaDB [studydb]> insert into test1(no, name) values(3, null);
Query OK, 1 row affected (0.002 sec)
MariaDB [studydb]> select * from test1;
+----+------+
| no | name |
+----+------+
| 1 | aaa |
| 3 | NULL |
+----+------+
2 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(no, name) values(null, 'bbb');
ERROR 1048 (23000): Column 'no' cannot be null
MariaDB [studydb]> drop table test1;
Query OK, 0 rows affected (0.003 sec)
MariaDB [studydb]> show tables;
Empty set (0.000 sec)
MariaDB [studydb]> create table test1 (
-> no int,
-> name varchar(20)
-> );
Query OK, 0 rows affected (0.016 sec)
MariaDB [studydb]> insert into test1(no, name) values(1, 'aaa');
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> insert into test1(no, name) values(null, 'bbb');
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> insert into test1(no, name) values(3, null);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> insert into test1(no, name) values(null, null);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> select * from test1;
+------+------+
| no | name |
+------+------+
| 1 | aaa |
| NULL | bbb |
| 3 | NULL |
| NULL | NULL |
+------+------+
4 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(no, name) values(1, 'aaa');
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> select * from test1;
+------+------+
| no | name |
+------+------+
| 1 | aaa |
| NULL | bbb |
| 3 | NULL |
| NULL | NULL |
| 1 | aaa |
+------+------+
5 rows in set (0.000 sec)
MariaDB [studydb]> drop table test1;
Query OK, 0 rows affected (0.004 sec)
MariaDB [studydb]> create table test1(
-> no int not null,
-> name varchar(20)
-> );
Query OK, 0 rows affected (0.021 sec)
MariaDB [studydb]> desc test1;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| no | int(11) | NO | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.003 sec)
MariaDB [studydb]> insert into test1(no, name) values(1, 'aaa');
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> insert into test1(no, name) values(null, 'bbb');
ERROR 1048 (23000): Column 'no' cannot be null
MariaDB [studydb]> insert into test1(no, name) values(3, null);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> desc test1;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| no | int(11) | NO | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.003 sec)
MariaDB [studydb]> select * from test1;
+----+------+
| no | name |
+----+------+
| 1 | aaa |
| 3 | NULL |
+----+------+
2 rows in set (0.000 sec)
MariaDB [studydb]> drop table test1;
Query OK, 0 rows affected (0.003 sec)
MariaDB [studydb]> create table test1(
-> no int not null,
-> name varchar(20) default 'noname',
-> age int default 20
-> );
Query OK, 0 rows affected (0.018 sec)
MariaDB [studydb]> insert into test1(no, name, age) values(1, 'aaa', 30);
Query OK, 1 row affected (0.002 sec)
MariaDB [studydb]> select * from test1;
+----+------+------+
| no | name | age |
+----+------+------+
| 1 | aaa | 30 |
+----+------+------+
1 row in set (0.000 sec)
MariaDB [studydb]> insert into test1(name, age) values('aaa', 30);
ERROR 1364 (HY000): Field 'no' doesn't have a default value
MariaDB [studydb]> insert into test1(no, age) values(3, 30);
Query OK, 1 row affected (0.002 sec)
MariaDB [studydb]> insert into test1(no, name) values(4, 'ddd');
Query OK, 1 row affected (0.002 sec)
MariaDB [studydb]> select * from test1;
+----+--------+------+
| no | name | age |
+----+--------+------+
| 1 | aaa | 30 |
| 3 | noname | 30 |
| 4 | ddd | 20 |
+----+--------+------+
3 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(no) values(5);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> select * from test1;
+----+--------+------+
| no | name | age |
+----+--------+------+
| 1 | aaa | 30 |
| 3 | noname | 30 |
| 4 | ddd | 20 |
| 5 | noname | 20 |
+----+--------+------+
4 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(no, age, name) values(6, null, null);
Query OK, 1 row affected (0.002 sec)
MariaDB [studydb]> select * from test1;
+----+--------+------+
| no | name | age |
+----+--------+------+
| 1 | aaa | 30 |
| 3 | noname | 30 |
| 4 | ddd | 20 |
| 5 | noname | 20 |
| 6 | NULL | NULL |
+----+--------+------+
5 rows in set (0.000 sec)
MariaDB [studydb]> drop table test1;
Query OK, 0 rows affected (0.003 sec)
MariaDB [studydb]> create table test1(
-> c1 int,
-> c2 float,
-> c3 numeric(6,2), /* 소수점 자릿수를 지정하면 부동소수점으로 사용 */
-> c4 numeric /* int와 같다 */
-> );
Query OK, 0 rows affected (0.016 sec)
MariaDB [studydb]> desc test1;
+-------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+-------+
| c1 | int(11) | YES | | NULL | |
| c2 | float | YES | | NULL | |
| c3 | decimal(6,2) | YES | | NULL | |
| c4 | decimal(10,0) | YES | | NULL | |
+-------+---------------+------+-----+---------+-------+
4 rows in set (0.004 sec)
MariaDB [studydb]> insert into test1(c1) values(100);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> select * from test1;
+------+------+------+------+
| c1 | c2 | c3 | c4 |
+------+------+------+------+
| 100 | NULL | NULL | NULL |
+------+------+------+------+
1 row in set (0.000 sec)
MariaDB [studydb]> insert into test1(c1) values(3.14);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> select * from test1;
+------+------+------+------+
| c1 | c2 | c3 | c4 |
+------+------+------+------+
| 100 | NULL | NULL | NULL |
| 3 | NULL | NULL | NULL |
+------+------+------+------+
2 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(c1) values(100.98);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> select * from test1;
+------+------+------+------+
| c1 | c2 | c3 | c4 |
+------+------+------+------+
| 100 | NULL | NULL | NULL |
| 3 | NULL | NULL | NULL |
| 101 | NULL | NULL | NULL |
+------+------+------+------+
3 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(c2) values(100);
Query OK, 1 row affected (0.002 sec)
MariaDB [studydb]> insert into test1(c2) values(3.14);
Query OK, 1 row affected (0.002 sec)
MariaDB [studydb]> insert into test1(c2) values(3.14159);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> select * from test1;
+------+---------+------+------+
| c1 | c2 | c3 | c4 |
+------+---------+------+------+
| 100 | NULL | NULL | NULL |
| 3 | NULL | NULL | NULL |
| 101 | NULL | NULL | NULL |
| NULL | 100 | NULL | NULL |
| NULL | 3.14 | NULL | NULL |
| NULL | 3.14159 | NULL | NULL |
+------+---------+------+------+
6 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(c3) values(100);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> insert into test1(c3) values(123456789); /* 입력 오류. 5자리 초과 */
ERROR 1264 (22003): Out of range value for column 'c3' at row 1
MariaDB [studydb]> insert into test1(c3) values(12345); /* 입력 오류. 1자리 초과 */
ERROR 1264 (22003): Out of range value for column 'c3' at row 1
MariaDB [studydb]> insert into test1(c3) values(1234.12);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> insert into test1(c3) values(1234.123);
Query OK, 1 row affected, 1 warning (0.001 sec)
MariaDB [studydb]> select * from test1;
+------+---------+---------+------+
| c1 | c2 | c3 | c4 |
+------+---------+---------+------+
| 100 | NULL | NULL | NULL |
| 3 | NULL | NULL | NULL |
| 101 | NULL | NULL | NULL |
| NULL | 100 | NULL | NULL |
| NULL | 3.14 | NULL | NULL |
| NULL | 3.14159 | NULL | NULL |
| NULL | NULL | 100.00 | NULL |
| NULL | NULL | 1234.12 | NULL |
| NULL | NULL | 1234.12 | NULL |
+------+---------+---------+------+
9 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(c3) values(1234.129);
Query OK, 1 row affected, 1 warning (0.001 sec)
MariaDB [studydb]> select * from test1;
+------+---------+---------+------+
| c1 | c2 | c3 | c4 |
+------+---------+---------+------+
| 100 | NULL | NULL | NULL |
| 3 | NULL | NULL | NULL |
| 101 | NULL | NULL | NULL |
| NULL | 100 | NULL | NULL |
| NULL | 3.14 | NULL | NULL |
| NULL | 3.14159 | NULL | NULL |
| NULL | NULL | 100.00 | NULL |
| NULL | NULL | 1234.12 | NULL |
| NULL | NULL | 1234.12 | NULL |
| NULL | NULL | 1234.13 | NULL |
+------+---------+---------+------+
10 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(c4) values(1234567890);
Query OK, 1 row affected (0.002 sec)
MariaDB [studydb]> insert into test1(c4) values(12.34567890); /* 소수점은 반올림 처리됨 */
Query OK, 1 row affected, 1 warning (0.001 sec)
MariaDB [studydb]> insert into test1(c4) values(12345678.90); /* 소수점은 반올림 처리됨 */
Query OK, 1 row affected, 1 warning (0.001 sec)
MariaDB [studydb]> insert into test1(c4) values(12345678901);
ERROR 1264 (22003): Out of range value for column 'c4' at row 1
MariaDB [studydb]> select * from test1;
+------+---------+---------+------------+
| c1 | c2 | c3 | c4 |
+------+---------+---------+------------+
| 100 | NULL | NULL | NULL |
| 3 | NULL | NULL | NULL |
| 101 | NULL | NULL | NULL |
| NULL | 100 | NULL | NULL |
| NULL | 3.14 | NULL | NULL |
| NULL | 3.14159 | NULL | NULL |
| NULL | NULL | 100.00 | NULL |
| NULL | NULL | 1234.12 | NULL |
| NULL | NULL | 1234.12 | NULL |
| NULL | NULL | 1234.13 | NULL |
| NULL | NULL | NULL | 1234567890 |
| NULL | NULL | NULL | 12 |
| NULL | NULL | NULL | 12345679 |
+------+---------+---------+------------+
13 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(c4) values(2234567890);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> select * from test1;
+------+---------+---------+------------+
| c1 | c2 | c3 | c4 |
+------+---------+---------+------------+
| 100 | NULL | NULL | NULL |
| 3 | NULL | NULL | NULL |
| 101 | NULL | NULL | NULL |
| NULL | 100 | NULL | NULL |
| NULL | 3.14 | NULL | NULL |
| NULL | 3.14159 | NULL | NULL |
| NULL | NULL | 100.00 | NULL |
| NULL | NULL | 1234.12 | NULL |
| NULL | NULL | 1234.12 | NULL |
| NULL | NULL | 1234.13 | NULL |
| NULL | NULL | NULL | 1234567890 |
| NULL | NULL | NULL | 12 |
| NULL | NULL | NULL | 12345679 |
| NULL | NULL | NULL | 2234567890 |
+------+---------+---------+------------+
14 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(c4) values(9234567890);
Query OK, 1 row affected (0.002 sec)
MariaDB [studydb]> select * from test1;
+------+---------+---------+------------+
| c1 | c2 | c3 | c4 |
+------+---------+---------+------------+
| 100 | NULL | NULL | NULL |
| 3 | NULL | NULL | NULL |
| 101 | NULL | NULL | NULL |
| NULL | 100 | NULL | NULL |
| NULL | 3.14 | NULL | NULL |
| NULL | 3.14159 | NULL | NULL |
| NULL | NULL | 100.00 | NULL |
| NULL | NULL | 1234.12 | NULL |
| NULL | NULL | 1234.12 | NULL |
| NULL | NULL | 1234.13 | NULL |
| NULL | NULL | NULL | 1234567890 |
| NULL | NULL | NULL | 12 |
| NULL | NULL | NULL | 12345679 |
| NULL | NULL | NULL | 2234567890 |
| NULL | NULL | NULL | 9234567890 |
+------+---------+---------+------------+
15 rows in set (0.000 sec)
MariaDB [studydb]> insert into test1(c4) values(19234567890);
ERROR 1264 (22003): Out of range value for column 'c4' at row 1
MariaDB [studydb]> insert into test1(c1) values(1234567890);
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> insert into test1(c1) values(2234567890);
ERROR 1264 (22003): Out of range value for column 'c1' at row 1
MariaDB [studydb]> drop table test1;
Query OK, 0 rows affected (0.003 sec)
MariaDB [studydb]> create table test1(
-> c1 char(5),
-> c2 varchar(5),
-> c3 varchar(21000)
-> );
Query OK, 0 rows affected (0.017 sec)
MariaDB [studydb]> insert into test1(c1) values('');
Query OK, 1 row affected (0.002 sec)
MariaDB [studydb]> select * from test1;
+------+------+------+
| c1 | c2 | c3 |
+------+------+------+
| | NULL | NULL |
+------+------+------+
1 row in set (0.000 sec)
MariaDB [studydb]> insert into test1(c1) values('abcde');
Query OK, 1 row affected (0.002 sec)
MariaDB [studydb]> insert into test1(c1) values('가나다라마');
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> insert into test1(c1) values('가나다라마1');
ERROR 1406 (22001): Data too long for column 'c1' at row 1
MariaDB [studydb]> insert into test1(c1) values('abcde1');
ERROR 1406 (22001): Data too long for column 'c1' at row 1
MariaDB [studydb]> insert into test1(c2) values('');
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> insert into test1(c2) values('abcde');
Query OK, 1 row affected (0.001 sec)
MariaDB [studydb]> insert into test1(c2) values('abcdefghi');
ERROR 1406 (22001): Data too long for column 'c2' at row 1
MariaDB [studydb]> select * from test1;
+-----------------+-------+------+
| c1 | c2 | c3 |
+-----------------+-------+------+
| | NULL | NULL |
| abcde | NULL | NULL |
| 가나다라마 | NULL | NULL |
| NULL | | NULL |
| NULL | abcde | NULL |
+-----------------+-------+------+
5 rows in set (0.000 sec)
MariaDB [studydb]> drop table test1;
Query OK, 0 rows affected (0.002 sec)
MariaDB [studydb]> create table test1(
-> c1 char(5),
-> c2 varchar(5),