-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDQL_basics.sql
More file actions
142 lines (109 loc) · 4.18 KB
/
Copy pathDQL_basics.sql
File metadata and controls
142 lines (109 loc) · 4.18 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
/*
Assignment : HumanResources.Employee table
*/
USE AdventureWorks2017
go
-- find all jobtitle that starts with e and ends with r
SELECT DISTINCT JobTitle FROM HumanResources.Employee WHERE JobTitle LIKE 'e%r';
go
-- find the jobtitle that have 3rd letter as a
SELECT DISTINCT JobTitle FROM HumanResources.Employee WHERE JobTitle LIKE '__a%';
go
-- Find all employees whose jobtitle starts with a,m,s and ends with e,s
SELECT * FROM HumanResources.Employee WHERE JobTitle LIKE '[a,m,s]%[e,s]';
go
-- Find all employees whose jobtitle does not start with P
SELECT * FROM HumanResources.Employee WHERE JobTitle NOT LIKE '[p]%';
go
-- Find all jobtitle's that have atleast 3 a's
-- ??
-- ?? can be achieved with length fcn, not sure with wildcard only though
SELECT * FROM HumanResources.Employee WHERE JobTitle LIKE '%a%a%a%';
go
-- find all jobtitle's that have letter 'a' exactly 3 times
-- ??
-- ?? can be achieved with length fcn, not sure with wildcard only though
SELECT * FROM HumanResources.Employee WHERE JobTitle LIKE '%a%a%a%' AND JobTitle NOT LIKE '%a%a%a%a%';
go
-- jobtitle should have keyword 'Designer' or 'Manager'
SELECT DISTINCT JobTitle FROM HumanResources.Employee WHERE JobTitle LIKE '%Designer%' OR JobTitle LIKE '%Manager%';
go
-- Find all jobtitles starting with either a,f or s
SELECT DISTINCT JobTitle FROM HumanResources.Employee WHERE JobTitle LIKE '[a,f,s]%';
go
-- Find all jobtitles starting anywhere between a to s
SELECT DISTINCT JobTitle FROM HumanResources.Employee WHERE JobTitle LIKE '[a-s]%';
go
-- Find the jobtitle that have atleast 2 underscores
-- whose title has 4th character as 'k' and 5th last character as 'a'
SELECT DISTINCT JobTitle FROM HumanResources.Employee WHERE JobTitle LIKE '___k%a____';
go
-- jobtitles have one % and end with an _
SELECT DISTINCT JobTitle FROM HumanResources.Employee WHERE JobTitle LIKE '%[%]%' AND JobTitle LIKE '%[_]';
go
--jobtitles that do not start with E but end with E
-- Select * FROM HumanResources.Employee
SELECT DISTINCT JobTitle FROM HumanResources.Employee WHERE JobTitle NOT LIKE 'e%' AND JobTitle LIKE '%e';
go
-- title does not start with a,b,c,e but if it starts with s it has to end with r
SELECT DISTINCT JobTitle FROM HumanResources.Employee WHERE JobTitle NOT LIKE '[abce]%' AND (JobTitle NOT LIKE 's%' OR JobTitle LIKE 's%r');
go
------------------------------------------------------------------
/*
Photo Assignment 1
*/
Use LUCIDEX;
go
CREATE TABLE MovieReview(
ReviewID INT PRIMARY KEY,
MovieName VARCHAR(100) NOT NULL,
Hero VARCHAR(100),
Heroine VARCHAR(100),
Review VARCHAR(1000) NOT NULL
)
GO
INSERT INTO MovieReview VALUES
(1, 'Eraser', 'Arnold', 'Vanessa', 'Vanessa does not have much role in movie, but Arnold did a good job'),
(2, 'Titanic', 'Leonardo', 'Kate', 'Initially I felt Kate might look older than hero but after watching I did not feel the same'),
(3, 'Zootopia', 'Ginnifer', 'Jason', 'Animation and screen play was good, not many 3D effects')
GO
-- Find names of the movies in which review mentioned both Hero and Heroine names.
SELECT * FROM MovieReview WHERE Review LIKE '%'+Hero+'%' AND Review LIKE '%'+Heroine+'%';
go
------------------------------------------------------------------
/*
Photo Assignment 2
*/
CREATE Table Person (
PersonID INT PRIMARY KEY,
Name VARCHAR(100),
Gender TINYINT,
Salary DECIMAL(10, 2),
MaritalStatus CHAR(1)
);
-- ALTER TABLE Person ADD CONSTRAINT Val_Gender WHERE Gender in (1,0)
ALTER TABLE Person ADD CONSTRAINT Val_Gender CHECK (Gender in (1,0));
ALTER TABLE Person ADD CONSTRAINT Val_MaritalStatus CHECK (MaritalStatus in ('M','S','W'));
CREATE TABLE Provider (
ProviderID INT PRIMARY KEY,
ProviderName VARCHAR(100),
ProviderSpecialty VARCHAR(100),
DateOfBirth DATE,
Gender TINYINT CHECK (Gender IN (0, 1)),
Phone CHAR(10)
);
CREATE TABLE AddressData (
AddressId INT NOT NULL PRIMARY KEY,
City VARCHAR(100),
ZIP CHAR(5),
Street VARCHAR(100),
StreetType VARCHAR(50),
StreetNumber INT,
StreetDirection VARCHAR(10),
State CHAR(2)
);
-- SELECT * FROM AddressData
ALTER TABLE Provider
ADD AddressId INT;
ALTER TABLE Provider
ADD CONSTRAINT FK_Address FOREIGN KEY (AddressId) REFERENCES AddressData(AddressId);