0% found this document useful (0 votes)
51 views

Day PI Questions

The document contains questions from a mock PI interview for a Database Management System role. It covers topics like SQL commands, differences between SQL and RDBMS, DDL, DML, and DCL statements, database concepts like tables, records, and fields, and SQL queries. Sample questions include explaining the differences between DELETE and TRUNCATE commands, writing queries to retrieve even and odd records from a table, and questions about SQL data types, foreign keys, and updating employee records.

Uploaded by

VIKAS KUMAR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Day PI Questions

The document contains questions from a mock PI interview for a Database Management System role. It covers topics like SQL commands, differences between SQL and RDBMS, DDL, DML, and DCL statements, database concepts like tables, records, and fields, and SQL queries. Sample questions include explaining the differences between DELETE and TRUNCATE commands, writing queries to retrieve even and odd records from a table, and questions about SQL data types, foreign keys, and updating employee records.

Uploaded by

VIKAS KUMAR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

MOCK PI QUESTIONS

Subject Name: Database Management System

Day: 1
Topics Covered: Introduction to Oracle platform, What is dbms and file storage? Difference between DBMS
and RDBMS? SQL commands - Data Definition Commands, Data Manipulation commands and Data Control
commands and their differences, (Create table, Describe, Alter (different variants of alter command), Truncate,
Drop, Rename, Insert, Update, delete and Difference between drop, delete and truncate command).

Question 1: What is SQL


Answer: Structured Query Language SQL is a database tool that is used to create and access the database to
support software applications.

Question 2: What are the different types of statements supported by SQL?


Answer: DDL, DML and DCL

Question 3: What is the difference between SQL and MySQL?


Answer: SQL is a standard language which stands for Structured Query Language based on the English
language whereas MySQL is a database management system. SQL is the core of relational database which is
used for accessing and managing database, MySQL is an RDMS (Relational Database Management System)
such as SQL Server, Informix etc

Question 4: What is RDBMS? How is it different from DBMS?


Answer: RDBMS stands for Relational Database Management System. The key difference here, compared to
DBMS, is that RDBMS stores data in the form of a collection of tables and relations can be defined between
the common fields of these tables. Most modern database management systems like MySQL, Microsoft SQL
Server, Oracle, IBM DB2 and Amazon Redshift are based on RDBMS.

Question 5: Define DML Compiler.

Department of Computer Science and EngineeringPage 1


Answer: DML compiler translates DML statements in a query language into a low-level instruction and the
generated instruction can be understood by Query Evaluation

Question 6: Explain the terms ‘Record’, ‘Field’ and ‘Table’ in terms of database

● Answer: Record: Record is a collection of values or fields of a specific entity. e.g An employee, Salary


account, etc.
● Field: A field refers to an area within a record that is reserved for specific data. e.g Employee ID.
● Table: Table is the collection of records of specific types. e.g the Employee table is a collection of
records related to all the employees

Question 7: What is the difference between Drop, Delete and Truncate statements in SQL Server?
Answer: Drop, Delete and Truncate - All operations can be rolled back.

Delete is a logged operation, which means deleted rows are written to the transaction log. Truncate is not a
logged operation, which means deleted rows are not written to the transaction log. 
Hence, truncate is a little faster than Delete. You can have a where clause in Delete statement whereas Truncate
statement cannot have a where clause. Truncate will delete all the rows in a Table, but the structure of the table
remains. Drop would delete all the rows including the structure of the Table.

Question 8: What are DDL commands?


Answer: DDL stands for Data Definition Language. DDL is used to create and modify the structure of database
objects.

Examples: CREATE, ALTER, DROP statements.

Question 9: What are DML Commands?


Answer: The SQL commands that deal with the manipulation of data present in the database belong to DML
or Data Manipulation Language and this includes most of the SQL statements.

Examples of DML:

● INSERT – is used to insert data into a table.


● UPDATE – is used to update existing data within a table.
DELETE – is used to delete records from a database table

