36 Anshuman RDBMS

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

1. Write Short notes on Data and Information.

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.

2. Differentiate between Data v/s Information.

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.

3. Define Following Term : Data, Database, Database Management System.

- 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.

4. Explain Traditional File system with its advantages and disadvantage.

Traditional File System:


A traditional file system is a method of organizing and storing files on a computer. It is based on
a hierarchical structure, where files are stored in directories and subdirectories.

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.

Traditional File System:


- Organizes files in a hierarchical structure
- No data integrity or consistency checks
- Limited scalability
- No support for transactions

Database Management System (DBMS):


- Organizes data in a structured manner
- Provides data integrity and consistency checks
- Supports transactions and concurrency
- Scalable and efficient

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.

7. Explain Various application of DBMS in details.

DBMS has various applications in different fields such as:

- 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.

8. Explain Dr. E F Codd Rules for RDBMS.

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:

- Rule 1: Information Rule: Each and every tuple in a table is unique.


- Rule 2: Guaranteed Access Rule: Each and every tuple in a table can be accessed by a single
and unique key.
- Rule 3: Systematic Treatment of NULL Values: NULL values are treated systematically and
consistently throughout the database.
- Rule 4: Dynamic Online Catalog Based on the Relational Model: The database catalog is
dynamic and based on the relational model.
- Rule 5: Comprehensive Data Sublanguage Rule: The database supports a comprehensive
data sublanguage that allows users to define and manipulate data.

9. What is SQL? Why we use it?

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.

10. Explain various SQL important datatypes.

SQL supports various data types such as:

- Integer: Whole numbers, such as 1, 2, 3, etc.


- String: Characters, such as 'hello', 'goodbye', etc.
- Date: Dates, such as '2022-01-01', '2022-01-02', etc.
- Time: Times, such as '12:00:00', '13:00:00', etc.
- Boolean: True or false values.

11. Differentiate between SQL v/s SQL * PLUS.

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.

12. Explain Various SQL Commands.

SQL commands include:

- CREATE: Creates a new database, table, or index.


- INSERT: Inserts new data into a table.
- UPDATE: Updates existing data in a table.
- DELETE: Deletes data from a table.
- SELECT: Retrieves data from a table.
- DROP: Deletes a database, table, or index.
13. Explain DDL Commands with Syntax and Example.

DDL (Data Definition Language) commands are used to define the structure of a database.
They include:

- CREATE TABLE: Creates a new table.


- CREATE INDEX: Creates a new index.
- CREATE VIEW: Creates a new view.
- CREATE PROCEDURE: Creates a new procedure.

Example:
sql
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(255),
age INT
);

14. Explain DML Commands with Syntax and Example.

DML (Data Manipulation Language) commands are used to manipulate data in a database.
They include:

- INSERT INTO: Inserts new data into a table.


- UPDATE: Updates existing data in a table.
- DELETE FROM: Deletes data from a table.

Example:
sql
INSERT INTO students (id, name, age) VALUES (1, 'John', 20);

15. Explain TCL Commands with Syntax and Example.

TCL (Transaction Control Language) commands are used to manage transactions in a


database. They include:

- BEGIN TRANSACTION: Starts a new transaction.


- COMMIT: Commits a transaction.
- ROLLBACK: Rolls back a transaction.

Example:
sql
BEGIN TRANSACTION;
INSERT INTO students (id, name, age) VALUES (1, 'John', 20);
COMMIT;

16. Explain DQL Commands with Syntax and Example.

DQL (Data Query Language) commands are used to query data in a database. They include:

- SELECT: Retrieves data from a table.


- SELECT DISTINCT: Retrieves distinct values from a table.

Example:
sql
SELECT * FROM students;

17. Explain various rules for Table name in RDBMS.

Table names in RDBMS should follow these rules:

- Start with a letter: Table names should start with a letter.


- Use only alphanumeric characters: Table names should only contain alphanumeric characters.
- Use underscores: Table names can use underscores to separate words.
- Avoid special characters: Table names should avoid special characters such as !, @, #, etc.

18. Define following terms : Tuple, Attribute, Cardinality, Domain, Degree.

- Tuple: A single row in a table.


- Attribute: A single column in a table.
- Cardinality: The number of rows in a table.
- Domain: The set of possible values for an attribute.
- Degree: The number of attributes in a table.

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';

22. Explain Order by clause in RDBMS with example.

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;

23. What is Distinct command'? How it is used in SQL?

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;

24. Explain AND, OR, NOT Operator with example.

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).

RDBMS special operators include:

- IN: Tests if a value is in a list.


- NOT IN: Tests if a value is not in a list.
- BETWEEN: Tests if a value is within a range.
- LIKE: Tests if a value matches a pattern.

Example:
sql
SELECT * FROM students WHERE rollno IN (1, 2, 3);

26. Explain various set operations (union, minus, intersect)

Set operations include:

- UNION: Combines two sets into one.


- MINUS: Subtracts one set from another.
- INTERSECT: Returns the intersection of two sets.

Example:
sql
SELECT * FROM students UNION SELECT * FROM teachers;

27. What is sub query? Why it is needed? Explain it with example.

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);

28. Explain Group by and Having clause in RDBMS.

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;

29. Explain DCL Commands with Syntax and Example.

DCL (Data Control Language) commands are used to manage access to a database. They
include:

