You are on page 1of 15

Superior University

CS & IT Department
Database Systems
MCS & MIT 2nd
Semester: 2nd Subject: Database Systems Total Marks: 10

What is Database?

A database is an organized series of dependent information, generally stored electronically in a computer


system. A database is normally controlled by means of a database management machine (DBMS).
collectively, the information and the DBMS, in conjunction with the programs that are related to them, are
called a database system
What is Database Management System?
A database commonly requires a complete database software program referred to as a database management
machine (DBMS). A DBMS serves as an interface between the database and its give up users or programs,
permitting customers to retrieve, update, and control how the statistics is prepared and optimized. A DBMS
additionally facilitates oversight and manipulate of databases, permitting an expansion of administrative
operations including performance monitoring, tuning, and backup and recuperation.
A few examples of famous database software or DBMSs consist of MySQL, Microsoft get entry to,
Microsoft sq. Server, FileMaker pro, Oracle Database, and dBASE

What is the difference between Data & information?


Data
1. data is unorganized and unrefined facts
2. Data is a raw material which has no meaning
3. statistics doesn’t rely upon records.
Information
1. Information is a processed, prepared from of data
2. Unlike data information has some meaningful context
3. information depends on data
Write down the name of minimum ten DBMSs?
1. Oracle
2. Microsoft SQL Server
3. MySQL
4. PostgreSQL
5. Microsoft Access.
6. SAP ASE
7. Amazon RDS (Relational Database Service)
8. Informix
9. Robot 3T
10. Toad
What is the difference between file systems and Database Systems?

File system
 file system is a software program that manages and organizes the files in a garage medium inside a
computer.
 DBMS is a software program for dealing with the database.
 Redundant facts may be found in a report system.
 It doesn’t offer backup and restoration of files if it is lost.
 there is no green query processing in file system.
 there's less data consistency in report gadget.
 it's miles much less complicated compared to DBMS.
 report systems provide much less safety in assessment to DBMS.
 it's miles less luxurious than DBMS.

DBMS
 DBMS is a software for managing with the database.
 In DBMS there is no redundant information.
 It gives backup and recovery of data even though it's lost.
 green question processing is there in DBMS.
 there is more data consistency because of the normalization process
 It has more complexity than file system.
 DBMS has greater protection mechanisms as compared to document system.
 It has a relatively higher cost than file system.

What is the difference between Centralized & Distributed Databases?


Centralized Databases
A distributed database is the term used to explain a set of databases stored on multiple computer systems,
but present as a single database to user.
Distributed Databases
A centralized database is saved at a single location; a mainframe pc, for example. it can be accessed,
maintained and changed only from that location
What is the difference between Homogeneous & Heterogeneous Databases?
Homogeneous Databases
 In a homogeneous system, all sites use the same DBMS product
 Homogeneous systems are easier to design and manage.
 The sites use very same software.
 The sites use identical DBMS or DBMS from the same vendor.
 Each site is aware of all other sites and cooperates with other sites to process user requests.
 The database is accessed through a single interface as if it is a single database.
Heterogeneous Databases
 In a heterogeneous distributed database, different sites have different operating systems
 Its system may be composed of relational, network, hierarchical and object-oriented DBMSs.
 Query processing is complex due to dissimilar schemas
 Transaction processing is complex due to dissimilar software.
 In heterogeneous translations are allow to communicate between different DBMS

What is the difference between DDL (Data Definition Language) & DML (Data
Manipulation Language)?

DDL DML
DDL stands for Data Definition DML stands Data Manipulation
Language language
DDL is used to create database schema, DML is used to insert, update or update
constraints, users, table record/data
DDL has no classification It is further divided into procedural
DML and non-procedural DML
Its commands are create, drop, rename Its commands are insert, update and
and alter delete

What is Associative Entity?


An associative entity is a term used in relational and entity–relationship theory. A relational database
requires the implementation of a base table to resolve many-to-many relationships. A base relation
representing this type of entity is referred to as, informally, an associative desk.
What are Keys and also describe all Keys with examples?
There are seven types of keys
1. Primary Key
2. Candidate Key
3. Super Key
4. Foreign Key
5. Composite Key
6. Alternate Key
7. Unique Key

