-
Notifications
You must be signed in to change notification settings - Fork 0
/
.mysql_history
1411 lines (1411 loc) · 68 KB
/
.mysql_history
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
CREATE TABLE SALESMAN
(SALESMANID NUMBER(4),
NAME VARCHAR(20),
CITY VARCHAR(20),
COMMISSION VARCHAR(20),
PRIMARY KEY (SALESMANID));
CREATE TABLE SALESMAN (SALESMANID NUMBER(4), NAME VARCHAR(20), CITY VARCHAR(20), COMMISSION VARCHAR(20), PRIMARY KEY (SALESMANID));
DESC SALESMAN;
create user 'tushar' identified by 'pandeytushar8';
CREATE TABLE SALESMAN
(SALESMANID NUMBER(4),
NAME VARCHAR(20),
CITY VARCHAR(20),
COMMISSION VARCHAR(20),
PRIMARY KEY (SALESMANID));
CREATE TABLE SALESMAN (SALESMANID NUMBER(4), NAME VARCHAR(20), CITY VARCHAR(20), COMMISSION VARCHAR(20), PRIMARY KEY (SALESMANID));
DESC SALESMAN;
create database order
;
CREATE DATABASE orderdb;
CREATE DATABASE ORDERDB;
USE db1;
CREATE TABLE SALESMAN
(SALESMANID NUMBER(4),
NAME VARCHAR(20),
CITY VARCHAR(20),
COMMISSION VARCHAR(20),
PRIMARY KEY (SALESMANID));
CREATE TABLE SALESMAN (SALESMANID NUMBER(4), NAME VARCHAR(20), CITY VARCHAR(20), COMMISSION VARCHAR(20), PRIMARY KEY (SALESMANID));
CREATE TABLE salesman(salesmanid INT PRIMARY KEY AUTO_INCREMENT, name TEXT, city TEXT, commission TEXT);
DESC salesman;
CREATE TABLE customer(customerid INT PRIMARY KEY AUTO_INCREMENT, custname TEXT, city TEXT, grade INT, FOREIGN KEY(salesmanid) REFERENCES salesman(salesmanid) ON DELETE SET NULL);
CREATE TABLE customer(customerid INT PRIMARY KEY AUTO_INCREMENT, custname TEXT, city TEXT, grade INT, salesmanid INT ,FOREIGN KEY(salesmanid) REFERENCES salesman(salesmanid) ON DELETE SET NULL);
DESC customer;
CREATE TABLE orders(ordno INT PRIMARY KEY AUTO_INCREMENT, purchaseamt FLOAT, orddate DATE, customerid INT ,FOREIGN KEY(customerid) REFERENCES customer(customerid) ON DELETE SET NULL);
DESC orders;
INSERT INTO salesman VALUES(1000,'JOHN','BANGALORE','25%');
INSERT INTO salesman VALUES(2000,'RAVI','BANGALORE','20%');
INSERT INTO salesman VALUES(3000,'KUMAR','MYSORE','15%');
INSERT INTO salesman VALUES(4000,'SMITH','DELHI','30%');
INSERT INTO salesman VALUES(5000,'HARSHA','HYDERABAD','15%');
SELECT * FROM salesman;
INSERT INTO customer VALUES(10,'PREETHI','BANGALORE',100,1000);
INSERT INTO customer VALUES(11,'VIVEK','MANGALORE',300,1000);
INSERT INTO customer VALUES(12,'BHASKAR','CHENNAI',400,2000);
INSERT INTO customer VALUES(13,'CHETTAN','BANGALORE',200,2000);
INSERT INTO customer VALUES(14,'MANISH','BANGALORE',400,3000);
SELECT * FROM customer;
INSERT INTO orders VALUES(50,5000,'04-MAY-17',10,1000);
INSERT INTO orders VALUES(51,450,'20-JAN-17',10,2000);
INSERT INTO orders VALUES(52,1000,'24-FEB-17',13,2000);
INSERT INTO orders VALUES(53,3500,'13-APR-17',14,3000);
INSERT INTO orders VALUES(54,550,'09-MAR-17',12,2000);
INSERT INTO orders VALUES(50,5000,'04-MAY-17',1000);
INSERT INTO orders VALUES(51,450,'20-JAN-17',2000);
INSERT INTO orders VALUES(52,1000,'24-FEB-17',2000);
INSERT INTO orders VALUES(53,3500,'13-APR-17',3000);
INSERT INTO orders VALUES(54,550,'09-MAR-17',2000);
SELECT * FROM orders;
INSERT INTO orders VALUES(50,5000,STR_TO_DATE('04-MAY-17'),1000);
INSERT INTO orders VALUES(51,450,STR_TO_DATE('20-JAN-17'),2000);
INSERT INTO orders VALUES(52,1000,STR_TO_DATE('24-FEB-17'),2000);
INSERT INTO orders VALUES(53,3500,STR_TO_DATE('13-APR-17'),3000);
INSERT INTO orders VALUES(54,550,STR_TO_DATE('09-MAR-17'),2000);
SELECT * FROM orders;
INSERT INTO orders VALUES(50,5000,STR_TO_DATE('05-04-17', '%m-%d-%y'),1000);
INSERT INTO orders VALUES(50,5000,STR_TO_DATE('05-04-17', '%m-%d-%y'),10);
INSERT INTO orders VALUES(51,450,STR_TO_DATE('01-20-17', '%m-%d-%y'),11);
INSERT INTO orders VALUES(52,1000,STR_TO_DATE('02-24-17', '%m-%d-%y'),12);
INSERT INTO orders VALUES(53,3500,STR_TO_DATE('04-13-17', '%m-%d-%y'),13);
INSERT INTO orders VALUES(54,550,STR_TO_DATE('03-09-17', '%m-%d-%y'),14);
SELECT * FROM orders;
SELECT grade,COUNT(DISTINCT customerID)
FROM customer
GROUP BY grade
HAVING grade>(SELECT AVG(grade)
FROM customer
WHERE CITY='BANGALORE');
SELECT grade,COUNT(DISTINCT customerID) FROM customer GROUP BY grade HAVING grade>(SELECT AVG(grade) FROM customer WHERE CITY='BANGALORE');
SELECT salesmanID, NAME
FROM salesman A
WHERE 1<(SELECT COUNT(*)
FROM customer
WHERE salesmanID=A.salesmanID);
SELECT salesmanID, NAME FROM salesman A WHERE 1<(SELECT COUNT(*) FROM customer WHERE salesmanID=A.salesmanID);
SELECT salesman.salesmanID, NAME,CUSTNAME,COMMISSION
FROM salesman,customer
WHERE salesman.CITY=customer.CITY
UNION
SELECT salesmanID,NAME,'NO MATCH',COMMISSION
FROM salesman
WHERE NOT CITY=ANY
(SELECT CITY
FROM customer)
ORDER BY 2 .schema;
SELECT salesman.salesmanID, NAME,CUSTNAME,COMMISSION FROM salesman,customer WHERE salesman.CITY=customer.CITY UNION SELECT salesmanID,NAME,'NO MATCH',COMMISSION FROM salesman WHERE NOT CITY=ANY (SELECT CITY FROM customer) ORDER BY 2 .schema;
SELECT salesman.salesmanID, NAME,CUSTNAME,COMMISSION FROM salesman,customer WHERE salesman.CITY=customer.CITY UNION SELECT salesmanID,NAME,'NO MATCH',COMMISSION FROM salesman WHERE NOT CITY=ANY (SELECT CITY FROM customer) ORDER BY 2 DESC;
USE db1;
CREATE TABLE actor(actid INT PRIMARY KEY, actname TEXT, actgender TEXT)
;
DESC actor;
USE db1;
DESC actor;
CREATE TABLE director(dirid INT PRIMARY KEY, dirname TEXT, dirphone INT), );
CREATE TABLE director(dirid INT PRIMARY KEY, dirname TEXT, dirphone INT));
CREATE TABLE director(
dirid INT PRIMARY KEY,
dirname TEXT,
dirphone INT
);
CREATE TABLE director( dirid INT PRIMARY KEY, dirname TEXT, dirphone INT );
USE db1;
CREATE TABLE director(
dirid INT PRIMARY KEY,
dirname TEXT,
dirphone INT
);
CREATE TABLE director( dirid INT PRIMARY KEY, dirname TEXT, dirphone INT );
DESC director;
CREATE TABLE movies(
movid INT PRIMARY KEY,
movtitle TEXT,
movyear INT,
movlang TEXT,
dirid INT,
FOREIGN KEY(dirid) REFERENCES director(dirid)
);
CREATE TABLE movies( movid INT PRIMARY KEY, movtitle TEXT, movyear INT, movlang TEXT, dirid INT, FOREIGN KEY(dirid) REFERENCES director(dirid) );
DESC movies;
CREATE TABLE moviecast(
actid INT,
movid INT PRIMARY KEY,
role TEXT,
FOREIGN KEY(actid) REFERENCES actor(actid),
FOREIGN KEY(movid) REFERENCES movies(movid)
);
CREATE TABLE moviecast( actid INT, movid INT PRIMARY KEY, role TEXT, FOREIGN KEY(actid) REFERENCES actor(actid), FOREIGN KEY(movid) REFERENCES movies(movid) );
DESC moviecast;
CREATE TABLE rating(
movid INT PRIMARY KEY,
revstars TEXT,
FOREIGN KEY(movid) REFERENCES movies(movid)
);
CREATE TABLE rating( movid INT PRIMARY KEY, revstars TEXT, FOREIGN KEY(movid) REFERENCES movies(movid) );
DESC rating;
INSERT INTO actor
VALUES(301, 'anushka', 'f');
INSERT INTO actor VALUES(301, 'anushka', 'f');
INSERT INTO actor
VALUES(302, 'prabhas', 'm');
INSERT INTO actor VALUES(302, 'prabhas', 'm');
INSERT INTO actor
VALUES(303, 'punith', 'm');
INSERT INTO actor VALUES(303, 'punith', 'm');
INSERT INTO actor
VALUES(304, 'sudeep', 'm');
INSERT INTO actor VALUES(304, 'sudeep', 'm');
SELECT *
FROM actor;
SELECT * FROM actor;
DROP TABLE actor;
DROP TABLE moviecast;
DROP TABLE movies;
DROP TABLE rating;
DROP TABLE movies;
DROP TABLE director;
DROP TABLE actor;
USE db1;
CREATE TABLE actor(
actid INT PRIMARY KEY,
actname TEXT,
actgender TEXT
) DESC actor;
CREATE TABLE actor( actid INT PRIMARY KEY, actname TEXT, actgender TEXT ) DESC actor;
CREATE TABLE director(
dirid INT PRIMARY KEY,
dirname TEXT,
dirphone INT
);
CREATE TABLE director( dirid INT PRIMARY KEY, dirname TEXT, dirphone INT );
DESC director;
CREATE TABLE movies(
movid INT PRIMARY KEY,
movtitle TEXT,
movyear INT,
movlang TEXT,
dirid INT,
FOREIGN KEY(dirid) REFERENCES director(dirid)
);
CREATE TABLE movies( movid INT PRIMARY KEY, movtitle TEXT, movyear INT, movlang TEXT, dirid INT, FOREIGN KEY(dirid) REFERENCES director(dirid) );
DESC movies;
CREATE TABLE moviecast(
actid INT,
movid INT PRIMARY KEY,
role TEXT,
FOREIGN KEY(actid) REFERENCES actor(actid),
FOREIGN KEY(movid) REFERENCES movies(movid)
);
CREATE TABLE moviecast( actid INT, movid INT PRIMARY KEY, role TEXT, FOREIGN KEY(actid) REFERENCES actor(actid), FOREIGN KEY(movid) REFERENCES movies(movid) );
DESC moviecast;
CREATE TABLE rating(
movid INT PRIMARY KEY,
revstars TEXT,
FOREIGN KEY(movid) REFERENCES movies(movid)
);
CREATE TABLE rating( movid INT PRIMARY KEY, revstars TEXT, FOREIGN KEY(movid) REFERENCES movies(movid) );
DESC rating;
DROP TABLE moviecast;
DROP TABLE movies;
DROP TABLE ratings;
DROP TABLE rating;
DROP TABLE actor;
USE db1;
DROP TABLE moviecast;
DROP TABLE rating;
DROP TABLE actor;
DROP TABLE movies;
DROP TABLE director;
USE db1;
CREATE TABLE actor(
actid INT PRIMARY KEY,
actname TEXT,
actgender TEXT
);
CREATE TABLE actor( actid INT PRIMARY KEY, actname TEXT, actgender TEXT );
DESC actor;
CREATE TABLE director(
dirid INT PRIMARY KEY,
dirname TEXT,
dirphone INT
);
CREATE TABLE director( dirid INT PRIMARY KEY, dirname TEXT, dirphone INT );
DESC director;
CREATE TABLE movies(
movid INT PRIMARY KEY,
movtitle TEXT,
movyear INT,
movlang TEXT,
dirid INT,
FOREIGN KEY(dirid) REFERENCES director(dirid)
);
CREATE TABLE movies( movid INT PRIMARY KEY, movtitle TEXT, movyear INT, movlang TEXT, dirid INT, FOREIGN KEY(dirid) REFERENCES director(dirid) );
DESC movies;
CREATE TABLE moviecast(
actid INT,
movid INT PRIMARY KEY,
role TEXT,
FOREIGN KEY(actid) REFERENCES actor(actid),
FOREIGN KEY(movid) REFERENCES movies(movid)
);
CREATE TABLE moviecast( actid INT, movid INT PRIMARY KEY, role TEXT, FOREIGN KEY(actid) REFERENCES actor(actid), FOREIGN KEY(movid) REFERENCES movies(movid) );
DESC moviecast;
CREATE TABLE rating(
movid INT PRIMARY KEY,
revstars TEXT,
FOREIGN KEY(movid) REFERENCES movies(movid)
);
CREATE TABLE rating( movid INT PRIMARY KEY, revstars TEXT, FOREIGN KEY(movid) REFERENCES movies(movid) );
DESC rating;
INSERT INTO actor
VALUES(301, 'actor1', 'f');
INSERT INTO actor VALUES(301, 'actor1', 'f');
INSERT INTO actor
VALUES(302, 'actor 2', 'm');
INSERT INTO actor VALUES(302, 'actor 2', 'm');
INSERT INTO actor
VALUES(303, 'actor3', 'm');
INSERT INTO actor VALUES(303, 'actor3', 'm');
INSERT INTO actor
VALUES(304, 'actor4', 'm');
INSERT INTO actor VALUES(304, 'actor4', 'm');
SELECT *
FROM actor;
SELECT * FROM actor;
INSERT INTO director
VALUES(60, 'director1', 9191919191);
INSERT INTO director VALUES(60, 'director1', 9191919191);
ALTER TABLE director MODIFY dirphone TEXT;
INSERT INTO director VALUES(60, 'director1', '9191919191');
INSERT INTO director
VALUES(61, 'hitchcock', '818181818');
INSERT INTO director VALUES(61, 'hitchcock', '818181818');
INSERT INTO director
VALUES(62, 'director3', '7171717171');
INSERT INTO director VALUES(62, 'director3', '7171717171');
INSERT INTO director
VALUES(63, 'steven spielberg', '6161616161');
INSERT INTO director VALUES(63, 'steven spielberg', '6161616161');
SELECT *
FROM director;
SELECT * FROM director;
INSERT INTO movies
VALUES(1001, 'movie1', 2017, 'english', 60);
INSERT INTO movies VALUES(1001, 'movie1', 2017, 'english', 60);
INSERT INTO movies
VALUES(1002, 'movie2', 2015, 'hindi', 60);
INSERT INTO movies VALUES(1002, 'movie2', 2015, 'hindi', 60);
INSERT INTO movies
VALUES(1003, 'movie3', 2008, 'english', 61);
INSERT INTO movies VALUES(1003, 'movie3', 2008, 'english', 61);
INSERT INTO movies
VALUES(1004, 'war horse', 2011, 'english', 63);
INSERT INTO movies VALUES(1004, 'war horse', 2011, 'english', 63);
SELECT *
FROM movies;
SELECT * FROM movies;
INSERT INTO moviecast
VALUES(301, 1002, 'heroine');
INSERT INTO moviecast VALUES(301, 1002, 'heroine');
INSERT INTO moviecast
VALUES(301, 1001, 'heroine');
INSERT INTO moviecast VALUES(301, 1001, 'heroine');
INSERT INTO moviecast
VALUES(303, 1003, 'hero');
INSERT INTO moviecast VALUES(303, 1003, 'hero');
INSERT INTO moviecast
VALUES(303, 1002, 'guest');
INSERT INTO moviecast VALUES(303, 1002, 'guest');
INSERT INTO moviecast
VALUES(304, 1004, 'hero');
INSERT INTO moviecast VALUES(304, 1004, 'hero');
SELECT *
FROM moviecast;
SELECT * FROM moviecast;
INSERT INTO rating
VALUES(1001, 4);
INSERT INTO rating VALUES(1001, 4);
INSERT INTO rating
VALUES(1002, 2);
INSERT INTO rating VALUES(1002, 2);
INSERT INTO rating
VALUES(1003, 5);
INSERT INTO rating VALUES(1003, 5);
INSERT INTO rating
VALUES(1004, 4);
INSERT INTO rating VALUES(1004, 4);
SELECT *
FROM rating;
SELECT * FROM rating;
SELECT m.movtitle from movies m, director d WHEN d.dirname='hitchcock' AND d.dirid=m.dirid;
SELECT m.movtitle FROM movies m, director d WHEN d.dirname='hitchcock' AND d.dirid=m.dirid;
SELECT M.movtitle FROM movies M, director D WHERE D.dirname='hitchcock' AND D.dirid=M.dirid;
SELECT movtitle
FROM movies m,
moviecast mv
WHERE m.movid = mv.movid
AND actid IN (
SELECT actid
FROM moviecast
group by actid
having count (actid) > 1
)
group by movtitle
having count(*) > 1;
SELECT movtitle FROM movies m, moviecast mv WHERE m.movid = mv.movid AND actid IN ( SELECT actid FROM moviecast group by actid having count (actid) > 1 ) group by movtitle having count(*) > 1;
SELECT movtitle
FROM movies m,
moviecast mv
WHERE m.movid = mv.movid
AND actid IN (
SELECT actid
FROM moviecast
group by actid
having COUNT(actid) > 1
)
group by movtitle
having COUNT *
) > 1;
SELECT movtitle FROM movies m, moviecast mv WHERE m.movid = mv.movid AND actid IN ( SELECT actid FROM moviecast group by actid having COUNT(actid) > 1 ) group by movtitle having COUNT * ) > 1;
SELECT movtitle
FROM movies m,
moviecast mv
WHERE m.movid = mv.movid
AND actid IN (
SELECT actid
FROM moviecast
GROUP BY actid
HAVING COUNT(actid) > 1
)
GROUP BY movtitle
HAVING COUNT *
) > 1;
SELECT movtitle FROM movies m, moviecast mv WHERE m.movid = mv.movid AND actid IN ( SELECT actid FROM moviecast GROUP BY actid HAVING COUNT(actid) > 1 ) GROUP BY movtitle HAVING COUNT * ) > 1;
SELECT movtitle
FROM movies M,
moviecast MV
WHERE M.movid = MV.movid
AND actid IN (
SELECT actid
FROM moviecast
GROUP BY actid
HAVING COUNT(actid) > 1
)
GROUP BY movtitle
HAVING COUNT *
) > 1;
SELECT movtitle FROM movies M, moviecast MV WHERE M.movid = MV.movid AND actid IN ( SELECT actid FROM moviecast GROUP BY actid HAVING COUNT(actid) > 1 ) GROUP BY movtitle HAVING COUNT * ) > 1;
SELECT movtitle
FROM movies M,
moviecast MV
WHERE M.movid = MV.movid
AND actid IN (
SELECT actid
FROM moviecast
GROUP BY actid
HAVING COUNT(actid) > 1
)
GROUP BY movtitle
HAVING COUNT(*) > 1;
SELECT movtitle FROM movies M, moviecast MV WHERE M.movid = MV.movid AND actid IN ( SELECT actid FROM moviecast GROUP BY actid HAVING COUNT(actid) > 1 ) GROUP BY movtitle HAVING COUNT(*) > 1;
INSERT INTO movies
VALUES(1004, 'movie4', 2011, 'english', 63);
INSERT INTO movies VALUES(1004, 'movie4', 2011, 'english', 63);
INSERT INTO movies VALUES(1005, 'movie4', 2011, 'english', 63);
SELECT movtitle FROM movies M, moviecast MV WHERE M.movid = MV.movid AND actid IN ( SELECT actid FROM moviecast GROUP BY actid HAVING COUNT(actid) > 1 ) GROUP BY movtitle HAVING COUNT(*) > 1;
INSERT INTO moviecast
VALUES(304, 1003, 'sidehero');
INSERT INTO moviecast VALUES(304, 1003, 'sidehero');
INSERT INTO moviecast VALUES(304, 1005, 'hero');
SELECT movtitle FROM movies M, moviecast MV WHERE M.movid = MV.movid AND actid IN ( SELECT actid FROM moviecast GROUP BY actid HAVING COUNT(actid) > 1 ) GROUP BY movtitle HAVING COUNT(*) > 1;
SELECT movtitle FROM movies M, moviecast MV WHERE M.movid = MV.movid AND actid IN ( SELECT actid FROM moviecast GROUP BY actid HAVING COUNT(actid) >= 1 ) GROUP BY movtitle HAVING COUNT(*) > 1;
SELECT movtitle FROM movies M, moviecast MV WHERE M.movid = MV.movid AND actid IN ( SELECT actid FROM moviecast GROUP BY actid HAVING COUNT(actid) > 0 ) GROUP BY movtitle HAVING COUNT(*) > 1;
SELECT movtitle FROM movies M, moviecast MV WHERE M.movid = MV.movid AND actid IN ( SELECT actid FROM moviecast GROUP BY actid HAVING COUNT(actid) > 1 ) GROUP BY movtitle HAVING COUNT(*) > 1;
SELECT actname,
movtitle,
movyear
FROM actor a
JOIN moviecast c ON a.actid = c.actid
JOIN movies M ON c.movid = M.movid
WHERE M.movyear NOT BETWEEN 2000 AND 2015;
SELECT actname, movtitle, movyear FROM actor a JOIN moviecast c ON a.actid = c.actid JOIN movies M ON c.movid = M.movid WHERE M.movyear NOT BETWEEN 2000 AND 2015;
SELECT movtitle,
max(revstars)
FROM movies
INNER JOIN rating USING (movid)
GROUP BY movtitle
HAVING MAX(revstars) > 0
ORDER BY movtitle;
SELECT movtitle, max(revstars) FROM movies INNER JOIN rating USING (movid) GROUP BY movtitle HAVING MAX(revstars) > 0 ORDER BY movtitle;
UPDATE rating
SET revstars = 5
WHERE movid IN (
SELECT movid
FROM movies
WHERE dirid IN (
SELECT dirid
FROM director
WHERE dirname = 'steven spielberg'
)
);
UPDATE rating SET revstars = 5 WHERE movid IN ( SELECT movid FROM movies WHERE dirid IN ( SELECT dirid FROM director WHERE dirname = 'steven spielberg' ) );
SELECT *
FROM rating;
SELECT * FROM rating;
USE db1;
CREATE TABLE STUDENT(
USN TEXT) PRIMARY KEY,
SNAME TEXT),
ADDRESS TEXT),
PHONE TEXT,
GENDER CHAR(1));
CREATE TABLE STUDENT( USN TEXT) PRIMARY KEY, SNAME TEXT), ADDRESS TEXT), PHONE TEXT, GENDER CHAR(1));
CREATE TABLE STUDENT(USN TEXT PRIMARY KEY,SNAME TEXT,ADDRESS TEXT,PHONE TEXT,GENDER CHAR(1));
USE db1;
CREATE TABLE STUDENT(USN TEXT PRIMARY KEY,SNAME TEXT,ADDRESS TEXT,PHONE TEXT,GENDER CHAR(1));
CREATE TABLE STUDENT(USN TEXT(10) PRIMARY KEY,SNAME TEXT,ADDRESS TEXT,PHONE TEXT,GENDER CHAR(1));
CREATE TABLE STUDENT(USN VARCHAR(10) PRIMARY KEY,SNAME TEXT,ADDRESS TEXT,PHONE TEXT,GENDER CHAR(1));
DROP STUDENT;
DROP TABLE STUDENT;
prompt 'SQL';
promt sql>
;
promt sql>;
promt sql;
prompt sql>;
\c
\c;
clear;
SELECT * FROM movies;
DROP TABLE STUDENT;
CREATE TABLE STUDENT(USN VARCHAR(10) PRIMARY KEY,SNAME VARCHAR(25),ADDRESS VARCHAR(25),PHONE NUMBER(10),GENDER CHAR(1));
CREATE TABLE STUDENT(USN VARCHAR(10) PRIMARY KEY,SNAME VARCHAR(25),ADDRESS VARCHAR(25),PHONE TEXT(10),GENDER CHAR(1));
DESC STUDENT;
CREATE TABLE SEMSEC(SSID VARCHAR(5) PRIMARY KEY, SEM INT, SEC CHAR(1));
DESC SEMSEC;
CREATE TABLE CLASS( USN VARCHAR(10), SSID VARCHAR(5), PRIMARY KEY(USN,SSID), FOREIGN KEY(USN) REFERENCES STUDENT(USN), FOREIGN KEY(SSID) REFERENCES SEMSEC(SSID));
DESC CLASS;
CREATE TABLE SUBJECT(SUBCODE VARCHAR(8),TITLE VARCHAR(20),SEM INT,CREDITS INT,PRIMARY KEY(SUBCODE));
DESC SUBJECT
;
CREATE TABLE IAMARKS(USN VARCHAR(10),SUBCODE VARCHAR(8),SSID VARCHAR(5),TEST1 INT,TEST2 INT,TEST3 INT,FINALIA INT,PRIMARY KEY(SUBCODE,USN,SSID),FOREIGN KEY(USN) REFERENCES STUDENT(USN),FOREIGN KEY(SUBCODE) REFERENCES SUBJECT(SUBCODE),FOREIGN KEY(SSID) REFERENCES SEMSEC(SSID));
DESC IAMARKS;
INSERT INTO STUDENT VALUES ('1BY18CS180', 'TUSHAR P', 'BLR', '1234567890', 'M');
INSERT INTO STUDENT VALUES ('1BY18CS101', 'STUDENT2', 'BLR', '1234567890', 'F');
INSERT INTO STUDENT VALUES ('1BY18CS102', 'STUDENT3', 'BLR', '1234567890', 'F');
INSERT INTO STUDENT VALUES ('1BY18CS103', 'STUDENT4', 'BLR', '1234567890', 'F');
INSERT INTO STUDENT VALUES ('1BY18CS104', 'STUDENT5', 'BLR', '1234567890', 'M');
INSERT INTO STUDENT VALUES ('1BY18CS105', 'STUDENT6', 'BLR', '1234567890', 'M');
INSERT INTO STUDENT VALUES ('1BY18CS106', 'STUDENT7', 'BLR', '1234567890', 'F');
INSERT INTO STUDENT VALUES ('1BY18CS107', 'STUDENT8', 'BLR', '1234567890', 'M');
INSERT INTO STUDENT VALUES ('1BY18CS108', 'STUDENT9', 'BLR', '1234567890', 'F');
INSERT INTO STUDENT VALUES ('1BY18CS109', 'STUDENT10', 'BLR', '1234567890', 'M');
SELECT * FROM STUDENT;
INSERT INTO SEMSEC VALUES ('CSE5A', 5, 'A');
INSERT INTO SEMSEC VALUES ('CSE5B', 5, 'B');
INSERT INTO SEMSEC VALUES ('CSE5C', 5, 'C');
SELECT * FROM SEMSEC;
INSERT INTO CLASS VALUES ('1BY18CS180', 'CSE5C');
INSERT INTO CLASS VALUES ('1BY18CS101', 'CSE5A');
INSERT INTO CLASS VALUES ('1BY18CS102', 'CSE5A');
INSERT INTO CLASS VALUES ('1BY18CS103', 'CSE5A');
INSERT INTO CLASS VALUES ('1BY18CS104', 'CSE5B');
INSERT INTO CLASS VALUES ('1BY18CS105', 'CSE5B');
INSERT INTO CLASS VALUES ('1BY18CS106', 'CSE5B');
INSERT INTO CLASS VALUES ('1BY18CS107', 'CSE5C');
INSERT INTO CLASS VALUES ('1BY18CS108', 'CSE5C');
INSERT INTO CLASS VALUES ('1BY18CS109', 'CSE5C');
SELECT * FROM CLASS;
INSERT INTO SUBJECT VALUES ('15CS51', 'ME', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS52', 'CN', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS53', 'DBMS', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS54', 'ATC', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS55', 'RADP', 5, 3);
INSERT INTO SUBJECT VALUES ('15CS56', 'UNIX', 5, 3);
SELECT * FROM SUBJECT;
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '10CS51', 'CSE5C', 15, 16, 18);
DELETE * FROM SUBJECT;
DELETE FROM SUBJECT;
SELECT * FROM SUBJECT;
INSERT INTO SUBJECT VALUES ('18CS51', 'ME', 5, 4);
INSERT INTO SUBJECT VALUES ('18CS52', 'CN', 5, 4);
INSERT INTO SUBJECT VALUES ('18CS53', 'DBMS', 5, 4);
INSERT INTO SUBJECT VALUES ('18CS54', 'ATC', 5, 4);
INSERT INTO SUBJECT VALUES ('18CS55', 'RADP', 5, 3);
INSERT INTO SUBJECT VALUES ('18CS56', 'UNIX', 5, 3);
SELECT * FROM SUBJECT;
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS51', 'CSE5C', 15, 16, 18);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS52', 'CSE5C', 18, 19, 14);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS53', 'CSE5C', 19, 15, 20);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS54', 'CSE5C', 20, 16, 19);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS55', 'CSE5C', 20, 20, 20);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS56', 'CSE5C', 17, 18, 19);
SELECT * FROM IAMARKS;
DELETE FROM IAMARKS;
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS51', 'CSE5C', 15, 16, 18, 45);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS52', 'CSE5C', 18, 19, 14, 45);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS53', 'CSE5C', 19, 15, 20, 45);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS54', 'CSE5C', 20, 16, 19, 45);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS55', 'CSE5C', 20, 20, 20, 45);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS56', 'CSE5C', 17, 18, 19, 45);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3, FINALIA) VALUES ('1BY18CS180', '18CS51', 'CSE5C', 15, 16, 18, 45);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3, FINALIA) VALUES ('1BY18CS180', '18CS52', 'CSE5C', 18, 19, 14, 45);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3, FINALIA) VALUES ('1BY18CS180', '18CS53', 'CSE5C', 19, 15, 20, 45);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3, FINALIA) VALUES ('1BY18CS180', '18CS54', 'CSE5C', 20, 16, 19, 45);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3, FINALIA) VALUES ('1BY18CS180', '18CS55', 'CSE5C', 20, 20, 20, 45);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3, FINALIA) VALUES ('1BY18CS180', '18CS56', 'CSE5C', 17, 18, 19, 45);
SELECT * FROM IAMARKS;
SELECT S.*, SS.SEM, SS.SEC FROM STUDENT S, SEMSEC SS, CLASS C WHERE SS.SEM=5 AND SS.SEC='C' AND SS.SSID=C.SSID AND S.USN=C.USN;
SELECT SS.SEM, SS.SEC, S.GENDER, COUNT(S.GENDER) AS CNT FROM STUDENT S, SEMSEC SS, CLASS C WHERE S.USN=C.USN AND C.SSID=SS.SSID GROUP BY SS.SEM, SS.SEC, S.GENDER;
CREATE VIEW TMP AS SELECT IAM.TEST1, IAM.SUBCODE, SBJ.TITLE FROM IAMARKS IAM, SUBJECT SBJ WHERE IAM.USN='1BY18CS180';
SELECT * FROM TMP;
CREATE VIEW TMP AS SELECT IAM.TEST1, IAM.SUBCODE, SBJ.TITLE FROM IAMARKS IAM, SUBJECT SBJ WHERE IAM.USN='1BY18CS180' SBJ.SUBCODE=IAM.SUBCODE;
CREATE VIEW TMP AS SELECT IAM.TEST1, IAM.SUBCODE, SBJ.TITLE FROM IAMARKS IAM, SUBJECT SBJ WHERE IAM.USN='1BY18CS180', SBJ.SUBCODE=IAM.SUBCODE;
CREATE VIEW TMP AS SELECT IAM.TEST1, IAM.SUBCODE, SBJ.TITLE FROM IAMARKS IAM, SUBJECT SBJ WHERE IAM.USN='1BY18CS180' AND SBJ.SUBCODE=IAM.SUBCODE;
DROP TABLE TMP;
DROP VIEW TMP;
CREATE VIEW TMP AS SELECT IAM.TEST1, IAM.SUBCODE, SBJ.TITLE FROM IAMARKS IAM, SUBJECT SBJ WHERE IAM.USN='1BY18CS180' AND SBJ.SUBCODE=IAM.SUBCODE;
SELECT * FROM TMP;
DELETE FROM IAMARKS
;
DROP TABLE IAMARKS
;
DROP TABLE SUBJECTS;
DROP TABLE SUBJECT;
DROP TABLE CLASS;
DROP TABLE SECSEM;
DROP TABLE SEMSEC;
DROP TABLE STUDENT;
DROP VIEW TMP;
CREATE TABLE STUDENT(USN VARCHAR(10) PRIMARY KEY,SNAME VARCHAR(25),ADDRESS VARCHAR(25),PHONE TEXT(10),GENDER CHAR(1));
DESC STUDENT;
CREATE TABLE SEMSEC(SSID VARCHAR(5) PRIMARY KEY, SEM INT, SEC CHAR(1));
DESC SEMSEC;
CREATE TABLE CLASS( USN VARCHAR(10), SSID VARCHAR(5), PRIMARY KEY(USN,SSID), FOREIGN KEY(USN) REFERENCES STUDENT(USN), FOREIGN KEY(SSID) REFERENCES SEMSEC(SSID));
DESC CLASS;
CREATE TABLE SUBJECT(SUBCODE VARCHAR(8),TITLE VARCHAR(20),SEM INT,CREDITS INT,PRIMARY KEY(SUBCODE));
DESC SUBJECT;
CREATE TABLE IAMARKS(USN VARCHAR(10),SUBCODE VARCHAR(8),SSID VARCHAR(5),TEST1 INT,TEST2 INT,TEST3 INT,FINALIA INT,PRIMARY KEY(SUBCODE,USN,SSID),FOREIGN KEY(USN) REFERENCES STUDENT(USN),FOREIGN KEY(SUBCODE) REFERENCES SUBJECT(SUBCODE),FOREIGN KEY(SSID) REFERENCES SEMSEC(SSID));
DESC IAMARKS;
INSERT INTO STUDENT VALUES ('1BY18CS180', 'TUSHAR P', 'BLR', '1234567890', 'M');
INSERT INTO STUDENT VALUES ('1BY18CS101', 'STUDENT2', 'BLR', '1234567890', 'F');
INSERT INTO STUDENT VALUES ('1BY18CS102', 'STUDENT3', 'BLR', '1234567890', 'F');
INSERT INTO STUDENT VALUES ('1BY18CS103', 'STUDENT4', 'BLR', '1234567890', 'F');
INSERT INTO STUDENT VALUES ('1BY18CS104', 'STUDENT5', 'BLR', '1234567890', 'M');
INSERT INTO STUDENT VALUES ('1BY18CS105', 'STUDENT6', 'BLR', '1234567890', 'M');
INSERT INTO STUDENT VALUES ('1BY18CS106', 'STUDENT7', 'BLR', '1234567890', 'F');
INSERT INTO STUDENT VALUES ('1BY18CS107', 'STUDENT8', 'BLR', '1234567890', 'M');
INSERT INTO STUDENT VALUES ('1BY18CS108', 'STUDENT9', 'BLR', '1234567890', 'F');
INSERT INTO STUDENT VALUES ('1BY18CS109', 'STUDENT10', 'BLR', '1234567890', 'M');
SELECT * FROM STUDENT;
INSERT INTO SEMSEC VALUES ('CSE5A', 5, 'A');
INSERT INTO SEMSEC VALUES ('CSE5B', 5, 'B');
INSERT INTO SEMSEC VALUES ('CSE5C', 5, 'C');
SELECT * FROM SEMSEC;
INSERT INTO CLASS VALUES ('1BY18CS180', 'CSE5C');
INSERT INTO CLASS VALUES ('1BY18CS101', 'CSE5A');
INSERT INTO CLASS VALUES ('1BY18CS102', 'CSE5A');
INSERT INTO CLASS VALUES ('1BY18CS103', 'CSE5A');
INSERT INTO CLASS VALUES ('1BY18CS104', 'CSE5B');
INSERT INTO CLASS VALUES ('1BY18CS105', 'CSE5B');
INSERT INTO CLASS VALUES ('1BY18CS106', 'CSE5B');
INSERT INTO CLASS VALUES ('1BY18CS107', 'CSE5C');
INSERT INTO CLASS VALUES ('1BY18CS108', 'CSE5C');
INSERT INTO CLASS VALUES ('1BY18CS109', 'CSE5C');
SELECT * FROM CLASS;
INSERT INTO SUBJECT VALUES ('15CS51', 'ME', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS52', 'CN', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS53', 'DBMS', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS54', 'ATC', 5, 4);
INSERT INTO SUBJECT VALUES ('15CS55', 'RADP', 5, 3);
INSERT INTO SUBJECT VALUES ('15CS56', 'UNIX', 5, 3);
SELECT * FROM SUBJECT;
DELETE FROM SUBJECT;
INSERT INTO SUBJECT VALUES ('18CS51', 'ME', 5, 4);
INSERT INTO SUBJECT VALUES ('18CS52', 'CN', 5, 4);
INSERT INTO SUBJECT VALUES ('18CS53', 'DBMS', 5, 4);
INSERT INTO SUBJECT VALUES ('18CS54', 'ATC', 5, 4);
INSERT INTO SUBJECT VALUES ('18CS55', 'RADP', 5, 3);
INSERT INTO SUBJECT VALUES ('18CS56', 'UNIX', 5, 3);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS51', 'CSE5C', 15, 16, 18);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS52', 'CSE5C', 18, 19, 14);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS53', 'CSE5C', 19, 15, 20);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS54', 'CSE5C', 20, 16, 19);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS55', 'CSE5C', 20, 20, 20);
INSERT INTO IAMARKS (USN, SUBCODE, SSID, TEST1, TEST2, TEST3) VALUES ('1BY18CS180', '18CS56', 'CSE5C', 17, 18, 19);
SELECT * FROM IAMARKS;
SELECT S.*, SS.SEM, SS.SEC FROM STUDENT S, SEMSEC SS, CLASS C WHERE SS.SEM=5 AND SS.SEC='C' AND SS.SSID=C.SSID AND S.USN=C.USN;
SELECT SS.SEM, SS.SEC, S.GENDER, COUNT(S.GENDER) AS CNT FROM STUDENT S, SEMSEC SS, CLASS C WHERE S.USN=C.USN AND C.SSID=SS.SSID GROUP BY SS.SEM, SS.SEC, S.GENDER;
CREATE VIEW TMP AS SELECT IAM.TEST1, IAM.SUBCODE, SBJ.TITLE FROM IAMARKS IAM, SUBJECT SBJ WHERE IAM.USN='1BY18CS180' AND SBJ.SUBCODE=IAM.SUBCODE;
SELECT * FROM TMP;
USE db1;
CREATE OR REPLACE PROCEDURE AVGMARKS
IS
CURSOR C_IAMARKS IS
SELECT GREATEST(TEST1,TEST2) AS A, GREATEST(TEST1,TEST3) AS B, GREATEST(TEST3,TEST2) AS C
FROM IAMARKS
WHERE FINALIA IS NULL
FOR UPDATE;
CREATE OR REPLACE PROCEDURE AVGMARKS IS CURSOR C_IAMARKS IS SELECT GREATEST(TEST1,TEST2) AS A, GREATEST(TEST1,TEST3) AS B, GREATEST(TEST3,TEST2) AS C FROM IAMARKS WHERE FINALIA IS NULL FOR UPDATE;
C_A NUMBER;
C_B NUMBER;
C_C NUMBER;
C_SM NUMBER;
C_AV NUMBER;
BEGIN
OPEN C_IAMARKS;
BEGIN OPEN C_IAMARKS;
LOOP
FETCH C_IAMARKS INTO C_A, C_B, C_C;
LOOP FETCH C_IAMARKS INTO C_A, C_B, C_C;
EXIT WHEN C_IAMARKS%NOTFOUND;
--DBMS_OUTPUT.PUT_LINE(C_A || ' ' || C_B || ' ' || C_C);
IF (C_A != C_B) THEN
C_SM:=C_A+C_B;
IF (C_A != C_B) THEN C_SM:=C_A+C_B;
ELSE
C_SM:=C_A+C_C;
ELSE C_SM:=C_A+C_C;
END IF;
C_AV:=C_SM/2;
--DBMS_OUTPUT.PUT_LINE('SUM = '||C_SM);
--DBMS_OUTPUT.PUT_LINE('AVERAGE = '||C_AV);
UPDATE IAMARKS SET FINALIA=C_AV WHERE CURRENT OF C_IAMARKS;
END LOOP;
CLOSE C_IAMARKS;
END;
/
SELECT * FROM IAMARKS;
/ SELECT * FROM IAMARKS;
BEGIN
AVGMARKS;
BEGIN AVGMARKS;
END;
SELECT * FROM IAMARKS;
CREATE OR REPLACE PROCEDURE AVGMARKS
IS
CURSOR C_IAMARKS IS
SELECT GREATEST(TEST1,TEST2) AS A, GREATEST(TEST1,TEST3) AS B, GREATEST(TEST3,TEST2) AS C
FROM IAMARKS
WHERE FINALIA IS NULL
FOR UPDATE;
CREATE OR REPLACE PROCEDURE AVGMARKS IS CURSOR C_IAMARKS IS SELECT GREATEST(TEST1,TEST2) AS A, GREATEST(TEST1,TEST3) AS B, GREATEST(TEST3,TEST2) AS C FROM IAMARKS WHERE FINALIA IS NULL FOR UPDATE;
C_A NUMBER;
C_B NUMBER;
C_C NUMBER;
C_SM NUMBER;
C_AV NUMBER;
BEGIN
OPEN C_IAMARKS;
BEGIN OPEN C_IAMARKS;
LOOP
FETCH C_IAMARKS INTO C_A, C_B, C_C;
LOOP FETCH C_IAMARKS INTO C_A, C_B, C_C;
EXIT WHEN C_IAMARKS%NOTFOUND;
--DBMS_OUTPUT.PUT_LINE(C_A || ' ' || C_B || ' ' || C_C);
IF (C_A != C_B) THEN
C_SM:=C_A+C_B;
IF (C_A != C_B) THEN C_SM:=C_A+C_B;
ELSE
C_SM:=C_A+C_C;
ELSE C_SM:=C_A+C_C;
END IF;
C_AV:=C_SM/2;
--DBMS_OUTPUT.PUT_LINE('SUM = '||C_SM);
--DBMS_OUTPUT.PUT_LINE('AVERAGE = '||C_AV);
UPDATE IAMARKS SET FINALIA=C_AV WHERE CURRENT OF C_IAMARKS;
END LOOP;
CLOSE C_IAMARKS;
END;
/
SELECT * FROM IAMARKS;
/ SELECT * FROM IAMARKS;
BEGIN
AVGMARKS;
BEGIN AVGMARKS;
END;
CREATE OR REPLACE PROCEDURE AVGMARKS
IN CURSOR
IN C_IAMARKS
SELECT GREATEST(TEST1,TEST2) AS A, GREATEST(TEST1,TEST3) AS B, GREATEST(TEST3,TEST2) AS C FROM IAMARKS WHERE FINALIA IS NULL
FOR UPDATE;
CREATE OR REPLACE PROCEDURE AVGMARKS IN CURSOR IN C_IAMARKS SELECT GREATEST(TEST1,TEST2) AS A, GREATEST(TEST1,TEST3) AS B, GREATEST(TEST3,TEST2) AS C FROM IAMARKS WHERE FINALIA IS NULL FOR UPDATE;
CREATE OR REPLACE PROCEDURE AVGMARKS (IN CURSOR IN C_IAMARKS) BEGIN SELECT GREATEST(TEST1,TEST2) AS A, GREATEST(TEST1,TEST3) AS B, GREATEST(TEST3,TEST2) AS C FROM IAMARKS WHERE FINALIA IS NULL;
CREATE TABLE DEPARTMENT
(DNO VARCHAR2 (20) PRIMARY KEY,
DNAME VARCHAR2 (20),
MGRSTARTDATE DATE);
CREATE TABLE DEPARTMENT (DNO VARCHAR2 (20) PRIMARY KEY, DNAME VARCHAR2 (20), MGRSTARTDATE DATE);
USE db1;
CREATE TABLE DEPARTMENT(DNO VARCHAR2(20) PRIMARY KEY,DNAME VARCHAR2(20),MGRSTARTDATE DATE);
CREATE TABLE DEPARTMENT(DNO VARCHAR(20) PRIMARY KEY,DNAME VARCHAR(20),MGRSTARTDATE DATE);
CREATE TABLE EMPLOYEE
(SSN VARCHAR(20) PRIMARY KEY,
FNAME VARCHAR(20),
LNAME VARCHAR(20),
ADDRESS VARCHAR(20),
SEX CHAR(1),
SALARY INTEGER,
FOREIGN KEY(SUPERSSN) REFERENCES EMPLOYEE(SSN),
FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE (SSN VARCHAR(20) PRIMARY KEY, FNAME VARCHAR(20), LNAME VARCHAR(20), ADDRESS VARCHAR(20), SEX CHAR(1), SALARY INTEGER, FOREIGN KEY(SUPERSSN) REFERENCES EMPLOYEE(SSN), FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE
(SSN VARCHAR(20) PRIMARY KEY,
FNAME VARCHAR(20),
LNAME VARCHAR(20),
ADDRESS VARCHAR(20),
SEX CHAR(1),
SALARY INTEGER,
SUPERSSN VARCHAR(20),
DNO VARCHAR(20)
FOREIGN KEY(SUPERSSN) REFERENCES EMPLOYEE(SSN),
FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE (SSN VARCHAR(20) PRIMARY KEY, FNAME VARCHAR(20), LNAME VARCHAR(20), ADDRESS VARCHAR(20), SEX CHAR(1), SALARY INTEGER, SUPERSSN VARCHAR(20), DNO VARCHAR(20) FOREIGN KEY(SUPERSSN) REFERENCES EMPLOYEE(SSN), FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE (SSN VARCHAR(20) PRIMARY KEY, FNAME VARCHAR(20), LNAME VARCHAR(20), ADDRESS VARCHAR(20), SEX CHAR(1), SALARY INTEGER, DNO VARCHAR(20),SUPERSSN VARCHAR(20) REFERENCES SSN, FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE
(SSN VARCHAR(20) PRIMARY KEY,
FNAME VARCHAR(20),
LNAME VARCHAR(20),
ADDRESS VARCHAR(20),
SEX CHAR(1),
SALARY INTEGER,
SUPERSSN VARCHAR(20),
DNO VARCHAR(20)
SUPERSSN VARCHAR(20) REFERENCES EMPLOYEE,
FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE (SSN VARCHAR(20) PRIMARY KEY, FNAME VARCHAR(20), LNAME VARCHAR(20), ADDRESS VARCHAR(20), SEX CHAR(1), SALARY INTEGER, SUPERSSN VARCHAR(20), DNO VARCHAR(20) SUPERSSN VARCHAR(20) REFERENCES EMPLOYEE, FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE
(SSN VARCHAR(20) PRIMARY KEY,
FNAME VARCHAR(20),
LNAME VARCHAR(20),
ADDRESS VARCHAR(20),
SEX CHAR(1),
SALARY INTEGER,
SUPERSSN VARCHAR(20),
DNO VARCHAR(20)
SUPERSSN VARCHAR(20) REFERENCES EMPLOYEE,
FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE (SSN VARCHAR(20) PRIMARY KEY, FNAME VARCHAR(20), LNAME VARCHAR(20), ADDRESS VARCHAR(20), SEX CHAR(1), SALARY INTEGER, SUPERSSN VARCHAR(20), DNO VARCHAR(20) SUPERSSN VARCHAR(20) REFERENCES EMPLOYEE, FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE
(SSN VARCHAR(20) PRIMARY KEY,
FNAME VARCHAR(20),
LNAME VARCHAR(20),
ADDRESS VARCHAR(20),
SEX CHAR(1),
SALARY INTEGER,
SUPERSSN VARCHAR(20),
DNO VARCHAR(20),
SUPERSSN VARCHAR(20) REFERENCES EMPLOYEE,
FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE (SSN VARCHAR(20) PRIMARY KEY, FNAME VARCHAR(20), LNAME VARCHAR(20), ADDRESS VARCHAR(20), SEX CHAR(1), SALARY INTEGER, SUPERSSN VARCHAR(20), DNO VARCHAR(20), SUPERSSN VARCHAR(20) REFERENCES EMPLOYEE, FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
;CREATE TABLE EMPLOYEE
(SSN VARCHAR(20) PRIMARY KEY,
FNAME VARCHAR(20),
LNAME VARCHAR(20),
ADDRESS VARCHAR(20),
SEX CHAR(1),
SALARY INTEGER,
DNO VARCHAR(20),
SUPERSSN VARCHAR(20) REFERENCES EMPLOYEE,
FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE (SSN VARCHAR(20) PRIMARY KEY, FNAME VARCHAR(20), LNAME VARCHAR(20), ADDRESS VARCHAR(20), SEX CHAR(1), SALARY INTEGER, DNO VARCHAR(20), SUPERSSN VARCHAR(20) REFERENCES EMPLOYEE, FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE
(SSN VARCHAR(20) PRIMARY KEY,
FNAME VARCHAR(20),
LNAME VARCHAR(20),
ADDRESS VARCHAR(20),
SEX CHAR(1),
SALARY INTEGER,
DNO VARCHAR(20),
SUPERSSN VARCHAR(20) REFERENCES EMPLOYEE(SSN),
FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE EMPLOYEE (SSN VARCHAR(20) PRIMARY KEY, FNAME VARCHAR(20), LNAME VARCHAR(20), ADDRESS VARCHAR(20), SEX CHAR(1), SALARY INTEGER, DNO VARCHAR(20), SUPERSSN VARCHAR(20) REFERENCES EMPLOYEE(SSN), FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
ALTER TABLE DEPARTMENT
ADD MGRSSN VARCHAR(20);
ALTER TABLE DEPARTMENT ADD MGRSSN VARCHAR(20);
ALTER TABLE DEPARTMENT
ADD FOREIGN KEY(MGRSSN) REFERENCES EMPLOYEE(SSN);
ALTER TABLE DEPARTMENT ADD FOREIGN KEY(MGRSSN) REFERENCES EMPLOYEE(SSN);
DESC DEPARTMENT;
CREATE TABLE DLOCATION
(DLOC VARCHAR(20),
DNO VARCHAR(20),
FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO),
PRIMARY KEY(DNO, DLOC));
CREATE TABLE DLOCATION (DLOC VARCHAR(20), DNO VARCHAR(20), FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO), PRIMARY KEY(DNO, DLOC));
CREATE TABLE PROJECT
(PNO INTEGER PRIMARY KEY,
PNAME VARCHAR(20),
PLOCATION VARCHAR(20),
DNO VARCHAR(20),
FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE PROJECT (PNO INTEGER PRIMARY KEY, PNAME VARCHAR(20), PLOCATION VARCHAR(20), DNO VARCHAR(20), FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DNO));
CREATE TABLE WORKS_ON
(HOURS NUMBER(2),
SSN VARCHAR(20),
PNO VARCHAR(20),
FOREIGN KEY(SSN) REFERENCES EMPLOYEE(SSN),
FOREIGN KEY(PNO) REFERENCES PROJECT(PNO),
PRIMARY KEY(SSN, PNO));
CREATE TABLE WORKS_ON (HOURS NUMBER(2), SSN VARCHAR(20), PNO VARCHAR(20), FOREIGN KEY(SSN) REFERENCES EMPLOYEE(SSN), FOREIGN KEY(PNO) REFERENCES PROJECT(PNO), PRIMARY KEY(SSN, PNO));
CREATE TABLE WORKS_ON
(HOURS INT,
SSN VARCHAR(20),
PNO VARCHAR(20),
FOREIGN KEY(SSN) REFERENCES EMPLOYEE(SSN),
FOREIGN KEY(PNO) REFERENCES PROJECT(PNO),
PRIMARY KEY(SSN, PNO));
CREATE TABLE WORKS_ON (HOURS INT, SSN VARCHAR(20), PNO VARCHAR(20), FOREIGN KEY(SSN) REFERENCES EMPLOYEE(SSN), FOREIGN KEY(PNO) REFERENCES PROJECT(PNO), PRIMARY KEY(SSN, PNO));
CREATE TABLE WORKS_ON
(HOURS INTEGER,
SSN VARCHAR(20),
PNO INTEGER,
FOREIGN KEY(SSN) REFERENCES EMPLOYEE(SSN),
FOREIGN KEY(PNO) REFERENCES PROJECT(PNO),
PRIMARY KEY(SSN, PNO));
CREATE TABLE WORKS_ON (HOURS INTEGER, SSN VARCHAR(20), PNO INTEGER, FOREIGN KEY(SSN) REFERENCES EMPLOYEE(SSN), FOREIGN KEY(PNO) REFERENCES PROJECT(PNO), PRIMARY KEY(SSN, PNO));
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES
(‘RNSECE01’,’JOHN’,’SCOTT’,’BANGALORE’,’M’, 450000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES (‘RNSECE01’,’JOHN’,’SCOTT’,’BANGALORE’,’M’, 450000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES
(‘RNSCSE01’,’JAMES’,’SMITH’,’BANGALORE’,’M’, 500000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES (‘RNSCSE01’,’JAMES’,’SMITH’,’BANGALORE’,’M’, 500000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES
(‘RNSCSE02’,’HEARN’,’BAKER’,’BANGALORE’,’M’, 700000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES (‘RNSCSE02’,’HEARN’,’BAKER’,’BANGALORE’,’M’, 700000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES
(‘RNSCSE03’,’EDWARD’,’SCOTT’,’MYSORE’,’M’, 500000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES (‘RNSCSE03’,’EDWARD’,’SCOTT’,’MYSORE’,’M’, 500000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES
(‘RNSCSE04’,’PAVAN’,’HEGDE’,’MANGALORE’,’M’, 650000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES (‘RNSCSE04’,’PAVAN’,’HEGDE’,’MANGALORE’,’M’, 650000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES
(‘RNSCSE05’,’GIRISH’,’MALYA’,’MYSORE’,’M’, 450000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES (‘RNSCSE05’,’GIRISH’,’MALYA’,’MYSORE’,’M’, 450000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES
(‘RNSCSE06’,’NEHA’,’SN’,’BANGALORE’,’F’, 800000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES (‘RNSCSE06’,’NEHA’,’SN’,’BANGALORE’,’F’, 800000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES
(‘RNSACC01’,’AHANA’,’K’,’MANGALORE’,’F’, 350000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES (‘RNSACC01’,’AHANA’,’K’,’MANGALORE’,’F’, 350000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES
(‘RNSACC02’,’SANTHOSH’,’KUMAR’,’MANGALORE’,’M’, 300000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES (‘RNSACC02’,’SANTHOSH’,’KUMAR’,’MANGALORE’,’M’, 300000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES
(‘RNSISE01’,’VEENA’,’M’,’MYSORE’,’M’, 600000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES (‘RNSISE01’,’VEENA’,’M’,’MYSORE’,’M’, 600000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES
(‘RNSIT01’,’NAGESH’,’HR’,’BANGALORE’,’M’, 500000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES (‘RNSIT01’,’NAGESH’,’HR’,’BANGALORE’,’M’, 500000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES("RNSECE01","JOHN","SCOTT","BANGALORE","M", 450000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES("RNSCSE01","JAMES","SMITH","BANGALORE","M", 500000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES("RNSCSE02","HEARN","BAKER","BANGALORE","M", 700000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES("RNSCSE03","EDWARD","SCOTT","MYSORE","M", 500000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES("RNSCSE04","PAVAN","HEGDE","MANGALORE","M", 650000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES("RNSCSE05","GIRISH","MALYA","MYSORE","M", 450000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES("RNSCSE06","NEHA","SN","BANGALORE","F", 800000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES("RNSACC01","AHANA","K","MANGALORE","F", 350000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES("RNSACC02","SANTHOSH","KUMAR","MANGALORE","M", 300000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES("RNSISE01","VEENA","M","MYSORE","M", 600000);
INSERT INTO EMPLOYEE(SSN, FNAME, LNAME, ADDRESS, SEX, SALARY) VALUES("RNSIT01","NAGESH","HR","BANGALORE","M", 500000);
INSERT INTO DEPARTMENT VALUES("1","ACCOUNTS","01-JAN-01","RNSACC02");
INSERT INTO DEPARTMENT VALUES("2","IT","01-AUG-16","RNSIT01");
INSERT INTO DEPARTMENT VALUES("3","ECE","01-JUN-08","RNSECE01");
INSERT INTO DEPARTMENT VALUES("4","ISE","01-AUG-15","RNSISE01");
INSERT INTO DEPARTMENT VALUES("5","CSE","01-JUN-02","RNSCSE05");INSERT INTO DEPARTMENT VALUES("1","ACCOUNTS","01-01-01","RNSACC02");
INSERT INTO DEPARTMENT VALUES("1","ACCOUNTS","01-01-01","RNSACC02");
SELECT * FROM DEPARTMENT;
INSERT INTO DEPARTMENT VALUES("2","IT","01-08-16","RNSIT01");
INSERT INTO DEPARTMENT VALUES("3","ECE","01-06-08","RNSECE01");
INSERT INTO DEPARTMENT VALUES("4","ISE","01-08-15","RNSISE01");
INSERT INTO DEPARTMENT VALUES("5","CSE","01-06-02","RNSCSE05");
UPDATE EMPLOYEE SET
SUPERSSN=NULL, DNO='3'
WHERE SSN='RNSECE01';
UPDATE EMPLOYEE SET SUPERSSN=NULL, DNO='3' WHERE SSN='RNSECE01';
UPDATE EMPLOYEE SET
SUPERSSN='RNSCSE02', DNO='5'
WHERE SSN='RNSCSE01';
UPDATE EMPLOYEE SET SUPERSSN='RNSCSE02', DNO='5' WHERE SSN='RNSCSE01';
UPDATE EMPLOYEE SET
SUPERSSN='RNSCSE03', DNO='5'
WHERE SSN='RNSCSE02';
UPDATE EMPLOYEE SET SUPERSSN='RNSCSE03', DNO='5' WHERE SSN='RNSCSE02';
UPDATE EMPLOYEE SET
SUPERSSN='RNSCSE04', DNO='5'
WHERE SSN='RNSCSE03';
UPDATE EMPLOYEE SET SUPERSSN='RNSCSE04', DNO='5' WHERE SSN='RNSCSE03';
UPDATE EMPLOYEE SET
DNO='5', SUPERSSN='RNSCSE05'
WHERE SSN='RNSCSE04';
UPDATE EMPLOYEE SET DNO='5', SUPERSSN='RNSCSE05' WHERE SSN='RNSCSE04';
UPDATE EMPLOYEE SET
DNO='5', SUPERSSN='RNSCSE06'
WHERE SSN='RNSCSE05';
UPDATE EMPLOYEE SET DNO='5', SUPERSSN='RNSCSE06' WHERE SSN='RNSCSE05';
UPDATE EMPLOYEE SET
DNO='5', SUPERSSN=NULL
WHERE SSN='RNSCSE06';
UPDATE EMPLOYEE SET DNO='5', SUPERSSN=NULL WHERE SSN='RNSCSE06';
UPDATE EMPLOYEE SET
DNO='1', SUPERSSN='RNSACC02'
WHERE SSN='RNSACC01';
UPDATE EMPLOYEE SET DNO='1', SUPERSSN='RNSACC02' WHERE SSN='RNSACC01';
UPDATE EMPLOYEE SET
DNO='1', SUPERSSN=NULL
WHERE SSN='RNSACC02';
UPDATE EMPLOYEE SET DNO='1', SUPERSSN=NULL WHERE SSN='RNSACC02';
UPDATE EMPLOYEE SET
DNO='4', SUPERSSN=NULL
WHERE SSN='RNSISE01';
UPDATE EMPLOYEE SET DNO='4', SUPERSSN=NULL WHERE SSN='RNSISE01';
UPDATE EMPLOYEE SET
DNO='2', SUPERSSN=NULL
WHERE SSN='RNSIT01';
UPDATE EMPLOYEE SET DNO='2', SUPERSSN=NULL WHERE SSN='RNSIT01';
INSERT INTO DLOCATION VALUES('BANGALORE', '1');
INSERT INTO DLOCATION VALUES('BANGALORE', '2');
INSERT INTO DLOCATION VALUES('BANGALORE', '3');
INSERT INTO DLOCATION VALUES('MANGALORE', '4');
INSERT INTO DLOCATION VALUES('MANGALORE', '5');
INSERT INTO PROJECT VALUES(100,'IOT','BANGALORE','5');
INSERT INTO PROJECT VALUES(101,'CLOUD','BANGALORE','5');
INSERT INTO PROJECT VALUES(102,'BIGDATA','BANGALORE','5');
INSERT INTO PROJECT VALUES(103,'SENSORS','BANGALORE','3');
INSERT INTO PROJECT VALUES(104,'BANK MANAGEMENT','BANGALORE','1');
INSERT INTO PROJECT VALUES(105,'SALARY MANAGEMENT','BANGALORE','1');
INSERT INTO PROJECT VALUES(106,'OPENSTACK','BANGALORE','4');
INSERT INTO PROJECT VALUES(107,'SMART CITY','BANGALORE','2');
INSERT INTO WORKS_ON VALUES(4, 'RNSCSE01', 100);
INSERT INTO WORKS_ON VALUES(6, 'RNSCSE01', 101);
INSERT INTO WORKS_ON VALUES(8, 'RNSCSE01', 102);
INSERT INTO WORKS_ON VALUES(10, 'RNSCSE02', 100);
INSERT INTO WORKS_ON VALUES(3, 'RNSCSE04', 100);
INSERT INTO WORKS_ON VALUES(4, 'RNSCSE05', 101);
INSERT INTO WORKS_ON VALUES(5, 'RNSCSE06', 102);
INSERT INTO WORKS_ON VALUES(6, 'RNSCSE03', 102);
INSERT INTO WORKS_ON VALUES(7, 'RNSECE01', 103);
INSERT INTO WORKS_ON VALUES(5, 'RNSACC01', 104);
INSERT INTO WORKS_ON VALUES(6, 'RNSACC02', 105);
INSERT INTO WORKS_ON VALUES(4, 'RNSISE01', 106);
INSERT INTO WORKS_ON VALUES(10,'RNSITE01', 107);
SELECT * FROM WORKS_ON;
INSERT INTO WORKS_ON VALUES(10,'RNSITE01', 107);
SELECT * FROM PROJECT;
SELECT * FROM DEPARTMENT;
SELECT * FROM EMPLOYEE;
SELECT * FROM DLOCATION;
SELECT * FROM PROJECT;
SELECT * FROM WORKS_ON;
USE db1;