0% found this document useful (0 votes)
61 views2 pages

DBMS Lab Viva Questions & Answers

Uploaded by

spandang945
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)
61 views2 pages

DBMS Lab Viva Questions & Answers

Uploaded by

spandang945
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

DBMS LAB VIVA QUESTIONS WITH ANSWERS

Q: What is a database?
Ans: A database is an organized collection of data that can be easily accessed, managed, and
updated using DBMS software like MySQL or Oracle.

Q: What is the command to create a database?


Ans: CREATE DATABASE database_name;

Q: What is the purpose of the USE command?


Ans: It selects a specific database to work with. Example: USE student_db;

Q: What command is used to create a table?


Ans: CREATE TABLE table_name (column1 datatype, column2 datatype, ...);

Q: What are data types in SQL?


Ans: Data types define the kind of values a column can store, such as INT, VARCHAR, DATE,
FLOAT, etc.

Q: What are constraints in SQL?


Ans: Constraints are rules applied to table columns to maintain data integrity. Examples:
PRIMARY KEY, FOREIGN KEY, NOT NULL, UNIQUE, CHECK.

Q: What is the purpose of an index?


Ans: An index improves the speed of data retrieval from a table. Example: CREATE INDEX
index_name ON table_name(column_name);

Q: What is the use of the INSERT statement?


Ans: It adds new records into a table. Example: INSERT INTO student VALUES (1, 'Akash',
'CSE');

Q: What is the difference between DELETE, TRUNCATE, and DROP?


Ans: DELETE removes specific rows. TRUNCATE removes all rows but keeps the table.
DROP removes the entire table structure.

Q: What does the UPDATE command do?


Ans: It modifies existing records. Example: UPDATE student SET name='Rahul' WHERE id=1;

Q: What is the purpose of the ALTER command?


Ans: It modifies the structure of an existing table, e.g., add or delete columns.

Q: What is the purpose of the SELECT statement?


Ans: It retrieves data from one or more tables. Example: SELECT * FROM student;

Q: What is the difference between WHERE and HAVING?


Ans: WHERE filters rows before grouping. HAVING filters groups after aggregation.

Q: What are aggregate functions?


Ans: They perform calculations on multiple values and return a single result. Examples:
COUNT(), AVG(), MAX(), MIN(), SUM().

Q: What is a JOIN in SQL?


Ans: A JOIN combines data from two or more tables based on a related column.

Q: What are the types of joins?


Ans: INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, CROSS JOIN, SELF JOIN.

Q: What is a subquery?
Ans: A query inside another SQL query is called a subquery. Example: SELECT name FROM
student WHERE id IN (SELECT id FROM marks WHERE marks > 80);

Q: What is a view?
Ans: A view is a virtual table based on the result of a SQL query. Example: CREATE VIEW
high_scorers AS SELECT name, marks FROM student WHERE marks > 80;

Q: What is an alias in SQL?


Ans: An alias gives a temporary name to a table or column. Example: SELECT name AS
student_name FROM student;

Q: What is the use of the GRANT command?


Ans: It gives privileges to users. Example: GRANT SELECT ON student TO user1;

Q: What is normalization?
Ans: It is the process of organizing data to reduce redundancy and improve data integrity.

Q: What are ACID properties?


Ans: Atomicity, Consistency, Isolation, Durability — properties that ensure reliable transaction
processing.

Common questions

Powered by AI

Normalization organizes database tables to minimize redundancy and dependency, leading to improvements in data integrity. By dividing larger tables into smaller ones and defining relationships between them, it avoids anomalies during data operations. For example, in a non-normalized table, a product's supplier information may be repeated multiple times, but normalization would separate this into a 'Product' and 'Supplier' table linked by a Supplier ID. Benefits include reduced data redundancy, ensuring data integrity by eliminating update anomalies, and optimized database performance .

Data types in SQL define the kind of values that can be stored in a column, which facilitates appropriate database operations and optimizes storage. Each column in a database table is assigned a data type, such as INT for integers, VARCHAR for variable-length strings, DATE for dates, and FLOAT for floating-point numbers. This definition is critical because it determines how SQL manages data storage, retrieval, and processing effectively. For example, assigning an INT data type properly allows SQL to perform arithmetic operations during queries efficiently, while VARCHAR facilitates text operations .