Question 10: What is a query in SQL?


Answer: This is the basic kind of question you might expect at the beginning of a line of SQL interview
questions. It asks you to demonstrate essential knowledge of what a query in SQL is.
Example: "A query in SQL is a request. It can be a request to retrieve data or perform an action like insert or
update."

Department of Computer Science and EngineeringPage 2


Question 11: What is the difference between CHAR and VARCHAR?

Answer: CHAR is a fixed-length character data type while VARCHAR is a variable-length character data
type.

Question 12: What is Null in SQL?

Answer: A NULL value in a table is a value in a field that appears to be blank, which means a field with a
NULL value is a field with no value.

It is very important to understand that a NULL value is different than a zero value or a field that contains
spaces. A field with a NULL value is one that has been left blank during record creation.

Question 13: What are tables and Fields?

Answer:

A table is a set of data that is organized in a model with Columns and Rows. Columns can be categorized as
vertical, and Rows are horizontal. A table has a specified number of columns called fields but can have any
number of rows which is called record.

Example:.

Table: Employee.

Field: Emp ID, Emp Name, Date of Birth.

Data: 201456, David, 11/15/1960.

Question 14: Consider a table COURSE with column ID, NAME and DURATION in days to finish the
course.

ID NAME DURATION

1 C++ 10

2 JAVA 15

Department of Computer Science and EngineeringPage 3


3 C# 10

4 PYTHON 20

Write an sql query to create a table and populate data in it.

Answer: CREATE TABLE COURSE(ID int Primary key,NAME VARCHAR(50),DURATION INT)

INSERT INTO COURSE VALUES(1,'C++',10)

INSERT INTO COURSE VALUES(2,'JAVA',15)

INSERT INTO COURSE VALUES(3,'C#',10)

INSERT INTO COURSE VALUES(4,'PYTHON',20)

Question 15: What is an ALIAS command?

Answer: ALIAS name can be given to a table or column. This alias name can be referred to in WHERE clause
to identify the table or column.

Example-.

Select st.StudentID, Ex.Result from student st, Exam as Ex where st.studentID = Ex. StudentID

Here, st refers to alias name for student table and Ex refers to alias name for exam table.

Question 16: Differentiate between DELETE and TRUNCATE commands?

Answer: The core difference between DELETE and TRUNCATE commands are as follows:

Department of Computer Science and EngineeringPage 4


● While the DELETE command is used to delete or remove one or more existing tables, the TRUNCATE
command deletes all the data from inside a table.
● DELETE is a DML command, whereas TRUNCATE is a DDL command.
● DELETE allows you to accomplish a trigger, but TRUNCATE doesn’t let you execute and trigger.
The TRUNCATE command doesn’t work when foreign key constraints reference a table. In such cases, you
have to use the DELETE command

Question 17: Write a SQL query that will drop table employees?

(Consider the table structure as given)

SQL> DESC employees

Name Null? Type

----------------------- -------- ----------------

EMPLOYEE_ID NOT NULL NUMBER(6)

FIRST_NAME VARCHAR2(20)

LAST_NAME NOT NULL VARCHAR2(25)

EMAIL NOT NULL VARCHAR2(25)

PHONE_NUMBER VARCHAR2(20)

HIRE_DATE NOT NULL DATE

JOB_ID NOT NULL VARCHAR2(10)

SALARY NUMBER(8,2)

COMMISSION_PCT NUMBER(2,2)

MANAGER_ID NUMBER(6)

DEPARTMENT_ID NUMBER(4)

Answer: DROP TABLE employees

Question 18: What is the difference between TRUNCATE and DROP statements?

Department of Computer Science and EngineeringPage 5


Answer: TRUNCATE removes all the rows from the table, and it cannot be rolled back. DROP command
removes a table from the database and the operation cannot be rolled back.

Question 19: Write a query to calculate the even and odd records from a table.
Answer: To retrieve the even records from a table, you have to use the MOD() function as follows:

