0% found this document useful (0 votes)
13 views12 pages

DBMS VIVA 1 - Merged - Merged

Uploaded by

Ajay Kumar R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views12 pages

DBMS VIVA 1 - Merged - Merged

Uploaded by

Ajay Kumar R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Viva Questions and Answers (Database Management

System)

1. What is a Database?
A database is an organized collection of data, generally stored and accessed electronically
from a computer system. Databases allow efficient management and retrieval of data.

2. What is a Database Management System (DBMS)?


A DBMS is software that enables the creation, manipulation, and management of data in a
database. It provides tools to store, retrieve, and ensure data integrity.

3. What are the types of DBMS?


The types of DBMS include:
1. Hierarchical DBMS
2. Network DBMS
3. Relational DBMS (RDBMS)
4. Object-oriented DBMS

4. What is the difference between DBMS and RDBMS?


A DBMS stores data as files, while an RDBMS stores data in tabular form and supports
relationships between tables. RDBMS also supports SQL and data integrity rules.

5. What is a primary key?


A primary key is a unique identifier for each record in a table. It ensures that no two rows
have the same value for the primary key column.

6. What is a foreign key?


A foreign key is a field in one table that uniquely identifies a row of another table. It is used
to maintain referential integrity between the two tables.

7. What is normalization in DBMS?


Normalization is the process of organizing data to minimize redundancy. It involves
dividing large tables into smaller ones and linking them using relationships.

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR


8. What is denormalization?
Denormalization is the process of combining normalized tables into one larger table for
performance optimization, even though it introduces some redundancy.

9. What are the ACID properties in DBMS?


ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure
reliable transaction processing in a DBMS.

10. What is indexing in DBMS?


Indexing is a technique to improve the performance of database queries. It allows faster
retrieval of records by creating an index on columns in the table.

11. What is a view in SQL?


A view is a virtual table that represents the result of a SQL query. It does not store data
physically but simplifies complex queries.

12. What are joins in SQL?


Joins combine rows from two or more tables based on a related column. Types of joins
include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN.

13. What is a trigger in DBMS?


A trigger is a stored procedure in a database that automatically executes in response to
certain events on a table or view (like INSERT, UPDATE, DELETE).

14. What is a stored procedure?


A stored procedure is a set of SQL statements stored in the database and can be executed
repeatedly. It is useful for automating tasks.

15. What is the difference between DELETE, TRUNCATE, and DROP in SQL?
- DELETE removes rows from a table based on a condition.
- TRUNCATE removes all rows from a table but keeps the table structure.
- DROP removes the table and its structure completely from the database.

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR


16. What are database constraints?
Constraints are rules applied to data in a table to enforce data integrity. Examples include
PRIMARY KEY, FOREIGN KEY, NOT NULL, UNIQUE, and CHECK.

17. What is a transaction in DBMS?


A transaction is a sequence of operations performed as a single logical unit. It follows ACID
properties to ensure consistency and reliability.

18. What is a deadlock in DBMS?


A deadlock occurs when two or more transactions are waiting for each other to release
resources, causing all of them to be blocked.

19. What is the role of the Data Definition Language (DDL)?


DDL includes SQL commands such as CREATE, ALTER, and DROP that are used to define and
modify the structure of database objects like tables and indexes.

20. What is a schema in DBMS?


A schema defines the structure and organization of a database. It outlines how data is
stored, including tables, views, and indexes.

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR


Viva Questions and Answers (DDL & DML)

1. What is DDL?
DDL stands for Data Definition Language. It is used to define and manage database schema
objects like tables, indexes, and views. DDL commands include CREATE, ALTER, DROP,
TRUNCATE, COMMENT, and RENAME.

2. What are the commonly used DDL commands?


- CREATE: Used to create new tables, databases, indexes, etc.
- ALTER: Used to modify the existing structure of a database object like tables.
- DROP: Used to delete tables, views, or databases.
- TRUNCATE: Used to remove all records from a table without affecting the table structure.
- RENAME: Used to change the name of a table or other objects.

3. What is the difference between TRUNCATE and DELETE?


- TRUNCATE is a DDL command that deletes all rows from a table but keeps the structure of
the table intact. It cannot be rolled back.
- DELETE is a DML command that removes rows based on a condition or all rows without
deleting the table structure, and it can be rolled back if done within a transaction.

4. What is DML?
DML stands for Data Manipulation Language. It is used to retrieve, insert, update, and delete
data in a database. DML commands include SELECT, INSERT, UPDATE, and DELETE.

5. What is the difference between DDL and DML?


- DDL commands define or alter the structure of database objects (tables, views, etc.), and
changes are permanent and cannot be rolled back (unless supported by transactional DDL).
- DML commands manipulate the data within the objects and can usually be rolled back in a
transaction.

6. What is the syntax for creating a table in SQL?


The syntax for creating a table is:
CREATE TABLE table_name (
column1 datatype [constraint],
column2 datatype [constraint],
...

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR


);
For example:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
Name VARCHAR(100),
Age INT,
Department VARCHAR(50)
);

7. What are constraints in SQL? Name a few types.


