Day PI Questions
Day PI Questions
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 6: Explain the terms ‘Record’, ‘Field’ and ‘Table’ in terms of database
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.
Examples of DML:
Answer: CHAR is a fixed-length character data type while VARCHAR is a variable-length character data
type.
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.
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.
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
4 PYTHON 20
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.
Answer: The core difference between DELETE and TRUNCATE commands are as follows:
Question 17: Write a SQL query that will drop table employees?
FIRST_NAME VARCHAR2(20)
PHONE_NUMBER VARCHAR2(20)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
Question 18: What is the difference between TRUNCATE and DROP statements?
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
Question 21: Write an SQL query to fetch the EmpId and FullName of all the employees working under
Manager with id – ‘986’.
Question 22: Fetch all the employees who are not working on any project.
Question 23: Write an SQL query to update the employee names by removing leading and trailing
spaces.
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
1 2253 3
2 3325 3
3 4521 2
4 8532 1
Customers
1 RAMESH DELHI
2 SURESH NOIDA
3 DHARMESH GURGAON
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
FROM EmployeeSalary;
Question 28: Write an SQL query to fetch the different projects available from the EmployeeSalary table.
FROM EmployeeSalary;
Question 29: Write an SQL query to create a new table with data and structure copied from another table.
WHERE EXISTS
Question 31: Write an SQL query to fetch the employee full names and replace the space with ‘-’.
FROM EmployeeDetails;