Indexes in SQL improve the speed of data retrieval operations on a table. They function similarly to an index in a book, allowing the database engine to find data quickly without scanning the entire table. However, they can also slow down data insertion and update operations since the index itself must be updated. Therefore, indexes should be applied to columns frequently used in WHERE clauses, JOIN conditions, and ORDER BY statements to enhance performance in query operations. For example, creating an index on a 'customer_id' column in a sales database can substantially speed up customer-specific queries .

The ALTER command is used to modify the structure of an existing table. This includes adding or deleting columns, changing the data type of a column, or renaming columns or the table itself. An example use case is when a new requirement necessitates the addition of a new column to store data not previously accounted for. The command format for adding a column is: ALTER TABLE table_name ADD column_name datatype. It can also be used to drop a column if it is no longer needed: ALTER TABLE table_name DROP COLUMN column_name. These modifications help maintain the database’s adaptability to evolving data needs .

Data integrity in a relational database is maintained through constraints that enforce rules on the data in tables. Specific SQL constraints include PRIMARY KEY, which ensures that each row in a table is unique and not null; FOREIGN KEY, which maintains referential integrity between tables by ensuring that a value in one table corresponds to a value in another; UNIQUE, which ensures that all values in a column are different; NOT NULL, which prevents null values in a column; and CHECK, which enforces data validation rules on columns. Together, these constraints help in preserving data accuracy and consistency across the database .

Subqueries, or nested queries, are used in SQL to perform operations that require multiple steps, such as filtering results based on aggregated data. They allow breaking a complex problem into smaller, logical parts, which simplifies query construction and increases readability. An example of a subquery is: SELECT name FROM students WHERE id IN (SELECT student_id FROM scores WHERE score > 80). This subquery selects student IDs from the 'scores' table where the score exceeds 80, and the outer query retrieves corresponding student names from the 'students' table. Subqueries are significant because they enable dynamic query inputs and conditions, supporting advanced data retrieval and analysis .

SQL JOIN operations are essential for enhancing database functionality by allowing data to be retrieved from multiple tables based on logical relationships. They are integral to relational databases because they enable queries that reflect complex real-world relationships and conditions. JOINS, such as INNER JOIN, LEFT JOIN, and FULL JOIN, allow combining rows from two or more tables based on related columns. For example, in a database with 'orders' and 'customers' tables, an INNER JOIN can be used to list orders alongside customer information where customer ID matches in both tables, thereby providing a comprehensive view of transactions .

Views in SQL are used in scenarios where a specific representation of data is required without altering the actual tables. They are particularly useful for simplifying complex queries, providing data security by restricting access to certain columns, and presenting aggregated data in a user-friendly manner. For example, a view can be created to show only the names and salaries of employees, which hides detailed information. Advantages of views include ease of reuse of SQL logic, reduced SQL query complexity for users, and enhanced security by showing only necessary data to specific users .

DELETE, TRUNCATE, and DROP are SQL commands with notably different implications. DELETE is used to remove specific rows from a table and allows for filtration through WHERE clauses, affecting only selected data; it also supports transaction rollback. TRUNCATE, on the other hand, removes all rows from a table without logging individual row deletions but keeps the table structure for future use. It is faster than DELETE since it does not generate row-level locks. DROP, the most drastic, removes the table structure completely, along with all its data, making it irreversible and non-recoverable without backups. The choice among them depends on whether only the data or the structure too should be discarded .

The GRANT command in SQL is significant for implementing and managing database security. It is used to give specific privileges on database objects to users, such as SELECT, INSERT, UPDATE, DELETE on tables or EXECUTE on procedures. By controlling access, it helps protect sensitive data from unauthorized users and regulates user actions within the database, which is crucial for maintaining data confidentiality, integrity, and availability. For instance, granting only SELECT privileges to a user for a table restricts them to data retrieval without altering it, thereby ensuring controlled data access .

You might also like