Constraints are rules applied to columns in a table to enforce data integrity. Types include:
- PRIMARY KEY: Ensures that the column has unique, non-null values.
- FOREIGN KEY: Enforces a relationship between two tables.
- UNIQUE: Ensures that all values in a column are different.
- NOT NULL: Ensures that a column cannot have NULL values.
- CHECK: Ensures that the values in a column satisfy a specific condition.

8. How does the ALTER command work in SQL?


The ALTER command is used to modify the structure of an existing table. Examples:
- Add a new column:
ALTER TABLE table_name ADD column_name datatype;
- Modify a column's datatype:
ALTER TABLE table_name MODIFY column_name new_datatype;
- Drop a column:
ALTER TABLE table_name DROP COLUMN column_name;

9. What is the purpose of the SELECT statement in SQL?


The SELECT statement is a DML command used to retrieve data from one or more tables in
a database. The basic syntax is:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
You can also use aggregate functions, joins, and subqueries with the SELECT statement.

10. What is the difference between a PRIMARY KEY and a UNIQUE


constraint?
- PRIMARY KEY: Enforces uniqueness and does not allow NULL values in the column. Each
table can have only one primary key.

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR


- UNIQUE: Enforces uniqueness but allows NULL values. A table can have multiple UNIQUE
constraints.

11. How do you delete a table from a database?


The DROP command is used to delete a table completely, along with all the data and
structure:
DROP TABLE table_name;

12. What is the purpose of the INSERT INTO statement in SQL?


The INSERT INTO statement is a DML command used to insert new rows into a table. The
syntax is:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);

13. What is the UPDATE statement used for?


The UPDATE statement is used to modify existing records in a table. The basic syntax is:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

14. Can you explain what a FOREIGN KEY is in SQL?


A FOREIGN KEY is a column or set of columns in one table that refers to the PRIMARY KEY
in another table. It is used to ensure referential integrity between the two tables,
establishing a relationship between them.

15. What is a view in SQL, and how is it created?


A view is a virtual table that is based on the result of a SELECT query. It doesn't store the
data physically, but presents data from one or more tables. The syntax for creating a view is:
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR


Viva Questions and Answers (Logical & Relational
Operators)

1. What are relational operators in SQL?


Relational operators are used to compare two values and return a boolean result (TRUE or
FALSE). The commonly used relational operators in SQL are:
- Equal to (=)
- Not equal to (<> or !=)
- Greater than (>)
- Less than (<)
- Greater than or equal to (>=)
- Less than or equal to (<=)

2. Can you give an example of using a relational operator in a SELECT


statement?
For example, to find employees with a salary greater than 5000, the query would be:
SELECT * FROM employees WHERE salary > 5000;

3. What are logical operators in SQL?


Logical operators are used to combine multiple conditions in SQL queries. The common
logical operators are:
- AND: Returns TRUE if both conditions are TRUE.
- OR: Returns TRUE if at least one condition is TRUE.
- NOT: Reverses the result of a condition (TRUE becomes FALSE, and vice versa).

4. How is the AND operator used in a SQL query?


The AND operator is used to combine two conditions, and both must be true for the result to
be returned. For example:
SELECT * FROM employees WHERE salary > 5000 AND department = 'Sales';
This query will return employees with a salary greater than 5000 and who work in the Sales
department.

5. How is the OR operator used in a SQL query?


The OR operator is used to combine two conditions, where at least one condition must be
true for the result to be returned. For example:
SELECT * FROM employees WHERE salary > 5000 OR department = 'HR';

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR


This query will return employees with a salary greater than 5000 or those who work in the
HR department.

6. How does the NOT operator work in SQL?


The NOT operator is used to negate a condition. For example, the query:
SELECT * FROM employees WHERE NOT department = 'Sales';
Will return all employees who do not work in the Sales department.

7. What is the difference between the = and <> operators?


- The = operator checks if two values are equal. For example:
SELECT * FROM employees WHERE department = 'HR';
This will return all employees in the HR department.
- The <> operator checks if two values are not equal. For example:
SELECT * FROM employees WHERE department <> 'HR';
This will return employees not in the HR department.

8. Can you combine relational and logical operators in a single query?


Yes, you can combine relational and logical operators to form more complex queries. For
example:
SELECT * FROM employees WHERE salary > 5000 AND department = 'Sales' OR department
= 'HR';
This query will return employees with a salary greater than 5000 in the Sales department,
or those in the HR department.

9. What is the precedence of logical operators in SQL?


In SQL, the precedence of logical operators is as follows:
1. NOT
2. AND
3. OR
You can use parentheses to change the precedence. For example:
SELECT * FROM employees WHERE department = 'Sales' OR (salary > 5000 AND
department = 'HR');

10. How can you test for null values in SQL using relational operators?
In SQL, you cannot use relational operators like = or <> to test for NULL values directly.
Instead, you should use the IS NULL or IS NOT NULL operators. For example:
SELECT * FROM employees WHERE salary IS NULL;
This will return employees whose salary is not set (NULL).

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR


11. How do you check if a value is between a certain range in SQL?
You can use the BETWEEN operator to check if a value lies within a certain range. For
example:
SELECT * FROM employees WHERE salary BETWEEN 3000 AND 6000;
This query will return employees with salaries between 3000 and 6000, inclusive.

12. How do you check if a value is part of a set of values in SQL?


You can use the IN operator to check if a value is part of a specified set of values. For
example:
SELECT * FROM employees WHERE department IN ('HR', 'Sales', 'IT');
This query will return employees in the HR, Sales, or IT departments.

13. What is the purpose of the LIKE operator in SQL?


The LIKE operator is used to search for a specified pattern in a column. It is commonly used
with wildcards (% for zero or more characters, and _ for a single character). For example:
SELECT * FROM employees WHERE name LIKE 'J%';
This query will return all employees whose names start with 'J'.

14. How do you negate a condition that uses the IN or BETWEEN


operators?
To negate an IN or BETWEEN condition, you can use the NOT operator. For example:
SELECT * FROM employees WHERE salary NOT BETWEEN 3000 AND 6000;
This query will return employees whose salary is not between 3000 and 6000.
Or
SELECT * FROM employees WHERE department NOT IN ('HR', 'Sales', 'IT');
This query will return employees who do not work in the HR, Sales, or IT departments.

15. Can logical operators be used with aggregate functions?


Yes, logical operators can be used with aggregate functions like COUNT, SUM, etc., when
filtering results with the HAVING clause. For example:
SELECT department, COUNT(*) FROM employees GROUP BY department HAVING
COUNT(*) > 10 AND AVG(salary) > 5000;

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR


Viva Questions and Answers (SELECT Clause & Arithmetic
Operators)

1. What is the purpose of the SELECT clause in SQL?


The SELECT clause is used to retrieve data from a database. It is the most commonly used
SQL statement and allows you to specify the columns that should be included in the result
set.

2. What is the basic syntax of the SELECT statement?


The basic syntax is:
SELECT column1, column2, ...
FROM table_name;
You can also use additional clauses like WHERE, ORDER BY, GROUP BY, etc., to refine the
result set.

3. How can you select all columns from a table?


To select all columns from a table, you can use the wildcard '*'. The syntax is:
SELECT * FROM table_name;

4. What is the use of the WHERE clause in a SELECT statement?


The WHERE clause is used to filter records that meet a specific condition. The syntax is:
SELECT column1, column2 FROM table_name WHERE condition;

5. Can you explain the use of the DISTINCT keyword in the SELECT
statement?
The DISTINCT keyword is used to return only distinct (different) values in the result set. It
removes duplicate values. The syntax is:
SELECT DISTINCT column1, column2 FROM table_name;

6. What are arithmetic operators in SQL?


Arithmetic operators are used to perform mathematical operations on numeric data. The
common arithmetic operators in SQL are:
- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Division (/)
- Modulus (%)

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR


7. How do you use arithmetic operators in a SELECT statement?
You can use arithmetic operators directly in the SELECT clause to perform calculations on
columns. For example:
SELECT column1, column2 + 5 AS ModifiedColumn FROM table_name;

8. What is the result of using the division operator (/) in a SELECT


statement?
The division operator (/) is used to divide one value by another. For example, in the query:
SELECT column1 / 2 AS HalfValue FROM table_name;
It will return half of the value of column1.

9. How is the modulus operator (%) used in SQL?


The modulus operator (%) returns the remainder of the division of two numbers. For
example, in the query:
SELECT column1 % 3 AS Remainder FROM table_name;
It will return the remainder when column1 is divided by 3.

10. Can you combine multiple arithmetic operators in a single SELECT


statement?
Yes, you can combine multiple arithmetic operators in a single SELECT statement. For
example:
SELECT (column1 + 5) * column2 / 2 AS Result FROM table_name;

11. How can you rename a column in the result of a SELECT query?
You can use the AS keyword to give a column an alias (a new name) in the result set. For
example:
SELECT column1 AS NewName FROM table_name;

12. How do you limit the number of rows returned by a SELECT


statement?
You can use the LIMIT clause (in MySQL) or the TOP keyword (in SQL Server) to limit the
number of rows returned. For example, in MySQL:
SELECT * FROM table_name LIMIT 10;
This will return the first 10 rows.

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR


13. What is the ORDER BY clause used for in SQL?
The ORDER BY clause is used to sort the result set in ascending (ASC) or descending (DESC)
order. For example:
SELECT * FROM table_name ORDER BY column1 ASC;

14. How does the GROUP BY clause work with SELECT?


The GROUP BY clause is used to group rows that have the same values in specified columns
into summary rows. It is commonly used with aggregate functions (COUNT, SUM, AVG, etc.).
For example:
SELECT department, COUNT(*) FROM employees GROUP BY department;

15. What is the HAVING clause in SQL?


The HAVING clause is used to filter groups created by the GROUP BY clause. It is similar to
the WHERE clause but is used for groups rather than individual rows. For example:
SELECT department, COUNT(*) FROM employees GROUP BY department HAVING
COUNT(*) > 5;

AJAY KUMAR R. ASSISTANT PROFESSOR, ST JOSEPH’S FIRST GRADE COLLEGE, HUNSUR

You might also like