Dbms Assignment: 1. What Is The Use of SQL and Nonsql Databases? When To Use Which One. Specify With Scenarios?
Dbms Assignment: 1. What Is The Use of SQL and Nonsql Databases? When To Use Which One. Specify With Scenarios?
Ayushi Agarwal
Roll No. - 12014
3rd Sem, B.Tech
1. What is the use of SQL and NonSQL databases? When to use which one. Specify
with scenarios?
SQL stands for Structured Query Language. It's used for relational databases. A SQL
database is a collection of tables that stores a specific set of structured data.
We can use it in:
● Creating a new database with SQL and inserting new data in the database,
● Modifying or update previous data and retrieving data from the database,
● Deleting data and creating a new table in one database or even drop the table,
● Setting permissions for tables, procedures and views, and creating functions,
views and storing procedures.
Hence, in a database management system, all works are accomplished with the assistance
of SQL.
NoSQL Database is a non-relational Data Management System that does not require a
fixed schema. It avoids joins, and is easy to scale. The major purpose of using a NoSQL
database is for distributed data stores with humongous data storage needs. NoSQL is used
for Big data and real-time web apps. For example, companies like Twitter, Facebook and
Google collect terabytes of user data every single day.
The preference among SQL and NoSQL relies upon completely on character
situations as each of them has blessings in addition to disadvantages. SQL databases are
long-set up with a hard and fast schema layout and a fixed structure. They are perfect for
packages that require multi-row transactions which include an accounting machine or for
legacy structures that had been constructed for a relational structure.
On the other hand, NoSQL databases are effortlessly scalable, flexible, and easy to apply
as they haven't any inflexible schema. They are perfect for packages without unique
schema definitions which include content material control structures, huge statistics
packages, real-time analytics, etc
2.
Table :- Employee
fname mname Iname ssn badate sex address salary sssn dno
(f-ssn) (f-dnumber)
Table :- Department
dname dnumber mgrssn (f-ssn) mgrstart date
Table :- Dept_loacation
dnumber (f-number) dlocation
Table :- Project
pname pnumber plocation pnum
Table :- Works_on
esssn (f-ssn) pno hrs
Table :- Dependent
essn dapentdentname sex bdate rel
Query 1: For every project located in “Safford” list pno, compolting dno, dept manager
name.
Answer 1: - SELECT pno, dno, fname
From Employee as emp, Department as dept, Project as prjt, Works_on as
wrks
Where emp.sssn=mgrssn
And emp.sssn=wks=.essn
And emp.ssn=dept.essn
And prjt.plocation= “%Safford”
Query 2: Count no. of employee in each dept in form of dname and count.
Answer 2: SELECT dname , count(fname)
From Employee as emp, Works_on as wks, Department as dept
Where emp.sssn=wks=.essn
And emp.ssn=depndt.essn
And wks. hrs>10
Query 3: Display employee names who are working more than 10 hrs.
Answer 3: SELECT fname, name,lname
From Employee as emp, Dependent as depndt, Works_on as wrks
Where emp.ssn=depndt.essn
And wrk.hrs>10
Query 4: Select query to find out project no. that involve an employee with the name
“SMITH” as worker.
Answer 4: SELECT pnumber
From Employee as emp, Project as prjt, Works_on as wrks
Where emp.fname= “%smith”
And wrks.pno=prjt.pnumber
And wrks.essn=emp.sssn
Query 5: All the project no. of the department which is managed by "smith".
Answer 5: SELECT pnumber
From Employee as emp, Department as dept, Project as prjt, Works_on as
wrks
Where emp.sssn=dept.mgrssn
And wrks.pno=prjt.pnumber
And wrks.essn=emp.sssn
And emp.fname= “%smith”
Query 6: List of all project no. Where employe smith working both as worker and
manager.
Answer 6: SELECT pnumber
From Employee as emp, Department as dept, Project as prjt, Works_on as
wrks
Where emp.sssn=dept.mgrssn
And wrks.pno=prjt.pnumber
And wrks.essn=emp.sssn
And emp.fname= “%smith”
And dept.dname in ( “worker”, “manager”)
4. Consider the relation R, which has attributes that hold schedules of courses and
sections at a university; R = {Course_no, Sec_no, Offering_dept, Credit_hours,
Course_level, Instructor_ssn, Semester, Year, Days_hours, Room_no,
No_of_students}. Suppose that the following functional dependencies hold on R:
{Course_no} → {Offering_dept, Credit_hours, Course_level} {Course_no, Sec_no,
Semester, Year} → {Days_hours, Room_no, No_of_students, Instructor_ssn}
{Room_no, Days_hours, Semester, Year} → {Instructor_ssn, Course_no, Sec_no}.
Try to determine which sets of attributes form keys of R. How would you normalize
this relation?
Let us use the following shorthand notation:
C = CourseNo, SN = SecNo, OD = OfferingDept, CH = CreditHours, CL = CourseLevel,
I = InstructorSSN, S = Semester, Y = Year, D = Days_Hours, RM = RoomNo,
NS = NoOfStudents
Hence, R = {C, SN, OD, CH, CL, I, S, Y, D, RM, NS}, and the following functional
dependencies hold:
{C} -> {OD, CH, CL}
{C, SN, S, Y} -> {D, RM, NS, I}
{RM, D, S, Y} -> {I, C, SN}
First, we can calculate the closures for each left-hand side of a functional dependency,
since these sets of attributes are the candidates to be keys:
+
(1) {𝐶} = {C, OD, CH, CL}
+
(2) Since {C, SN, S, Y} -> {D, RM, NS, I}, and {𝐶} = {C, OD, CH, CL}, we get:
+
{𝑅𝑀, 𝐷, 𝑆, 𝑌} = {C, SN, S, Y, D, RM, NS, I, OD, CH, CL} = R
+
(3) Since {RM, D, S, Y} -> {I, C, SN}, we know that {𝑅𝑀, 𝐷, 𝑆, 𝑌} contains {RM, D,
+
S, Y, I, C, SN}. But{𝐶} contains {OD, CH, CL} so these are also contained in
+
{𝑅𝑀, 𝐷, 𝑆, 𝑌} since C is already there. Finally, since {C, SN, S, Y} are now all in
+ +
{𝑅𝑀, 𝐷, 𝑆, 𝑌} and {𝑅𝑀, 𝐷, 𝑆, 𝑌} contains {NS} (from (2) above), we get:
+
{𝑅𝑀, 𝐷, 𝑆, 𝑌} = {RM, D, S, Y, I, C, SN, OD, CH, CL, NS} = R
Hence, both K1 = {C, SN, S, Y} and K2 = {RM, D, S, Y} are (candidate) keys of R.
By applying the general definition of 2NF, we find that the functional dependency {C} ->
{OD, CH, CL} is a partial dependency for K1 (since C is included in K1). Hence, R is
normalized into R1 and R2 as follows:
R1 = {C, OD, CH, CL}
R2 = {RM, D, S, Y, I, C, SN, NS} with candidate keys K1 and K2
Since neither R1 nor R2 have transitive dependencies on either of the candidate keys, R1
and R2 are in 3NF also. They also both satisfy the definition of BCNF.