1. Primary Key
A primary key is a column of a table or a set of columns that helps to identify every record present in that
table uniquely. There can be only one primary Key in a table. Also, the primary Key cannot have the same
values repeating for any row. Every value of the primary key has to be different with no repetitions.
The PRIMARY KEY (PK) constraint put on a column or set of columns will not allow them to have any null
values or any duplicates. One table can have only one primary key constraint. Any value in the primary key
cannot be changed by any foreign keys (explained below) which refer to it.
2. Super Key
Super Key is the set of all the keys which help to identify rows in a table uniquely. This means that all those
columns of a table than capable of identifying the other columns of that table uniquely will all be considered
super keys.
Super Key is the superset of a candidate key (explained below). The Primary Key of a table is picked from
the super key set to be made the table’s identity attribute.
3 Candidate Key
Candidate keys are those attributes that uniquely identify rows of a table. The Primary Key of a table is
selected from one of the candidate keys. So, candidate keys have the same properties as the primary keys
explained above. There can be more than one candidate keys in a table.
4. Alternate Key
As stated above, a table can have multiple choices for a primary key; however, it can choose only one. So, all
the keys which did not become the primary Key are called alternate keys.
5. Foreign Key
Foreign Key is used to establish relationships between two tables. A foreign key will require each value in a
column or set of columns to match the Primary Key of the referential table. Foreign keys help to maintain
data and referential integrity. 
6. Composite Key
Composite Key is a set of two or more attributes that help identify each tuple in a table uniquely. The
attributes in the set may not be unique when considered separately. However, when taken all together, they
will ensure uniqueness.
7. Unique Key
Unique Key is a column or set of columns that uniquely identify each record in a table. All values will have
to be unique in this Key. A unique Key differs from a primary key because it can have only one null value,
whereas a primary Key cannot have any null values.
Explain operators with examples?
SQL operators are reserved keywords used in the WHERE clause of a SQL statement to perform
arithmetic, logical and comparison operations. Operators act as conjunctions in SQL statements to fulfill
multiple conditions in a statement.
Since, there are different types of operators in SQL, let us understand the same in the next section of this
article on SQL operators.
Types of SQL Operators

Arithmetic Operators
These operators are used to perform operations such as addition, multiplication, subtraction etc.

Operato
Operation Description
r
+ Addition Add values on either side of the operator
– Subtraction Used to subtract the right-hand side value from the left-hand side value 
Multiplicatio
*  Multiples the values present on each side of the operator
n
/ Division Divides the left-hand side value by the right-hand side value
Divides the left-hand side value by the right-hand side value; and returns the
% Modulus
remainder 

Example
SELECT 40 + 20;
SELECT 40 - 20;
SELECT 40 * 20;
SELECT 40 / 20;
SELECT 40 % 20;
Comparison Operators

These operators are used to perform operations such as equal to, greater than, less than etc.

Operato
Operation Description
r
Used to check if the values of both operands are equal or not. If they are equal,
= Equal to
then it returns TRUE.
> Greater than Returns TRUE if the value of left operand is greater than the right operand.
Checks whether the value of left operand is less than the right operand, if yes
< Less than
returns TRUE.
Greater than or Used to check if the left operand is greater than or equal to the right operand, and
>=
equal to returns TRUE, if the condition is true.
Less than or equal
<= Returns TRUE if the left operand is less than or equal to the right operand.
to
Used to check if values of operands are equal or not. If they are not equal then, it
<> or != Not equal to
returns TRUE.
Checks whether the left operand is not greater than the right operand, if yes then
!> Not greater than
returns TRUE.
!< Not less than Returns TRUE, if the left operand is not less than the right operand.

Nameame Atul LastName Age


Atul Priya Mishra 23
Priya Rohan Kapoor 21
Akanksh
Rohan Singhania 21 Example
a
Example [less then]
Akanksha Vaibhav Jain 20
Select * from student where age <20;
Vaibhav Atul Gupta 25 Example [greater then]
Select * from student where age >20;
Example [less then Equal To]
Select * from student where age <=20;
Example [greater then Equal To]
Select * from student where age >=20;
Logical Operators

The logical operators are used to perform operations such as ALL, ANY, NOT, BETWEEN etc.

