-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsql_201.txt
More file actions
142 lines (102 loc) · 3.23 KB
/
sql_201.txt
File metadata and controls
142 lines (102 loc) · 3.23 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
SECTION-'A'
--1.>
select movie.mov_title
from movie
join movie_genres
on movie.mov_id=movie_genres.mov_id
join genres
on genres.gen_id=movie_genres.gen_id AND genres.gen_title='Horror';
--2.>
select reviewer.rev_name
from reviewer join rating
on reviewer.rev_id=rating.rev_id AND rating.rev_stars>=8;
--3.>
select
actor.act_id AS ActorId,
actor.act_fname AS ActorFirstName,
actor.act_lname AS ActorLastName,
actor.act_gender As Gender
from actor
where act_id IN(
select movie_cast.act_id from movie_cast where movie_cast.mov_id IN(
select movie.mov_id from movie where mov_title ='Deliverance'));
--4.>
select
(director.dir_fname+director.dir_lname)
AS
Director_Name from director where
director.dir_id=(
select movie_direction.dir_id from movie_direction where movie_direction.mov_id IN(
select movie.mov_id from movie where mov_title='EyesWideShut'));
--5.>
select
movie.mov_title AS Movie_Title,
movie.mov_year AS MovieYear,
movie.mov_dt_rel AS MovieReleaseDate,
(director.dir_fname+director.dir_lname) AS DirectorName,
(actor.act_fname+actor.act_lname) AS ActorName
from movie join movie_direction
on movie.mov_id=movie_direction.mov_id
join director
on director.dir_id=movie_direction.dir_id
join movie_cast on movie_cast.mov_id=movie.mov_id
join actor
on movie_cast.act_id=actor.act_id
join rating
on movie.mov_id=rating.mov_id
join reviewer
on rating.rev_id=reviewer.rev_id
And reviewer.rev_name='NealWruck';
--6.>
select distinct movie.mov_year AS Year from movie where mov_id IN(
select mov_id from rating where rating.rev_stars>4) order by mov_year;
--7.>
select movie.mov_title AS MovieTitle from movie where mov_id IN
(select mov_id from rating where rating.no_of_ratings IS null);
--8.>
select movie.mov_title As MovieTitle from movie
join movie_direction on movie.mov_id=movie_direction.mov_id
join director on movie_direction.dir_id=director.dir_id
AND director.dir_fname='David';
--9.>
select actor.act_fname As ActorFirstName,actor.act_lname As ActorLastName from actor
join movie_cast on actor.act_id=movie_cast.act_id
join movie on movie_cast.mov_id=movie.mov_id
AND movie.mov_title='BoogieNights';
--10.>
select (actor.act_fname+actor.act_lname) AS ActorName
from actor
where act_id IN(
select act_id
from movie_cast
Group BY
act_id
Having COUNT(act_id)>1);
--************************************************************************************************
SECTION-B
--STORED PROCEDURE::
CREATE PROCEDURE sp_castActorToMovie
@actorId int,
@movieId int
AS
BEGIN
Declare @oldMovieId int;
Declare @countActor int;
BEGIN TRY
select @countActor=count(movie_cast.act_id) from movie_cast where movie_cast.act_id=@actorId And movie_cast.mov_id=@movieId;
print(@countActor)
IF(@countActor=0)
BEGIN
insert into movie_cast(act_id,mov_id) values(@actorId,@movieId);
print('New Record Successfully Inserted');
END
Else
BEGIN
print('Record Already Updated');
END
END TRY
BEGIN CATCH
PRINT('Invalid Operation!!');
END CATCH
END
GO