SELECT EmpID FROM (SELECT rowno, EmpID from EmployeeInfo) WHERE MOD(rowno,2)=0;

Similarly, to retrieve the odd records from a table, you can write a query as follows:

SELECT EmpID FROM (SELECT rowno, EmpID from EmployeeInfo) WHERE MOD(rowno,2)=1;

Question 20 : Write a SQL query to retrieve employee details from EmployeeInfo table who have a date
of joining in the EmployeePosition table.
Answer: SELECT * FROM EmployeeInfo E

WHERE EXISTS

(SELECT * FROM EmployeePosition P WHERE E.EmpId = P.EmpId);

Question 21: Write an SQL query to fetch the EmpId and FullName of all the employees working under
Manager with id – ‘986’.

Answer: SELECT EmpId, FullName


FROM EmployeeDetails
WHERE ManagerId = 986;

Question 22: Fetch all the employees who are not working on any project.

Answer: SELECT EmpId


FROM EmployeeSalary
WHERE Project IS NULL;

Question 23: Write an SQL query to update the employee names by removing leading and trailing
spaces.

Answer: UPDATE EmployeeDetails


SET FullName = LTRIM(RTRIM(FullName));

Department of Computer Science and EngineeringPage 6


Question 24: Explain SQL Data Types?
Answer: In SQL Server, each column in a database table has a name and a data type. We need to decide what
type of data to store inside each and every column of a table while creating a SQL table.

Question 25: What do you mean by foreign key? Give an example to explain it.
Answer: A Foreign key is a field that can uniquely identify each row in another table. And this constraint is
used to specify a field as a Foreign key. That is, this field points to the primary key of another table. This
usually creates a kind of link between the two tables.
Consider the two tables as shown below:
Orders

O_ID ORDER_NO C_ID

1 2253 3

2 3325 3

3 4521 2

4 8532 1

Customers

C_ID NAME ADDRESS

1 RAMESH DELHI

2 SURESH NOIDA

3 DHARMESH GURGAON

Department of Computer Science and EngineeringPage 7


The field C_ID in the Orders table is the primary key in the Customers’ table, i.e. it uniquely identifies each
row in the Customers table. Therefore, it is a Foreign Key in the Orders table.
Syntax:
CREATE TABLE Orders
(
O_ID int NOT NULL,
ORDER_NO int NOT NULL,
C_ID int,
PRIMARY KEY (O_ID),
FOREIGN KEY (C_ID) REFERENCES Customers(C_ID)
)

Question 26: What is the main disadvantage of deleting data from an existing table using the DROP
TABLE command?
Answer: Drop Table command deletes complete data from the table along with removing the complete table
structure too. In case our requirement entails just removing the data, then we would need to recreate the table to
store data in it. In such cases, it is advised to use the TRUNCATE command.

Question 27: Write an SQL query to fetch the different projects available from the EmployeeSalary
table

Answer: SELECT DISTINCT(Project)

FROM EmployeeSalary;

Question 28: Write an SQL query to fetch the different projects available from the EmployeeSalary table.

Answer: SELECT DISTINCT(Project)

FROM EmployeeSalary;

Question 29: Write an SQL query to create a new table with data and structure copied from another table.

Answer: CREATE TABLE NewTable

SELECT * FROM EmployeeSalary;

Department of Computer Science and EngineeringPage 8


Question 30: Write an SQL query to fetch all employee records from EmployeeDetails table who have a
salary record in EmployeeSalary table.

Answer: SELECT * FROM EmployeeDetails E

WHERE EXISTS

(SELECT * FROM EmployeeSalary S

WHERE E.EmpId = S.EmpId);

Question 31: Write an SQL query to fetch the employee full names and replace the space with ‘-’.

Answer: SELECT REPLACE(FullName, ' ', '-')

FROM EmployeeDetails;

Department of Computer Science and EngineeringPage 9

You might also like