Operator Description
ALL Used to compare a specific value to all other values in a set
ANY Compares a specific value to any of the values present in a set.
IN Used to compare a specific value to the literal values mentioned.
BETWEEN Searches for values within the range mentioned.
AND Allows the user to mention multiple conditions in a WHERE clause.
OR Combines multiple conditions in a WHERE clause.
NOT A negate operators, used to reverse the output of the logical operator.
EXISTS Used to search for the row’s presence in the table.
LIKE Compares a pattern using wildcard operators.
Similar to the ANY operator, and is used compares a specific value to some of the values present
SOME
in a set.
Explain all types of Joins with examples?
A JOIN clause is used to combine rows from two or more tables, based on a related column between them.

 SELF-JOIN: A self-join is a regular join, but the table is joined with itself.

SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City


FROM Customers A, Customers B
WHERE A.CustomerID <> B.CustomerID
AND A.City = B.City
ORDER BY A.City;

 (INNER) JOIN: Returns records that have matching values in both tables

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate


FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

 LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right
table

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate


FROM Orders
left JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

 RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left
table

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate


FROM Orders
right JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

 FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table

SELECT Customers.CustomerName, Orders.OrderID


FROM Customers
FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;
What is Selection, Projection and Concatenation explain with examples?
Selection
This operation chooses the subset of tuples from the relation that satisfies the given condition mentioned
in the syntax of selection.
SQL Statement
SELECT, FROM, WHERE
Example
select * from customer where state =’NJ’;
Projection
This operation selects certain required attributes, while discarding other attributes.
SQL Statement
SELECT FROM
Example
Select city, state, address from customer;
concatenation
SQL defines a concatenation operator (||), which joins two distinct strings into one string value.

What are relations and also explain all types of relations with examples?

 One-to-One Relationship

 One-to-Many or Many-to-One Relationship


 Many-to-Many Relationship

One-to-One Relationship
Such a relationship exists when each record of one table is related to only one record of the other table.

For example, if there are two entities ‘Person’ (Id, Name, Age, Address) and ‘Passport’ (Passport_id,
Passport_no). So, each person can have only one passport and each passport belongs to only one person.

Such a relationship is not very common. However, such a relationship is used for security purposes. In the
above example, we can easily store the passport id in the ‘Person’ table only. But, we make another table for
the ‘Passport’ because Passport number may be sensitive data and it should be hidden from certain users. So,
by making a separate table we provide extra security that only certain database users can see it.
One-to-Many or Many-to-One Relationship
Such a relationship exists when each record of one table can be related to one or more than one record of the
other table. This relationship is the most common relationship found. A one-to-many relationship can also be
said as a many-to-one relationship depending upon the way we view it.

For example, if there are two entity type ‘Customer’ and ‘Account’ then each ‘Customer’ can have more than
one ‘Account’ but each ‘Account’ is held by only one ‘Customer’. In this example, we can say that each
Customer is associated with many Accounts. So, it is a one-to-many relationship. But if we see it the other way
i.e. many Accounts is associated with one Customer then we can say that it is a many-to-one relationship.

Many-to-Many Relationship
Such a relationship exists when each record of the first table can be related to one or more than one record of
the second table and a single record of the second table can be related to one or more than one record of the
first table. A many-to-many relationship can be seen as a two one-to-many relationship which is linked by a
'linking table' or 'associate table'. The linking table links two tables by having fields which are the primary key
of the other two tables. We can understand this with the following example.

Example: If there are two entity type ‘Customer’ and ‘Product’ then each customer can buy more than one
product and a product can be bought by many different customers.

Now, to understand the concept of the linking table here, we can have the ‘Order’ entity as a linking table
which links the ‘Customer’ and ‘Product’ entity. We can break this many-to-many relationship in two one-to-
many relationships. First, each ‘Customer’ can have many ‘Order’ whereas each ‘Order’ is related to only one
‘Customer’. Second, each ‘Order’ is related only one Product wheres there can many orders for the same
Product.
In the above concept of linking can be understood with the help of taking into consideration all the attributes
of the entities 'Customer', 'Order' and 'Product'. We can see that the primary key of both 'Customer' and
'Product' entity are included in the linking table i.e 'Order' table. These key act as foreign keys while referring
to the respective table from the 'Order' table.