- GRANT: Grants privileges to a user.


- REVOKE: Revokes privileges from a user.

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:

- PRIMARY KEY: Ensures that a column is unique.


- FOREIGN KEY: Ensures that a column references a column in another table.
- UNIQUE: Ensures that a column is unique.
- CHECK: Ensures that a column meets a specific condition.

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;

32. Explain Inner Join with syntax and Example.

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;

33. Explain Outer Join with syntax and Example.

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;

34. Explain Self Join with syntax and Example.

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;

35. What is Normalization? What happen if relation are not normalize'?


Normalization is the process of organizing the data in a database to minimize data redundancy
and improve data integrity. It involves dividing the data into smaller, more manageable pieces
and storing them in separate tables.

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.

36. Explain SQL Built in functions.

SQL built-in functions include:

- SUM: Returns the sum of a column.


- AVG: Returns the average of a column.
- MAX: Returns the maximum value in a column.
- MIN: Returns the minimum value in a column.
- COUNT: Returns the number of rows in a table.

Example:
sql
SELECT SUM(age) FROM students;

37. Explain Aggregate Function (Multi row functions)

Aggregate functions are used to perform operations on multiple rows. They include:

- SUM: Returns the sum of a column.


- AVG: Returns the average of a column.
- MAX: Returns the maximum value in a column.
- MIN: Returns the minimum value in a column.
- COUNT: Returns the number of rows in a table.

Example:
sql
SELECT SUM(age) FROM students;

38. Explain at least seven Numeric functions with example.

Numeric functions include:

- ABS: Returns the absolute value of a number.


- CEIL: Returns the ceiling of a number.
- FLOOR: Returns the floor of a number.
- MOD: Returns the remainder of a division.
- POWER: Returns the power of a number.
- SQRT: Returns the square root of a number.
- TRUNCATE: Returns the truncated value of a number.

Example:
sql
SELECT ABS(age) FROM students;

39. Explain at least seven Character functions with example.

Character functions include:

- ASCII: Returns the ASCII value of a character.


- CHAR: Returns a character based on a number.
- CONCAT: Concatenates two strings.
- LENGTH: Returns the length of a string.
- LOWER: Returns the lowercase of a string.
- UPPER: Returns the uppercase of a string.
- SUBSTRING: Returns a substring from a string.

Example:
sql
SELECT ASCII(name) FROM students;

40. Explain at least seven Date functions with example.

Date functions include:

- CURRENT_DATE: Returns the current date.


- CURRENT_TIME: Returns the current time.
- CURRENT_TIMESTAMP: Returns the current timestamp.
- DATE: Returns the date part of a timestamp.
- TIME: Returns the time part of a timestamp.
- TIMESTAMP: Returns the timestamp part of a timestamp.
- EXTRACT: Returns a specific part of a timestamp.

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.

42. Explain PL/SQL Block Structure.

A PL/SQL block is a sequence of statements that are executed together. It consists of a


declaration section, an executable section, and an exception section.

Example:
sql
BEGIN
DECLARE
x INT;
BEGIN
x := 10;
END;
END;

43. Explain various control statement in PL/SQL.

Control statements in PL/SQL include:

- IF: Used to execute a statement based on a condition.


- ELSIF: Used to execute a statement based on a condition.
- ELSE: Used to execute a statement if the condition is false.
- LOOP: Used to execute a statement repeatedly.
- WHILE: Used to execute a statement repeatedly based on a condition.
- CASE: Used to execute a statement based on a condition.

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;

44. Explain various types of loops in PL/SQL.

PL/SQL provides several types of loops to repeat a set of statements:

1. FOR LOOP: Used to iterate over a range of values.


sql
FOR i IN 1..10 LOOP
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;

2. WHILE LOOP: Used to repeat a set of statements while a condition is true.


sql
DECLARE
i NUMBER := 1;
BEGIN
WHILE i <= 10 LOOP
DBMS_OUTPUT.PUT_LINE(i);
i := i + 1;
END LOOP;
END;

3. LOOP: Used to repeat a set of statements until a condition is met.


sql
DECLARE
i NUMBER := 1;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE(i);
i := i + 1;
EXIT WHEN i > 10;
END LOOP;
END;

4. CURSOR LOOP: Used to iterate over a cursor.


sql
DECLARE
CURSOR emp_cur IS
SELECT * FROM employees;
emp_rec emp_cur%ROWTYPE;
BEGIN
OPEN emp_cur;
LOOP
FETCH emp_cur INTO emp_rec;
DBMS_OUTPUT.PUT_LINE(emp_rec.ename);
EXIT WHEN emp_cur%NOTFOUND;
END LOOP;
CLOSE emp_cur;
END;

45. Explain PL/SQL Stored Procedure.

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;

46. Explain PL/SQL User-defined Function.

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;

47. Compare between user-defined function and stored procedure.


User-defined Function (UDF):

- Return value: Can return a value.


- Usage: Can be used in SQL statements like SELECT, INSERT, UPDATE, and DELETE.
- Syntax: Uses the `FUNCTION` keyword.

Stored Procedure (SP):

- Return value: Does not return a value.


- Usage: Can be used to perform complex operations, but cannot be used directly in SQL
statements.
- Syntax: Uses the `PROCEDURE` keyword.

48. Explain Trigger with example.

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.

You might also like