DBMS
DBMS
What is Data ?
Ans : Data is a raw fact that is not processes into information.
What is Information ?
Ans : Information that is consist of raw bytes in processed form/
Information is nothing but that data being viewed in a structured
format.
What is a Database?
Ans : A location where data is stored form where it can be easily
accessed modify and update . A database is an organized collection of
related data, so that it can be easily accessed and managed. The main
purpose of the database is to operate a large amount of information by
storing, retrieving, and managing data.
Evolution of Database :
What is DBMS ?
Ans : Database Management System is software or technology used to
manage data from a database. DBMS is a system that enables you to
store, modify and retrieve data in an organized way. It also provides
security to the database.
Features Of DBMS ?
Ans :
Data modeling: A DBMS provides tools for creating and modifying
data models, which define the structure and relationships of the data
in a database.
Data storage and retrieval: A DBMS is responsible for storing and
retrieving data from the database, and can provide various methods
for searching and querying the data.
RDBMS: Data is organized in the form of tables and each table has a
set of rows and columns.
Define ?
Tuple - A tuple is a single row in a database that contains a single
record.
Cardinality : cardinality represents the number of times an entity of
an entity set participates in a relationship set. Or we can say that the
cardinality of a relationship is the number of tuples (rows) in a
relationship.
External level
Internal level
The file management system was the first method used to store
data in the computer is a database
Each data item is stored on a disc sequentially in one large file
If you want to locate a particular item the search start from the
beginning and each item is checked one by one sequentially till
the match is found.
Drawbacks
Data duplication, very poor security, retrieving of data is very
slow,
Ans :
Atomcity - The term atomicity defines that the data remains atomic. It
means if any operation is performed on the data, either it should be
performed or executed completely or should not be executed at all. It
further means that the operation should not break in between or
execute partially.
Durability - In DBMS, the term durability ensures that the data after
the successful execution of the operation becomes permanent in the
database. The durability of the data should be so perfect that even if
the system fails or leads to a crash, the database still survives with the
help of a secondary disk.
What is ER Model ?
Ans - This model is used to define the data elements and relationship for a
specified system.It develops a conceptual design for the database.
Weak Entity – Entity that doesn’t contain any key attribute and depends on
other entity . Represented by double box
Composite Attribute :An attribute that composed of many other attributes is known
as a composite attribute. The composite attribute is represented by an ellipse, and
those ellipses are connected with an ellipse.
Multivalued Attribute :An attribute can have more than one value. These attributes
are known as a multivalued attribute. The double oval is used to represent
multivalued attribute.For example, a student can have more than one phone
number.
Derived Attribute : An attribute that can be derived from other attribute is known as
a derived attribute. It can be represented by a dashed ellipse.
Link : https://www.javatpoint.com/dbms-er-model-concept
Keys : https://prepinsta.com/dbms/keys/
Generalization Specialization
Generalization is a bottom-up manner approach Specialization is a top-down manner approach
In Generalization, schema size reduces. In Specialization, schema size increases.
Generalization is applied to a group of entities. Specialization is applied to a single entity.
Generalization forms a single entity from Specialization forms multiple entities from a
multiple entities. single entity.
Inheritance is not used in generalization. Inheritance can be used in specialization.
What is Normalization ?
1st Normal Form : Every column should have same name and should maintain domain
integrity and most important there should not be any multivalue attribues in a
column.
2nd Normal Form : The table should be in 1 st NF and there should not be any partial
dependency of a non-prime attribute on a prime attribute . For Eg : There are four
attributes A,B,C,D in which A&B determines D and B Determines C and A&B are
prime attributes and C&D are non prime attributes . So if there is a partial
dependency between B and C then if the value of B attribute is NULL then it would
not be possible to determine D , but in the case of C since it is fully dependent on
both A&B then even if the value of B is Null it can be determine by A alone.
3rd Normal Form : The table should be in 2 nd Normal Form and there should not be
any transitive dependency(when a non-prime attribute determines another non-
prime attribute) between non prime attributes . For Eg - There are four attributes
A,B,C,D in which A&B determines C and C Determines D and A&B are prime
attributes and C&D are non prime attributes . In this scenario A&B tries to determine
D with the help of C which is an non-prime attributes , but since C is an NPA there is
a possibility that C may be NULL in that case it would be difficult to find the D. In
order to solve this we will make two tables one in which A&B will determine C and
one in which C will act as PA and determines D .
Boyce Codd Normal Form : It states that the attribute should belongs to a super key
in-order to derive another attribute which could possibly be a prime attribute also.
CONSTRAINTS :
Default : when a default clause or constraint is applied on a column , the rows gets
inserted with that default value if the user has not given a value.
Not Null : Column should have values other than Null Value. Null value is different
from zero value or a field that contain spaces Null represents a record where data may be
missing data or data for that record may be optiona
Unique : It ensures that all the data in the columns are unique . It can be applied to
any number of columns.
Identifies a record uniquely in a table It helps to maintain unique data in the required columns of the
table
It will not allow null values It helps to maintain unique data in the required columns of the
table
Only one primary key is allowed in a A unique key can be applied to any number of columns in the table
table
Check : It helps to verify whether the data enter by user satisfy the condition or not.
Relational Algebra :
https://www.geeksforgeeks.org/introduction-of-relational-
algebra-in-dbms/
Types of Indexing :
1.Primary Index: When the data file is ordered and unique it satisfy the primary
index condtion .
1. Primary Index : The index table which is formed using primary key is called as
primary index . It is operated on unique key and ordered data (sorted).
It is of two type :
Dense Indexing : In this technique for every record in a block of database ,
individual key and pointer is been inserted in index table. Due to this searching
becomes fast but it takes more memory .
II. Sparse Indexing : In this technique , search is slow and pointer for a block is stored
which contains a limited set of data and not for individual data as in dense ,
consumes less memory.
2. Clustered Indexing : In this technique the data is ordered and not unique , hence
to access the data we use a concept called as block hanger inorder to access the data
that might be present in multiple blocks. https://www.youtube.com/watch?
v=UpJ9ICmzaAM
3. Secondary Index : Consider a table which consist of Eid,name and pan card , so we
can use primary index if we want to search a data based on Eid since it is unique and
sorted , but atimes we require to search a data based on unordered data hence
primary index will not work in that case . Hence secondary index is used , suppose we
want to search a data based on pan card so we will create a dense secondary index
or if we want to search data based on name then we can use this index.
SQL
SQL is a standard database language used to access and manipulate data in databases. SQL
stands for Structured Query Language. SQL was developed by IBM Computer Scientists in the
1970s.
SQL Datatypes:
2. Character : char(fixed length), varchar(variables length). The main difference between char
and varchar is that in char if the input is less than the fixed length than it is padded with extra
memory space whereas in varchar it is ok if the length is less than the mentinoned argument.
3. Date : It has DATE function which has format YYYY-MM-DD. Select NOW is used for
getting the latest date and time.
4.Binary Large Object (BLOB): It is used to store binary objects like images and
audios.
Types of Language :
1.DDL : It is called as data definition language which is used to define the structure of database
and also the storage for it.
INSERT INTO :
Inserting with column and value : INSERT INTO table_name
(columns….) VALUES (values….);
Inserting with only value : INSERT INTO table_name
VALUES(values….);
Inserting the values from other table : INSERT INTO table1 SELECT
* FROM table2;
Inserting specific columns from other table : INSERT INTO table1
(column1,column2) SELECT column1,column2 FROM table2;
Revoke – It is used to take away the privilegdes and rights from the user.
TCL : Transaction refers to a set of tasks which is executed as a single execution unit.
Savepoint – It is a point from where the rollback can be performed rather than
rollbacking entire transaction.
DD
L TCL
Files can be easily maintained It manages the different tasks with the
4.
by DDL commands. important feature, Atomicity.
Where clause : It is used to filter the records without grouping based on a condition.
Group by clause : It is used to group the rows based on a specific column.It is used
with aggregrate functions like avg,count,min,max.
Joins : A JOIN clause is used to combine rows from two or more tables, based
on a related column between them.
Natural Join : Natural Join in SQL combines records from two or more tables
based on the common column between them. The common column must have
the same name and data type in both the tables. SQL joins the tables based on
this common column and hence, we do not need to explicitly specify the join
condition.
The INNER JOIN keyword selects records that have matching values in
both tables.
The LEFT JOIN keyword returns all records from the left table
(table1), and the matching records from the right table (table2).
The RIGHT JOIN keyword returns all records from the right table
(table2), and the matching records from the left table (table1).
The FULL OUTER JOIN keyword returns all records when there is a
match in left (table1) or right (table2) table records.
DBMS RDBMS
It deals with small quantity of data. It deals with large amount of data.
Data redundancy is common in this Keys and indexes do not allow Data
model. redundancy.
Ans : It is a short piece of code that gets exceuted automatically when a set of
events occurred on a table .It plays an important role in maintain the data
integrity and consistency. Eg : John is a marketing officer in a company so
when a new customer comes they had to send a greeting msg , if it were 2-3
customers john could have done it manually but what if there are more
customers.
Syntax :
On table_name
For each row | for each column
Stored procedures are prepared SQL code that you save so you can reuse it 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 call it to run it. You can also pass parameters to stored
procedures so that the stored procedure can act on the passed parameter values.
Stored Procedures are created to perform one or more DML operations on Database.
It is nothing but the group of SQL statements that accepts some input in the form of
parameters and performs some task and may or may not return a value.
UNION and UNION ALL are used to join the data from two or more
tables. However,
UNION removes duplicate rows and picks. The rows are distinct
after combining the data from the tables were
UNION ALL does not remove the duplicate rows; it just picks all
the data from the tables.
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.
B-TREE : It is a balanced tree which has a leaf node at same level . It is used for
the indexing purposes to create a index table by using tree data structure in which a
node represent key value and pointer to point in the secondary memory.
NOSQL : It means NO SQL i.e it works with unstructured non relational data like document
based or key-value pair . Eg – MONGO DB . It supports semi-structured data and volatile
data
No, a NULL value is distinct from zero and blank space in that it denotes a
value that is assigned, unknown, unavailable, or not applicable, as opposed to
blank space, which denotes a character, and zero, which denotes a number.
For instance, a NULL value in "number of courses" taken by a student
indicates that the value is unknown, but a value of 0 indicates that the
student has not taken any courses.