What is Normalization and also explain all types of normalization with examples?
Normalization is the process of data organization in the form of tables. The normalization process includes
dividing data into tables and making relationships among them.
there are different types of normalization but some of most commonly used normalization is
given below: -
• First Normal Form (1NF)
• Second Normal Form (2NF)
• Third Normal Form (3NF)

First Normal Form (1NF)


In this Normal Form, we tackle the problem of atomicity. Here atomicity means values in the table
should not be further divided. In simple terms, a single cell cannot hold multiple values. If a table
contains a composite or multi-valued attribute, it violates the First Normal Form.

In the above table, we can clearly see that the Phone Number column has two values. Thus it violated the
1st NF. Now if we apply the 1st NF to the above table we get the below table as the result.

By this, we have achieved atomicity and also each and every column has unique values.

Second Normal Form (2NF)


The first condition in the 2nd NF is that the table has to be in 1st NF. The table also should not contain
partial dependency. Here partial dependency means the proper subset of candidate key determines a non-
prime attribute. To understand in a better way let’s look at the below example.
Consider the table

This table has a composite primary key Employee ID, Department ID. The non-key attribute is Office
Location. In this case, Office Location only depends on Department ID, which is only part of the primary
key. Therefore, this table does not satisfy the second Normal Form.
To bring this table to Second Normal Form, we need to break the table into two parts. Which will give us
the below tables:

As you can see, we have removed the partial functional dependency that we initially had. Now, in the
table, the column Office Location is fully dependent on the primary key of that table, which is
Department ID.
Third Normal Form (3NF)
The same rule applies as before i.e., the table has to be in 2NF before proceeding to 3NF. The other
condition is there should be no transitive dependency for non-prime attributes. That means non-prime
attributes (which doesn’t form a candidate key) should not be dependent on other non-prime attributes in
a given table. So a transitive dependency is a functional dependency in which X → Z (X determines Z)
indirectly, by virtue of X → Y and Y → Z (where it is not the case that Y → X)
Let’s understand this more clearly with the help of an example:
The same rule applies as before i.e., the table has to be in 2NF before proceeding to 3NF. The other
condition is there should be no transitive dependency for non-prime attributes. That means non-prime
attributes (which doesn’t form a candidate key) should not be dependent on other non-prime attributes in
a given table.

Let’s understand this more clearly with the help of an example:

As you can see from the above tables all the non-key attributes are now fully functional dependent only
on the primary key. In the first table, columns Student Name, Subject ID and Address are only
dependent on Student ID. In the second table, Subject is only dependent on Subject ID.

What is Views explain it with examples?


Views in SQL are kind of virtual tables. A view also has rows and columns as they are in a real table
in the database. We can create a view by selecting fields from one or more tables present in the
database. A View can either have all the rows of a table or specific rows based on certain condition.
Examples:
Creating View from a single table:
In this example we will create a View named Details View from the table Student-Details.

Query:
CREATE VIEW DetailsView AS
SELECT NAME, ADDRESS
FROM StudentDetails
WHERE S_ID < 5;
To see the data in the View, we can query the view in the
same manner as we query a table.

SELECT * FROM DetailsView;


output
What is Store Procedure explain it with examples?
A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over
again. So if you have an SQL query that you write over and over again, save it as a stored procedure, and
then just call it to execute it. You can also pass parameters to a stored procedure, so that the stored
procedure can act based on the parameter value(s) that is passed.
Stored Procedure Syntax
CREATE PROCEDURE procedure_name
AS
sql_statement
GO;
Example
CREATE PROCEDURE SelectAllCustomers @City nvarchar(30)
AS
SELECT * FROM Customers WHERE City = @City
GO;

What is the use of Group by clause, having clause in Database?


Group by clause
It is used to group row that has a same value. It is used in select statement
Syntax
SELECT column1, column2
FROM table_name
WHERE [ conditions ]
GROUP BY column1, column2
ORDER BY column1, column2

Having clause
It returns row when result matched with the given condition only. It is used with the combination with
group clause. It restricts the data on the group rather than individual record
Example
SELECT Country, COUNT(Id) AS Count
FROM Supplier
GROUP BY Country
HAVING COUNT(Id) > 2
Note:

Complete this assignment in your own words and plagiarism will not be acceptable otherwise marks will be
deducted.

You might also like