36 Anshuman RDBMS
36 Anshuman RDBMS
36 Anshuman RDBMS
Data refers to the raw facts and figures that are collected and stored in a computer system. It
can be in the form of numbers, text, images, or other types of digital content. Data is the
foundation of any computer system, and it is used to create information.
Information is the result of processing and analyzing data. It is the meaning that is derived from
the data, and it is used to make decisions, solve problems, or gain insights. Information is the
ultimate goal of any computer system, and it is what users are looking for when they interact
with a system.
Data is raw and unprocessed, while information is processed and meaningful. Data is a
collection of facts and figures, while information is the result of analyzing and interpreting those
facts and figures.
- Data: Raw facts and figures that are collected and stored in a computer system.
- Database: A collection of related data that is stored in a computer system. A database is a
structured collection of data that is organized in a way that allows for efficient retrieval and
manipulation.
- Database Management System (DBMS): A software system that allows users to define,
create, maintain, and manipulate databases. A DBMS provides a way to interact with a
database and perform various operations such as querying, updating, and deleting data.
Advantages:
- Simple to use: Traditional file systems are easy to understand and use.
- Fast access: Files can be accessed quickly using the file system.
Disadvantages:
- Limited scalability: Traditional file systems can become slow and inefficient as the number of
files grows.
- No data integrity: Traditional file systems do not provide any data integrity or consistency
checks.
5. Differentiate between Traditional File System v/s Database Management System.
6. Explain how database management system is better than Traditional File System.
A DBMS is better than a traditional file system because it provides a structured way of
organizing and storing data, which allows for better data integrity and consistency. It also
supports transactions and concurrency, which ensures that data is updated correctly and
efficiently. Additionally, a DBMS is scalable and can handle large amounts of data, making it a
more efficient and effective way of managing data.
- Financial institutions: DBMS is used to manage financial transactions, customer data, and
account information.
- Healthcare: DBMS is used to manage patient data, medical records, and treatment
information.
- E-commerce: DBMS is used to manage customer data, order information, and inventory levels.
- Education: DBMS is used to manage student data, course information, and grade records.
Dr. E.F. Codd's rules for RDBMS are a set of principles that define the characteristics of a
relational database management system. The rules are:
SQL (Structured Query Language) is a programming language designed for managing and
manipulating data in relational database management systems. It is used to perform various
operations such as creating, modifying, and querying databases.
We use SQL because it provides a standard way of interacting with databases, making it easier
to manage and manipulate data. It also provides a way to ensure data consistency and integrity,
and it supports transactions and concurrency.
SQL: A standard language for managing and manipulating data in relational database
management systems.
SQL * PLUS: A proprietary extension to SQL that provides additional features and functionality.
SQL * PLUS is used by Oracle databases.
DDL (Data Definition Language) commands are used to define the structure of a database.
They include:
Example:
sql
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(255),
age INT
);
DML (Data Manipulation Language) commands are used to manipulate data in a database.
They include:
Example:
sql
INSERT INTO students (id, name, age) VALUES (1, 'John', 20);
Example:
sql
BEGIN TRANSACTION;
INSERT INTO students (id, name, age) VALUES (1, 'John', 20);
COMMIT;
DQL (Data Query Language) commands are used to query data in a database. They include:
Example:
sql
SELECT * FROM students;
19. Write SQL Query to Create one student relation which contain rollno, name, subject,
state as field.
sql
CREATE TABLE students (
rollno INT,
name VARCHAR(255),
subject VARCHAR(255),
state VARCHAR(255)
);
20. Write SQL Query to insert 3 different record in above student table.
sql
INSERT INTO students (rollno, name, subject, state) VALUES
(1, 'John', 'Math', 'Gujarat'),
(2, 'Alice', 'Science', 'Maharashtra'),
(3, 'Bob', 'English', 'Rajasthan');
21. Write SQL Query to display only name of student who come from Gujarat state.
sql
SELECT name FROM students WHERE state = 'Gujarat';
The ORDER BY clause is used to sort the result set in ascending or descending order. It can be
used with the SELECT, ORDER BY, and LIMIT clauses.
Example:
sql
SELECT * FROM students ORDER BY rollno ASC;
The DISTINCT command is used to return only distinct values from a query. It can be used with
the SELECT and ORDER BY clauses.
Example:
sql
SELECT DISTINCT state FROM students;
The AND, OR, and NOT operators are used to combine conditions in a query.
Example:
sql
SELECT * FROM students WHERE state = 'Gujarat' AND subject = 'Math';
25. Explain RDBMS special operators(in, not in, between .. and, like).
Example:
sql
SELECT * FROM students WHERE rollno IN (1, 2, 3);
Example:
sql
SELECT * FROM students UNION SELECT * FROM teachers;
A subquery is a query that is nested inside another query. It is used to retrieve data from a table
that is related to the data in another table.
Example:
sql
SELECT * FROM students WHERE rollno IN (SELECT rollno FROM teachers);
The GROUP BY clause is used to group rows based on one or more columns. The HAVING
clause is used to filter the grouped rows based on a condition.
Example:
sql
SELECT state, AVG(age) AS average_age FROM students GROUP BY state HAVING
average_age > 20;
DCL (Data Control Language) commands are used to manage access to a database. They
include:
Example:
sql
GRANT SELECT ON students TO user1;
30. What is Constraints? Explain various types of its with syntax and example.
Constraints are rules that are applied to a table to ensure data consistency and integrity. They
include:
Example:
sql
CREATE TABLE students (
rollno INT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
age INT CHECK (age > 18)
);
31. Why we use join in RDBMS? Explain its types with syntax and Example.
We use joins in RDBMS to combine data from two or more tables based on a common column.
There are several types of joins, including:
- INNER JOIN: Returns only the rows that have matching values in both tables.
- LEFT JOIN: Returns all rows from the left table and matching rows from the right table.
- RIGHT JOIN: Returns all rows from the right table and matching rows from the left table.
- FULL OUTER JOIN: Returns all rows from both tables, with NULL values in the columns
where there are no matches.
Example:
sql
SELECT * FROM students INNER JOIN teachers ON students.rollno = teachers.rollno;
An inner join is used to combine two tables based on a common column. It returns only the rows
that have matching values in both tables.
Example:
sql
SELECT * FROM students INNER JOIN teachers ON students.rollno = teachers.rollno;
An outer join is used to combine two tables based on a common column. It returns all rows from
both tables, with NULL values in the columns where there are no matches.
Example:
sql
SELECT * FROM students LEFT JOIN teachers ON students.rollno = teachers.rollno;
A self join is used to combine a table with itself based on a common column. It is used to
retrieve data from the same table.
Example:
sql
SELECT * FROM students AS s1 INNER JOIN students AS s2 ON s1.rollno = s2.rollno;
If a relation is not normalized, it can lead to data redundancy and inconsistencies. This can
cause problems when updating or deleting data, and can also make it difficult to maintain the
database.
Example:
sql
SELECT SUM(age) FROM students;
Aggregate functions are used to perform operations on multiple rows. They include:
Example:
sql
SELECT SUM(age) FROM students;
Example:
sql
SELECT ABS(age) FROM students;
Example:
sql
SELECT ASCII(name) FROM students;
Example:
sql
SELECT CURRENT_DATE FROM students;
41. Compare between SQL and PLSQL.
SQL is a standard language for managing and manipulating data in relational database
management systems. PLSQL is a proprietary extension to SQL that is used by Oracle
databases.
Example:
sql
BEGIN
DECLARE
x INT;
BEGIN
x := 10;
END;
END;
Example:
sql
BEGIN
IF x > 10 THEN
DBMS_OUTPUT.PUT_LINE('x is greater than 10');
ELSIF x = 10 THEN
DBMS_OUTPUT.PUT_LINE('x is equal to 10');
ELSE
DBMS_OUTPUT.PUT_LINE('x is less than 10');
END IF;
END;
A PL/SQL stored procedure is a block of code that can be executed multiple times from different
parts of a program. It is stored in the database and can be called from various locations.
Example:
sql
CREATE OR REPLACE PROCEDURE greet AS
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello, World!');
END;
A PL/SQL user-defined function is a block of code that can be executed multiple times from
different parts of a program. It is stored in the database and can be called from various
locations.
Example:
sql
CREATE OR REPLACE FUNCTION greet AS
RETURN VARCHAR2
AS
BEGIN
RETURN 'Hello, World!';
END;
A trigger is a set of instructions that are executed automatically when a specific event occurs. It
can be used to enforce data integrity, perform auditing, or implement complex business logic.
Example:
sql
CREATE OR REPLACE TRIGGER trg_insert_employee
BEFORE INSERT ON employees
FOR EACH ROW
BEGIN
IF :NEW.salary < 10000 THEN
RAISE_APPLICATION_ERROR(-20001, 'Salary must be at least 10000');
END IF;
END;
This trigger checks if the salary of a new employee is less than 10000 and raises an error if it is.